aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-grub
blob: 20fd296be950702205c187efa8009041614335a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# udt-grub: rebuild the GRUB theme and say what root has to copy into /boot.
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
# Licensed under the GNU General Public License v2 only.
#
# Built, not installed: GRUB reads /boot before /home is mounted, so the theme
# is a root-owned copy of grub-theme-udt's dist/udt/, and this script only
# prints the command that refreshes it. Its background is a snapshot of the
# wallpaper and its colours come from the scheme, so both a wallpaper change
# and a scheme switch leave the copy stale.
#
# udt-accent starts this detached on every run; install.sh runs it in the
# foreground. A notification goes out only when an installed theme is stale:
# a machine that never installed it has nothing to refresh.

repo="$(dirname "$(readlink -f "$0")")/.."
grub_repo="$(realpath -m "$repo/../grub-theme-udt")"
[ -x "$grub_repo/build" ] || exit 0

# install.sh runs udt-accent, which starts this detached, and then runs this
# itself. build swaps dist/udt/ in with a rename, so two at once can collide.
mkdir -p "$grub_repo/dist"
exec 9>"$grub_repo/dist/.lock"
flock 9

"$grub_repo/build" >/dev/null || { echo "grub: its build failed, theme not refreshed" >&2; exit 1; }

theme=/boot/grub/themes/udt
copy="rm -rf $theme && cp -r \"$grub_repo/dist/udt\" /boot/grub/themes/"

if diff -rq "$grub_repo/dist/udt" "$theme" >/dev/null 2>&1; then
    echo "grub theme: up to date"
elif [ -d "$theme" ]; then
    echo "grub theme: refresh as root"
    echo "  $copy"
    command -v notify-send >/dev/null 2>&1 &&
        notify-send -a udt "grub: theme rebuilt" "As root:
$copy"
else
    echo "grub theme: run these as root to install it"
    echo "  $copy"
fi
grep -q "^GRUB_THEME=\"$theme/theme.txt\"" /etc/default/grub 2>/dev/null || {
    echo "  # once: GRUB_THEME=\"$theme/theme.txt\" in /etc/default/grub, then"
    echo "  grub-mkconfig -o /boot/grub/grub.cfg"
}
# The panel title falls back to the OS name until one is set.
[ -n "$("$repo/bin/udt-machine-name")" ] ||
    echo "  # optional, the panel title: sudo \"$repo/bin/udt-machine-name\" \"My Machine\""
exit 0