Skip to content

Commit f0ddbc3

Browse files
committed
Add automated installation script
1 parent eddb0ba commit f0ddbc3

File tree

1 file changed

+46
-17
lines changed
  • root/etc/s6-overlay/s6-rc.d/init-nextcloud-config

1 file changed

+46
-17
lines changed

root/etc/s6-overlay/s6-rc.d/init-nextcloud-config/run

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ for dir in apps config themes; do
3333
fi
3434
done
3535

36+
# set data directory
37+
if [[ ! -s /config/www/nextcloud/config/config.php ]]; then
38+
echo -e "<?php\n\$CONFIG = array (\n 'datadirectory' => '/data',\n);" >/config/www/nextcloud/config/config.php
39+
elif [[ -f /config/www/nextcloud/config/config.php ]]; then
40+
sed -i "s|/app/www/public/data|/data|g" /config/www/nextcloud/config/config.php
41+
fi
42+
43+
#modify javascript mime type and add .mjs support
44+
if [[ -s /etc/nginx/mime.types ]]; then
45+
sed -i 's|\bjs;|js mjs;|g' /etc/nginx/mime.types
46+
sed -i 's|\bapplication/javascript|text/javascript|g' /etc/nginx/mime.types
47+
fi
48+
3649
# get versions
3750
image_version=$(php -r "require '/app/www/src/version.php'; echo implode('.', \$OC_Version);" 2>/dev/null | xargs)
3851
installed_version=$(php -r "require '/config/www/nextcloud/config/config.php'; echo \$CONFIG['version'];" 2>/dev/null | xargs)
@@ -97,10 +110,39 @@ if [[ -f /config/www/nextcloud/config/needs_migration ]] || [[ -f /tmp/needs_ins
97110
if [[ -f /config/www/nextcloud/config/needs_migration ]] || [[ -f /tmp/needs_upgrade ]]; then
98111
# Upgrade
99112
occ upgrade
100-
else
101-
if [[ "${installed_version}" = "0.0.0.0" ]]; then
102-
# Install
103-
echo "New nextcloud instance"
113+
elif [[ -f /tmp/needs_install ]]; then
114+
# Install
115+
echo "New nextcloud instance"
116+
117+
# Make sure all database settings are set
118+
if [[ "${DB_HOST+x}" && "${DB_USER+x}" && "${DB_NAME+x}" && "${#DB_PASS}" -gt "3" ]] && \
119+
[[ "${DB_TYPE}" == "sqlite" || "${DB_TYPE}" == "pgsql" || "${DB_TYPE}" == "mysql" ]]; then
120+
121+
# Generate admin password, if missing
122+
if [[ ! "${ADMIN_PASS+x}" ]]; then
123+
ADMIN_PASS="$(openssl rand -hex 64)"
124+
echo "Nextcloud admin password: $ADMIN_PASS"
125+
fi
126+
127+
# Run installation process
128+
echo "Running Nextcloud installation..."
129+
occ maintenance:install \
130+
--database="${DB_TYPE}" \
131+
--database-host="${DB_HOST}" \
132+
--database-name="${DB_NAME}" \
133+
--database-user="${DB_USER}" \
134+
--database-pass="${DB_PASS}" \
135+
--admin-pass="${ADMIN_PASS}" \
136+
--data-dir=/data
137+
138+
# Check return code
139+
if [[ $? -eq 0 ]]; then
140+
echo "Nextcloud installation successful!"
141+
else
142+
echo "Nextcloud installation failed!"
143+
echo "Please run the web-based installer or check the logs."
144+
fi
145+
else
104146
echo "Please run the web-based installer on first connect!"
105147
fi
106148
fi
@@ -161,16 +203,3 @@ for APP in richdocumentscode; do
161203
occ app:remove "${APP}" >/dev/null 2>&1
162204
rm -rf "${APP_PATH}"
163205
done
164-
165-
# set data directory
166-
if [[ ! -s /config/www/nextcloud/config/config.php ]]; then
167-
echo -e "<?php\n\$CONFIG = array (\n 'datadirectory' => '/data',\n);" >/config/www/nextcloud/config/config.php
168-
elif [[ -f /config/www/nextcloud/config/config.php ]]; then
169-
sed -i "s|/app/www/public/data|/data|g" /config/www/nextcloud/config/config.php
170-
fi
171-
172-
#modify javascript mime type and add .mjs support
173-
if [[ -s /etc/nginx/mime.types ]]; then
174-
sed -i 's|\bjs;|js mjs;|g' /etc/nginx/mime.types
175-
sed -i 's|\bapplication/javascript|text/javascript|g' /etc/nginx/mime.types
176-
fi

0 commit comments

Comments
 (0)