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.

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