Skip to content

Commit e42fe06

Browse files
committed
nc-autoupdate-nc: Optionally prevent update if NC apps are incompatible
1 parent c4b9ded commit e42fe06

10 files changed

Lines changed: 95 additions & 18 deletions

File tree

bin/ncp-update-nc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ set -eE${DBG}
2222
BIN="${0##*/}"
2323
VER="$1"
2424
[[ "$VER" == "" ]] && { echo "Usage ${BIN} <version>"; exit 1; }
25+
extra_args=()
26+
if [[ " $* " =~ " "--allow-incompatible-apps" " ]]
27+
then
28+
extra_args+=(--allow-incompatible-apps)
29+
fi
2530

2631
connect_to_nc_update() {
2732
tail -n 100 -f "/var/log/ncp-update-nc.log" &
@@ -54,7 +59,7 @@ fi
5459

5560
systemctl reset-failed ncp-update-nc 2>/dev/null ||:
5661
systemd-run -u 'ncp-update-nc' --service-type=oneshot --no-block -p TimeoutStartSec="24h" -p TimeoutStopSec="1h" \
57-
bash -c "set -o pipefail; DBG='${DBG:-}' /usr/local/bin/ncp-update-nc.d/update-nc.sh '${VER}' |& tee /var/log/ncp-update-nc.log"
62+
bash -c "set -o pipefail; DBG='${DBG:-}' /usr/local/bin/ncp-update-nc.d/update-nc.sh '${VER}' ${extra_args[*]} |& tee /var/log/ncp-update-nc.log"
5863
sleep 1
5964

6065
if ! [[ "$(systemctl is-active ncp-update-nc ||:)" =~ ^(active|inactive|activating|deactivating)$ ]]

bin/ncp-update-nc.d/update-nc.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ URL="https://download.nextcloud.com/server/releases/nextcloud-$TARGET_VERSION.ta
9494
echo "Download Nextcloud $TARGET_VERSION..."
9595
wget -q "$URL" -O nextcloud.tar.bz2 || { echo "Error downloading"; exit 1; }
9696

97+
# Check if installed apps are compatible
98+
server_apps="$(tar -tf nextcloud.tar.bz2 --exclude='nextcloud/apps/*/*' | grep '^nextcloud/apps' | sed -e 's|^nextcloud/apps/||g' -e 's|/$||g')"
99+
compatible_apps="$(curl "https://apps.nextcloud.com/api/v1/platform/$TARGET_VERSION/apps.json" | jq '.[].id' -r)"
100+
enabled_apps="$(ncc app:list --output json | jq '.enabled | keys | .[]' -r)"
101+
102+
incompatible="$(comm -2 -3 <( echo "${enabled_apps?}" | sort ) <( { echo "${compatible_apps?}"; echo "${server_apps?}"; echo "nextcloudpi"; } | sort ))"
103+
104+
if [[ -n "$incompatible" ]]
105+
then
106+
if [[ " ${*} " =~ " "--allow-incompatible-apps" " ]]
107+
then
108+
echo "WARNING: The following apps are incompatible with the new Nextcloud version and will be disabled (update is running with --allow-incompatible-apps):"
109+
echo "$incompatible"
110+
else
111+
echo "ERROR: Some installed apps are incompatible with the new Nextcloud version. Aborting update (run with --allow-incompatible-apps to ignore this)."
112+
echo "Incompatible apps:"
113+
echo "$incompatible"
114+
exit 1
115+
fi
116+
fi
117+
97118
# backup
98119
####################
99120
BKPDIR="$BASEDIR"

bin/ncp/CONFIG/nc-previews-auto.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ configure()
3333
ncc config:app:set --value=0 --type=integer previewgenerator job_max_previews
3434

3535
mkdir -p /etc/cron.hourly
36-
install_template cron.hourly/ncp-previewgenerator /etc/cron.hourly/ncp-previewgenerator
36+
install_template cron.hourly/ncp-previewgenerator.sh /etc/cron.hourly/ncp-previewgenerator
3737
chmod +x /etc/cron.hourly/ncp-previewgenerator
3838
echo "Automatic preview generation enabled"
3939
return 0

bin/ncp/UPDATES/nc-autoupdate-nc.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
# just change NCLATESTVER and re-activate in update.sh to upgrade users
1212

13+
tmpl_ncp_update_nc_args() {
14+
15+
CHECK_INCOMPATIBLE_APPS="$(
16+
. /usr/local/etc/library.sh
17+
find_app_param nc-autoupdate-nc CHECK_INCOMPATIBLE_APPS
18+
)"
19+
if [[ "${CHECK_INCOMPATIBLE_APPS:-yes}" != "yes" ]]
20+
then
21+
echo "--allow-incompatible-apps"
22+
fi
23+
24+
}
25+
1326
configure()
1427
{
1528
[[ "$ACTIVE" != "yes" ]] && {
@@ -18,21 +31,7 @@ configure()
1831
return 0
1932
}
2033

21-
cat > /etc/cron.daily/ncp-autoupdate-nc <<EOF
22-
#!/bin/bash
23-
source /usr/local/etc/library.sh
24-
25-
echo -e "[ncp-update-nc]" >> /var/log/ncp.log
26-
/usr/local/bin/ncp-update-nc "latest" 2>&1 | tee -a /var/log/ncp.log
27-
28-
if [[ \${PIPESTATUS[0]} -eq 0 ]]; then
29-
30-
VER="\$(nc_version)"
31-
32-
notify_admin "NextCloudPi" "Nextcloud was updated to \$VER"
33-
fi
34-
echo "" >> /var/log/ncp.log
35-
EOF
34+
install_template cron.daily/ncp-autoupdate-nc.sh "/etc/cron.daily/ncp-autoupdate-nc"
3635
chmod 755 /etc/cron.daily/ncp-autoupdate-nc
3736
echo "automatic Nextcloud updates enabled"
3837
}

bin/ncp/UPDATES/nc-update-nextcloud.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ LATEST="$NCLATESTVER"
1212

1313
configure()
1414
{
15-
bash /usr/local/bin/ncp-update-nc "$VERSION"
15+
extra_args=()
16+
if [[ "${CHECK_INCOMPATIBLE_APPS:-yes}" != "yes" ]]
17+
then
18+
extra_args+=(--allow-incompatible-apps)
19+
fi
20+
bash /usr/local/bin/ncp-update-nc "$VERSION" "${extra_args[@]}"
1621
}
1722

1823
install() { :; }

etc/ncp-config.d/nc-autoupdate-nc.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"name": "Active",
1212
"value": "no",
1313
"type": "bool"
14+
},
15+
{
16+
"id": "CHECK_INCOMPATIBLE_APPS",
17+
"name": "Check for incompatible apps",
18+
"value": "yes",
19+
"type": "bool"
1420
}
1521
]
1622
}

etc/ncp-config.d/nc-update-nextcloud.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"name": "Version",
1212
"value": "0",
1313
"suggest": "0"
14+
},
15+
{
16+
"id": "CHECK_INCOMPATIBLE_APPS",
17+
"name": "Check for incompatible apps",
18+
"value": "yes",
19+
"type": "bool"
1420
}
1521
]
1622
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set +u
5+
source /usr/local/etc/library.sh
6+
7+
ncp_update_nc_args=""
8+
if [[ "$1" != "--defaults" ]]
9+
then
10+
ncp_update_nc_args="$(
11+
source "${BINDIR}/UPDATES/nc-autoupdate-nc.sh"
12+
tmpl_ncp_update_nc_args
13+
)"
14+
fi
15+
16+
cat <<EOF
17+
#!/bin/bash
18+
source /usr/local/etc/library.sh
19+
20+
echo -e "[ncp-update-nc]" >> /var/log/ncp.log
21+
/usr/local/bin/ncp-update-nc ${ncp_update_nc_args} "latest" 2>&1 | tee -a /var/log/ncp.log
22+
23+
if [[ \${PIPESTATUS[0]} -eq 0 ]]; then
24+
25+
VER="\$(nc_version)"
26+
27+
notify_admin "NextCloudPi" "Nextcloud was updated to \$VER"
28+
fi
29+
echo "" >> /var/log/ncp.log
30+
EOF
File renamed without changes.

updates/1.57.0.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ install_template nextcloud.conf.sh /etc/apache2/sites-available/001-nextcloud.co
1717
}
1818
systemctl reload apache2
1919

20+
if is_active_app nc-autoupdate-nc
21+
then
22+
run_app nc-autoupdate-nc
23+
fi
24+
2025
if [[ -L /var/www/nextcloud/apps/previewgenerator ]]
2126
then
2227
echo "Removing custom version of previewgenerator app ..."

0 commit comments

Comments
 (0)