cleaning sthe cript a little

This commit is contained in:
Steven Mondji-Lerider 2013-08-14 13:16:34 +00:00
parent 1ed328e0a3
commit 1ca1a6a248
1 changed files with 69 additions and 62 deletions

View File

@ -24,15 +24,19 @@ set -x
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# #
# Default Query : fixperms for all account # four optionals argument to chose from
query="SELECT uid,login FROM membres"
sub_dir=""
file=""
# Two optionals argument
# -l string : a specific login to fix # -l string : a specific login to fix
# -u integer : a specific uid to fix # -u integer : a specific uid to fix
# -f string : a specific file to fix according to a given uid # -f string : a specific file to fix according to a given uid
# -d string : a specific folder to fix according to a given uid # -d string : a specific subdirectory to fix according to a given uid
# The u and l switch are used to fix a given user whole directory including his base directory ($ALTERNC_HTML/<letter>/<login>/
# 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
query="SELECT uid,login FROM membres"
sub_dir=""
file=""
while getopts "l:u:f:d:" optname while getopts "l:u:f:d:" optname
do do
@ -54,10 +58,14 @@ while getopts "l:u:f:d:" optname
fi fi
;; ;;
"f") "f")
file="$OPTARG" #Is this kinf of escaping enough ?
file=$(printf %q $OPTARG)
echo $file
;; ;;
"d") "d")
sub_dir="$OPTARG" #Is this kinf of escaping enough ?
sub_dir=$(printf %q $OPTARG)
echo $sub_dir
;; ;;
"?") "?")
echo "Unknown option $OPTARG - stop processing" echo "Unknown option $OPTARG - stop processing"
@ -121,12 +129,11 @@ doone() {
} }
fixdir() { fixdir() {
read GID LOGIN || true
if [ "$DEBUG" ]; then if [ "$DEBUG" ]; then
echo "Setting rights and ownership for user $LOGIN having gid $GID" echo "Setting rights and ownership for user $LOGIN having gid $GID"
fi fi
REP="$sub_dir" REP="$sub_dir"
# # We assume that the owner of the directory should be the one from the html user base directory ( $ALTERNC_HTML/<letter>/<login>)
REP_ID="$(get_uid_by_path "$REP")" REP_ID="$(get_uid_by_path "$REP")"
# Clean the line, then add a ligne indicating current working directory # Clean the line, then add a ligne indicating current working directory
printf '\r%*s' "${COLUMNS:-$(tput cols)}" '' printf '\r%*s' "${COLUMNS:-$(tput cols)}" ''
@ -146,30 +153,30 @@ fixdir() {
} }
fixfile() { fixfile() {
read GID LOGIN
/usr/bin/setfacl -bk "$file" /usr/bin/setfacl -bk "$file"
echo "gid: $GID" # We assume that the owner of the file should be the one from the html user base directory ( $ALTERNC_HTML/<letter>/<login>)
echo "file: $file"
chown $GID:$GID "$file"
chmod 0770 "$file"
REP_ID="$(get_uid_by_path "$file")" REP_ID="$(get_uid_by_path "$file")"
chown $REP_ID:$REP_ID "$file"
chmod 0770 "$file"
/usr/bin/setfacl -m u:$REP_ID:rw- -m g:$REP_ID:rw- -m g:alterncpanel:rw- -m u:$REP_ID:rw- -m g:$REP_ID:rw- "$file" /usr/bin/setfacl -m u:$REP_ID:rw- -m g:$REP_ID:rw- -m g:alterncpanel:rw- -m u:$REP_ID:rw- -m g:$REP_ID:rw- "$file"
echo file ownership and ACLs changed echo file ownership and ACLs changed
} }
#Start of the script actions
if [[ "$file" != "" ]]; then if [[ "$file" != "" ]]; then # if we are dealing with a file
if [ -e "$file" ]; then if [ -e "$file" ]; then
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |fixfile fixfile
else else
echo "file not found" echo "file not found"
fi fi
elif [[ "$sub_dir" != "" ]]; then elif [[ "$sub_dir" != "" ]]; then #if we are dealing with a directory
if [ -d "$sub_dir" ]; then if [ -d "$sub_dir" ]; then
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |fixdir fixdir
else else
echo "dir not found" echo "dir not found"
fi fi
else else
#we are fixing the whole html directory
#either for all user (default) or a specific one ( -u or -l switch )
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |doone mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |doone
fi fi