feat: provision Chrome and DVD codecs without a manual step
A fresh classroom needed two things installed by hand on every box: Google Chrome, which is not in Debian, and the DVD codecs, which Debian cannot ship. Both now happen on their own. ekklesia-classroom-provision.service runs after every boot and does the work that needs the network and the apt lock, neither of which a package postinst can have. Each step returns immediately if it is already done, so a provisioned machine costs nothing and a machine that was offline the first time gets another go at the next boot. Nothing there is allowed to fail the boot: a classroom with no DVD codecs is still a working classroom, and it says so in the log rather than silently. The postinst enables the service but deliberately does not start it. Every OTA update reboots the moment the install finishes, and an apt run killed by that reboot would leave dpkg half-configured. Chrome comes from Google's own repository rather than a one-off .deb, so it keeps getting security updates. Google's package migrates whatever we write into a deb822 file of its own, so the repository is looked for across every source file instead of only the one we would write; otherwise a machine that had Chrome removed would end up with two copies of the same repository. The DVD codec helper previously assumed deb822 sources and did nothing on a machine using a classic /etc/apt/sources.list, which is what the hardware actually runs. It now handles both formats, and only ever adds a missing component to an existing Debian entry — so it cannot produce a duplicate repository or a duplicate component however many times it runs, and third-party repositories like Chrome's are never touched. It also answers libdvd-pkg's debconf questions, so nothing blocks on a prompt in a service with no terminal. Tested against fixture APT trees for classic sources.list, deb822 .sources, contrib already enabled, repeated runs, third-party repositories and the awkward real lines: bracketed options, indentation, trailing comments and flat repositories. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c81fc1b0b9
commit
a3dba6e8fb
Executable
+215
@@ -0,0 +1,215 @@
|
||||
#!/bin/bash
|
||||
set -uo pipefail
|
||||
|
||||
# Tests contrib enabling against fixture APT trees: classic sources.list,
|
||||
# deb822 .sources, contrib already present, and repeated runs.
|
||||
#
|
||||
# tests/test-classroom-dvd-css-setup.sh
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
SCRIPT="$ROOT/scripts/classroom-dvd-css-setup"
|
||||
|
||||
WORK="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
passed=0
|
||||
failed=0
|
||||
|
||||
check() {
|
||||
local label="$1" expected="$2" actual="$3"
|
||||
|
||||
if [[ "$actual" == "$expected" ]]; then
|
||||
echo " ok $label"
|
||||
passed=$((passed + 1))
|
||||
else
|
||||
echo " FAIL $label"
|
||||
echo " expected: $expected"
|
||||
echo " got: $actual"
|
||||
failed=$((failed + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
# A fixture APT tree. Prints the root.
|
||||
fixture() {
|
||||
local name="$1"
|
||||
local root="$WORK/$name"
|
||||
|
||||
rm -rf "$root"
|
||||
mkdir -p "$root/etc/apt/sources.list.d"
|
||||
|
||||
echo "$root"
|
||||
}
|
||||
|
||||
enable_contrib() {
|
||||
CLASSROOM_APT_ROOT="$1" python3 "$SCRIPT" --enable-contrib-only 2>&1
|
||||
}
|
||||
|
||||
# ------------------------------------------------- 1. classic sources.list
|
||||
|
||||
echo "1. classic /etc/apt/sources.list"
|
||||
|
||||
root="$(fixture classic)"
|
||||
cat > "$root/etc/apt/sources.list" <<'LIST'
|
||||
# Debian Trixie
|
||||
deb http://deb.debian.org/debian/ trixie main non-free-firmware
|
||||
deb-src http://deb.debian.org/debian/ trixie main non-free-firmware
|
||||
|
||||
deb http://security.debian.org/debian-security trixie-security main non-free-firmware
|
||||
deb http://deb.debian.org/debian/ trixie-updates main non-free-firmware
|
||||
LIST
|
||||
|
||||
enable_contrib "$root" > /dev/null
|
||||
|
||||
check "binary entry gains contrib" \
|
||||
"deb http://deb.debian.org/debian/ trixie main non-free-firmware contrib" \
|
||||
"$(sed -n '2p' "$root/etc/apt/sources.list")"
|
||||
check "source entry gains contrib" \
|
||||
"deb-src http://deb.debian.org/debian/ trixie main non-free-firmware contrib" \
|
||||
"$(sed -n '3p' "$root/etc/apt/sources.list")"
|
||||
check "security entry gains contrib" \
|
||||
"deb http://security.debian.org/debian-security trixie-security main non-free-firmware contrib" \
|
||||
"$(sed -n '5p' "$root/etc/apt/sources.list")"
|
||||
check "comment line untouched" "# Debian Trixie" "$(sed -n '1p' "$root/etc/apt/sources.list")"
|
||||
check "line count unchanged" "6" "$(wc -l < "$root/etc/apt/sources.list")"
|
||||
check "contrib appears once per line" "0" \
|
||||
"$(grep -c 'contrib.*contrib' "$root/etc/apt/sources.list")"
|
||||
|
||||
# ------------------------------------------------------------ 2. deb822
|
||||
|
||||
echo "2. deb822 .sources"
|
||||
|
||||
root="$(fixture deb822)"
|
||||
cat > "$root/etc/apt/sources.list.d/debian.sources" <<'SOURCES'
|
||||
Types: deb deb-src
|
||||
URIs: http://deb.debian.org/debian/
|
||||
Suites: trixie trixie-updates
|
||||
Components: main non-free-firmware
|
||||
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
|
||||
|
||||
Types: deb
|
||||
URIs: http://security.debian.org/debian-security/
|
||||
Suites: trixie-security
|
||||
Components: main non-free-firmware
|
||||
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
|
||||
SOURCES
|
||||
|
||||
enable_contrib "$root" > /dev/null
|
||||
|
||||
check "first stanza gains contrib" \
|
||||
"Components: main non-free-firmware contrib" \
|
||||
"$(sed -n '4p' "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
check "second stanza gains contrib" \
|
||||
"Components: main non-free-firmware contrib" \
|
||||
"$(sed -n '10p' "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
check "other fields untouched" \
|
||||
"URIs: http://deb.debian.org/debian/" \
|
||||
"$(sed -n '2p' "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
check "stanza separator kept" "" \
|
||||
"$(sed -n '6p' "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
|
||||
# ------------------------------------------------ 3. contrib already there
|
||||
|
||||
echo "3. contrib already enabled"
|
||||
|
||||
root="$(fixture already)"
|
||||
cat > "$root/etc/apt/sources.list" <<'LIST'
|
||||
deb http://deb.debian.org/debian/ trixie main contrib non-free-firmware
|
||||
LIST
|
||||
cat > "$root/etc/apt/sources.list.d/extra.sources" <<'SOURCES'
|
||||
Types: deb
|
||||
URIs: http://deb.debian.org/debian/
|
||||
Suites: trixie
|
||||
Components: main contrib
|
||||
SOURCES
|
||||
|
||||
before_list="$(cat "$root/etc/apt/sources.list")"
|
||||
before_sources="$(cat "$root/etc/apt/sources.list.d/extra.sources")"
|
||||
|
||||
out="$(enable_contrib "$root")"
|
||||
|
||||
check "reports nothing to do" "[classroom-dvd-css-setup] contrib was already enabled" "$out"
|
||||
check "sources.list byte-identical" "$before_list" "$(cat "$root/etc/apt/sources.list")"
|
||||
check ".sources byte-identical" "$before_sources" "$(cat "$root/etc/apt/sources.list.d/extra.sources")"
|
||||
|
||||
# ------------------------------------------------------- 4. repeated runs
|
||||
|
||||
echo "4. repeated runs are idempotent"
|
||||
|
||||
root="$(fixture repeat)"
|
||||
cat > "$root/etc/apt/sources.list" <<'LIST'
|
||||
deb http://deb.debian.org/debian/ trixie main non-free-firmware
|
||||
LIST
|
||||
cat > "$root/etc/apt/sources.list.d/debian.sources" <<'SOURCES'
|
||||
Types: deb
|
||||
URIs: http://deb.debian.org/debian/
|
||||
Suites: trixie
|
||||
Components: main
|
||||
SOURCES
|
||||
|
||||
enable_contrib "$root" > /dev/null
|
||||
first_list="$(cat "$root/etc/apt/sources.list")"
|
||||
first_sources="$(cat "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
|
||||
for _ in 1 2 3; do
|
||||
enable_contrib "$root" > /dev/null
|
||||
done
|
||||
|
||||
check "sources.list unchanged after 4 runs" "$first_list" "$(cat "$root/etc/apt/sources.list")"
|
||||
check ".sources unchanged after 4 runs" "$first_sources" "$(cat "$root/etc/apt/sources.list.d/debian.sources")"
|
||||
check "exactly one contrib in sources.list" "1" \
|
||||
"$(grep -o 'contrib' "$root/etc/apt/sources.list" | wc -l)"
|
||||
check "exactly one contrib in .sources" "1" \
|
||||
"$(grep -o 'contrib' "$root/etc/apt/sources.list.d/debian.sources" | wc -l)"
|
||||
check "no repository was added" "1" "$(wc -l < "$root/etc/apt/sources.list")"
|
||||
|
||||
# ------------------------------------------- 5. third-party repos untouched
|
||||
|
||||
echo "5. third-party repositories are left alone"
|
||||
|
||||
root="$(fixture thirdparty)"
|
||||
cat > "$root/etc/apt/sources.list" <<'LIST'
|
||||
deb http://deb.debian.org/debian/ trixie main
|
||||
LIST
|
||||
chrome='deb [arch=amd64 signed-by=/etc/apt/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main'
|
||||
echo "$chrome" > "$root/etc/apt/sources.list.d/google-chrome.list"
|
||||
|
||||
enable_contrib "$root" > /dev/null
|
||||
|
||||
check "chrome repository untouched" "$chrome" \
|
||||
"$(cat "$root/etc/apt/sources.list.d/google-chrome.list")"
|
||||
check "debian entry still updated" \
|
||||
"deb http://deb.debian.org/debian/ trixie main contrib" \
|
||||
"$(cat "$root/etc/apt/sources.list")"
|
||||
|
||||
# ---------------------------------------------------- 6. awkward real lines
|
||||
|
||||
echo "6. options, comments and flat repositories"
|
||||
|
||||
root="$(fixture awkward)"
|
||||
cat > "$root/etc/apt/sources.list" <<'LIST'
|
||||
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian/ trixie main
|
||||
deb http://deb.debian.org/debian/ trixie main # indented, with a comment
|
||||
deb http://deb.debian.org/debian/ ./
|
||||
# deb http://deb.debian.org/debian/ trixie main
|
||||
LIST
|
||||
|
||||
enable_contrib "$root" > /dev/null
|
||||
|
||||
check "bracketed options preserved" \
|
||||
"deb [arch=amd64 signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] http://deb.debian.org/debian/ trixie main contrib" \
|
||||
"$(sed -n '1p' "$root/etc/apt/sources.list")"
|
||||
check "indent and trailing comment preserved" \
|
||||
" deb http://deb.debian.org/debian/ trixie main contrib # indented, with a comment" \
|
||||
"$(sed -n '2p' "$root/etc/apt/sources.list")"
|
||||
check "flat repository untouched" \
|
||||
"deb http://deb.debian.org/debian/ ./" \
|
||||
"$(sed -n '3p' "$root/etc/apt/sources.list")"
|
||||
check "commented-out entry untouched" \
|
||||
"# deb http://deb.debian.org/debian/ trixie main" \
|
||||
"$(sed -n '4p' "$root/etc/apt/sources.list")"
|
||||
|
||||
# ------------------------------------------------------------- summary
|
||||
|
||||
echo
|
||||
echo "passed: $passed failed: $failed"
|
||||
[[ "$failed" -eq 0 ]]
|
||||
Reference in New Issue
Block a user