@@ -7,191 +7,191 @@ chown www-data:root /var/www/html/config
77
88# version_greater A B returns whether A > B
99version_greater () {
10- [ " $( printf ' %s\n' " $@ " | sort -t ' .' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1) " != " $1 " ]
10+ [ " $( printf ' %s\n' " $@ " | sort -t ' .' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1) " != " $1 " ]
1111}
1212
1313# return true if specified directory is empty
1414directory_empty () {
15- [ -z " $( ls -A " $1 /" ) " ]
15+ [ -z " $( ls -A " $1 /" ) " ]
1616}
1717
1818run_as () {
19- if [ " $( id -u) " = 0 ]; then
20- su -p www-data -s /bin/sh -c " $1 "
21- else
22- sh -c " $1 "
23- fi
19+ if [ " $( id -u) " = 0 ]; then
20+ su -p www-data -s /bin/sh -c " $1 "
21+ else
22+ sh -c " $1 "
23+ fi
2424}
2525
2626# usage: file_env VAR [DEFAULT]
2727# ie: file_env 'XYZ_DB_PASSWORD' 'example'
2828# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
2929# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
3030file_env () {
31- local var=" $1 "
32- local fileVar=" ${var} _FILE"
33- local def=" ${2:- } "
34- local varValue=$( env | grep -E " ^${var} =" | sed -E -e " s/^${var} =//" )
35- local fileVarValue=$( env | grep -E " ^${fileVar} =" | sed -E -e " s/^${fileVar} =//" )
36- if [ -n " ${varValue} " ] && [ -n " ${fileVarValue} " ]; then
37- echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
38- exit 1
39- fi
40- if [ -n " ${varValue} " ]; then
41- export " $var " =" ${varValue} "
42- elif [ -n " ${fileVarValue} " ]; then
43- export " $var " =" $( cat " ${fileVarValue} " ) "
44- elif [ -n " ${def} " ]; then
45- export " $var " =" $def "
46- fi
47- unset " $fileVar "
31+ local var=" $1 "
32+ local fileVar=" ${var} _FILE"
33+ local def=" ${2:- } "
34+ local varValue=$( env | grep -E " ^${var} =" | sed -E -e " s/^${var} =//" )
35+ local fileVarValue=$( env | grep -E " ^${fileVar} =" | sed -E -e " s/^${fileVar} =//" )
36+ if [ -n " ${varValue} " ] && [ -n " ${fileVarValue} " ]; then
37+ echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
38+ exit 1
39+ fi
40+ if [ -n " ${varValue} " ]; then
41+ export " $var " =" ${varValue} "
42+ elif [ -n " ${fileVarValue} " ]; then
43+ export " $var " =" $( cat " ${fileVarValue} " ) "
44+ elif [ -n " ${def} " ]; then
45+ export " $var " =" $def "
46+ fi
47+ unset " $fileVar "
4848}
4949
5050if expr " $1 " : " apache" 1> /dev/null; then
51- if [ -n " ${APACHE_DISABLE_REWRITE_IP+x} " ]; then
52- a2disconf remoteip
53- fi
51+ if [ -n " ${APACHE_DISABLE_REWRITE_IP+x} " ]; then
52+ a2disconf remoteip
53+ fi
5454fi
5555
5656if expr " $1 " : " apache" 1> /dev/null || [ " $1 " = " php-fpm" ] || [ " ${NEXTCLOUD_UPDATE:- 0} " -eq 1 ]; then
57- if [ -n " ${REDIS_HOST+x} " ]; then
58-
59- echo " Configuring Redis as session handler"
60- {
61- echo ' session.save_handler = redis'
62- # check if redis host is an unix socket path
63- if [ " $( echo " $REDIS_HOST " | cut -c1-1) " = " /" ]; then
64- if [ -n " ${REDIS_HOST_PASSWORD+x} " ]; then
65- echo " session.save_path = \" unix://${REDIS_HOST} ?auth=${REDIS_HOST_PASSWORD} \" "
66- else
67- echo " session.save_path = \" unix://${REDIS_HOST} \" "
68- fi
69- # check if redis password has been set
70- elif [ -n " ${REDIS_HOST_PASSWORD+x} " ]; then
71- echo " session.save_path = \" tcp://${REDIS_HOST} :${REDIS_HOST_PORT:= 6379} ?auth=${REDIS_HOST_PASSWORD} \" "
72- else
73- echo " session.save_path = \" tcp://${REDIS_HOST} :${REDIS_HOST_PORT:= 6379} \" "
74- fi
75- } > /usr/local/etc/php/conf.d/redis-session.ini
57+ if [ -n " ${REDIS_HOST+x} " ]; then
58+
59+ echo " Configuring Redis as session handler"
60+ {
61+ echo ' session.save_handler = redis'
62+ # check if redis host is an unix socket path
63+ if [ " $( echo " $REDIS_HOST " | cut -c1-1) " = " /" ]; then
64+ if [ -n " ${REDIS_HOST_PASSWORD+x} " ]; then
65+ echo " session.save_path = \" unix://${REDIS_HOST} ?auth=${REDIS_HOST_PASSWORD} \" "
66+ else
67+ echo " session.save_path = \" unix://${REDIS_HOST} \" "
68+ fi
69+ # check if redis password has been set
70+ elif [ -n " ${REDIS_HOST_PASSWORD+x} " ]; then
71+ echo " session.save_path = \" tcp://${REDIS_HOST} :${REDIS_HOST_PORT:= 6379} ?auth=${REDIS_HOST_PASSWORD} \" "
72+ else
73+ echo " session.save_path = \" tcp://${REDIS_HOST} :${REDIS_HOST_PORT:= 6379} \" "
74+ fi
75+ } > /usr/local/etc/php/conf.d/redis-session.ini
76+ fi
77+
78+ installed_version=" 0.0.0.0"
79+ if [ -f /var/www/html/version.php ]; then
80+ # shellcheck disable=SC2016
81+ installed_version=" $( php -r ' require "/var/www/html/version.php"; echo implode(".", $OC_Version);' ) "
82+ fi
83+ # shellcheck disable=SC2016
84+ image_version=" $( php -r ' require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);' ) "
85+
86+ if version_greater " $installed_version " " $image_version " ; then
87+ echo " Can't start Nextcloud because the version of the data ($installed_version ) is higher than the docker image version ($image_version ) and downgrading is not supported. Are you sure you have pulled the newest image version?"
88+ exit 1
89+ fi
90+
91+ if version_greater " $image_version " " $installed_version " ; then
92+ echo " Initializing nextcloud $image_version ..."
93+ if [ " $installed_version " != " 0.0.0.0" ]; then
94+ echo " Upgrading nextcloud from $installed_version ..."
95+ run_as ' php /var/www/html/occ app:list' | sed -n " /Enabled:/,/Disabled:/p" > /tmp/list_before
7696 fi
77-
78- installed_version=" 0.0.0.0"
79- if [ -f /var/www/html/version.php ]; then
80- # shellcheck disable=SC2016
81- installed_version=" $( php -r ' require "/var/www/html/version.php"; echo implode(".", $OC_Version);' ) "
97+ if [ " $( id -u) " = 0 ]; then
98+ rsync_options=" -rlDog --chown www-data:root"
99+ else
100+ rsync_options=" -rlD"
82101 fi
83- # shellcheck disable=SC2016
84- image_version=" $( php -r ' require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);' ) "
102+ rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/
85103
86- if version_greater " $installed_version " " $image_version " ; then
87- echo " Can't start Nextcloud because the version of the data ($installed_version ) is higher than the docker image version ($image_version ) and downgrading is not supported. Are you sure you have pulled the newest image version?"
88- exit 1
89- fi
104+ for dir in config data custom_apps themes; do
105+ if [ ! -d " /var/www/html/$dir " ] || directory_empty " /var/www/html/$dir " ; then
106+ rsync $rsync_options --include " /$dir /" --exclude ' /*' /usr/src/nextcloud/ /var/www/html/
107+ fi
108+ done
109+ rsync $rsync_options --include ' /version.php' --exclude ' /*' /usr/src/nextcloud/ /var/www/html/
110+ echo " Initializing finished"
111+
112+ # install
113+ if [ " $installed_version " = " 0.0.0.0" ]; then
114+ echo " New nextcloud instance"
115+
116+ file_env NEXTCLOUD_ADMIN_PASSWORD
117+ file_env NEXTCLOUD_ADMIN_USER
118+
119+ if [ -n " ${NEXTCLOUD_ADMIN_USER+x} " ] && [ -n " ${NEXTCLOUD_ADMIN_PASSWORD+x} " ]; then
120+ # shellcheck disable=SC2016
121+ install_options=' -n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
122+ if [ -n " ${NEXTCLOUD_DATA_DIR+x} " ]; then
123+ # shellcheck disable=SC2016
124+ install_options=$install_options ' --data-dir "$NEXTCLOUD_DATA_DIR"'
125+ fi
90126
91- if version_greater " $image_version " " $installed_version " ; then
92- echo " Initializing nextcloud $image_version ..."
93- if [ " $installed_version " != " 0.0.0.0" ]; then
94- echo " Upgrading nextcloud from $installed_version ..."
95- run_as ' php /var/www/html/occ app:list' | sed -n " /Enabled:/,/Disabled:/p" > /tmp/list_before
127+ file_env MYSQL_DATABASE
128+ file_env MYSQL_PASSWORD
129+ file_env MYSQL_USER
130+ file_env POSTGRES_DB
131+ file_env POSTGRES_PASSWORD
132+ file_env POSTGRES_USER
133+
134+ install=false
135+ if [ -n " ${SQLITE_DATABASE+x} " ]; then
136+ echo " Installing with SQLite database"
137+ # shellcheck disable=SC2016
138+ install_options=$install_options ' --database-name "$SQLITE_DATABASE"'
139+ install=true
140+ elif [ -n " ${MYSQL_DATABASE+x} " ] && [ -n " ${MYSQL_USER+x} " ] && [ -n " ${MYSQL_PASSWORD+x} " ] && [ -n " ${MYSQL_HOST+x} " ]; then
141+ echo " Installing with MySQL database"
142+ # shellcheck disable=SC2016
143+ install_options=$install_options ' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"'
144+ install=true
145+ elif [ -n " ${POSTGRES_DB+x} " ] && [ -n " ${POSTGRES_USER+x} " ] && [ -n " ${POSTGRES_PASSWORD+x} " ] && [ -n " ${POSTGRES_HOST+x} " ]; then
146+ echo " Installing with PostgreSQL database"
147+ # shellcheck disable=SC2016
148+ install_options=$install_options ' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'
149+ install=true
96150 fi
97- if [ " $( id -u) " = 0 ]; then
98- rsync_options=" -rlDog --chown www-data:root"
151+
152+ if [ " $install " = true ]; then
153+ echo " starting nextcloud installation"
154+ max_retries=10
155+ try=0
156+ until run_as " php /var/www/html/occ maintenance:install $install_options " || [ " $try " -gt " $max_retries " ]; do
157+ echo " retrying install..."
158+ try=$(( try + 1 ))
159+ sleep 10s
160+ done
161+ if [ " $try " -gt " $max_retries " ]; then
162+ echo " installing of nextcloud failed!"
163+ exit 1
164+ fi
165+ if [ -n " ${NEXTCLOUD_TRUSTED_DOMAINS+x} " ]; then
166+ echo " setting trusted domains…"
167+ NC_TRUSTED_DOMAIN_IDX=1
168+ for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
169+ DOMAIN=$( echo " $DOMAIN " | sed -e ' s/^[[:space:]]*//' -e ' s/[[:space:]]*$//' )
170+ run_as " php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN "
171+ NC_TRUSTED_DOMAIN_IDX=$(( NC_TRUSTED_DOMAIN_IDX + 1 ))
172+ done
173+ fi
99174 else
100- rsync_options= " -rlD "
175+ echo " running web-based installer on first connect! "
101176 fi
102- rsync $rsync_options --delete --exclude-from=/upgrade.exclude /usr/src/nextcloud/ /var/www/html/
103-
104- for dir in config data custom_apps themes; do
105- if [ ! -d " /var/www/html/$dir " ] || directory_empty " /var/www/html/$dir " ; then
106- rsync $rsync_options --include " /$dir /" --exclude ' /*' /usr/src/nextcloud/ /var/www/html/
107- fi
108- done
109- rsync $rsync_options --include ' /version.php' --exclude ' /*' /usr/src/nextcloud/ /var/www/html/
110- echo " Initializing finished"
111-
112- # install
113- if [ " $installed_version " = " 0.0.0.0" ]; then
114- echo " New nextcloud instance"
115-
116- file_env NEXTCLOUD_ADMIN_PASSWORD
117- file_env NEXTCLOUD_ADMIN_USER
118-
119- if [ -n " ${NEXTCLOUD_ADMIN_USER+x} " ] && [ -n " ${NEXTCLOUD_ADMIN_PASSWORD+x} " ]; then
120- # shellcheck disable=SC2016
121- install_options=' -n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
122- if [ -n " ${NEXTCLOUD_DATA_DIR+x} " ]; then
123- # shellcheck disable=SC2016
124- install_options=$install_options ' --data-dir "$NEXTCLOUD_DATA_DIR"'
125- fi
126-
127- file_env MYSQL_DATABASE
128- file_env MYSQL_PASSWORD
129- file_env MYSQL_USER
130- file_env POSTGRES_DB
131- file_env POSTGRES_PASSWORD
132- file_env POSTGRES_USER
133-
134- install=false
135- if [ -n " ${SQLITE_DATABASE+x} " ]; then
136- echo " Installing with SQLite database"
137- # shellcheck disable=SC2016
138- install_options=$install_options ' --database-name "$SQLITE_DATABASE"'
139- install=true
140- elif [ -n " ${MYSQL_DATABASE+x} " ] && [ -n " ${MYSQL_USER+x} " ] && [ -n " ${MYSQL_PASSWORD+x} " ] && [ -n " ${MYSQL_HOST+x} " ]; then
141- echo " Installing with MySQL database"
142- # shellcheck disable=SC2016
143- install_options=$install_options ' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"'
144- install=true
145- elif [ -n " ${POSTGRES_DB+x} " ] && [ -n " ${POSTGRES_USER+x} " ] && [ -n " ${POSTGRES_PASSWORD+x} " ] && [ -n " ${POSTGRES_HOST+x} " ]; then
146- echo " Installing with PostgreSQL database"
147- # shellcheck disable=SC2016
148- install_options=$install_options ' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'
149- install=true
150- fi
151-
152- if [ " $install " = true ]; then
153- echo " starting nextcloud installation"
154- max_retries=10
155- try=0
156- until run_as " php /var/www/html/occ maintenance:install $install_options " || [ " $try " -gt " $max_retries " ]; do
157- echo " retrying install..."
158- try=$(( try + 1 ))
159- sleep 10s
160- done
161- if [ " $try " -gt " $max_retries " ]; then
162- echo " installing of nextcloud failed!"
163- exit 1
164- fi
165- if [ -n " ${NEXTCLOUD_TRUSTED_DOMAINS+x} " ]; then
166- echo " setting trusted domains…"
167- NC_TRUSTED_DOMAIN_IDX=1
168- for DOMAIN in $NEXTCLOUD_TRUSTED_DOMAINS ; do
169- DOMAIN=$( echo " $DOMAIN " | sed -e ' s/^[[:space:]]*//' -e ' s/[[:space:]]*$//' )
170- run_as " php /var/www/html/occ config:system:set trusted_domains $NC_TRUSTED_DOMAIN_IDX --value=$DOMAIN "
171- NC_TRUSTED_DOMAIN_IDX=$(( NC_TRUSTED_DOMAIN_IDX + 1 ))
172- done
173- fi
174- else
175- echo " running web-based installer on first connect!"
176- fi
177- fi
178- # upgrade
179- else
180- run_as ' php /var/www/html/occ upgrade'
177+ fi
178+ # upgrade
179+ else
180+ run_as ' php /var/www/html/occ upgrade'
181181
182- run_as ' php /var/www/html/occ app:list' | sed -n " /Enabled:/,/Disabled:/p" > /tmp/list_after
183- echo " The following apps have been disabled:"
184- diff /tmp/list_before /tmp/list_after | grep ' <' | cut -d- -f2 | cut -d: -f1
185- rm -f /tmp/list_before /tmp/list_after
182+ run_as ' php /var/www/html/occ app:list' | sed -n " /Enabled:/,/Disabled:/p" > /tmp/list_after
183+ echo " The following apps have been disabled:"
184+ diff /tmp/list_before /tmp/list_after | grep ' <' | cut -d- -f2 | cut -d: -f1
185+ rm -f /tmp/list_before /tmp/list_after
186186
187- fi
188187 fi
188+ fi
189189
190- # if we get an error "ln: /var/www/html/apps/qownnotesapi: cannot overwrite directory" we need to remove that directory in the container
191- run_as ' rm -Rf /var/www/html/apps/qownnotesapi'
190+ # if we get an error "ln: /var/www/html/apps/qownnotesapi: cannot overwrite directory" we need to remove that directory in the container
191+ run_as ' rm -Rf /var/www/html/apps/qownnotesapi'
192192
193- run_as ' ln -sfT /var/www/html/custom_apps/qownnotesapi /var/www/html/apps/qownnotesapi'
194- run_as " php /var/www/html/occ app:enable qownnotesapi"
193+ run_as ' ln -sfT /var/www/html/custom_apps/qownnotesapi /var/www/html/apps/qownnotesapi'
194+ run_as " php /var/www/html/occ app:enable qownnotesapi"
195195fi
196196
197197# Install and enable Nextcloud Notes
0 commit comments