Browse Source
+ smart restore perms - for files set 664 mode (u: rw, g: rw, o: r) and for directories 774 mode (u: rwx, g: rwx, o: rx)
master
+ smart restore perms - for files set 664 mode (u: rw, g: rw, o: r) and for directories 774 mode (u: rwx, g: rwx, o: rx)
master
dimti
1 year ago
2 changed files with 65 additions and 3 deletions
@ -1,20 +1,80 @@ |
|||||
#!/bin/bash |
#!/bin/bash |
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
||||
|
|
||||
|
. "${SCRIPT_DIR}/settings.sh" || { |
||||
|
echo "no settings" && exit 1 |
||||
|
} |
||||
|
|
||||
WP_CONTENT_DIRS=( |
WP_CONTENT_DIRS=( |
||||
plugins |
plugins |
||||
|
languages |
||||
upgrade |
upgrade |
||||
uploads |
uploads |
||||
|
themes |
||||
) |
) |
||||
|
|
||||
export WEB_GID=33 |
export WEB_GID=33 |
||||
|
|
||||
|
echo -n "Check sudo permissions... " |
||||
|
|
||||
|
sudo whoami |
||||
|
|
||||
perms() { |
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 |
for DIR in "${WP_CONTENT_DIRS[@]}"; do |
||||
perms "$SCRIPT_DIR/../wp-content/$DIR" |
perms "$SCRIPT_DIR/../wp-content/$DIR" |
||||
done |
done |
||||
|
|
||||
|
perms "$SCRIPT_DIR/../wp-content/index.php" |
Write
Preview
Loading…
Cancel
Save
Reference in new issue