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.

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