From bc7443dc861f3f66c60e7739e6e182bd6b55f2e9 Mon Sep 17 00:00:00 2001 From: dimti Date: Tue, 24 Oct 2023 16:54:37 +0300 Subject: [PATCH] * refactoring use cat {} in subcommand with xargs + tmp dir for restore-perms script --- quick/restore-perms.sh.example | 19 +++++++++++++++---- quick/tmp/.gitignore | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 quick/tmp/.gitignore diff --git a/quick/restore-perms.sh.example b/quick/restore-perms.sh.example index 049753e..ff152c9 100644 --- a/quick/restore-perms.sh.example +++ b/quick/restore-perms.sh.example @@ -24,11 +24,22 @@ sudo whoami perms() { TARGET=$1 + chmodFromFile() { + MODE=$1 + FILE_LIST_FILE=$2 + + # shellcheck disable=SC2046 + # shellcheck disable=SC2006 + chmod "$MODE" `cat "$FILE_LIST_FILE"` + } + + export -f chmodFromFile + echo -n "Set correct ownerships for $(basename ${TARGET})... " sudo chown -R $UID:$WEB_GID "${TARGET}" if [[ -d "${TARGET}" ]]; then - echo -n "and fixing permission for this directory... " +# echo -n "and fixing permissions for these directory... " # echo "Fetching dirs without spaces" find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/dirs-without-spaces @@ -50,12 +61,12 @@ perms() { # echo "Fixing permissions for dirs" # shellcheck disable=SC2038 # shellcheck disable=SC2016 - find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c "chmod $DIRS_MODE `cat {}`" + find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $DIRS_MODE {}' # echo "Fixing permissions for files" # shellcheck disable=SC2038 # shellcheck disable=SC2016 - find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c "chmod $FILES_MODE `cat {}`" + find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $FILES_MODE {}' # echo "Fixing permissions for dirs with spaces" cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod $DIRS_MODE "{}" @@ -79,4 +90,4 @@ for DIR in "${WP_CONTENT_DIRS[@]}"; do perms "$SCRIPT_DIR/../wp-content/$DIR" done -perms "$SCRIPT_DIR/../wp-content/index.php" +#perms "$SCRIPT_DIR/../wp-content/index.php" diff --git a/quick/tmp/.gitignore b/quick/tmp/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/quick/tmp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore