diff --git a/README.md b/README.md index b5c0c1c..2c80500 100644 --- a/README.md +++ b/README.md @@ -48,28 +48,22 @@ The timer runs 5 minutes after boot, then every 6 hours. update-notify [threshold] ``` -`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. The default is 30. - -To change the threshold used by the timer, override the service: - -``` -systemctl --user edit update-notify.service -``` - -```ini -[Service] -ExecStart= -ExecStart=/usr/bin/update-notify 50 -``` +`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. It overrides the `THRESHOLD` setting below. ## Configuration -These settings are at the top of the script: +Settings are read from `$XDG_CONFIG_HOME/update-notify/config` (default `~/.config/update-notify/config`), a bash file that is sourced by the script. All settings are optional: +- `THRESHOLD`: minimum number of updates before update counts are shown (default 30). - `AUR_REPO`: name of the local aurutils repository (default `aur-local`). -- `KERNELS`: maps each stock kernel package to its custom build. Kernels where either package isn't installed are skipped. +- `KERNELS`: maps each stock kernel package to its custom build (default: `linux`, `linux-lts` and `linux-zen` to `-custom`). Kernels where either package isn't installed are skipped. Set `KERNELS=()` to disable the kernel check. -Changes to the installed script are overwritten on upgrade, so change them in the source and rebuild the package. +A commented sample config is installed with the package. To start from it: + +``` +mkdir -p ~/.config/update-notify +cp /usr/share/doc/update-notify/config.example ~/.config/update-notify/config +``` Kernel versions are compared without `pkgrel`, so a stock packaging-only update doesn't trigger a rebuild reminder. A custom build already in the local repository but not installed yet counts as up to date. diff --git a/config.example b/config.example new file mode 100644 index 0000000..0558b4e --- /dev/null +++ b/config.example @@ -0,0 +1,19 @@ +# update-notify configuration, sourced as bash. +# Copy to ~/.config/update-notify/config and uncomment what you want to change. +# The values shown are the defaults. + +# Minimum number of updates (repo + AUR) before update counts are shown. +# The command-line argument takes precedence. +#THRESHOLD=30 + +# Name of the local aurutils repository. +#AUR_REPO="aur-local" + +# Stock kernel package -> your custom build of it. Replaces the whole list; +# kernels where either package isn't installed are skipped. +# Set KERNELS=() to disable the kernel check. +#KERNELS=( +# [linux]="linux-custom" +# [linux-lts]="linux-lts-custom" +# [linux-zen]="linux-zen-custom" +#) diff --git a/update-notify b/update-notify index e60803a..385811c 100755 --- a/update-notify +++ b/update-notify @@ -2,20 +2,27 @@ set -u # --------------------------------------------------------------------------- -# Config +# Config: defaults, overridden by the config file, then by the argument # --------------------------------------------------------------------------- -threshold=${1:-30} +THRESHOLD=30 AUR_REPO="aur-local" -# stock kernel package -> your custom build of it. Add or remove entries freely. +# stock kernel package -> your custom build of it declare -A KERNELS=( [linux]="linux-custom" [linux-lts]="linux-lts-custom" [linux-zen]="linux-zen-custom" ) +config_file="${XDG_CONFIG_HOME:-$HOME/.config}/update-notify/config" state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/update-notify" -[[ $threshold =~ ^[0-9]+$ ]] || { echo "Threshold must be a number" >&2; exit 1; } -threshold=$((10#$threshold)) # force base 10, so e.g. "08" isn't read as octal +if [[ -r $config_file ]]; then + # shellcheck source=/dev/null + source "$config_file" +fi +THRESHOLD=${1:-$THRESHOLD} + +[[ $THRESHOLD =~ ^[0-9]+$ ]] || { echo "Threshold must be a number" >&2; exit 1; } +THRESHOLD=$((10#$THRESHOLD)) # force base 10, so e.g. "08" isn't read as octal mkdir -p "$state_dir" # notify-send from cron/systemd needs the session bus address @@ -122,7 +129,7 @@ done # - update counts and reminders only when the threshold is reached # --------------------------------------------------------------------------- over_threshold=0 -(( updates >= threshold )) && over_threshold=1 +(( updates >= THRESHOLD )) && over_threshold=1 parts=() if (( over_threshold )); then diff --git a/update-notify.service b/update-notify.service index dfa0bca..9fce723 100644 --- a/update-notify.service +++ b/update-notify.service @@ -2,5 +2,5 @@ Description=Notify if updates are available [Service] -ExecStart=/usr/bin/update-notify 30 +ExecStart=/usr/bin/update-notify Type=oneshot