From 1548b03a9e2fcc479d38440181702fdd1f21fc99 Mon Sep 17 00:00:00 2001 From: mag37 Date: Fri, 7 Feb 2025 20:47:01 +0100 Subject: [PATCH] added else with inclusion of new function, rewrote 2 templates for testing --- dockcheck.sh | 14 ++++++----- notify_templates/notify_DSM.sh | 38 +++++++++++++++++++++++------- notify_templates/notify_apprise.sh | 38 +++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index f42febf..f69979f 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -152,7 +152,7 @@ progress_bar() { } # Function to add user-provided urls to releasenotes -releasenotes() { +releasenotes() { for update in ${GotUpdates[@]}; do found=false while read -r container url; do @@ -168,6 +168,8 @@ if [[ "$VERSION" != "$LatestRelease" ]] ; then if [[ -z "$AutoUp" ]] ; then read -r -p "Would you like to update? y/[n]: " SelfUpdate [[ "$SelfUpdate" =~ [yY] ]] && self_update + else + [[ -n "$Notify" ]] && { [[ $(type -t dockcheck_notification) == function ]] && dockcheck_notification "$VERSION" "$LatestRelease" "$LatestChanges" || printf "Could not source notification function.\n" ; } fi fi @@ -186,8 +188,8 @@ binary_downloader() { *) printf "\n%bArchitecture not supported, exiting.%b\n" "$c_red" "$c_reset" ; exit 1;; esac GetUrl="${BinaryUrl/TEMP/"$architecture"}" - if [[ $(command -v curl) ]]; then curl -L $GetUrl > "$ScriptWorkDir/$BinaryName" ; - elif [[ $(command -v wget) ]]; then wget $GetUrl -O "$ScriptWorkDir/$BinaryName" ; + if [[ $(command -v curl) ]]; then curl -L $GetUrl > "$ScriptWorkDir/$BinaryName" ; + elif [[ $(command -v wget) ]]; then wget $GetUrl -O "$ScriptWorkDir/$BinaryName" ; else printf "%s\n" "curl/wget not available - get $BinaryName manually from the repo link, exiting."; exit 1; fi [[ -f "$ScriptWorkDir/$BinaryName" ]] && chmod +x "$ScriptWorkDir/$BinaryName" @@ -211,13 +213,13 @@ else GetJq=${GetJq:-no} # set default to no if nothing is given if [[ "$GetJq" =~ [yYsS] ]] ; then [[ "$GetJq" =~ [yY] ]] && distro_checker - if [[ -n "$PkgInstaller" && "$PkgInstaller" != "ERROR" ]] ; then + if [[ -n "$PkgInstaller" && "$PkgInstaller" != "ERROR" ]] ; then (sudo $PkgInstaller jq) ; PkgExitcode="$?" [[ "$PkgExitcode" == 0 ]] && jqbin="jq" || printf "\n%bPackagemanager install failed%b, falling back to static binary.\n" "$c_yellow" "$c_reset" fi if [[ "$GetJq" =~ [nN] || "$PkgInstaller" == "ERROR" || "$PkgExitcode" != 0 ]] ; then binary_downloader "jq" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP" - [[ -f "$ScriptWorkDir/jq" ]] && jqbin="$ScriptWorkDir/jq" + [[ -f "$ScriptWorkDir/jq" ]] && jqbin="$ScriptWorkDir/jq" fi else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ; fi @@ -232,7 +234,7 @@ else read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetRegctl if [[ "$GetRegctl" =~ [yY] ]] ; then binary_downloader "regctl" "https://github.com/regclient/regclient/releases/latest/download/regctl-linux-TEMP" - [[ -f "$ScriptWorkDir/regctl" ]] && regbin="$ScriptWorkDir/regctl" + [[ -f "$ScriptWorkDir/regctl" ]] && regbin="$ScriptWorkDir/regctl" else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset" ; exit 1 ; fi fi diff --git a/notify_templates/notify_DSM.sh b/notify_templates/notify_DSM.sh index 6aabf1f..eec76b8 100644 --- a/notify_templates/notify_DSM.sh +++ b/notify_templates/notify_DSM.sh @@ -17,10 +17,9 @@ else echo "No msmtp or ssmtp binary found in PATH: $PATH" ; exit 1 fi -send_notification() { -[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") -UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) + +trigger_notification() { CfgFile="/usr/syno/etc/synosmtp.conf" # User variables: @@ -34,15 +33,11 @@ SenderName=$(grep 'smtp_from_name' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p') SenderMail=$(grep 'smtp_from_mail' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p') SenderMail=${SenderMail:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')} -printf "\nSending email notification.\n" - -printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString" - $MailPkg $SendMailTo << __EOF From: "$SenderName" <$SenderMail> date:$(date -R) To: <$SendMailTo> -Subject: $SubjectTag Updates available on $FromHost +Subject: $SubjectTag $MessageTitle $FromHost Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit @@ -52,3 +47,30 @@ __EOF # This ensures DSM's container manager will also see the update /var/packages/ContainerManager/target/tool/image_upgradable_checker } + +send_notification() { +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + +printf "\nSending email notification\n" + +MessageTitle="Updates available on" +# Setting the MessageBody variable here. +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString" + +trigger_notification + +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { +printf "\nSending email dockcheck notification\n" + +MessageTitle="New version of dockcheck available on" +# Setting the MessageBody variable here. +printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + +trigger_notification + +} diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh index 8663d43..377dd73 100644 --- a/notify_templates/notify_apprise.sh +++ b/notify_templates/notify_apprise.sh @@ -4,18 +4,11 @@ # Required receiving services must already be set up. # Modify to fit your setup - if API, set AppriseURL to your Apprise ip/domain. -send_notification() { -[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") -UpdToString=$( printf '%s\\n' "${Updates[@]}" ) FromHost=$(hostname) -printf "\nSending Apprise notification\n" +trigger_notification() { -MessageTitle="$FromHost - updates available." -# Setting the MessageBody variable here. -printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" - -# Modify to fit your setup: +### Modify to fit your setup: apprise -vv -t "$MessageTitle" -b "$MessageBody" \ mailto://myemail:mypass@gmail.com \ mastodons://{token}@{host} \ @@ -28,3 +21,30 @@ apprise -vv -t "$MessageTitle" -b "$MessageBody" \ # curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL } + +send_notification() { +[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") +UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + +printf "\nSending Apprise notification\n" + +MessageTitle="$FromHost - updates available." +# Setting the MessageBody variable here. +printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" + +trigger_notification + +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { +printf "\nSending Apprise dockcheck notification\n" + +MessageTitle="$FromHost - New version of dockcheck available." +# Setting the MessageBody variable here. +printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + +trigger_notification + +}