Skip to content

Commit

Permalink
Add Perms/Owner Backup option (resolves PeachFlame#10)
Browse files Browse the repository at this point in the history
-b option for perms/ownership backup to resolve PeachFlame#10
  • Loading branch information
lsthompson authored Jan 5, 2023
1 parent fab91a4 commit 006b485
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions fixperms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ helptext () {
tput setaf 2
echo "Fix Permissions (fixperms) Script help:"
echo "Sets file/directory permissions to match suPHP and FastCGI schemes"
echo "USAGE: fixperms [options] -a account_name"
echo "USAGE: fixperms [options] [scope]"
echo "-------"
echo "Options:"
echo "-h or --help: Print this screen and exit"
echo "Scope:"
echo "--account or -a: Specify a cPanel account"
echo "-all: Run on all cPanel accounts"
echo "-all: Run fixperms on all cPanel accounts"
echo "Options:"
echo "-b: Backup perms (declare before -a/-all)"
echo "-v: Verbose output"
echo "-h or --help: Print this screen and exit"
tput sgr0
exit 0
}
Expand Down Expand Up @@ -55,6 +57,18 @@ fixperms () {
# Get the account's homedir
HOMEDIR=$(egrep "^${account}:" /etc/passwd | cut -d: -f6)

# Backup if flag passed through
if [ "$backup" = true ] ; then
backupdate=$(date +%F)
backuptime=$(date "+%F-%T")
backupdir="/root/fixperms_backups/fixperms_backups_"${backupdate}""
mkdir -p $backupdir
echo "Backing up perms for $account"
find $HOMEDIR -printf 'chmod %#m "%p"\n' > "${backupdir}"/backup_perms_"${account}"_"${backuptime}".sh
echo "Backing up ownership for $account"
find $HOMEDIR -printf 'chown %u:%g "%p"\n' > "${backupdir}"/backup_owner_"${account}"_"${backuptime}".sh
fi

tput bold
tput setaf 4
echo "(fixperms) for: $account"
Expand Down Expand Up @@ -130,7 +144,8 @@ all () {
case "$1" in
-h) helptext ;;
--help) helptext ;;
-v) verbose="-v"
-v) verbose="-v" ;;
-b) backup="true"

case "$2" in
-all) all ;;
Expand Down

0 comments on commit 006b485

Please sign in to comment.