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:
@@ -48,28 +48,22 @@ The timer runs 5 minutes after boot, then every 6 hours.
|
|||||||
update-notify [threshold]
|
update-notify [threshold]
|
||||||
```
|
```
|
||||||
|
|
||||||
`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. The default is 30.
|
`threshold` is the minimum number of updates (repo + AUR) before update counts are shown. It overrides the `THRESHOLD` setting below.
|
||||||
|
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## 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`).
|
- `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.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -2,20 +2,27 @@
|
|||||||
set -u
|
set -u
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Config
|
# Config: defaults, overridden by the config file, then by the argument
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
threshold=${1:-30}
|
THRESHOLD=30
|
||||||
AUR_REPO="aur-local"
|
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=(
|
declare -A KERNELS=(
|
||||||
[linux]="linux-custom"
|
[linux]="linux-custom"
|
||||||
[linux-lts]="linux-lts-custom"
|
[linux-lts]="linux-lts-custom"
|
||||||
[linux-zen]="linux-zen-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"
|
state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/update-notify"
|
||||||
|
|
||||||
[[ $threshold =~ ^[0-9]+$ ]] || { echo "Threshold must be a number" >&2; exit 1; }
|
if [[ -r $config_file ]]; then
|
||||||
threshold=$((10#$threshold)) # force base 10, so e.g. "08" isn't read as octal
|
# 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"
|
mkdir -p "$state_dir"
|
||||||
|
|
||||||
# notify-send from cron/systemd needs the session bus address
|
# 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
|
# - update counts and reminders only when the threshold is reached
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
over_threshold=0
|
over_threshold=0
|
||||||
(( updates >= threshold )) && over_threshold=1
|
(( updates >= THRESHOLD )) && over_threshold=1
|
||||||
|
|
||||||
parts=()
|
parts=()
|
||||||
if (( over_threshold )); then
|
if (( over_threshold )); then
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
Description=Notify if updates are available
|
Description=Notify if updates are available
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/update-notify 30
|
ExecStart=/usr/bin/update-notify
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
|
|||||||
Reference in New Issue
Block a user