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.

87 lines
2.6 KiB

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