cleaning sthe cript a little
This commit is contained in:
parent
1ed328e0a3
commit
1ca1a6a248
131
src/fixperms.sh
131
src/fixperms.sh
|
@ -24,56 +24,64 @@ 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
|
||||||
case "$optname" in
|
case "$optname" in
|
||||||
"l")
|
"l")
|
||||||
if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]] ; then
|
if [[ "$OPTARG" =~ ^[a-zA-Z0-9_]+$ ]] ; then
|
||||||
query="SELECT uid,login FROM membres WHERE login LIKE '$OPTARG'"
|
query="SELECT uid,login FROM membres WHERE login LIKE '$OPTARG'"
|
||||||
else
|
else
|
||||||
echo "Bad login provided"
|
echo "Bad login provided"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"u")
|
"u")
|
||||||
if [[ "$OPTARG" =~ ^[0-9]+$ ]] ; then
|
if [[ "$OPTARG" =~ ^[0-9]+$ ]] ; then
|
||||||
query="SELECT uid,login FROM membres WHERE uid LIKE '$OPTARG'"
|
query="SELECT uid,login FROM membres WHERE uid LIKE '$OPTARG'"
|
||||||
else
|
else
|
||||||
echo "Bad uid provided"
|
echo "Bad uid provided"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"f")
|
"f")
|
||||||
file="$OPTARG"
|
#Is this kinf of escaping enough ?
|
||||||
;;
|
file=$(printf %q $OPTARG)
|
||||||
"d")
|
echo $file
|
||||||
sub_dir="$OPTARG"
|
;;
|
||||||
;;
|
"d")
|
||||||
"?")
|
#Is this kinf of escaping enough ?
|
||||||
echo "Unknown option $OPTARG - stop processing"
|
sub_dir=$(printf %q $OPTARG)
|
||||||
exit
|
echo $sub_dir
|
||||||
;;
|
;;
|
||||||
":")
|
"?")
|
||||||
echo "No argument value for option $OPTARG - stop processing"
|
echo "Unknown option $OPTARG - stop processing"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
*)
|
":")
|
||||||
# Should not occur
|
echo "No argument value for option $OPTARG - stop processing"
|
||||||
echo "Unknown error while processing options"
|
exit
|
||||||
exit
|
;;
|
||||||
;;
|
*)
|
||||||
esac
|
# Should not occur
|
||||||
done
|
echo "Unknown error while processing options"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
|
@ -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)}" ''
|
||||||
|
@ -142,34 +149,34 @@ fixdir() {
|
||||||
setfacl -b -k -n -R -m d:g:alterncpanel:rwx -m d:u::rwx -m d:g::rwx -m d:u:$REP_ID:rwx -m d:g:$REP_ID:rwx -m d:o::--- -m d:mask:rwx\
|
setfacl -b -k -n -R -m d:g:alterncpanel:rwx -m d:u::rwx -m d:g::rwx -m d:u:$REP_ID:rwx -m d:g:$REP_ID:rwx -m d:o::--- -m d:mask:rwx\
|
||||||
-Rm g:alterncpanel:rwx -m u:$REP_ID:rwx -m g:$REP_ID:rwx -m mask:rwx\
|
-Rm g:alterncpanel:rwx -m u:$REP_ID:rwx -m g:$REP_ID:rwx -m mask:rwx\
|
||||||
"$REP"
|
"$REP"
|
||||||
echo -e "\nDone"
|
echo -e "\nDone"
|
||||||
}
|
}
|
||||||
|
|
||||||
fixfile() {
|
fixfile() {
|
||||||
read GID LOGIN
|
/usr/bin/setfacl -bk "$file"
|
||||||
/usr/bin/setfacl -bk "$file"
|
# We assume that the owner of the file should be the one from the html user base directory ( $ALTERNC_HTML/<letter>/<login>)
|
||||||
echo "gid: $GID"
|
REP_ID="$(get_uid_by_path "$file")"
|
||||||
echo "file: $file"
|
chown $REP_ID:$REP_ID "$file"
|
||||||
chown $GID:$GID "$file"
|
chmod 0770 "$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"
|
||||||
REP_ID="$(get_uid_by_path "$file")"
|
echo file ownership and ACLs changed
|
||||||
/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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
Loading…
Reference in New Issue