2022-04-04 19:12:07 +02:00
#!/bin/bash
2021-11-30 11:20:42 +01:00
# version_greater A B returns whether A > B
version_greater( ) {
[ " $( printf '%s\n' " $@ " | sort -t '.' -n -k1,1 -k2,2 -k3,3 -k4,4 | head -n 1) " != " $1 " ]
}
# return true if specified directory is empty
directory_empty( ) {
[ -z " $( ls -A " $1 / " ) " ]
}
2022-08-17 19:10:54 +02:00
echo "Configuring Redis as session handler..."
2021-11-30 11:20:42 +01:00
cat << REDIS_CONF > /usr/local/etc/php/conf.d/redis-session.ini
session.save_handler = redis
session.save_path = " tcp:// ${ REDIS_HOST } : ${ REDIS_HOST_PORT : =6379 } ?auth= ${ REDIS_HOST_PASSWORD } "
redis.session.locking_enabled = 1
redis.session.lock_retries = -1
# redis.session.lock_wait_time is specified in microseconds.
# Wait 10ms before retrying the lock rather than the default 2ms.
redis.session.lock_wait_time = 10000
REDIS_CONF
2022-08-17 19:10:54 +02:00
echo "Setting php max children..."
MEMORY = $( mawk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
PHP_MAX_CHILDREN = $(( MEMORY/50))
2022-08-22 22:45:03 +02:00
if [ -n " $PHP_MAX_CHILDREN " ] ; then
sed -i " s/^pm.max_children =.*/pm.max_children = $PHP_MAX_CHILDREN / " /usr/local/etc/php-fpm.d/www.conf
fi
2022-08-17 19:10:54 +02:00
2022-03-08 16:49:13 +01:00
# Check permissions in ncdata
2022-09-20 16:33:43 +02:00
touch " $NEXTCLOUD_DATA_DIR /this-is-a-test-file " & >/dev/null
if ! [ -f " $NEXTCLOUD_DATA_DIR /this-is-a-test-file " ] ; then
echo " The www-data user doesn't seem to have access rights in the datadir.
2022-10-11 20:29:52 +02:00
Most likely are the files located on a drive that does not follow linux permissions.
Please adjust the permissions like mentioned below.
2022-09-20 16:33:43 +02:00
The found permissions are:
$( stat -c "%u:%g %a" " $NEXTCLOUD_DATA_DIR " )
( userID:groupID permissions)
but they should be:
33:0 750
( userID:groupID permissions) "
2022-03-08 16:49:13 +01:00
exit 1
fi
2022-09-20 16:33:43 +02:00
rm " $NEXTCLOUD_DATA_DIR /this-is-a-test-file "
2022-03-08 16:49:13 +01:00
2021-11-30 11:20:42 +01:00
if [ -f /var/www/html/version.php ] ; then
# shellcheck disable=SC2016
installed_version = " $( php -r 'require "/var/www/html/version.php"; echo implode(".", $OC_Version);' ) "
else
installed_version = "0.0.0.0"
fi
if [ -f "/usr/src/nextcloud/version.php" ] ; then
# shellcheck disable=SC2016
image_version = " $( php -r 'require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);' ) "
else
image_version = " $installed_version "
fi
# unset admin password
if [ " $installed_version " != "0.0.0.0" ] ; then
unset ADMIN_PASSWORD
fi
2022-04-26 19:17:38 +02:00
# Don't start the container if Nextcloud is not compatible with the PHP version
if [ -f "/var/www/html/lib/versioncheck.php" ] && ! php /var/www/html/lib/versioncheck.php; then
echo "It seems like your installed Nextcloud is not compatible with the by the container provided PHP version."
echo "This most likely happened because you tried to restore an old Nextcloud version from backup that is not compatible with the PHP version that comes with the container."
echo "Please try to restore a more recent backup which contains a Nextcloud version that is compatible with the PHP version that comes with the container."
2022-05-16 13:06:08 +02:00
echo "If you do not have a more recent backup, feel free to have a look at this documentation: https://github.com/nextcloud/all-in-one/blob/main/manual-upgrade.md"
2022-04-26 19:17:38 +02:00
exit 1
fi
2022-08-15 14:00:48 +02:00
# Do not start the container if the last update failed
2022-09-20 16:33:43 +02:00
if [ -f " $NEXTCLOUD_DATA_DIR /update.failed " ] ; then
2022-08-15 14:00:48 +02:00
echo "The last Nextcloud update failed."
echo "Please restore from backup and try again!"
echo "If you do not have a backup in place, you can simply delete the update.failed file in the datadir which will allow the container to start again."
exit 1
fi
2022-12-16 10:57:42 +01:00
# Do not start the container if the install failed
if [ -f " $NEXTCLOUD_DATA_DIR /install.failed " ] ; then
echo "The initial Nextcloud installation failed."
echo "Please reset AIO properly and try again. For further clues what went wrong, check the logs above."
echo "See https://github.com/nextcloud/all-in-one#how-to-properly-reset-the-instance"
exit 1
fi
2021-12-07 18:45:52 +01:00
# Skip any update if Nextcloud was just restored
2022-09-20 16:33:43 +02:00
if ! [ -f " $NEXTCLOUD_DATA_DIR /skip.update " ] ; then
2021-12-07 18:45:52 +01:00
if version_greater " $image_version " " $installed_version " ; then
# Check if it skips a major version
INSTALLED_MAJOR = " ${ installed_version %%.* } "
2021-11-30 11:20:42 +01:00
IMAGE_MAJOR = " ${ image_version %%.* } "
2022-11-17 17:54:09 +01:00
if [ " $installed_version " != "0.0.0.0" ] ; then
# Write output to logfile.
exec > >( tee -i "/var/www/html/data/update.log" )
exec 2>& 1
fi
2021-12-07 18:45:52 +01:00
if [ " $installed_version " != "0.0.0.0" ] && [ " $(( IMAGE_MAJOR - INSTALLED_MAJOR)) " -gt 1 ] ; then
set -ex
NEXT_MAJOR = " $(( INSTALLED_MAJOR + 1 )) "
curl -fsSL -o nextcloud.tar.bz2 " https://download.nextcloud.com/server/releases/latest- ${ NEXT_MAJOR } .tar.bz2 "
curl -fsSL -o nextcloud.tar.bz2.asc " https://download.nextcloud.com/server/releases/latest- ${ NEXT_MAJOR } .tar.bz2.asc "
2022-02-11 11:37:05 +01:00
GNUPGHOME = " $( mktemp -d) "
export GNUPGHOME
2021-12-07 18:45:52 +01:00
# gpg key from https://nextcloud.com/nextcloud.asc
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 28806A878AE423A28372792ED75899B9A724937A
gpg --batch --verify nextcloud.tar.bz2.asc nextcloud.tar.bz2
mkdir -p /usr/src/tmp
tar -xjf nextcloud.tar.bz2 -C /usr/src/tmp/
gpgconf --kill all
rm nextcloud.tar.bz2.asc nextcloud.tar.bz2
mkdir -p /usr/src/tmp/nextcloud/data
mkdir -p /usr/src/tmp/nextcloud/custom_apps
chmod +x /usr/src/tmp/nextcloud/occ
2023-02-06 13:05:51 +01:00
cp -r /usr/src/nextcloud/config/* /usr/src/tmp/nextcloud/config/
2022-05-02 17:01:04 +02:00
mkdir -p /usr/src/tmp/nextcloud/apps/nextcloud-aio
2023-02-06 13:05:51 +01:00
cp -r /usr/src/nextcloud/apps/nextcloud-aio/* /usr/src/tmp/nextcloud/apps/nextcloud-aio/
2021-12-07 18:45:52 +01:00
mv /usr/src/nextcloud /usr/src/temp-nextcloud
mv /usr/src/tmp/nextcloud /usr/src/nextcloud
rm -r /usr/src/tmp
rm -r /usr/src/temp-nextcloud
# shellcheck disable=SC2016
image_version = " $( php -r 'require "/usr/src/nextcloud/version.php"; echo implode(".", $OC_Version);' ) "
IMAGE_MAJOR = " ${ image_version %%.* } "
set +ex
fi
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
if [ " $installed_version " != "0.0.0.0" ] ; then
while true; do
echo -e "Checking connection to appstore"
CURL_STATUS = " $( curl -LI "https://apps.nextcloud.com/" -o /dev/null -w '%{http_code}\n' -s) "
if [ [ " $CURL_STATUS " = "200" ] ]
then
echo "Appstore is reachable"
break
else
echo "Curl didn't produce a 200 status, is appstore reachable?"
2022-01-21 14:02:35 +01:00
sleep 5
2021-12-07 18:45:52 +01:00
fi
done
php /var/www/html/occ maintenance:mode --off
echo "Getting and backing up the status of apps for later, this might take a while..."
2022-11-17 17:54:09 +01:00
NC_APPS = " $( find /var/www/html/custom_apps/ -type d -maxdepth 1 -mindepth 1 | sed 's|/var/www/html/custom_apps/||g' ) "
if [ -z " $NC_APPS " ] ; then
echo "No apps detected, aborting export of app status..."
APPSTORAGE = "no-export-done"
else
2022-11-21 18:38:34 +01:00
mapfile -t NC_APPS_ARRAY <<< " $NC_APPS "
2022-11-17 17:54:09 +01:00
declare -Ag APPSTORAGE
echo "Disabling apps before the update in order to make the update procedure more safe. This can take a while..."
for app in " ${ NC_APPS_ARRAY [@] } " ; do
APPSTORAGE[ $app ] = $( php /var/www/html/occ config:app:get " $app " enabled)
php /var/www/html/occ app:disable " $app "
done
fi
2021-12-07 18:45:52 +01:00
if [ " $(( IMAGE_MAJOR - INSTALLED_MAJOR)) " -eq 1 ] ; then
php /var/www/html/occ config:system:delete app_install_overwrite
2021-11-30 11:20:42 +01:00
fi
2021-12-07 18:45:52 +01:00
php /var/www/html/occ app:update --all
2022-01-29 22:29:15 +01:00
# Fix removing the updatenotification for old instances
2022-09-18 23:26:06 +02:00
UPDATENOTIFICATION_STATUS = " $( php /var/www/html/occ config:app:get updatenotification enabled) "
2022-01-29 22:29:15 +01:00
if [ -d "/var/www/html/apps/updatenotification" ] ; then
php /var/www/html/occ app:disable updatenotification
2022-09-18 23:26:06 +02:00
elif [ " $UPDATENOTIFICATION_STATUS " != "no" ] && [ -n " $UPDATENOTIFICATION_STATUS " ] ; then
php /var/www/html/occ config:app:set updatenotification enabled --value= "no"
2022-01-29 22:29:15 +01:00
fi
2021-11-30 11:20:42 +01:00
fi
2021-12-07 18:45:52 +01:00
echo " Initializing nextcloud $image_version ... "
rsync -rlD --delete --exclude-from= /upgrade.exclude /usr/src/nextcloud/ /var/www/html/
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
for dir in config data custom_apps themes; do
if [ ! -d " /var/www/html/ $dir " ] || directory_empty " /var/www/html/ $dir " ; then
rsync -rlD --include " / $dir / " --exclude '/*' /usr/src/nextcloud/ /var/www/html/
fi
done
2022-12-15 14:32:03 +01:00
rsync -rlD --delete --include '/config/' --exclude '/*' --exclude '/config/CAN_INSTALL' --exclude '/config/config.sample.php' --exclude '/config/config.php' /usr/src/nextcloud/ /var/www/html/
2021-12-07 18:45:52 +01:00
rsync -rlD --include '/version.php' --exclude '/*' /usr/src/nextcloud/ /var/www/html/
echo "Initializing finished"
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
#install
if [ " $installed_version " = "0.0.0.0" ] ; then
2023-02-06 18:07:57 +01:00
echo "New Nextcloud instance."
# Write output to logfile.
mkdir -p /var/www/html/data
exec > >( tee -i "/var/www/html/data/install.log" )
exec 2>& 1
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
INSTALL_OPTIONS = ( -n --admin-user " $ADMIN_USER " --admin-pass " $ADMIN_PASSWORD " )
if [ -n " ${ NEXTCLOUD_DATA_DIR } " ] ; then
INSTALL_OPTIONS += ( --data-dir " $NEXTCLOUD_DATA_DIR " )
fi
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
echo "Installing with PostgreSQL database"
INSTALL_OPTIONS += ( --database pgsql --database-name " $POSTGRES_DB " --database-user " $POSTGRES_USER " --database-pass " $POSTGRES_PASSWORD " --database-host " $POSTGRES_HOST " )
2023-02-02 19:41:41 +01:00
echo "Starting Nextcloud installation..."
2023-02-06 18:07:57 +01:00
if ! php /var/www/html/occ maintenance:install " ${ INSTALL_OPTIONS [@] } " ; then
echo "Installation of Nextcloud failed!"
touch " $NEXTCLOUD_DATA_DIR /install.failed "
exit 1
fi
2023-02-06 18:32:14 +01:00
# Try to force generation of appdata dir:
php /var/www/html/occ maintenance:repair
2023-02-23 17:09:10 +01:00
if [ -z " $OBJECTSTORE_S3_BUCKET " ] && [ -z " $OBJECTSTORE_SWIFT_URL " ] ; then
max_retries = 10
try = 0
while [ -z " $( find " $NEXTCLOUD_DATA_DIR / " -maxdepth 1 -mindepth 1 -type d -name "appdata_*" ) " ] && [ " $try " -lt " $max_retries " ] ; do
echo "Waiting for appdata to become available..."
try = $(( try+1))
sleep 10s
done
2023-02-06 18:18:52 +01:00
2023-02-23 17:09:10 +01:00
if [ " $try " -ge " $max_retries " ] ; then
echo "Installation of Nextcloud failed!"
echo " Install errors: $( cat /var/www/html/data/nextcloud.log) "
touch " $NEXTCLOUD_DATA_DIR /install.failed "
exit 1
fi
2021-12-07 18:45:52 +01:00
fi
2021-11-30 11:20:42 +01:00
2021-12-07 18:45:52 +01:00
# unset admin password
unset ADMIN_PASSWORD
# Apply log settings
echo "Applying default settings..."
mkdir -p /var/www/html/data
php /var/www/html/occ config:system:set loglevel --value= 2
php /var/www/html/occ config:system:set log_type --value= file
2022-05-25 15:15:52 +02:00
php /var/www/html/occ config:system:set logfile --value= "/var/www/html/data/nextcloud.log"
2021-12-07 18:45:52 +01:00
php /var/www/html/occ config:system:set log_rotate_size --value= "10485760"
php /var/www/html/occ app:enable admin_audit
2022-05-25 15:15:52 +02:00
php /var/www/html/occ config:app:set admin_audit logfile --value= "/var/www/html/data/audit.log"
2021-12-07 18:45:52 +01:00
php /var/www/html/occ config:system:set log.condition apps 0 --value= "admin_audit"
# Apply preview settings
echo "Applying preview settings..."
php /var/www/html/occ config:system:set preview_max_x --value= "2048"
php /var/www/html/occ config:system:set preview_max_y --value= "2048"
php /var/www/html/occ config:system:set jpeg_quality --value= "60"
php /var/www/html/occ config:app:set preview jpeg_quality --value= "60"
php /var/www/html/occ config:system:delete enabledPreviewProviders
php /var/www/html/occ config:system:set enabledPreviewProviders 1 --value= "OC\\Preview\\Image"
php /var/www/html/occ config:system:set enabledPreviewProviders 2 --value= "OC\\Preview\\MarkDown"
php /var/www/html/occ config:system:set enabledPreviewProviders 3 --value= "OC\\Preview\\MP3"
php /var/www/html/occ config:system:set enabledPreviewProviders 4 --value= "OC\\Preview\\TXT"
php /var/www/html/occ config:system:set enabledPreviewProviders 5 --value= "OC\\Preview\\OpenDocument"
php /var/www/html/occ config:system:set enabledPreviewProviders 6 --value= "OC\\Preview\\Movie"
php /var/www/html/occ config:system:set enable_previews --value= true --type= boolean
# Apply other settings
echo "Applying other settings..."
php /var/www/html/occ config:system:set upgrade.disable-web --type= bool --value= true
php /var/www/html/occ config:system:set mail_smtpmode --value= "smtp"
php /var/www/html/occ config:system:set trashbin_retention_obligation --value= "auto, 30"
php /var/www/html/occ config:system:set versions_retention_obligation --value= "auto, 30"
php /var/www/html/occ config:system:set activity_expire_days --value= "30"
php /var/www/html/occ config:system:set simpleSignUpLink.shown --type= bool --value= false
php /var/www/html/occ config:system:set share_folder --value= "/Shared"
# Not needed anymore with the removal of the updatenotification app:
# php /var/www/html/occ config:app:set updatenotification notify_groups --value="[]"
2022-02-03 10:28:33 +01:00
# Install some apps by default
2022-09-26 20:27:35 +02:00
if [ -n " $STARTUP_APPS " ] ; then
read -ra STARTUP_APPS_ARRAY <<< " $STARTUP_APPS "
for app in " ${ STARTUP_APPS_ARRAY [@] } " ; do
2023-01-02 16:08:02 +01:00
if ! echo " $app " | grep -q '^-' ; then
if [ -z " $( find /var/www/html/apps -type d -maxdepth 1 -mindepth 1 -name " $app " ) " ] ; then
# If not shipped, install and enable the app
php /var/www/html/occ app:install " $app "
else
# If shipped, enable the app
php /var/www/html/occ app:enable " $app "
fi
else
app = " ${ app #- } "
# Disable the app if '-' was provided in front of the appid
php /var/www/html/occ app:disable " $app "
fi
2022-09-26 20:27:35 +02:00
done
fi
2022-02-03 10:28:33 +01:00
2021-12-07 18:45:52 +01:00
#upgrade
else
2022-11-21 18:38:34 +01:00
touch " $NEXTCLOUD_DATA_DIR /update.failed "
2021-12-07 18:45:52 +01:00
echo " Upgrading nextcloud from $installed_version to $image_version ... "
if ! php /var/www/html/occ upgrade || ! php /var/www/html/occ -V; then
echo "Upgrade failed. Please restore from backup."
2022-04-20 17:16:43 +02:00
bash /notify.sh " Nextcloud update to $image_version failed! " "Please restore from backup!"
2021-12-07 18:45:52 +01:00
exit 1
fi
2021-11-30 11:20:42 +01:00
2022-09-20 16:33:43 +02:00
rm " $NEXTCLOUD_DATA_DIR /update.failed "
2022-04-20 17:16:43 +02:00
bash /notify.sh " Nextcloud update to $image_version successful! " "Feel free to inspect the Nextcloud container logs for more info."
2022-11-17 18:05:23 +01:00
php /var/www/html/occ app:update --all
2022-11-17 17:54:09 +01:00
# Restore app status
if [ " ${ APPSTORAGE [0] } " != "no-export-done" ] ; then
echo "Restoring the status of apps. This can take a while..."
for app in " ${ !APPSTORAGE[@] } " ; do
if [ -n " ${ APPSTORAGE [ $app ] } " ] ; then
if [ " ${ APPSTORAGE [ $app ] } " != "no" ] ; then
echo " Enabling $app ... "
if ! php /var/www/html/occ app:enable " $app " >/dev/null; then
2022-11-21 16:44:51 +01:00
echo " The $app app could not get enabled. Probably because it is not compatible with the new Nextcloud version. "
if [ " $app " = apporder ] ; then
CUSTOM_HINT = "The apporder app was deprecated. A possible replacement is the side_menu app, aka 'Custom menu'."
else
CUSTOM_HINT = "Most likely because it is not compatible with the new Nextcloud version."
fi
bash /notify.sh " Could not enable the $app app after the Nextcloud update! " " $CUSTOM_HINT Feel free to look at the Nextcloud update logs and force-enable the app again from the app-store UI. "
2022-11-17 17:54:09 +01:00
continue
fi
# Only restore the group settings, if the app was enabled (and is thus compatible with the new NC version)
if [ " ${ APPSTORAGE [ $app ] } " != "yes" ] ; then
2022-11-17 18:05:23 +01:00
php /var/www/html/occ config:app:set " $app " enabled --value= " ${ APPSTORAGE [ $app ] } "
2022-11-17 17:54:09 +01:00
fi
fi
fi
done
fi
2021-12-07 18:45:52 +01:00
2022-11-17 18:05:23 +01:00
php /var/www/html/occ app:update --all
2021-12-07 18:45:52 +01:00
# Apply optimization
echo "Doing some optimizations..."
php /var/www/html/occ maintenance:repair
php /var/www/html/occ db:add-missing-indices
php /var/www/html/occ db:add-missing-columns
php /var/www/html/occ db:add-missing-primary-keys
yes | php /var/www/html/occ db:convert-filecache-bigint
php /var/www/html/occ maintenance:mimetype:update-js
php /var/www/html/occ maintenance:mimetype:update-db
2021-11-30 11:20:42 +01:00
fi
fi
2022-04-04 19:12:07 +02:00
2022-07-08 11:24:03 +02:00
# Performing update of all apps if daily backups are enabled, running and successful and if it is saturday
2022-07-10 21:47:25 +02:00
if [ " $UPDATE_NEXTCLOUD_APPS " = 'yes' ] && [ " $( date +%u) " = 6 ] ; then
2022-04-20 17:16:43 +02:00
UPDATED_APPS = " $( php /var/www/html/occ app:update --all) "
if [ -n " $UPDATED_APPS " ] ; then
bash /notify.sh "Your apps just got updated!" " $UPDATED_APPS "
fi
2022-04-04 19:12:07 +02:00
fi
2022-10-27 13:50:26 +02:00
else
SKIP_UPDATE = 1
2021-11-30 11:20:42 +01:00
fi
2022-08-22 11:14:19 +02:00
if [ -z " $OBJECTSTORE_S3_BUCKET " ] && [ -z " $OBJECTSTORE_SWIFT_URL " ] ; then
2023-02-23 17:09:10 +01:00
# Check if appdata is present
# If not, something broke (e.g. changing ncdatadir after aio was first started)
if [ -z " $( find " $NEXTCLOUD_DATA_DIR / " -maxdepth 1 -mindepth 1 -type d -name "appdata_*" ) " ] ; then
echo "Appdata is not present. Did you maybe change the datadir after aio was first started?"
echo "See https://github.com/nextcloud/all-in-one#how-to-change-the-default-location-of-nextclouds-datadir"
echo "In the datadir was found:"
ls -la " $NEXTCLOUD_DATA_DIR / "
exit 1
fi
# Configure tempdirectory
2022-09-20 16:33:43 +02:00
mkdir -p " $NEXTCLOUD_DATA_DIR /tmp/ "
2022-08-22 11:14:19 +02:00
if ! grep -q upload_tmp_dir /usr/local/etc/php/conf.d/nextcloud.ini; then
2022-09-20 16:33:43 +02:00
echo " upload_tmp_dir = $NEXTCLOUD_DATA_DIR /tmp/ " >> /usr/local/etc/php/conf.d/nextcloud.ini
2022-08-22 11:14:19 +02:00
fi
2022-09-20 16:33:43 +02:00
php /var/www/html/occ config:system:set tempdirectory --value= " $NEXTCLOUD_DATA_DIR /tmp/ "
2022-08-22 11:14:19 +02:00
fi
2022-04-26 15:44:13 +02:00
# Perform fingerprint update if instance was restored
2022-09-20 16:33:43 +02:00
if [ -f " $NEXTCLOUD_DATA_DIR /fingerprint.update " ] ; then
2022-04-26 15:44:13 +02:00
php /var/www/html/occ maintenance:data-fingerprint
2022-09-20 16:33:43 +02:00
rm " $NEXTCLOUD_DATA_DIR /fingerprint.update "
2022-04-26 15:44:13 +02:00
fi
2021-11-30 11:20:42 +01:00
# Apply one-click-instance settings
echo "Applying one-click-instance settings..."
php /var/www/html/occ config:system:set one-click-instance --value= true --type= bool
php /var/www/html/occ config:system:set one-click-instance.user-limit --value= 100 --type= int
2022-10-25 18:13:16 +02:00
php /var/www/html/occ config:system:set one-click-instance.link --value= "https://nextcloud.com/all-in-one/"
php /var/www/html/occ app:enable support
2021-11-30 11:20:42 +01:00
2022-05-25 15:15:52 +02:00
# Adjusting log files to be stored on a volume
echo "Adjusting log files..."
php /var/www/html/occ config:system:set logfile --value= "/var/www/html/data/nextcloud.log"
php /var/www/html/occ config:app:set admin_audit logfile --value= "/var/www/html/data/audit.log"
2021-11-30 11:20:42 +01:00
# Apply network settings
echo "Applying network settings..."
php /var/www/html/occ config:system:set trusted_domains 1 --value= " $NC_DOMAIN "
php /var/www/html/occ config:system:set overwrite.cli.url --value= " https:// $NC_DOMAIN / "
php /var/www/html/occ config:system:set htaccess.RewriteBase --value= "/"
php /var/www/html/occ maintenance:update:htaccess
2022-03-14 15:35:37 +01:00
# Disallow creating local external storages when nothing was mounted
if [ -z " $NEXTCLOUD_MOUNT " ] ; then
php /var/www/html/occ config:system:set files_external_allow_create_new_local --type= bool --value= false
else
php /var/www/html/occ config:system:set files_external_allow_create_new_local --type= bool --value= true
fi
2021-11-30 12:50:08 +01:00
# AIO app
2023-01-12 13:59:10 +01:00
if [ " $( php /var/www/html/occ config:app:get nextcloud-aio enabled) " != "yes" ] ; then
2021-11-30 12:50:08 +01:00
php /var/www/html/occ app:enable nextcloud-aio
fi
2021-11-30 11:20:42 +01:00
# Notify push
if ! [ -d "/var/www/html/custom_apps/notify_push" ] ; then
php /var/www/html/occ app:install notify_push
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get notify_push enabled) " != "yes" ] ; then
2021-11-30 11:20:42 +01:00
php /var/www/html/occ app:enable notify_push
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2021-11-30 11:20:42 +01:00
php /var/www/html/occ app:update notify_push
fi
2022-02-22 13:26:48 +01:00
php /var/www/html/occ config:system:set trusted_proxies 0 --value= "127.0.0.1"
2022-06-15 12:42:14 +02:00
php /var/www/html/occ config:system:set trusted_proxies 1 --value= "::1"
2021-11-30 11:20:42 +01:00
php /var/www/html/occ config:app:set notify_push base_endpoint --value= " https:// $NC_DOMAIN /push "
# Collabora
2022-03-17 10:13:21 +01:00
if [ " $COLLABORA_ENABLED " = 'yes' ] ; then
if ! [ -d "/var/www/html/custom_apps/richdocuments" ] ; then
php /var/www/html/occ app:install richdocuments
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get richdocuments enabled) " != "yes" ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:enable richdocuments
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:update richdocuments
fi
2022-04-06 21:14:41 +02:00
php /var/www/html/occ config:app:set richdocuments wopi_url --value= " https:// $NC_DOMAIN / "
2022-03-17 10:13:21 +01:00
# Fix https://github.com/nextcloud/all-in-one/issues/188:
php /var/www/html/occ config:system:set allow_local_remote_servers --type= bool --value= true
2022-12-09 12:42:15 +01:00
# Make collabora more save
2023-02-21 17:31:03 +01:00
COLLABORA_IPv4_ADDRESS = " $( echo " <?php echo gethostbyname(' $NC_DOMAIN '); " | php | head -1) "
COLLABORA_IPv6_ADDRESS = " <?php \$record = dns_get_record(' $NC_DOMAIN ', DNS_AAAA); "
2022-12-09 12:42:15 +01:00
# shellcheck disable=SC2016
2023-02-17 16:49:25 +01:00
COLLABORA_IPv6_ADDRESS += 'if (!empty($record)) {echo $record[0]["ipv6"];}'
COLLABORA_IPv6_ADDRESS = " $( echo " $COLLABORA_IPv6_ADDRESS " | php | head -1) "
2022-12-09 12:42:15 +01:00
COLLABORA_ALLOW_LIST = " $( php /var/www/html/occ config:app:get richdocuments wopi_allowlist) "
if [ -n " $COLLABORA_IPv4_ADDRESS " ] ; then
if ! echo " $COLLABORA_ALLOW_LIST " | grep -q " $COLLABORA_IPv4_ADDRESS " ; then
if [ -z " $COLLABORA_ALLOW_LIST " ] ; then
COLLABORA_ALLOW_LIST = " $COLLABORA_IPv4_ADDRESS "
else
COLLABORA_ALLOW_LIST += " , $COLLABORA_IPv4_ADDRESS "
fi
fi
else
2023-02-21 17:31:03 +01:00
echo " Warning: No ipv4-address found for $NC_DOMAIN . "
2022-12-09 12:42:15 +01:00
fi
if [ -n " $COLLABORA_IPv6_ADDRESS " ] ; then
if ! echo " $COLLABORA_ALLOW_LIST " | grep -q " $COLLABORA_IPv6_ADDRESS " ; then
if [ -z " $COLLABORA_ALLOW_LIST " ] ; then
COLLABORA_ALLOW_LIST = " $COLLABORA_IPv6_ADDRESS "
else
COLLABORA_ALLOW_LIST += " , $COLLABORA_IPv6_ADDRESS "
fi
fi
else
2023-02-21 17:31:03 +01:00
echo " No ipv6-address found for $NC_DOMAIN . "
2022-12-09 12:42:15 +01:00
fi
if [ -n " $COLLABORA_ALLOW_LIST " ] ; then
2023-02-21 17:31:03 +01:00
PRIVATE_IP_RANGES = '127.0.0.1/8,192.168.0.0/16,172.16.0.0/12,10.0.0.0/8,fd00::/8,::1'
if ! echo " $COLLABORA_ALLOW_LIST " | grep -q " $PRIVATE_IP_RANGES " ; then
COLLABORA_ALLOW_LIST += " , $PRIVATE_IP_RANGES "
fi
2022-12-09 12:42:15 +01:00
php /var/www/html/occ config:app:set richdocuments wopi_allowlist --value= " $COLLABORA_ALLOW_LIST "
else
echo "Warning: wopi_allowlist is empty which should not be the case!"
fi
2021-11-30 11:20:42 +01:00
else
2022-03-17 10:13:21 +01:00
if [ -d "/var/www/html/custom_apps/richdocuments" ] ; then
php /var/www/html/occ app:remove richdocuments
fi
fi
# OnlyOffice
if [ " $ONLYOFFICE_ENABLED " = 'yes' ] ; then
2022-03-22 19:34:16 +01:00
while ! nc -z " $ONLYOFFICE_HOST " 80; do
echo "waiting for OnlyOffice to become available..."
sleep 5
done
2022-03-17 10:13:21 +01:00
if ! [ -d "/var/www/html/custom_apps/onlyoffice" ] ; then
php /var/www/html/occ app:install onlyoffice
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get onlyoffice enabled) " != "yes" ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:enable onlyoffice
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:update onlyoffice
fi
2022-06-27 17:29:37 +02:00
php /var/www/html/occ config:system:set onlyoffice jwt_secret --value= " $ONLYOFFICE_SECRET "
php /var/www/html/occ config:system:set onlyoffice jwt_header --value= "AuthorizationJwt"
2022-03-17 10:13:21 +01:00
php /var/www/html/occ config:app:set onlyoffice DocumentServerUrl --value= " https:// $NC_DOMAIN /onlyoffice "
2022-07-04 13:35:23 +02:00
php /var/www/html/occ config:system:set allow_local_remote_servers --type= bool --value= true
2022-03-17 10:13:21 +01:00
else
2022-09-26 12:22:05 +02:00
if [ -d "/var/www/html/custom_apps/onlyoffice" ] && [ -n " $ONLYOFFICE_SECRET " ] && [ " $( php /var/www/html/occ config:system:get onlyoffice jwt_secret) " = " $ONLYOFFICE_SECRET " ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:remove onlyoffice
fi
2021-11-30 11:20:42 +01:00
fi
# Talk
2022-03-17 10:13:21 +01:00
if [ " $TALK_ENABLED " = 'yes' ] ; then
if ! [ -d "/var/www/html/custom_apps/spreed" ] ; then
php /var/www/html/occ app:install spreed
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get spreed enabled) " != "yes" ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:enable spreed
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-03-17 10:13:21 +01:00
php /var/www/html/occ app:update spreed
fi
2022-10-24 21:38:17 +02:00
# Based on https://github.com/nextcloud/spreed/issues/960#issuecomment-416993435
2022-10-25 21:03:10 +02:00
if [ -z " $( php /var/www/html/occ talk:turn:list --output= "plain" ) " ] ; then
2022-12-20 11:16:50 +01:00
php /var/www/html/occ talk:turn:add turn " $NC_DOMAIN : $TALK_PORT " "udp,tcp" --secret= " $TURN_SECRET "
2022-10-24 21:38:17 +02:00
fi
2022-10-25 21:03:10 +02:00
if php /var/www/html/occ talk:stun:list --output= "plain" | grep -oP '[a-zA-Z.:0-9]+' | grep -q " ^stun.nextcloud.com:443 $" ; then
2022-10-24 21:38:17 +02:00
php /var/www/html/occ talk:stun:add " $NC_DOMAIN : $TALK_PORT "
2022-10-25 21:03:10 +02:00
php /var/www/html/occ talk:stun:delete "stun.nextcloud.com:443"
2022-10-24 21:38:17 +02:00
fi
if ! php /var/www/html/occ talk:signaling:list --output= "plain" | grep -q " https:// $NC_DOMAIN /standalone-signaling/ " ; then
2022-10-25 21:03:10 +02:00
php /var/www/html/occ talk:signaling:add " https:// $NC_DOMAIN /standalone-signaling/ " " $SIGNALING_SECRET " --verify
2022-10-24 21:38:17 +02:00
fi
2021-11-30 11:20:42 +01:00
else
2022-03-17 10:13:21 +01:00
if [ -d "/var/www/html/custom_apps/spreed" ] ; then
php /var/www/html/occ app:remove spreed
fi
2021-11-30 11:20:42 +01:00
fi
2021-12-07 18:45:52 +01:00
2022-03-15 23:46:58 +01:00
# Clamav
if [ " $CLAMAV_ENABLED " = 'yes' ] ; then
2023-03-02 09:21:45 +01:00
count = 0
while ! nc -z " $CLAMAV_HOST " 3310 && [ " $count " -lt 90 ] ; do
2022-03-16 22:28:17 +01:00
echo "waiting for clamav to become available..."
2023-03-02 09:21:45 +01:00
count = $(( count+5))
2022-03-16 22:28:17 +01:00
sleep 5
done
2023-03-02 09:21:45 +01:00
if [ " $count " -ge 90 ] ; then
echo "Clamav did not start in time. Skipping initialization and disabling files_antivirus app."
php /var/www/html/occ app:disable files_antivirus
else
if ! [ -d "/var/www/html/custom_apps/files_antivirus" ] ; then
php /var/www/html/occ app:install files_antivirus
elif [ " $( php /var/www/html/occ config:app:get files_antivirus enabled) " != "yes" ] ; then
php /var/www/html/occ app:enable files_antivirus
elif [ " $SKIP_UPDATE " != 1 ] ; then
php /var/www/html/occ app:update files_antivirus
fi
php /var/www/html/occ config:app:set files_antivirus av_mode --value= "daemon"
php /var/www/html/occ config:app:set files_antivirus av_port --value= "3310"
php /var/www/html/occ config:app:set files_antivirus av_host --value= " $CLAMAV_HOST "
php /var/www/html/occ config:app:set files_antivirus av_stream_max_length --value= "104857600"
php /var/www/html/occ config:app:set files_antivirus av_max_file_size --value= "-1"
php /var/www/html/occ config:app:set files_antivirus av_infected_action --value= "only_log"
2022-03-15 23:46:58 +01:00
fi
else
if [ -d "/var/www/html/custom_apps/files_antivirus" ] ; then
php /var/www/html/occ app:remove files_antivirus
fi
fi
2022-08-17 15:09:22 +02:00
# Imaginary
2022-08-22 23:14:05 +02:00
if version_greater " $installed_version " "24.0.0.0" ; then
2022-08-17 15:09:22 +02:00
if [ " $IMAGINARY_ENABLED " = 'yes' ] ; then
php /var/www/html/occ config:system:set enabledPreviewProviders 0 --value= "OC\\Preview\\Imaginary"
php /var/www/html/occ config:system:set preview_imaginary_url --value= " http:// $IMAGINARY_HOST :9000 "
else
2023-02-08 00:32:48 +01:00
if [ -n " $( php /var/www/html/occ config:system:get preview_imaginary_url) " ] ; then
php /var/www/html/occ config:system:delete enabledPreviewProviders 0
php /var/www/html/occ config:system:delete preview_imaginary_url
php /var/www/html/occ config:system:delete enabledPreviewProviders 20
php /var/www/html/occ config:system:delete enabledPreviewProviders 21
php /var/www/html/occ config:system:delete enabledPreviewProviders 22
fi
2022-08-17 15:09:22 +02:00
fi
fi
2022-08-22 13:04:44 +02:00
# Fulltextsearch
if [ " $FULLTEXTSEARCH_ENABLED " = 'yes' ] ; then
while ! nc -z " $FULLTEXTSEARCH_HOST " 9200; do
echo "waiting for Fulltextsearch to become available..."
sleep 5
done
if ! [ -d "/var/www/html/custom_apps/fulltextsearch" ] ; then
php /var/www/html/occ app:install fulltextsearch
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get fulltextsearch enabled) " != "yes" ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:enable fulltextsearch
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:update fulltextsearch
fi
if ! [ -d "/var/www/html/custom_apps/fulltextsearch_elasticsearch" ] ; then
php /var/www/html/occ app:install fulltextsearch_elasticsearch
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get fulltextsearch_elasticsearch enabled) " != "yes" ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:enable fulltextsearch_elasticsearch
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:update fulltextsearch_elasticsearch
fi
if ! [ -d "/var/www/html/custom_apps/files_fulltextsearch" ] ; then
php /var/www/html/occ app:install files_fulltextsearch
2023-01-10 12:32:33 +01:00
elif [ " $( php /var/www/html/occ config:app:get files_fulltextsearch enabled) " != "yes" ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:enable files_fulltextsearch
2022-10-27 13:50:26 +02:00
elif [ " $SKIP_UPDATE " != 1 ] ; then
2022-08-22 13:04:44 +02:00
php /var/www/html/occ app:update files_fulltextsearch
fi
php /var/www/html/occ fulltextsearch:configure '{"search_platform":"OCA\\FullTextSearch_Elasticsearch\\Platform\\ElasticSearchPlatform"}'
2022-08-26 13:59:04 +02:00
php /var/www/html/occ fulltextsearch_elasticsearch:configure " {\"elastic_host\":\"http:// $FULLTEXTSEARCH_HOST :9200\",\"elastic_index\":\"nextcloud-aio\"} "
2022-08-22 13:04:44 +02:00
php /var/www/html/occ files_fulltextsearch:configure "{\"files_pdf\":\"1\",\"files_office\":\"1\"}"
2022-08-26 13:59:04 +02:00
# Do the index
2022-09-20 16:33:43 +02:00
if ! [ -f " $NEXTCLOUD_DATA_DIR /fts-index.done " ] ; then
2022-08-26 13:59:04 +02:00
echo "Waiting 10s before activating FTS..."
sleep 10
echo "Activating fulltextsearch..."
2023-01-07 16:14:25 +01:00
if php /var/www/html/occ fulltextsearch:test && php /var/www/html/occ fulltextsearch:index "{\"errors\": \"reset\"}" --no-readline; then
2022-09-20 16:33:43 +02:00
touch " $NEXTCLOUD_DATA_DIR /fts-index.done "
2022-08-26 13:59:04 +02:00
else
echo "Fulltextsearch failed. Could not index."
2023-01-07 16:14:25 +01:00
echo "Feel free to follow https://github.com/nextcloud/all-in-one/discussions/1709 if you want to skip the indexing in the future."
2022-08-26 13:59:04 +02:00
fi
fi
2022-08-22 13:04:44 +02:00
else
if [ -d "/var/www/html/custom_apps/fulltextsearch" ] ; then
php /var/www/html/occ app:remove fulltextsearch
fi
if [ -d "/var/www/html/custom_apps/fulltextsearch_elasticsearch" ] ; then
php /var/www/html/occ app:remove fulltextsearch_elasticsearch
fi
if [ -d "/var/www/html/custom_apps/files_fulltextsearch" ] ; then
php /var/www/html/occ app:remove files_fulltextsearch
fi
fi
2021-12-07 18:45:52 +01:00
# Remove the update skip file always
2022-09-20 16:33:43 +02:00
rm -f " $NEXTCLOUD_DATA_DIR " /skip.update