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.
|
- **Repo updates**, using `checkupdates` from pacman-contrib.
|
||||||
- **AUR updates** for packages in a local aurutils repository (`aur repo -u`).
|
- **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.
|
- **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:
|
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).
|
- `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 (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`).
|
- `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.
|
- `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.
|
# Name of the local aurutils repository.
|
||||||
#AUR_REPO="aur-local"
|
#AUR_REPO="aur-local"
|
||||||
|
|
||||||
# Stock kernel package -> your custom build of it. Replaces the whole list;
|
# Stock kernel package -> your custom build of it, to be reminded to rebuild
|
||||||
# kernels where either package isn't installed are skipped.
|
# it. Empty by default (no kernel check); kernels where either package isn't
|
||||||
# Set KERNELS=() to disable the kernel check.
|
# installed are skipped. Example:
|
||||||
#KERNELS=(
|
#KERNELS=(
|
||||||
# [linux]="linux-custom"
|
# [linux]="linux-custom"
|
||||||
# [linux-lts]="linux-lts-custom"
|
# [linux-lts]="linux-lts-custom"
|
||||||
# [linux-zen]="linux-zen-custom"
|
|
||||||
#)
|
#)
|
||||||
|
|
||||||
# Remind about .pacnew/.pacsave files to merge with pacdiff (0 to disable).
|
# 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
|
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() {
|
setup() {
|
||||||
export STUB_DATA=$BATS_TEST_TMPDIR/data
|
export STUB_DATA=$BATS_TEST_TMPDIR/data
|
||||||
export XDG_CONFIG_HOME=$BATS_TEST_TMPDIR/config
|
export XDG_CONFIG_HOME=$BATS_TEST_TMPDIR/config
|
||||||
export XDG_STATE_HOME=$BATS_TEST_TMPDIR/state
|
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
|
STATE=$XDG_STATE_HOME/update-notify
|
||||||
BIN=$BATS_TEST_TMPDIR/bin
|
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
|
# PATH holds only the stubs and the real tools the script needs, so a removed stub is a missing command
|
||||||
local tool
|
local tool
|
||||||
for tool in mkdir mv rm id timeout vercmp; do
|
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"; }
|
aur_updates() { printf '%s\n' "$@" > "$STUB_DATA/aur"; }
|
||||||
installed() { printf '%s\n' "$@" > "$STUB_DATA/installed"; }
|
installed() { printf '%s\n' "$@" > "$STUB_DATA/installed"; }
|
||||||
pacnew_files() { printf '%s\n' "$@" > "$STUB_DATA/pacdiff"; }
|
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
|
# Runs the script; notifications and stub calls are logged from this run only
|
||||||
run_script() {
|
run_script() {
|
||||||
@@ -178,7 +169,17 @@ assert_called() {
|
|||||||
|
|
||||||
# --- Kernel check ---
|
# --- 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" {
|
@test "stock kernel update notifies the rebuild below the threshold" {
|
||||||
|
custom_linux
|
||||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||||
run_script
|
run_script
|
||||||
@@ -189,6 +190,7 @@ assert_called() {
|
|||||||
|
|
||||||
@test "kernel rebuild joins the counts over the threshold" {
|
@test "kernel rebuild joins the counts over the threshold" {
|
||||||
config THRESHOLD=1
|
config THRESHOLD=1
|
||||||
|
custom_linux
|
||||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||||
run_script 0
|
run_script 0
|
||||||
assert_success
|
assert_success
|
||||||
@@ -196,6 +198,7 @@ assert_called() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "kernel check ignores pkgrel" {
|
@test "kernel check ignores pkgrel" {
|
||||||
|
custom_linux
|
||||||
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
installed "linux 6.1.1-1" "linux-custom 6.1.1-1"
|
||||||
repo_updates "linux 6.1.1-1 -> 6.1.1-2"
|
repo_updates "linux 6.1.1-1 -> 6.1.1-2"
|
||||||
run_script
|
run_script
|
||||||
@@ -204,6 +207,7 @@ assert_called() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "custom kernel already built into the repo isn't flagged" {
|
@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"
|
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"
|
repo_updates "linux 6.1.1-1 -> 6.1.2-1" "linux-custom 6.1.1-1 -> 6.1.2-1"
|
||||||
run_script
|
run_script
|
||||||
@@ -212,6 +216,7 @@ assert_called() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "kernels without a custom build installed are skipped" {
|
@test "kernels without a custom build installed are skipped" {
|
||||||
|
custom_linux
|
||||||
installed "linux 6.1.1-1"
|
installed "linux 6.1.1-1"
|
||||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
||||||
run_script
|
run_script
|
||||||
@@ -221,8 +226,7 @@ assert_called() {
|
|||||||
|
|
||||||
@test "custom kernel map comes from the config" {
|
@test "custom kernel map comes from the config" {
|
||||||
config "KERNELS=([linux-hardened]=linux-hardened-mine)"
|
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"
|
installed "linux-hardened 6.1.2-1" "linux-hardened-mine 6.1.1-1"
|
||||||
repo_updates "linux 6.1.1-1 -> 6.1.2-1"
|
|
||||||
run_script
|
run_script
|
||||||
assert_success
|
assert_success
|
||||||
assert_notification "Kernel update available" "Rebuild linux-hardened-mine (linux-hardened 6.1.2-1)"
|
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" {
|
@test "no reminders below the threshold" {
|
||||||
enable_stub git-monitor
|
enable_stub git-monitor
|
||||||
enable_stub fwupdmgr
|
enable_stub fwupdmgr
|
||||||
|
custom_linux
|
||||||
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
installed "linux 6.1.2-1" "linux-custom 6.1.1-1"
|
||||||
run_script
|
run_script
|
||||||
assert_notification "Kernel update available" "Rebuild linux-custom (linux 6.1.2-1)"
|
assert_notification "Kernel update available" "Rebuild linux-custom (linux 6.1.2-1)"
|
||||||
|
|||||||
+5
-7
@@ -6,12 +6,9 @@ set -u
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
THRESHOLD=30
|
THRESHOLD=30
|
||||||
AUR_REPO="aur-local"
|
AUR_REPO="aur-local"
|
||||||
# stock kernel package -> your custom build of it
|
# stock kernel package -> your custom build of it; none by default.
|
||||||
declare -A KERNELS=(
|
# Declared here so a [stock]=custom list in the config stays associative.
|
||||||
[linux]="linux-custom"
|
declare -A KERNELS=()
|
||||||
[linux-lts]="linux-lts-custom"
|
|
||||||
[linux-zen]="linux-zen-custom"
|
|
||||||
)
|
|
||||||
PACNEW_CHECK=1 # remind about .pacnew/.pacsave files (0 to disable)
|
PACNEW_CHECK=1 # remind about .pacnew/.pacsave files (0 to disable)
|
||||||
REBOOT_CHECK=1 # remind to reboot after a kernel upgrade (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"
|
config_file="${XDG_CONFIG_HOME:-$HOME/.config}/update-notify/config"
|
||||||
@@ -137,8 +134,9 @@ if [[ $PACNEW_CHECK != 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
running_kernel=$(uname -r)
|
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
|
# 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_items+=("reboot $running_kernel")
|
||||||
maint_lines+=("Reboot to load the new kernel (running $running_kernel)")
|
maint_lines+=("Reboot to load the new kernel (running $running_kernel)")
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user