This repository has been archived on 2023-05-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BCK-ServTest/Tools/aclutil
2020-06-25 10:22:52 +02:00

138 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
#Funtions
Help()
{
# Display Help
echo
echo "#######################"
echo "# ACL_UTIL Help #"
echo "#######################"
echo
echo "Syntax: aclutil [-u <username> [-g <groupname>][-a|r] <target folder>"
echo "options:"
echo "-h, --help Print this Help."
echo
echo "Get info about set ALC's"
echo "-l, --list #get current ACL rules"
echo "-lg --listgui #get current ACL rules using the eiciel GUI"
echo
echo "Set user/group for ACL change"
echo "-u <username>, --user <username> #User for ACL change"
echo "-g <groupname>, --group <groupname> #group for ACL change "
echo
echo "Action for ACL rule"
echo "-a, --add #add ACL rule"
echo "-r, --remove #Remove ACL rule"
echo
}
#Input Handeler
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h | --help)
Help
exit
;;
-u | --user)
TARGET=user
USER=$2
shift
shift
;;
-g | --group)
TARGET=group
GROUP=$2
shift
shift
;;
-a | --add)
ACTION=add
shift
;;
-r | --remove)
ACTION=remove
shift
;;
-l | --list)
ACTION=list
shift
;;
-lg | --listgui)
ACTION=listgui
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
FOLDERPATH="$1"
#input Validation
##Action flag
if [ -z ${ACTION+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##Target Flag
if [ "$ACTION" = "remove" ] || [ "$ACTION" = "add" ]; then
if [ -z ${TARGET+x} ]; then echo "Incorrect or missing parameter(s)" && Help && exit; fi
##User flag
if [ "$TARGET" = "user" ] && [ -z $USER ]; then
echo "User name not specified"
exit
fi
##Group flag
if [ "$TARGET" = "group" ] && [ -z $GROUP ]; then
echo "Group name not specified"
exit
fi
fi
##Path
if [ -z $FOLDERPATH ]; then echo "File or directory not specified" && exit; fi
if [ ! -d "$FOLDERPATH" ] && [ ! -f "$FOLDERPATH" ]; then
echo "'$FOLDERPATH': No such file or directory"
fi
#Script
if [ "$ACTION" = "list" ]; then
getfacl $FOLDERPATH
fi
if [ "$ACTION" = "listgui" ]; then
echo "If gui did not start make sure X11 forwarding is enabled"
echo "and eiciel it is installed"
eiciel $FOLDERPATH
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "user" ]; then
setfacl -R -m u:"$USER":rx "$FOLDERPATH"
setfacl -R -d -m u:"$USER":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "add" ] && [ "$TARGET" = "group" ]; then
setfacl -R -m g:"$GROUP":rx "$FOLDERPATH"
setfacl -R -d -m g:"$GROUP":rx "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "user" ]; then
setfacl -R -x u:"$USER" "$FOLDERPATH"
setfacl -R -d -x u:"$USER" "$FOLDERPATH"
fi
if [ "$ACTION" = "remove" ] && [ "$TARGET" = "group" ]; then
setfacl -R -x g:"$GROUP" "$FOLDERPATH"
setfacl -R -d -x g:"$GROUP" "$FOLDERPATH"
fi