@@ -8,37 +8,53 @@ log_info 'Setting ownership ...'
88# root
99chown root /tmp/nginx
1010
11- # npm user and group
12- chown -R " $PUID :$PGID " /data
13- chown -R " $PUID :$PGID " /etc/letsencrypt
14- chown -R " $PUID :$PGID " /run/nginx
15- chown -R " $PUID :$PGID " /tmp/nginx
16- chown -R " $PUID :$PGID " /var/cache/nginx
17- chown -R " $PUID :$PGID " /var/lib/logrotate
18- chown -R " $PUID :$PGID " /var/lib/nginx
19- chown -R " $PUID :$PGID " /var/log/nginx
20-
21- # Don't chown entire /etc/nginx folder as this causes crashes on some systems
22- chown -R " $PUID :$PGID " /etc/nginx/nginx
23- chown -R " $PUID :$PGID " /etc/nginx/nginx.conf
24- chown -R " $PUID :$PGID " /etc/nginx/conf.d
25-
26- # Certbot directories - optimized approach
27- CERT_INIT_FLAG=" /opt/certbot/.ownership_initialized"
28-
29- if [ ! -f " $CERT_INIT_FLAG " ]; then
30- # Prevents errors when installing python certbot plugins when non-root
31- if [ " $SKIP_CERTBOT_OWNERSHIP " != " true" ]; then
32- log_info ' Changing ownership of /opt/certbot directories ...'
33- chown " $PUID :$PGID " /opt/certbot /opt/certbot/bin
11+ locations=(
12+ " /data"
13+ " /etc/letsencrypt"
14+ " /run/nginx"
15+ " /tmp/nginx"
16+ " /var/cache/nginx"
17+ " /var/lib/logrotate"
18+ " /var/lib/nginx"
19+ " /var/log/nginx"
20+ " /etc/nginx/nginx"
21+ " /etc/nginx/nginx.conf"
22+ " /etc/nginx/conf.d"
23+ )
24+
25+ chownit () {
26+ local dir=" $1 "
27+ local recursive=" ${2:- true} "
28+
29+ local have
30+ have=" $( stat -c ' %u:%g' " $dir " ) "
31+ echo " - $dir ... "
32+
33+ if [ " $have " != " $PUID :$PGID " ]; then
34+ if [ " $recursive " = ' true' ] && [ -d " $dir " ]; then
35+ chown -R " $PUID :$PGID " " $dir "
36+ else
37+ chown " $PUID :$PGID " " $dir "
38+ fi
39+ echo " DONE"
40+ else
41+ echo " SKIPPED"
3442 fi
43+ }
44+
45+ for loc in " ${locations[@]} " ; do
46+ chownit " $loc "
47+ done
48+
49+ if [ " $( is_true " ${SKIP_CERTBOT_OWNERSHIP:- } " ) " = ' 1' ]; then
50+ log_info ' Skipping ownership change of certbot directories'
51+ else
52+ log_info ' Changing ownership of certbot directories, this may take some time ...'
53+ chownit " /opt/certbot" false
54+ chownit " /opt/certbot/bin" false
3555
3656 # Handle all site-packages directories efficiently
3757 find /opt/certbot/lib -type d -name " site-packages" | while read -r SITE_PACKAGES_DIR; do
38- chown -R " $PUID : $PGID " " $SITE_PACKAGES_DIR "
58+ chownit " $SITE_PACKAGES_DIR "
3959 done
40-
41- # Create a flag file to skip this step on subsequent runs
42- touch " $CERT_INIT_FLAG "
43- chown " $PUID :$PGID " " $CERT_INIT_FLAG "
4460fi
0 commit comments