Improve update code

This commit is contained in:
Alexandre
2023-03-30 10:07:22 +02:00
parent 8604fbde95
commit 828ac14b82
3 changed files with 54 additions and 52 deletions

View File

@@ -3,14 +3,24 @@
PUID=$(bashio::config "PUID")
PGID=$(bashio::config "PGID")
datadirectory=$(bashio::config 'data_directory')
echo "Checking permissions"
# Check current version
if [ -f /data/config/www/nextcloud/config/config.php ]; then
datadirectory="$(sed -n "s|.*datadirectory' => '*\(.*[^ ]\) *',.*|\1|p" /data/config/www/nextcloud/config/config.php)"
else
datadirectory=/share/nextcloud
fi
echo "Updating permissions..."
echo "... Config directory : /data"
mkdir -p /data/config
chmod 755 -R /data/config
chown -R "$PUID:$PGID" "/data/config"
echo "... Data directory detected : $datadirectory"
mkdir -p "$datadirectory"
chmod 755 -R "$datadirectory"
chmod 755 -R /data/config
chown -R "$PUID:$PGID" "$datadirectory"
chown -R "$PUID:$PGID" "/data/config"
echo "...done"
echo " "

View File

@@ -36,6 +36,13 @@ fi
# Get launcher
LAUNCHER="sudo -u abc php /data/config/www/nextcloud/occ"
# Inform if new version available
function nextcloud_download {
mkdir -p /app
if [ -f /app/nextcloud.tar.bz2 ]; then rm /app/nextcloud.tar.bz2; fi
curl -o /app/nextcloud.tar.bz2 -L "https://download.nextcloud.com/server/releases/$1.tar.bz2"
}
# Check current version
if [ -f /data/config/www/nextcloud/version.php ]; then
CURRENTVERSION="$(sed -n "s|.*\OC_VersionString = '*\(.*[^ ]\) *';.*|\1|p" /data/config/www/nextcloud/version.php)"
@@ -55,23 +62,31 @@ if [[ $($LAUNCHER -V 2>&1) == *"not installed"* ]] || [ ! -f /data/config/www/ne
exit 0
# Is there an error
elif [[ $($LAUNCHER -V 2>&1) == *"Composer autoloader not found"* ]]; then
bashio::log.red "--------------------------------------------------------"
bashio::log.red "Issue in installation detected, Nextcloud will reinstall"
bashio::log.red "--------------------------------------------------------"
bashio::log.red "--------------------------------------------------"
bashio::log.red " Missing files detected, Nextcloud will reinstall "
bashio::log.red "--------------------------------------------------"
touch /reinstall
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair-share-owner"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ upgrade"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:mode --off"
elif [[ $($LAUNCHER -V 2>&1) == *"Nextcloud"* ]] || grep -q "/mnt/" /data/config/www/nextcloud/config/config.php &>/dev/null; then
# Log
bashio::log.green "--------------------------------------"
bashio::log.green "Nextcloud $CURRENTVERSION is installed"
bashio::log.green "--------------------------------------"
bashio::log.green "----------------------------------------"
bashio::log.green " Nextcloud $CURRENTVERSION is installed "
bashio::log.green "----------------------------------------"
elif ! grep -q "/mnt/" /data/config/www/nextcloud/config/config.php; then
bashio::log.red "------------------------------------------------------------------"
bashio::log.red "Unknown error detected, please create issue in github or reinstall"
bashio::log.red "------------------------------------------------------------------"
bashio::log.red "-------------------------------------------------"
bashio::log.red " Unknown error detected, auto-repair will launch "
bashio::log.red "-------------------------------------------------"
bashio::log.red "Error message:"
bashio::log.red "$($LAUNCHER -V 2>&1)"
bashio::log.red "------------------------------------------------------------------"
bashio::exit.nok
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair-share-owner"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ upgrade"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:mode --off"
fi
echo " "
@@ -95,22 +110,12 @@ if [ -f /reinstall ]; then
# Reinstall
bashio::log.green "... reinstall ongoing, please wait"
if [ -f /data/config/www/nextcloud/index.php ]; then rm /data/config/www/nextcloud/index.php; fi && \
/./etc/s6-overlay/s6-rc.d/init-nextcloud-config/run
occ upgrade &>/proc/1/fd/1 || true
# INSTALL
/./etc/s6-overlay/s6-rc.d/init-nextcloud-config/run
# RESET PERMISSIONS
/./etc/cont-init.d/01-folders.sh
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:repair-share-owner"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ upgrade"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ maintenance:mode --off"
fi
#####################
# RESET PERMISSIONS #
#####################
PUID=$(bashio::config "PUID")
PGID=$(bashio::config "PGID")
datadirectory=$(bashio::config 'data_directory')
echo "Checking permissions"
mkdir -p /data/config
mkdir -p "$datadirectory"
chmod 755 -R "$datadirectory"
chmod 755 -R /data/config
chown -R "$PUID:$PGID" "$datadirectory"
chown -R "$PUID:$PGID" "/data/config"

View File

@@ -10,29 +10,26 @@ if [ -f /data/config/www/nextcloud/version.php ]; then
else
CURRENTVERSION="Not found"
fi
# Check container version
CONTAINERVERSION="$(cat /nextcloudversion)"
# Inform if new version available
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
# Inform if new version available
function nextcloud_download {
mkdir -p /app
if [ -f /app/nextcloud.tar.bz2 ]; then rm /app/nextcloud.tar.bz2; fi
curl -o /app/nextcloud.tar.bz2 -L "https://download.nextcloud.com/server/releases/$1.tar.bz2"
}
# Updater code
if bashio::config.true 'auto_updater'; then
if ! bashio::config.true "disable_updates"; then
bashio::log.green "Auto_updater set, checking for updates"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/updater/updater.phar --no-interaction"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ upgrade"
while [[ $(occ update:check 2>&1) == *"update available"* ]]; do
bashio::log.yellow "-----------------------------------------------------------------------"
bashio::log.yellow " new version available, updating. Please do not turn off your addon! "
bashio::log.yellow "-----------------------------------------------------------------------"
updater.phar --no-interaction
occ upgrade
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/updater/updater.phar --no-interaction"
sudo -u abc -s /bin/bash -c "php /data/config/www/nextcloud/occ upgrade"
done
elif [ "$(version "$CONTAINERVERSION")" -gt "$(version "$CURRENTVERSION")" ]; then
elif bashio::config.true "disable_updates" && [ "$(version "$CONTAINERVERSION")" -gt "$(version "$CURRENTVERSION")" ]; then
bashio::log.yellow " "
bashio::log.yellow "New version available : $CONTAINERVERSION"
bashio::log.yellow "...auto_updater not set in addon options, please update from nextcloud settings"
@@ -42,14 +39,4 @@ fi
# RESET PERMISSIONS #
#####################
PUID=$(bashio::config "PUID")
PGID=$(bashio::config "PGID")
datadirectory=$(bashio::config 'data_directory')
echo "Checking permissions"
mkdir -p /data/config
mkdir -p "$datadirectory"
chmod 755 -R "$datadirectory"
chmod 755 -R /data/config
chown -R "$PUID:$PGID" "$datadirectory"
chown -R "$PUID:$PGID" "/data/config"
/./01-folders.sh