Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/omamobile-firstboot/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ arch=(any)
url="https://github.com/derekross/omarchy-mobile"
license=(MIT)
depends=(bash coreutils grep sed gawk shadow sudo systemd openssh ufw networkmanager pacman util-linux)
checkdepends=(diffutils)
backup=(etc/ssh/sshd_config.d/10-omamobile.conf)
install=omamobile-firstboot.install

Expand Down
14 changes: 14 additions & 0 deletions packages/omamobile-firstboot/bin/omamobile-firstboot
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ step() {
}

s_keyring() {
# A phone without a working RTC can boot before its signing keys existed.
# Installed public keyrings are part of the root image; use their
# newest mtime as a floor before GnuPG creates or imports keys offline.
# Never move a valid clock backwards, and do nothing without a keyring.
local keyring stamp floor=0 now
for keyring in "$ROOT"/usr/share/pacman/keyrings/*.gpg; do
[[ -f $keyring ]] || continue
stamp=$(stat -c %Y "$keyring")
((stamp <= floor)) || floor=$stamp
done
now=$(date -u +%s)
if ((now < floor)); then
date -u -s "@$floor" >/dev/null
fi
if [[ ! -f $ROOT/etc/pacman.d/gnupg/trustdb.gpg ]]; then
pacman-key --init
fi
Expand Down
23 changes: 23 additions & 0 deletions packages/omamobile-firstboot/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ pass "values are data, never executed"
# --- a whole run against fakes ------------------------------------------------
F=$t/fakes; mkdir -p "$F"; CALLS=$t/calls; : > "$CALLS"
fake() { printf '#!/bin/bash\n%s\n' "$2" > "$F/$1"; chmod +x "$F/$1"; }
export REAL_DATE=$(command -v date) TEST_NOW=1
fake date 'case "$*" in
"-u +%s") echo "$TEST_NOW" ;;
"-u -s "*) echo "clock-set ${3#@}" >> "$CALLS" ;;
*) "$REAL_DATE" "$@" ;;
esac'
mkdir -p "$R/usr/share/pacman/keyrings"
touch -d @2000000000 "$R/usr/share/pacman/keyrings/archlinuxarm.gpg"
touch -d @2000000060 "$R/usr/share/pacman/keyrings/omamobile.gpg"
for cmd in pacman-key systemctl ufw chown hostname nmcli usermod omamobile-setup-system; do
fake "$cmd" 'echo "$(basename "$0") $*" >> "$CALLS"'
done
Expand All @@ -146,6 +155,9 @@ run() { OMAMOBILE_FIRSTBOOT_ROOT=$R OMARCHY_PATH=$O OMAMOBILE_LOCK_PAM=$F/lock-p

good > "$R/etc/omamobile/firstboot.conf"
run || { cat "$t/run.out"; fail "a run with a good conf succeeds"; }
grep -qx 'clock-set 2000000060' "$CALLS" || fail "clock advances to the newest installed keyring"
[[ $(head -1 "$CALLS") == 'clock-set 2000000060' ]] || fail "clock is seeded before pacman-key"
pass "an offline clock is seeded before creating and importing keys"
[[ ! -e $R/etc/omamobile/firstboot.conf ]] || fail "the conf is deleted after a run"
[[ -f $R/var/lib/omamobile/firstboot/done ]] || fail "the run is recorded"
grep -q '^useradd -m -G wheel,audio,video,input -s /bin/bash -c Alice Example alice$' "$CALLS" || fail "the user gets the groups and name"
Expand Down Expand Up @@ -181,11 +193,22 @@ pass "the lock's PAM file comes from lock-pam, not omarchy-apply-lock"
run || fail "without a conf, nothing to do"
[[ ! -s $CALLS ]] || fail "without a conf, nothing runs"
good | sed '/^WIFI_/d' > "$R/etc/omamobile/firstboot.conf"
export TEST_NOW=2000000100
run || { cat "$t/run.out"; fail "a second run succeeds"; }
grep -q '^clock-set' "$CALLS" && fail "an accurate clock is never moved backwards"
grep -q '^usermod -aG wheel,audio,video,input' "$CALLS" || fail "a second run updates the user it made"
[[ $(grep -cxF "$KEY" "$R/home/alice/.ssh/authorized_keys") == 1 ]] || fail "a second run doesn't duplicate the key"
pass "running again is safe"

: > "$CALLS"
rm "$R/usr/share/pacman/keyrings/"*.gpg
export TEST_NOW=1
good > "$R/etc/omamobile/firstboot.conf"
run || { cat "$t/run.out"; fail "a root without keyrings still runs"; }
grep -q '^clock-set' "$CALLS" && fail "no keyrings means no clock adjustment"
grep -q '^pacman-key --populate' "$CALLS" || fail "key setup still runs without a floor"
pass "missing keyrings leave the clock alone"

# An essential step failing keeps the conf (minus the Wi-Fi secret) for the next boot
rm -f "$R/var/lib/omamobile/firstboot/user"
sed -i '/^alice:/d' "$R/etc/passwd"
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-firstboot/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.1.3