Skip to content

Commit

Permalink
ncp-check-nc-version: dont notify the same version more than once
Browse files Browse the repository at this point in the history
Signed-off-by: nachoparker <[email protected]>
  • Loading branch information
nachoparker committed Oct 7, 2021
1 parent 9e27660 commit 8a6c1c0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
9 changes: 8 additions & 1 deletion bin/ncp-check-nc-version
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ source /usr/local/etc/library.sh # sets NCLATESTVER

CURRENT="$(ncc status | grep "version:" | awk '{ print $3 }')"
LATEST="$(wget -qO- https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/etc/ncp.cfg | jq -r .nextcloud_version)"
NOTIFIED=/var/run/.nc-version-notified

test -e "${NOTIFIED}" && [[ "${LATEST}" == "$( cat "${NOTIFIED}" )" ]] && {
echo "Found update from ${CURRENT} to ${LATEST}. Already notified"
exit 0
}

if is_more_recent_than "${LATEST}" "${CURRENT}"; then
notify_admin \
"Nextcloud update" \
"Update from ${CURRENT} to "${LATEST}" is available. Update from https://$(get_ip):4443"
"Update from ${CURRENT} to ${LATEST} is available. Update from https://$(get_ip):4443"
echo "${LATEST}" > "${NOTIFIED}"
fi
16 changes: 8 additions & 8 deletions bin/ncp/UPDATES/nc-notify-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ cat $LATEST > $NOTIFIED
EOF
chmod +x /usr/local/bin/ncp-notify-update

cat > /usr/local/bin/ncp-notify-unattended-upgrade <<EOF
cat > /usr/local/bin/ncp-notify-unattended-upgrade <<'EOF'
#!/bin/bash
source /usr/local/etc/library.sh
LOGFILE=/var/log/unattended-upgrades/unattended-upgrades.log
STAMPFILE=/var/run/.ncp-notify-unattended-upgrades
VERFILE=/usr/local/etc/ncp-version
test -e "\$LOGFILE" || { echo "\$LOGFILE not found"; exit 1; }
test -e "$LOGFILE" || { echo "$LOGFILE not found"; exit 1; }
# find lines with package updates
LINE=\$( grep "INFO Packages that will be upgraded:" "\$LOGFILE" )
LINE=$( grep "INFO Packages that will be upgraded:" "$LOGFILE" )
[[ "\$LINE" == "" ]] && { echo "no new upgrades"; exit 0; }
[[ "$LINE" == "" ]] && { echo "no new upgrades"; exit 0; }
# extract package names
PKGS=\$( sed 's|^.*Packages that will be upgraded: ||' <<< "\$LINE" | tr '\\n' ' ' )
PKGS=$( sed 's|^.*Packages that will be upgraded: ||' <<< "$LINE" | tr '\n' ' ' )
# mark lines as read
sed -i 's|INFO Packages that will be upgraded:|INFO Packages that will be upgraded :|' \$LOGFILE
sed -i 's|INFO Packages that will be upgraded:|INFO Packages that will be upgraded :|' \LOGFILE
echo -e "Packages automatically upgraded: \$PKGS\\n"
echo -e "Packages automatically upgraded: $PKGS\n"
# notify
notify_admin \
"NextCloudPi Unattended Upgrades" \
"Packages automatically upgraded \$PKGS"
"Packages automatically upgraded $PKGS"
EOF
chmod +x /usr/local/bin/ncp-notify-unattended-upgrade

Expand Down
40 changes: 40 additions & 0 deletions updates/1.41.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

## BACKWARD FIXES ( for older images )

source /usr/local/etc/library.sh # sets NCLATESTVER PHPVER RELEASE

# all images

# we handle this ourselves now
ncc app:disable updatenotification
run_app nc-notify-updates

# docker images only
[[ -f /.docker-image ]] && {
:
}

# for non docker images
[[ ! -f /.docker-image ]] && {

# make sure redis is up before running nextclud-domain
cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF'
[Unit]
Description=Register Current IP as Nextcloud trusted domain
Requires=network.target
After=mysql.service redis.service
[Service]
ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
}

exit 0

0 comments on commit 8a6c1c0

Please sign in to comment.