You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #!/bin/bash
  2. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. . "${SCRIPT_DIR}/settings.sh" || {
  4. echo "no settings" && exit 1
  5. }
  6. WP_CONTENT_DIRS=(
  7. plugins
  8. languages
  9. upgrade
  10. uploads
  11. themes
  12. )
  13. export WEB_GID=33
  14. export DIRS_MODE=775
  15. export FILES_MODE=664
  16. echo -n "Check sudo permissions... "
  17. sudo whoami
  18. perms() {
  19. TARGET=$1
  20. echo -n "Set correct ownerships for $(basename ${TARGET})... "
  21. sudo chown -R $UID:$WEB_GID "${TARGET}"
  22. if [[ -d "${TARGET}" ]]; then
  23. echo -n "and fixing permission for this directory... "
  24. # echo "Fetching dirs without spaces"
  25. find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/dirs-without-spaces
  26. # echo "Splitting dirs by 10000 lines"
  27. split -l 10000 $TMP_DIR/dirs-without-spaces $TMP_DIR/dirs-without-spaces-part-
  28. # echo "Fetching files without spaces"
  29. find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/files-without-spaces
  30. # echo "Splitting files at 10000 lines"
  31. split -l 10000 $TMP_DIR/files-without-spaces $TMP_DIR/files-without-spaces-part-
  32. # echo "Fetching dirs with spaces"
  33. find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/dirs-with-spaces
  34. # echo "Fetching files with spaces"
  35. find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/files-with-spaces
  36. # echo "Fixing permissions for dirs"
  37. # shellcheck disable=SC2038
  38. # shellcheck disable=SC2016
  39. find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c "chmod $DIRS_MODE `cat {}`"
  40. # echo "Fixing permissions for files"
  41. # shellcheck disable=SC2038
  42. # shellcheck disable=SC2016
  43. find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c "chmod $FILES_MODE `cat {}`"
  44. # echo "Fixing permissions for dirs with spaces"
  45. cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod $DIRS_MODE "{}"
  46. # echo "Fixing permissions for files with spaces"
  47. cat $TMP_DIR/files-with-spaces | xargs -I {} chmod $FILES_MODE "{}"
  48. # echo "Removing temporary files"
  49. rm $TMP_DIR/files-*
  50. rm $TMP_DIR/dirs-*
  51. echo "ok"
  52. else
  53. echo -n "and fixing permission for this file... "
  54. # echo "Fixing permissions"
  55. chmod $FILES_MODE "${TARGET}"
  56. echo "ok"
  57. fi
  58. }
  59. for DIR in "${WP_CONTENT_DIRS[@]}"; do
  60. perms "$SCRIPT_DIR/../wp-content/$DIR"
  61. done
  62. perms "$SCRIPT_DIR/../wp-content/index.php"