diff --git a/grav/quick/.gitignore b/grav/quick/.gitignore new file mode 100644 index 0000000..c97f963 --- /dev/null +++ b/grav/quick/.gitignore @@ -0,0 +1 @@ +*.sh diff --git a/grav/quick/_settings.sh.example b/grav/quick/_settings.sh.example new file mode 100644 index 0000000..2ee5165 --- /dev/null +++ b/grav/quick/_settings.sh.example @@ -0,0 +1,18 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +export TMP_DIR=$SCRIPT_DIR/tmp + +DIRS=( + cache + logs + user/config + user/data + user/accounts + user/pages + user/themes/quark/images + tmp + backup + images + assets +) diff --git a/grav/quick/restore-perms.sh.example b/grav/quick/restore-perms.sh.example new file mode 100644 index 0000000..b255090 --- /dev/null +++ b/grav/quick/restore-perms.sh.example @@ -0,0 +1,87 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +. "${SCRIPT_DIR}/_settings.sh" || { + echo "no settings" && exit 1 +} + +export WEB_GID=33 +export DIRS_MODE=775 +export FILES_MODE=664 + +echo -n "Check sudo permissions... " + +sudo whoami + +[ ! -d "$TMP_DIR" ] && { + echo "no tmp dir" && exit 1 +} + +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 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 + + # 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 '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 'chmodFromFile $FILES_MODE {}' + + # echo "Fixing permissions for dirs with spaces" + cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod $DIRS_MODE "{}" + + # echo "Fixing permissions for files with spaces" + cat $TMP_DIR/files-with-spaces | xargs -I {} chmod $FILES_MODE "{}" + + # 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 $FILES_MODE "${TARGET}" + echo "ok" + fi +} + +for DIR in "${DIRS[@]}"; do + perms "$SCRIPT_DIR/../$DIR" +done diff --git a/grav/quick/tmp/.gitignore b/grav/quick/tmp/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/grav/quick/tmp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/quick/restore-perms.sh.example b/quick/restore-perms.sh.example index ff152c9..6529294 100644 --- a/quick/restore-perms.sh.example +++ b/quick/restore-perms.sh.example @@ -21,6 +21,10 @@ echo -n "Check sudo permissions... " sudo whoami +[ ! -d "$TMP_DIR" ] && { + echo "no tmp dir" && exit 1 +} + perms() { TARGET=$1 @@ -39,48 +43,48 @@ perms() { sudo chown -R $UID:$WEB_GID "${TARGET}" if [[ -d "${TARGET}" ]]; then -# echo -n "and fixing permissions for these directory... " -# echo "Fetching dirs without spaces" + # 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 -# echo "Splitting dirs by 10000 lines" + # 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" + # 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" + # 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" + # 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" + # 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" + # 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 'chmodFromFile $DIRS_MODE {}' -# echo "Fixing permissions for files" + # 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 'chmodFromFile $FILES_MODE {}' -# echo "Fixing permissions for dirs with spaces" + # echo "Fixing permissions for dirs with spaces" cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod $DIRS_MODE "{}" -# echo "Fixing permissions for files with spaces" + # echo "Fixing permissions for files with spaces" cat $TMP_DIR/files-with-spaces | xargs -I {} chmod $FILES_MODE "{}" -# echo "Removing temporary files" + # 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" + # echo "Fixing permissions" chmod $FILES_MODE "${TARGET}" echo "ok" fi