Empty the default KERNELS map and make tests chroot-safe
Custom kernels are now set only in the config, so the defaults suit any system. The reboot check's modules folder can be overridden with UPDATE_NOTIFY_MODULES_DIR, so the tests no longer need an installed kernel.
This commit is contained in:
@@ -6,7 +6,7 @@ update-notify runs on a systemd user timer and checks:
|
||||
|
||||
- **Repo updates**, using `checkupdates` from pacman-contrib.
|
||||
- **AUR updates** for packages in a local aurutils repository (`aur repo -u`).
|
||||
- **Custom kernel rebuilds**: when a stock kernel (e.g. `linux-lts`) has a newer version than your custom build of it (e.g. `linux-lts-custom`).
|
||||
- **Custom kernel rebuilds**: when a stock kernel (e.g. `linux-lts`) has a newer version than your custom build of it (e.g. `linux-lts-custom`), for the kernels set in `KERNELS`.
|
||||
- **Maintenance**: `.pacnew`/`.pacsave` files to merge (`pacdiff -o`), and a reboot after the running kernel was upgraded.
|
||||
|
||||
It sends one notification, and only when its content changes since the last one:
|
||||
@@ -80,7 +80,7 @@ Settings are read from `$XDG_CONFIG_HOME/update-notify/config` (default `~/.conf
|
||||
|
||||
- `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 (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.
|
||||
- `KERNELS`: maps each stock kernel package to its custom build, e.g. `KERNELS=([linux-lts]=linux-lts-custom)`. Empty by default, which disables the kernel check. Kernels where either package isn't installed are skipped.
|
||||
- `PACNEW_CHECK`: set to `0` to disable the `.pacnew`/`.pacsave` reminder (default `1`).
|
||||
- `REBOOT_CHECK`: set to `0` to disable the reboot reminder (default `1`). A reboot is needed when the running kernel's `/usr/lib/modules/<version>/vmlinuz` is gone.
|
||||
|
||||
|
||||
+3
-4
@@ -9,13 +9,12 @@
|
||||
# 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.
|
||||
# Stock kernel package -> your custom build of it, to be reminded to rebuild
|
||||
# it. Empty by default (no kernel check); kernels where either package isn't
|
||||
# installed are skipped. Example:
|
||||
#KERNELS=(
|
||||
# [linux]="linux-custom"
|
||||
# [linux-lts]="linux-lts-custom"
|
||||
# [linux-zen]="linux-zen-custom"
|
||||
#)
|
||||
|
||||
# Remind about .pacnew/.pacsave files to merge with pacdiff (0 to disable).
|
||||
|
||||
+22
-17
@@ -7,27 +7,17 @@ bats_load_library bats-assert
|
||||
|
||||
SCRIPT=$BATS_TEST_DIRNAME/../update-notify
|
||||
|
||||
setup_file() {
|
||||
# A kernel release whose vmlinuz exists, so the reboot check stays quiet unless a test fakes one
|
||||
local f
|
||||
for f in /usr/lib/modules/*/vmlinuz; do
|
||||
[[ -e $f ]] || continue
|
||||
f=${f%/vmlinuz}
|
||||
export INSTALLED_KERNEL=${f##*/}
|
||||
return
|
||||
done
|
||||
echo "no /usr/lib/modules/*/vmlinuz found" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
setup() {
|
||||
export STUB_DATA=$BATS_TEST_TMPDIR/data
|
||||
export XDG_CONFIG_HOME=$BATS_TEST_TMPDIR/config
|
||||
export XDG_STATE_HOME=$BATS_TEST_TMPDIR/state
|
||||
export STUB_KERNEL=$INSTALLED_KERNEL
|
||||
# The running kernel has its vmlinuz, so the reboot check stays quiet unless a test changes STUB_KERNEL
|
||||
export STUB_KERNEL=6.1.1-test
|
||||
export UPDATE_NOTIFY_MODULES_DIR=$BATS_TEST_TMPDIR/modules
|
||||
STATE=$XDG_STATE_HOME/update-notify
|
||||
BIN=$BATS_TEST_TMPDIR/bin
|
||||
mkdir -p "$STUB_DATA" "$XDG_CONFIG_HOME/update-notify" "$BIN"
|
||||
mkdir -p "$STUB_DATA" "$XDG_CONFIG_HOME/update-notify" "$BIN" "$UPDATE_NOTIFY_MODULES_DIR/$STUB_KERNEL"
|
||||
touch "$UPDATE_NOTIFY_MODULES_DIR/$STUB_KERNEL/vmlinuz"
|
||||
# PATH holds only the stubs and the real tools the script needs, so a removed stub is a missing command
|
||||
local tool
|
||||
for tool in mkdir mv rm id timeout vercmp; do
|
||||
@@ -45,6 +35,7 @@ repo_updates() { printf '%s\n' "$@" > "$STUB_DATA/checkupdates"; }
|
||||
aur_updates() { printf '%s\n' "$@" > "$STUB_DATA/aur"; }
|
||||
installed() { printf '%s\n' "$@" > "$STUB_DATA/installed"; }
|
||||
pacnew_files() { printf '%s\n' "$@" > "$STUB_DATA/pacdiff"; }
|
||||
custom_linux() { config "KERNELS=([linux]=linux-custom)"; }
|
||||
|
||||
# Runs the script; notifications and stub calls are logged from this run only
|
||||
run_script() {
|
||||
@@ -178,7 +169,17 @@ assert_called() {
|
||||
|
||||
# --- Kernel check ---
|
||||
|
||||
@test "no kernel check by default" {
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
assert_success
|
||||
assert_no_notification
|
||||
assert_pending "threshold 30" "repo linux 6.1.2-1"
|
||||
}
|
||||
|
||||
@test "stock kernel update notifies the rebuild below the threshold" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -189,6 +190,7 @@ assert_called() {
|
||||
|
||||
@test "kernel rebuild joins the counts over the threshold" {
|
||||
config THRESHOLD=1
|
||||
custom_linux
|
||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||
run_script 0
|
||||
assert_success
|
||||
@@ -196,6 +198,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "kernel check ignores pkgrel" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.1-2"
|
||||
run_script
|
||||
@@ -204,6 +207,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "custom kernel already built into the repo isn't flagged" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1" "linux-custom 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -212,6 +216,7 @@ assert_called() {
|
||||
}
|
||||
|
||||
@test "kernels without a custom build installed are skipped" {
|
||||
custom_linux
|
||||
installed "linux 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
run_script
|
||||
@@ -221,8 +226,7 @@ assert_called() {
|
||||
|
||||
@test "custom kernel map comes from the config" {
|
||||
config "KERNELS=([linux-hardened]=linux-hardened-mine)"
|
||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1" "linux-hardened 6.1.2-1" "linux-hardened-mine 6.1.1-1"
|
||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||
installed "linux-hardened 6.1.2-1" "linux-hardened-mine 6.1.1-1"
|
||||
run_script
|
||||
assert_success
|
||||
assert_notification "Kernel update available" "Rebuild linux-hardened-mine (linux-hardened 6.1.2-1)"
|
||||
@@ -398,6 +402,7 @@ assert_called() {
|
||||
@test "no reminders below the threshold" {
|
||||
enable_stub git-monitor
|
||||
enable_stub fwupdmgr
|
||||
custom_linux
|
||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||
run_script
|
||||
assert_notification "Kernel update available" "Rebuild linux-custom (linux 6.1.2-1)"
|
||||
|
||||
+5
-7
@@ -6,12 +6,9 @@ set -u
|
||||
# ---------------------------------------------------------------------------
|
||||
THRESHOLD=30
|
||||
AUR_REPO="aur-local"
|
||||
# stock kernel package -> your custom build of it
|
||||
declare -A KERNELS=(
|
||||
[linux]="linux-custom"
|
||||
[linux-lts]="linux-lts-custom"
|
||||
[linux-zen]="linux-zen-custom"
|
||||
)
|
||||
# stock kernel package -> your custom build of it; none by default.
|
||||
# Declared here so a [stock]=custom list in the config stays associative.
|
||||
declare -A KERNELS=()
|
||||
PACNEW_CHECK=1 # remind about .pacnew/.pacsave files (0 to disable)
|
||||
REBOOT_CHECK=1 # remind to reboot after a kernel upgrade (0 to disable)
|
||||
config_file="${XDG_CONFIG_HOME:-$HOME/.config}/update-notify/config"
|
||||
@@ -137,8 +134,9 @@ if [[ $PACNEW_CHECK != 0 ]]; then
|
||||
fi
|
||||
fi
|
||||
running_kernel=$(uname -r)
|
||||
modules_dir=${UPDATE_NOTIFY_MODULES_DIR:-/usr/lib/modules} # override for tests (build chroots have no kernel)
|
||||
# vmlinuz belongs to the kernel package, while DKMS files can keep the folder around
|
||||
if [[ $REBOOT_CHECK != 0 && ! -e /usr/lib/modules/$running_kernel/vmlinuz ]]; then
|
||||
if [[ $REBOOT_CHECK != 0 && ! -e $modules_dir/$running_kernel/vmlinuz ]]; then
|
||||
maint_items+=("reboot $running_kernel")
|
||||
maint_lines+=("Reboot to load the new kernel (running $running_kernel)")
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user