Read settings from a config file

Source ~/.config/update-notify/config to override THRESHOLD, AUR_REPO
and KERNELS, so settings survive package upgrades. The threshold
argument still takes precedence, so drop it from the service. Add a
commented sample config.
This commit is contained in:
Daniele Fucini
2026-10-14 18:56:17 +02:00
parent aca5a0213e
commit 8c94be5a08
4 changed files with 43 additions and 23 deletions
+10 -16
View File
@@ -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 `<name>-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.
+19
View File
@@ -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"
#)
+13 -6
View File
@@ -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
+1 -1
View File
@@ -2,5 +2,5 @@
Description=Notify if updates are available
[Service]
ExecStart=/usr/bin/update-notify 30
ExecStart=/usr/bin/update-notify
Type=oneshot