From 4d47fd31db7c9659fb4b3ca71f1d0b8f1d1e5d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Wed, 25 Jan 2023 09:26:00 +0100 Subject: [PATCH] Make check updates more generic, fix failure notify requirements and update docs --- README.md | 33 ++++++---- _man/src/check_updates.1.md | 2 + _man/src/system-helpers.1.md | 2 +- usr/local/bin/check_updates | 90 ++++++++++++++++++---------- usr/local/bin/systemd_failure_notify | 5 +- usr/share/man/man1/check_updates.1 | 6 ++ 6 files changed, 93 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 55cfe98..049ea2f 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,30 @@ # README -system-helpers is a collection of helper systemd services, systemd timers and -shell scripts for common configuration and tasks like +system-helpers - Collection of helper systemd services, systemd timers and +shell scripts for common configuration. -* checking if systemd services and timers are running -* borgmatic backup -* restic backup -* checking if docker containers are running -* batch docker-compose upgrades -* docker housekeeping for removing unused docker containers, volumes and images -* dynamic dns update -* update check for pacman -* memory and disk checks +**system-helpers** collection provides the following helpers + +- checking if systemd services and timers are running (see **man systemd_check**) +- borgmatic backup (see exposed systemd services *borgmatic@* which require a valid *borgmatic.yml* file in */etc/borgmatic* or your **$HOME/.config/borgmatic**) +- restic backup (see */usr/share/doc/system-helpers/restic* for an example *mybackup*) +- checking if docker containers are running (see **man docker_check**) +- batch docker-compose upgrades (see **man docker_compose_update**) +- dynamic dns update (see **man docker_compose_update**) +- memory and disk checks (see **man disk_space_alert** and **man memory_usage_alert**) +- docker housekeeping for removing unused docker containers, volumes and images +- update check for pacman (ArchLinux specific, see **man check_updates**) Provided systemd services mostly support mail notifications if they have failed -via systemd_failure_notify. +via `systemd_failure_notify`. See `/usr/share/doc/system-helpers` for example configurations which should be copied inside $HOME or /etc depending on the helper script. ## Installation +### Package manager for Arch Linux + 1. Build a `pacman` package for ArchLinux via `makepkg -csi` inside the `_pkg/` folder 2. Alternatively, use `./sync` from the git clone and pick an action which should be self-explaining 3. Use the custom provided ArchLinux repository hosted at `aur.myservermanager.com` @@ -31,6 +35,11 @@ SigLevel = Never Server = https://aur.myservermanager.com ``` +### system-helpers-sync script to synchronize files to locations + +1. Clone this repository +2. Run `./system-helpers-sync` and use the option you like to use + ## Usage Services and scripts don't depend on each other but have hints that they can be diff --git a/_man/src/check_updates.1.md b/_man/src/check_updates.1.md index 26acb00..423449f 100644 --- a/_man/src/check_updates.1.md +++ b/_man/src/check_updates.1.md @@ -17,6 +17,8 @@ If no *CONFIG_FILE* is provided, **check_updates** tries to read from *$HOME/.ch The following are at least required for the script to work:\ - **CHECK_UPDATES_MAIL_ADDRESS=""** which requires *mail.rc* to be configured and '*mailx*' command has be available. +- **CHECK_UPDATES_UPDATES_CMD** is the command for retrieving which updates are available, by default it's set to */usr/bin/checkupdates* (Arch Linux default). +- **CHECK_UPDATES_UPDATES_AMOUNT_CMD** is the command used to determine the amount of updates, by default it's set to */usr/bin/checkupdates | wc -l* (Arch Linux default). You can copy this script to */usr/local/bin* and use create a custom **CONFIG_FILE** as user. diff --git a/_man/src/system-helpers.1.md b/_man/src/system-helpers.1.md index 53da59b..eba39d1 100644 --- a/_man/src/system-helpers.1.md +++ b/_man/src/system-helpers.1.md @@ -4,7 +4,7 @@ # NAME system-helpers - Collection of helper systemd services, systemd timers and -shell scripts for common configuration. Designed for use with ArchLinux, although most scripts should work on any distribution. +shell scripts for common configuration. # DESCRIPTION **system-helpers** collection provides the following helpers diff --git a/usr/local/bin/check_updates b/usr/local/bin/check_updates index e0646aa..e96a949 100755 --- a/usr/local/bin/check_updates +++ b/usr/local/bin/check_updates @@ -2,65 +2,95 @@ # usage usage() { -USAGE=$(cat < /dev/null || { echo "Requiring 'hostname' but it's not installed"; exit 1; } + type mailx &> /dev/null || { echo "Requiring 'mailx' but it's not installed"; exit 1; } +} + source_config "$1" "$HOME/.check_updates.conf" "/etc/check_updates.conf" +apply_defaults +check_required -if [ "$UPDATES_AMOUNT" -gt "0" ]; then - mailx -s "[updates $HOSTNAME]" "$CHECK_UPDATES_MAIL_ADDRESS" << EOF -There are $UPDATES_AMOUNT updates available on $HOSTNAME. +HOSTNAME=$(hostname) +CHECK_UPDATES_UPDATES=$(eval "${CHECK_UPDATES_UPDATES_CMD}") +CHECK_UPDATES_UPDATES_AMOUNT=$(eval "${CHECK_UPDATES_UPDATES_AMOUNT_CMD}") -$UPDATES +if [[ "$CHECK_UPDATES_UPDATES_AMOUNT" -gt "0" ]]; then + SUBJECT="[updates ${HOSTNAME}]" + MESSAGE=$( + cat < /dev/null || echo "Requiring 'mailx' but it's not installed"; exit 1 + type mailx &> /dev/null || { echo "Requiring 'mailx' but it's not installed"; exit 1; } + fi if [[ "${gotifyEnabled}" == "true" ]]; then - type gotify &> /dev/null || echo "Requiring 'gotify' but it's not installed"; exit 1 + type gotify &> /dev/null || { echo "Requiring 'gotify' but it's not installed"; exit 1; } fi } diff --git a/usr/share/man/man1/check_updates.1 b/usr/share/man/man1/check_updates.1 index 3a0d41d..e76742d 100644 --- a/usr/share/man/man1/check_updates.1 +++ b/usr/share/man/man1/check_updates.1 @@ -46,6 +46,12 @@ The following are at least required for the script to work: - \f[B]CHECK_UPDATES_MAIL_ADDRESS=\[lq]\[lq]\f[R] which requires \f[I]mail.rc\f[R] to be configured and `\f[I]mailx\f[R]' command has be available. +- \f[B]CHECK_UPDATES_UPDATES_CMD\f[R] is the command for retrieving +which updates are available, by default it\[cq]s set to +\f[I]/usr/bin/checkupdates\f[R] (Arch Linux default). +- \f[B]CHECK_UPDATES_UPDATES_AMOUNT_CMD\f[R] is the command used to +determine the amount of updates, by default it\[cq]s set to +\f[I]/usr/bin/checkupdates | wc -l\f[R] (Arch Linux default). .PP You can copy this script to \f[I]/usr/local/bin\f[R] and use create a custom \f[B]CONFIG_FILE\f[R] as user.