diff --git a/README.md b/README.md index a8ec8b1..f751d89 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Options: -I Prints custom releasenote urls alongside each container with updates (requires urls.list). -l Only update if label is set. See readme. -m Monochrome mode, no printf colour codes and hides progress bar. +-M Prints custom releasenote urls as markdown. -n No updates, only checking availability. -p Auto-Prune dangling images after update. -r Allow updating images for docker run, wont update the container. @@ -147,6 +148,7 @@ There's a function to use a lookup-file to add release note URL's to the notific Copy the notify_templates/`urls.list` file to the script directory, it will be used automatically if it's there. Modify it as necessary, the names of interest in the left column needs to match your container names. To also list the URL's in the CLI output (choose containers list) use the `-I` option or variable config. +For Markdown formatting - also add the `-M` option. The output of the notification will look something like this: ``` @@ -165,6 +167,11 @@ Change the default value by editing the `MaxAsync=N` variable in `dockcheck.sh`. ## :chart_with_upwards_trend: Extra plugins and tools: +### :small_orange_diamond: Using dockcheck.sh with the Synology DSM +If you run your container through the *Container Manager GUI* - only notifications are supported. +While if running manual (vanilla docker compose CLI) will allow you to use the update function too. +Some extra setup to tie together with Synology DSM - check out the [addons/DSM/README.md](./addons/DSM/README.md). + ### :small_orange_diamond: Prometheus and node_exporter Dockcheck can be used together with [Prometheus](https://github.com/prometheus/prometheus) and [node_exporter](https://github.com/prometheus/node_exporter) to export metrics via the file collector, scheduled with cron or likely. This is done with the `-c` option, like this: diff --git a/addons/DSM/README.md b/addons/DSM/README.md new file mode 100644 index 0000000..d786ba1 --- /dev/null +++ b/addons/DSM/README.md @@ -0,0 +1,35 @@ +## Using Dockcheck in DSM +Dockcheck cannot directly update containers managed in the Container Manager GUI, but it can still be used to notify you of containers with updates available. There are two ways to be notified, each with their own caveats: + +1. Enabling email notifications within the Task Scheduler (_step 6i below_) will send an email that includes the entire script as run. This will not include the `urls.list` links to release notes, but it will show a full list of containers checked, up to date, and needing updates (following the args included in the scheduled task). +2. The [DSM notification template](https://github.com/mag37/dockcheck/blob/main/notify_templates/notify_DSM.sh) will enable Dockcheck to directly send an email when using the `-i` flag. This is most useful when paired with an accurate [urls.list](https://github.com/mag37/dockcheck/blob/next063/notify_templates/urls.list) file, and results in a neat succinct email notification of only containers to be updated. + +This is a user preference, and both notifications are not necessary. However, regardless of the notification method, it is necessary to set up a scheduled task to run Dockcheck at a set interval (otherwise it will only run when manually triggered). + + +## Automate Dockcheck with DSM Task Scheduler: + +1. Open Control Panel and navigate to Task Scheduler +2. Create a Scheduled Task > User-defined script +3. Task Name: Dockcheck +4. User: root +5. Schedule: _User Preference_ +6. Task Settings: + 1. ✔ Send run details by email (include preferred email) _This is the optional step as described above)_ + 2. User-defined script: `export HOME=/root && cd /path/to/dockcheck && ./dockcheck.sh -n -i -I ` _or other custom args_ +8. Click OK, accept warning message + + +## Set up the DSM Notification template + +Copy the [dockcheck/notify_templates/notify_DSM.sh](https://github.com/mag37/dockcheck/blob/main/notify_templates/notify_DSM.sh) to the same directory as where you keep `dockcheck.sh`. +Use as is (uses your default notification email setting) or edit and override manually. + +![](./dsm1.png) + +![](./dsm2.png) + +![](./dsm3.png) + + +Made with much help and contribution from [@firmlyundecided](https://github.com/firmlyundecided) and [@yoyoma2](https://github.com/yoyoma2). diff --git a/addons/DSM/dsm1.png b/addons/DSM/dsm1.png new file mode 100644 index 0000000..2b36720 Binary files /dev/null and b/addons/DSM/dsm1.png differ diff --git a/addons/DSM/dsm2.png b/addons/DSM/dsm2.png new file mode 100644 index 0000000..3dd9b0c Binary files /dev/null and b/addons/DSM/dsm2.png differ diff --git a/addons/DSM/dsm3.png b/addons/DSM/dsm3.png new file mode 100644 index 0000000..33b01fa Binary files /dev/null and b/addons/DSM/dsm3.png differ diff --git a/dockcheck.sh b/dockcheck.sh index 85487ab..4b5f280 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -229,6 +229,7 @@ progress_bar() { # Function to add user-provided urls to releasenotes releasenotes() { + unset Updates for update in "${GotUpdates[@]}"; do found=false while read -r container url; do @@ -261,11 +262,18 @@ binary_downloader() { } distro_checker() { - if [[ -f /etc/arch-release ]]; then PkgInstaller="sudo pacman -S" - elif [[ -f /etc/redhat-release ]]; then PkgInstaller="sudo dnf install" - elif [[ -f /etc/SuSE-release ]]; then PkgInstaller="sudo zypper install" - elif [[ -f /etc/debian_version ]]; then PkgInstaller="sudo apt-get install" - elif [[ -f /etc/alpine-release ]] ; then PkgInstaller="doas apk add" + isRoot=false + [[ ${EUID:-} == 0 ]] && isRoot=true + if [[ -f /etc/alpine-release ]] ; then + [[ "$isRoot" == true ]] && PkgInstaller="apk add" || PkgInstaller="doas apk add" + elif [[ -f /etc/arch-release ]]; then + [[ "$isRoot" == true ]] && PkgInstaller="pacman -S" || PkgInstaller="sudo pacman -S" + elif [[ -f /etc/debian_version ]]; then + [[ "" == true ]] && PkgInstaller="apt-get install" || PkgInstaller="sudo apt-get install" + elif [[ -f /etc/redhat-release ]]; then + [[ "$isRoot" == true ]] && PkgInstaller="dnf install" || PkgInstaller="sudo dnf install" + elif [[ -f /etc/SuSE-release ]]; then + [[ "$isRoot" == true ]] && PkgInstaller="zypper install" || PkgInstaller="sudo zypper install" elif [[ $(uname -s) == "Darwin" ]]; then PkgInstaller="brew install" else PkgInstaller="ERROR"; printf "\n%bNo distribution could be determined%b, falling back to static binary.\n" "$c_yellow" "$c_reset" fi @@ -279,7 +287,7 @@ dependency_check() { if command -v "$AppName" &>/dev/null; then export "$AppVar"="$AppName"; elif [[ -f "$ScriptWorkDir/$AppName" ]]; then export "$AppVar"="$ScriptWorkDir/$AppName"; else - printf "%s\n" "Required dependency '$AppName' missing, do you want to install it?" + printf "%s\n" "Required dependency %b'%s'%b missing, do you want to install it?\n" "$c_teal" "$AppName" "$c_reset" read -r -p "y: With packagemanager (sudo). / s: Download static binary. y/s/[n] " GetBin GetBin=${GetBin:-no} # set default to no if nothing is given if [[ "$GetBin" =~ [yYsS] ]]; then @@ -297,7 +305,7 @@ dependency_check() { fi if [[ "$GetBin" =~ [sS] ]] || [[ "$PkgInstaller" == "ERROR" ]]; then binary_downloader "$AppName" "$AppUrl" - [[ -f "$ScriptWorkDir/$AppName" ]] && { export "$AppVar"="$ScriptWorkDir/$1" && printf "\n%b%b downloaded.%b\n" "$c_green" "$AppName" "$c_reset"; } + [[ -f "$ScriptWorkDir/$AppName" ]] && { export "$AppVar"="$ScriptWorkDir/$1" && printf "\n%b%s downloaded.%b\n" "$c_green" "$AppName" "$c_reset"; } fi else printf "\n%bDependency missing, exiting.%b\n" "$c_red" "$c_reset"; exit 1; fi @@ -310,9 +318,8 @@ dependency_check() { # Numbered List function # if urls.list exists add release note url per line -options() { +list_options() { num=1 - if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi for update in "${Updates[@]}"; do echo "$num) $update" ((num++)) @@ -335,6 +342,7 @@ dependency_check "regctl" "regbin" "https://github.com/regclient/regclient/relea dependency_check "jq" "jqbin" "https://github.com/jqlang/jq/releases/latest/download/jq-linux-TEMP" # Check docker compose binary +docker info &>/dev/null || { printf "\n%bYour current user does not have permissions to the docker socket - may require root / docker group. Exiting.%b\n" "$c_red" "$c_reset"; exit 1; } if docker compose version &>/dev/null; then DockerBin="docker compose" ; elif docker-compose -v &>/dev/null; then DockerBin="docker-compose" ; elif docker -v &>/dev/null; then @@ -408,7 +416,7 @@ if (echo "test" | xargs -P 2 >/dev/null 2>&1) && [[ "$MaxAsync" != 0 ]]; then XargsAsync="-P $MaxAsync" else XargsAsync="" - [[ "$MaxAsync" != 0 ]] && printf "%bMissing POSIX xargs, consider installing 'findutils' for asynchronous lookups.%b\n" "$c_red" "$c_reset" + [[ "$MaxAsync" != 0 ]] && printf "%bMissing POSIX xargs, consider installing 'findutils' for asynchronous lookups.%b\n" "$c_yellow" "$c_reset" fi # Asynchronously check the image-hash of every running container VS the registry @@ -460,9 +468,10 @@ if [[ -n ${GotErrors[*]:-} ]]; then printf "%binfo:%b 'unauthorized' often means not found in a public registry.\n" "$c_blue" "$c_reset" fi if [[ -n ${GotUpdates[*]:-} ]]; then - printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" - [[ "$AutoMode" == false ]] && options || printf "%s\n" "${GotUpdates[@]}" - [[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n"; } + printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" + if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi + [[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}" + [[ "$Notify" == true ]] && { type -t send_notification &>/dev/null && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n"; } fi # Optionally get updates if there's any @@ -525,7 +534,7 @@ if [[ -n "${GotUpdates:-}" ]]; then if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]]; then ${DockerBin} ${CompleteConfs} stop; ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d else - ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${ContName} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } + ${DockerBin} ${CompleteConfs} ${ContEnvs} up -d || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; } fi done if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune dangling images? y/[n]: " AutoPrune; fi diff --git a/notify_templates/notify_telegram.sh b/notify_templates/notify_telegram.sh index 5113f35..b86f2a0 100644 --- a/notify_templates/notify_telegram.sh +++ b/notify_templates/notify_telegram.sh @@ -1,5 +1,5 @@ ### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. -NOTIFY_TELEGRAM_VERSION="v0.1" +NOTIFY_TELEGRAM_VERSION="v0.2" # # Copy/rename this file to notify.sh to enable the notification snippet. # Required receiving services must already be set up. @@ -8,12 +8,19 @@ NOTIFY_TELEGRAM_VERSION="v0.1" FromHost=$(hostname) trigger_notification() { + + if [[ "$PrintMarkdownURL" == true ]]; then + ParseMode="Markdown" + else + ParseMode="HTML" + fi + # Modify to fit your setup: TelegramToken="Your Telegram token here" TelegramChatId="Your Telegram ChatId here" TelegramUrl="https://api.telegram.org/bot$TelegramToken" TelegramTopicID=12345678 ## Set to 0 if not using specific topic within chat - TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false}" + TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false,\"parse_mode\": \"$ParseMode\",\"disable_web_page_preview\": true}" curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData" }