From 6a4ee2dc3b291d95c260cea474c7e8af1cab17f2 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 25 Oct 2018 17:27:16 +0200 Subject: [PATCH 1/2] [fix] fixperms should have a -h option and colors --- src/fixperms.sh | 58 ++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/fixperms.sh b/src/fixperms.sh index bd39c977..938167c9 100755 --- a/src/fixperms.sh +++ b/src/fixperms.sh @@ -22,36 +22,47 @@ # Purpose of file: Fix permission, ACL and ownership of AlternC's files # ---------------------------------------------------------------------- # +red () { echo -e "\e[31m$@ \e[0m" ; } +usage () { + [[ -n "$@" ]] && red "$@\n" + cat<// -# The f and d switch are used to fix a given file or directory under the user's base directory. They use the base directory to get the permissions they should use. -# Be sure to have correct base directory permissions before attemplting to fix use those two switch - + The u and l switch are used to fix a given user whole directory including his base directory ($ALTERNC_HTML/// + The f and d switch are used to fix a given file or directory under the user's base directory. They use the base directory to get the permissions they should use. + Be sure to have correct base directory permissions before attemplting to fix use those two switch +End-of-message + exit 1 +} query="SELECT uid,login FROM membres ORDER BY login" sub_dir="" file="" LOCK_FIXPERMS="/etc/alternc/disable_all_fixperms" +LOCK_FIXPERMS="/tmp/test" if [ -f "$LOCK_FIXPERMS" ] ; then - ( - echo " ------------- " - echo '/!\ WARNING /!\ ' - echo "The fixperms script is disabled" - echo "To enable it, delete $LOCK_FIXPERMS " - echo " ------------- " - ) 1>&2 - exit 0 + + usage " +------------------------------------ +/!\ WARNING /!\ +The fixperms script is disabled +To enable it, delete $LOCK_FIXPERMS +------------------------------------ +" + fi -while getopts "l:u:f:d:" optname + +while getopts "hl:u:f:d:" optname do case "$optname" in + "h") usage + ;; + "l") if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]] ; then query="SELECT uid,login FROM membres WHERE login LIKE '$OPTARG' ORDER BY login" @@ -79,17 +90,14 @@ do echo $sub_dir ;; "?") - echo "Unknown option $OPTARG - stop processing" - exit + usage "Unknown option $OPTARG - stop processing" ;; ":") - echo "No argument value for option $OPTARG - stop processing" - exit + usage "No argument value for option $OPTARG - stop processing" ;; *) # Should not occur - echo "Unknown error while processing options" - exit + usage "Unknown error while processing options" ;; esac done From a3627a5f35a51edd88dcc6bf8a45e372423b0e05 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 25 Oct 2018 17:30:22 +0200 Subject: [PATCH 2/2] [fix] + fixperms should have a -h option and colors --- src/fixperms.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/fixperms.sh b/src/fixperms.sh index 938167c9..7bf4bc49 100755 --- a/src/fixperms.sh +++ b/src/fixperms.sh @@ -42,7 +42,6 @@ query="SELECT uid,login FROM membres ORDER BY login" sub_dir="" file="" LOCK_FIXPERMS="/etc/alternc/disable_all_fixperms" -LOCK_FIXPERMS="/tmp/test" if [ -f "$LOCK_FIXPERMS" ] ; then @@ -67,16 +66,14 @@ do if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]] ; then query="SELECT uid,login FROM membres WHERE login LIKE '$OPTARG' ORDER BY login" else - echo "Bad login provided" - exit + usage "Bad login provided" fi ;; "u") if [[ "$OPTARG" =~ ^[0-9]+$ ]] ; then query="SELECT uid,login FROM membres WHERE uid LIKE '$OPTARG' ORDER BY login" else - echo "Bad uid provided" - exit + usage "Bad uid provided" fi ;; "f")