diff --git a/quick/restore-perms.sh.example b/quick/restore-perms.sh.example index 493be44..a25f294 100644 --- a/quick/restore-perms.sh.example +++ b/quick/restore-perms.sh.example @@ -1,20 +1,80 @@ #!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. "${SCRIPT_DIR}/settings.sh" || { + echo "no settings" && exit 1 +} + WP_CONTENT_DIRS=( plugins + languages upgrade uploads + themes ) export WEB_GID=33 +echo -n "Check sudo permissions... " + +sudo whoami + perms() { - sudo chown -R $UID:$WEB_GID "$1" - find "$1" -type d -exec chmod g+rwx '{}' \; - find "$1" -type f -exec chmod g+rw '{}' \; + TARGET=$1 + + 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 "Fetching dirs without spaces" + find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/dirs-without-spaces + +# echo "Splitting dirs by 10000 lines" + split -l 10000 $TMP_DIR/dirs-without-spaces $TMP_DIR/dirs-without-spaces-part- + +# echo "Fetching files without spaces" + find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/files-without-spaces + +# echo "Splitting files at 10000 lines" + split -l 10000 $TMP_DIR/files-without-spaces $TMP_DIR/files-without-spaces-part- + +# echo "Fetching dirs with spaces" + find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/dirs-with-spaces + +# echo "Fetching files with spaces" + find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/files-with-spaces + +# 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 774 `cat {}`' + +# 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 664 `cat {}`' + +# echo "Fixing permissions for dirs with spaces" + cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod 775 "{}" + +# echo "Fixing permissions for files with spaces" + cat $TMP_DIR/files-with-spaces | xargs -I {} chmod 664 "{}" + +# echo "Removing temporary files" + rm $TMP_DIR/files-* + rm $TMP_DIR/dirs-* + echo "ok" + else + echo -n "and fixing permission for this file... " +# echo "Fixing permissions" + chmod 664 "${TARGET}" + echo "ok" + fi } for DIR in "${WP_CONTENT_DIRS[@]}"; do perms "$SCRIPT_DIR/../wp-content/$DIR" done + +perms "$SCRIPT_DIR/../wp-content/index.php" diff --git a/quick/settings.sh.example b/quick/settings.sh.example index 1633afd..dc98556 100755 --- a/quick/settings.sh.example +++ b/quick/settings.sh.example @@ -1,6 +1,8 @@ #!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export TMP_DIR=$SCRIPT_DIR/tmp + export PROJECT_NAME=wpstudio export PROJECT_WEB_ROOT="${SCRIPT_DIR}/.."