Skip to content

Commit

Permalink
update-nc.sh: Implement upgrade of PHP to 8.3
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Knöppler <[email protected]>
  • Loading branch information
theCalcaholic committed Aug 18, 2024
1 parent 6da8994 commit d39f213
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 20 deletions.
8 changes: 4 additions & 4 deletions bin/ncp-update-nc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VER="$1"
connect_to_nc_update() {
tail -f "/var/log/ncp-update-nc.log" &
tail_pid=$!
while [[ "$(systemctl is-active ncp-update-nc ||:)" == "active" ]]
while [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|activating|deactivating)$ ]]
do
sleep 3
done
Expand All @@ -45,17 +45,17 @@ connect_to_nc_update() {
fi
}

if [[ "$(systemctl is-active ncp-update-nc ||:)" == "activating" ]]
if [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|activating|deactivating)$ ]]
then
echo "Existing ncp-update-nc process detected. Connecting..."
connect_to_nc_update
exit 0
exit $?
fi

systemd-run -u 'ncp-update-nc' bash -c "DBG='${DBG:-}' /usr/local/bin/ncp-update-nc.d/update-nc.sh '${VER}' |& tee /var/log/ncp-update-nc.log"
sleep 5

if [[ "$(systemctl is-active ncp-update-nc ||:)" != "activating" ]]
if ! [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|activating|deactivating)$ ]]
then
echo "Failed to start ncp-update-nc"
systemctl status --no-pager ncp-update-nc
Expand Down
16 changes: 6 additions & 10 deletions bin/ncp-update-nc.d/update-nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,12 @@ then

# Reload library.sh to reset PHPVER
source /usr/local/etc/library.sh
export PHPVER
export RELEASE
#elif ! is_more_recent_than "29.0.0" "${NCVER}" && is_more_recent_than "8.3.0" "${PHPVER}.0" && [[ "$DEBIAN_VERSION" -ge 12 ]]
#then
# /usr/local/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh
#
# # Reload library.sh to reset PHPVER
# source /usr/local/etc/library.sh
# export PHPVER
# export RELEASE
elif ! is_more_recent_than "29.0.0" "${NCVER}" && is_more_recent_than "8.3.0" "${PHPVER}.0" && [[ "$DEBIAN_VERSION" -ge 12 ]]
then
/usr/local/bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh

# Reload library.sh to reset PHPVER
source /usr/local/etc/library.sh
fi

# refresh completions
Expand Down
64 changes: 64 additions & 0 deletions bin/ncp-update-nc.d/upgrade-php-bookworm-8.3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

source /usr/local/etc/library.sh

echo "Upgrading PHP..."
export DEBIAN_FRONTEND=noninteractive
PHPVER_OLD="$PHPVER"
PHPVER_NEW="8.3"
PHP_PACKAGES_OLD=("php${PHPVER_OLD}" \
"php${PHPVER_OLD}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common})
PHP_PACKAGES_NEW=("php${PHPVER_NEW}" \
"php${PHPVER_NEW}"-{curl,gd,fpm,cli,opcache,mbstring,xml,zip,fileinfo,ldap,intl,bz2,mysql,bcmath,gmp,redis,common})

php_restore() {
trap "" INT TERM HUP ERR
echo "Something went wrong while upgrading PHP. Rolling back to version ${PHPVER_OLD}..."
set +e
service "php${PHPVER_NEW}-fpm" stop
a2disconf php${PHPVER_NEW}-fpm
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ ${RELEASE%-security} main" > /etc/apt/sources.list.d/php.list
apt-get update
apt-get remove --purge -y "${PHP_PACKAGES_NEW[@]}"
apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_OLD[@]}"
set_ncpcfg "php_version" "${PHPVER_OLD}"
install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini"
run_app nc-limits
a2enconf "php${PHPVER_OLD}-fpm"
service "php${PHPVER_OLD}-fpm" start
service apache2 restart
echo "PHP upgrade has been successfully reverted"
set -e
}

trap php_restore INT TERM HUP ERR

apt-get update

clear_opcache

echo "Stopping apache and php-fpm..."
service "php${PHPVER_OLD}-fpm" stop
service apache2 stop

echo "Remove old PHP (${PHPVER_OLD})..."
a2disconf "php${PHPVER_OLD}-fpm"

apt-get remove --purge -y "${PHP_PACKAGES_OLD[@]}"

echo "Install PHP ${PHPVER_NEW}..."
install_with_shadow_workaround --no-install-recommends systemd
apt-get install -y --no-install-recommends -t "$RELEASE" "${PHP_PACKAGES_NEW[@]}"

set_ncpcfg "php_version" "${PHPVER_NEW}"
install_template "php/opcache.ini.sh" "/etc/php/${PHPVER_NEW}/mods-available/opcache.ini"
( set -e; export PHPVER="${PHPVER_NEW}"; run_app nc-limits )

a2enconf "php${PHPVER_NEW}-fpm"

echo "Starting apache and php-fpm..."
service "php${PHPVER_NEW}-fpm" start
service apache2 start
ncc status
rm -f /etc/apt/sources.list.d/php.list /etc/apt/trusted.gpg.d/php.gpg
2 changes: 2 additions & 0 deletions bin/ncp-update-nc.d/upgrade-php-bullseye-8.1.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source /usr/local/etc/library.sh

echo "Upgrading PHP..."
export DEBIAN_FRONTEND=noninteractive
PHPVER_OLD="$PHPVER"
Expand Down
10 changes: 5 additions & 5 deletions bin/ncp/CONFIG/nc-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ EOF
}

mysql nextcloud <<EOF
replace into ${DB_PREFIX}appconfig values ( 'theming', 'name' , "NextCloudPi" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'slogan' , "keep your data close" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'url' , "https://nextcloudpi.com" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'logoMime' , "image/svg+xml" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'backgroundMime', "image/png" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'name' , "NextCloudPi" , 2, 0);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'slogan' , "keep your data close" , 2, 0);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'url' , "https://nextcloudpi.com" , 2, 0);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'logoMime' , "image/svg+xml" , 2, 0);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'backgroundMime', "image/png" , 2, 0);
EOF

# NCP app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The first time you install this app, before using a cron job, you properly want
</types>
<dependencies>
<php min-version="7.2"/>
<nextcloud min-version="20" max-version="28" />
<nextcloud min-version="20" max-version="29" />
</dependencies>

<commands>
Expand Down

0 comments on commit d39f213

Please sign in to comment.