30-ownership.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. # npm user and group
  8. chown -R "$PUID:$PGID" /data
  9. chown -R "$PUID:$PGID" /etc/letsencrypt
  10. chown -R "$PUID:$PGID" /run/nginx
  11. chown -R "$PUID:$PGID" /tmp/nginx
  12. chown -R "$PUID:$PGID" /var/cache/nginx
  13. chown -R "$PUID:$PGID" /var/lib/logrotate
  14. chown -R "$PUID:$PGID" /var/lib/nginx
  15. chown -R "$PUID:$PGID" /var/log/nginx
  16. # Don't chown entire /etc/nginx folder as this causes crashes on some systems
  17. chown -R "$PUID:$PGID" /etc/nginx/nginx
  18. chown -R "$PUID:$PGID" /etc/nginx/nginx.conf
  19. chown -R "$PUID:$PGID" /etc/nginx/conf.d
  20. # Certbot directories - optimized approach
  21. CERT_INIT_FLAG="/opt/certbot/.ownership_initialized"
  22. if [ ! -f "$CERT_INIT_FLAG" ] || [ "$SKIP_CERTBOT_OWNERSHIP" != "true" ]; then
  23. # Prevents errors when installing python certbot plugins when non-root
  24. log_info 'Changing ownership of /opt/certbot directories ...'
  25. chown "$PUID:$PGID" /opt/certbot /opt/certbot/bin
  26. # Handle all site-packages directories efficiently
  27. find /opt/certbot/lib -type d -name "site-packages" | while read -r SITE_PACKAGES_DIR; do
  28. chown -R "$PUID:$PGID" "$SITE_PACKAGES_DIR"
  29. done
  30. # Create a flag file to skip this step on subsequent runs
  31. touch "$CERT_INIT_FLAG"
  32. chown "$PUID:$PGID" "$CERT_INIT_FLAG"
  33. fi