30-ownership.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/command/with-contenv bash
  2. # shellcheck shell=bash
  3. set -e
  4. log_info 'Setting ownership ...'
  5. # root
  6. chown root /tmp/nginx
  7. locations=(
  8. "/data"
  9. "/etc/letsencrypt"
  10. "/run/nginx"
  11. "/tmp/nginx"
  12. "/var/cache/nginx"
  13. "/var/lib/logrotate"
  14. "/var/lib/nginx"
  15. "/var/log/nginx"
  16. "/etc/nginx/nginx"
  17. "/etc/nginx/nginx.conf"
  18. "/etc/nginx/conf.d"
  19. )
  20. chownit() {
  21. local dir="$1"
  22. local recursive="${2:-true}"
  23. local have
  24. have="$(stat -c '%u:%g' "$dir")"
  25. echo -n "- $dir ... "
  26. if [ "$have" != "$PUID:$PGID" ]; then
  27. if [ "$recursive" = 'true' ] && [ -d "$dir" ]; then
  28. chown -R "$PUID:$PGID" "$dir"
  29. else
  30. chown "$PUID:$PGID" "$dir"
  31. fi
  32. echo "DONE"
  33. else
  34. echo "SKIPPED"
  35. fi
  36. }
  37. for loc in "${locations[@]}"; do
  38. chownit "$loc"
  39. done
  40. if [ "${SKIP_CERTBOT_OWNERSHIP:-}" != "true" ]; then
  41. log_info 'Changing ownership of certbot directories, this may take some time ...'
  42. chownit "/opt/certbot" false
  43. chownit "/opt/certbot/bin" false
  44. # Handle all site-packages directories efficiently
  45. find /opt/certbot/lib -type d -name "site-packages" | while read -r SITE_PACKAGES_DIR; do
  46. chownit "$SITE_PACKAGES_DIR"
  47. done
  48. else
  49. log_info 'Skipping ownership change of certbot directories'
  50. fi