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.

80 lines
2.4 KiB

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. echo -n "Check sudo permissions... "
  15. sudo whoami
  16. perms() {
  17. TARGET=$1
  18. echo -n "Set correct ownerships for $(basename ${TARGET})... "
  19. sudo chown -R $UID:$WEB_GID "${TARGET}"
  20. if [[ -d "${TARGET}" ]]; then
  21. echo -n "and fixing permission for this directory... "
  22. # echo "Fetching dirs without spaces"
  23. find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/dirs-without-spaces
  24. # echo "Splitting dirs by 10000 lines"
  25. split -l 10000 $TMP_DIR/dirs-without-spaces $TMP_DIR/dirs-without-spaces-part-
  26. # echo "Fetching files without spaces"
  27. find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/files-without-spaces
  28. # echo "Splitting files at 10000 lines"
  29. split -l 10000 $TMP_DIR/files-without-spaces $TMP_DIR/files-without-spaces-part-
  30. # echo "Fetching dirs with spaces"
  31. find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/dirs-with-spaces
  32. # echo "Fetching files with spaces"
  33. find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/files-with-spaces
  34. # echo "Fixing permissions for dirs"
  35. # shellcheck disable=SC2038
  36. # shellcheck disable=SC2016
  37. find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c 'chmod 774 `cat {}`'
  38. # echo "Fixing permissions for files"
  39. # shellcheck disable=SC2038
  40. # shellcheck disable=SC2016
  41. find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c 'chmod 664 `cat {}`'
  42. # echo "Fixing permissions for dirs with spaces"
  43. cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod 775 "{}"
  44. # echo "Fixing permissions for files with spaces"
  45. cat $TMP_DIR/files-with-spaces | xargs -I {} chmod 664 "{}"
  46. # echo "Removing temporary files"
  47. rm $TMP_DIR/files-*
  48. rm $TMP_DIR/dirs-*
  49. echo "ok"
  50. else
  51. echo -n "and fixing permission for this file... "
  52. # echo "Fixing permissions"
  53. chmod 664 "${TARGET}"
  54. echo "ok"
  55. fi
  56. }
  57. for DIR in "${WP_CONTENT_DIRS[@]}"; do
  58. perms "$SCRIPT_DIR/../wp-content/$DIR"
  59. done
  60. perms "$SCRIPT_DIR/../wp-content/index.php"