Skip to content

Commit a0728d7

Browse files
committed
nc-notify-updates: notify of new supported NC versions
Signed-off-by: nachoparker <nacho@ownyourbits.com>
1 parent 2037064 commit a0728d7

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

bin/ncp-check-nc-version

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# notify latest available NC version
4+
5+
set -e
6+
7+
source /usr/local/etc/library.sh # sets NCLATESTVER
8+
9+
CURRENT="$(ncc status | grep "version:" | awk '{ print $3 }')"
10+
LATEST="$(wget -qO- https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/etc/ncp.cfg | jq -r .nextcloud_version)"
11+
12+
if is_more_recent_than "${LATEST}" "${CURRENT}"; then
13+
notify_admin \
14+
"Nextcloud update" \
15+
"Update from ${CURRENT} to "${LATEST}" is available. Update from https://$(get_ip):4443"
16+
fi

bin/ncp-update-nc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,9 @@ CURRENT="$( $SUDO php /var/www/nextcloud/occ status | grep "version:" | awk '{ p
4545
grep -qP "\d+\.\d+\.\d+" <<<"$CURRENT" || { echo "Malformed version $CURRENT"; exit 1; }
4646
grep -qP "\d+\.\d+\.\d+" <<<"$VER" || { echo "Malformed version $VER" ; exit 1; }
4747

48-
MAJOR=$( grep -oP "\d+\.\d+\.\d+" <<<"$VER" | cut -d. -f1 )
49-
MINOR=$( grep -oP "\d+\.\d+\.\d+" <<<"$VER" | cut -d. -f2 )
50-
PATCH=$( grep -oP "\d+\.\d+\.\d+" <<<"$VER" | cut -d. -f3 )
51-
52-
MAJ=$( grep -oP "\d+\.\d+\.\d+" <<<"$CURRENT" | cut -d. -f1 )
53-
MIN=$( grep -oP "\d+\.\d+\.\d+" <<<"$CURRENT" | cut -d. -f2 )
54-
PAT=$( grep -oP "\d+\.\d+\.\d+" <<<"$CURRENT" | cut -d. -f3 )
55-
56-
NEED_UPDATE=false
57-
if [ "$MAJOR" -gt "$MAJ" ]; then
58-
NEED_UPDATE=true
59-
elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -gt "$MIN" ]; then
60-
NEED_UPDATE=true
61-
elif [ "$MAJOR" -eq "$MAJ" ] && [ "$MINOR" -eq "$MIN" ] && [ "$PATCH" -gt "$PAT" ]; then
62-
NEED_UPDATE=true
63-
fi
64-
6548
echo "Current Nextcloud version $CURRENT"
6649
echo "Available Nextcloud version $VER"
67-
[[ "$NEED_UPDATE" == "true" ]] || { echo "Nothing to update"; exit 1; } # we want `exit 1` so the autoupdate doesn't notify success in this case
50+
is_more_recent_than "${VER}" "${CURRENT}" || { echo "Nothing to update"; exit 1; } # we want `exit 1` so the autoupdate doesn't notify success in this case
6851

6952
# make sure that cron.php is not running and there are no pending jobs
7053
# https://github.com/nextcloud/server/issues/10949

bin/ncp/CONFIG/nc-init.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ EOF
148148
ncc app:install tasks
149149
ncc app:enable tasks
150150

151+
# we handle this ourselves
152+
ncc app:disable updatenotification
153+
151154
# News dropped support for 32-bit -> https://github.com/nextcloud/news/issues/1423
152155
if ! [[ "$(uname -m)" =~ "armv7" ]]; then
153156
ncc app:install news

bin/ncp/UPDATES/nc-notify-updates.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@ configure()
2323
}
2424

2525
# code
26-
cat > /usr/local/bin/ncp-notify-update <<EOF
26+
cat > /usr/local/bin/ncp-notify-update <<'EOF'
2727
#!/bin/bash
2828
source /usr/local/etc/library.sh
2929
VERFILE=/usr/local/etc/ncp-version
3030
LATEST=/var/run/.ncp-latest-version
3131
NOTIFIED=/var/run/.ncp-version-notified
3232
33-
test -e \$LATEST || exit 0;
33+
/usr/local/bin/ncp-check-nc-version
34+
35+
test -e $LATEST || exit 0;
3436
/usr/local/bin/ncp-test-updates || { echo "NextCloudPi up to date"; exit 0; }
3537
36-
test -e \$NOTIFIED && [[ "\$( cat \$LATEST )" == "\$( cat \$NOTIFIED )" ]] && {
37-
echo "Found update from \$( cat \$VERFILE ) to \$( cat \$LATEST ). Already notified"
38+
test -e $NOTIFIED && [[ "$( cat $LATEST )" == "$( cat $NOTIFIED )" ]] && {
39+
echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Already notified"
3840
exit 0
3941
}
4042
41-
echo "Found update from \$( cat \$VERFILE ) to \$( cat \$LATEST ). Sending notification..."
43+
echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Sending notification..."
4244
4345
notify_admin \
4446
"NextCloudPi update" \
45-
"Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$(get_ip):4443"
47+
"Update from $( cat $VERFILE ) to $( cat $LATEST ) is available. Update from https://$(get_ip):4443"
4648
47-
cat \$LATEST > \$NOTIFIED
49+
cat $LATEST > $NOTIFIED
4850
EOF
4951
chmod +x /usr/local/bin/ncp-notify-update
5052

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
[v1.39.21](https://github.com/nextcloud/nextcloudpi/commit/a4fdff6) (2021-10-04) ncp-web: disable activation page once activated
2+
[v1.40.0](https://github.com/nextcloud/nextcloudpi/commit/fbc4ab8) (2021-10-04) nc-notify-updates: notify of new supported NC versions
3+
4+
[v1.39.21](https://github.com/nextcloud/nextcloudpi/commit/2037064) (2021-10-04) ncp-web: disable activation page once activated
35

46
[v1.39.20](https://github.com/nextcloud/nextcloudpi/commit/714c3e5) (2021-10-04) ncp-config: fix first time error with no known latest version
57

updates/1.40.0.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ EOF
5050
chmod +x /usr/local/bin/ncc
5151
fi
5252

53+
# we handle this ourselves now
54+
ncc app:disable updatenotification
55+
run_app nc-notify-updates
56+
5357
# docker images only
5458
[[ -f /.docker-image ]] && {
5559
:

0 commit comments

Comments
 (0)