+ optimize restore perms for any project and grav perms set
This commit is contained in:
1
grav/quick/.gitignore
vendored
Normal file
1
grav/quick/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.sh
|
18
grav/quick/_settings.sh.example
Normal file
18
grav/quick/_settings.sh.example
Normal file
@ -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
|
||||||
|
)
|
87
grav/quick/restore-perms.sh.example
Normal file
87
grav/quick/restore-perms.sh.example
Normal file
@ -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
|
2
grav/quick/tmp/.gitignore
vendored
Normal file
2
grav/quick/tmp/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
@ -21,6 +21,10 @@ echo -n "Check sudo permissions... "
|
|||||||
|
|
||||||
sudo whoami
|
sudo whoami
|
||||||
|
|
||||||
|
[ ! -d "$TMP_DIR" ] && {
|
||||||
|
echo "no tmp dir" && exit 1
|
||||||
|
}
|
||||||
|
|
||||||
perms() {
|
perms() {
|
||||||
TARGET=$1
|
TARGET=$1
|
||||||
|
|
||||||
@ -39,48 +43,48 @@ perms() {
|
|||||||
sudo chown -R $UID:$WEB_GID "${TARGET}"
|
sudo chown -R $UID:$WEB_GID "${TARGET}"
|
||||||
|
|
||||||
if [[ -d "${TARGET}" ]]; then
|
if [[ -d "${TARGET}" ]]; then
|
||||||
# echo -n "and fixing permissions for these directory... "
|
# echo -n "and fixing permissions for these directory... "
|
||||||
# echo "Fetching dirs without spaces"
|
# echo "Fetching dirs without spaces"
|
||||||
find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/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-
|
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
|
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-
|
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
|
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
|
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=SC2038
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $DIRS_MODE {}'
|
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=SC2038
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $FILES_MODE {}'
|
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 "{}"
|
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 "{}"
|
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/files-*
|
||||||
rm $TMP_DIR/dirs-*
|
rm $TMP_DIR/dirs-*
|
||||||
echo "ok"
|
echo "ok"
|
||||||
else
|
else
|
||||||
echo -n "and fixing permission for this file... "
|
echo -n "and fixing permission for this file... "
|
||||||
# echo "Fixing permissions"
|
# echo "Fixing permissions"
|
||||||
chmod $FILES_MODE "${TARGET}"
|
chmod $FILES_MODE "${TARGET}"
|
||||||
echo "ok"
|
echo "ok"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user