#!/bin/bash #Funtions Help() { # Display Help echo echo "#########################" echo "# ez ACL_UTIL Help #" echo "#########################" echo echo "Syntax: ezaclutil [-u | -g | -av][-a|r] [-f ] [-s ]" echo "options:" echo "-h, --help Print this Help." echo echo "Get info about set ALC's" echo "-l, --list #get current ACL rules" echo echo "Set user/group for ACL change" echo "-u , --user #User for ACL change" echo "-g , --group #group for ACL change " echo "-av, --allviewers #Set group to backup viewers (-g not needed)" echo echo "Action for ACL rule" echo "-a, --add #add ACL rule" echo "-r, --remove #Remove ACL rule" echo echo "Set target for ACL change" echo "-f , --ftp #User for ACL change" echo "-s , --sftp #group for ACL change " 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 ;; -av | --allviewers) TARGET=group GROUP=BCKviewer shift ;; -f | --ftp) FOLDERPATH="/backups/ftp/$2" shift shift ;; -s | --sftp) FOLDERPATH="/backups/sftp/$2/home" shift shift ;; *) # unknown option POSITIONAL+=("$1") # save it in an array for later shift # past argument ;; esac done set -- "${POSITIONAL[@]}" # restore positional parameters #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 "Target backup not specified" && exit; fi if [ ! -d "$FOLDERPATH" ] && [ ! -f "$FOLDERPATH" ]; then echo "Target backup not found" 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