- Drop perl, perl-io-socket-ssl, tcl-lib, tcl-tls, sqlite-tcl, lua5.4, lua5.4-dev, lua5.5, lua5.5-dev and sqlite (CLI) from the package set and add them to the prune denylist: 13 packages / 49.45 MiB including dependents. sqlite-libs, tcl, and all paramount runtimes stay. - Promote curl to an explicit world entry and pin curl, bc, ed, rlwrap, mandoc, nano, less and frotz as core tools in check-rebuild.sh. - Remove the lua/luac symlink creation and the lua5.5 critical-binary check from the build scripts; apply-bananarchy-overlay.sh deletes stale links. - Drop four legacy pmbootstrap-era so: world constraints (@ entries in the prune list); so:libperl.so was pinning perl and blocking its removal. - Update README.md, MANUAL.md, AGENTS.md, SDK.md section 7 and CHANGELOG.md. - Rebuild images/bananarchy-nokia-argon.img (1.59 GiB, down from 1.66 GiB) and verify with qemu-arm that yabasic, neoui.yab, neonet.yab, curl, bc and ed still work while perl, lua, sqlite3, gcc and janet are gone.
244 lines
8.3 KiB
Bash
Executable File
244 lines
8.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Bananarchy rootfs bootstrap, container side.
|
|
# Runs inside alpine:3.24 with the target rootfs mounted at /rootfs and the
|
|
# repository mounted read-only at /bananarchy. Invoked by bootstrap-rootfs.sh.
|
|
set -eu
|
|
|
|
ROOTFS="/rootfs"
|
|
REPO="/bananarchy"
|
|
PKGS_FILE="$REPO/scripts/rootfs-packages.txt"
|
|
DEVICE="${TARGET_DEVICE:-nokia-argon}"
|
|
PASSWORD="${BANANARCHY_USER_PASSWORD:-147147}"
|
|
HOST_UID="${HOST_UID:-0}"
|
|
HOST_GID="${HOST_GID:-0}"
|
|
BOOTSTRAP_VERSION="${BOOTSTRAP_VERSION:-1}"
|
|
PKG_HASH="${PKG_HASH:-unknown}"
|
|
|
|
echo "============================================================"
|
|
echo "Bootstrapping Bananarchy armv7 rootfs for $DEVICE"
|
|
echo "============================================================"
|
|
|
|
echo "[1/8] Configuring apk repositories and trusted keys..."
|
|
cat > /etc/apk/repositories <<EOF
|
|
https://mirror.nura.eco/postmarketos/v26.06
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
|
EOF
|
|
mkdir -p /etc/apk/keys
|
|
cp "$REPO"/keys/*.rsa.pub /etc/apk/keys/
|
|
|
|
mkdir -p "$ROOTFS/etc/apk/keys" "$ROOTFS/lib/apk/db" "$ROOTFS/var/cache/apk"
|
|
cp /etc/apk/repositories "$ROOTFS/etc/apk/repositories"
|
|
cp "$REPO"/keys/*.rsa.pub "$ROOTFS/etc/apk/keys/"
|
|
|
|
echo "[2/8] Installing host helper tools..."
|
|
apk add --no-cache python3 kmod openssl >/dev/null
|
|
|
|
echo "[3/8] Installing the Bananarchy armv7 package set..."
|
|
PKGS="$(grep -v '^[[:space:]]*#' "$PKGS_FILE" | grep -v '^[[:space:]]*$' | tr '\n' ' ')"
|
|
# Retired world entries must go first: apk cannot install C sudo while the
|
|
# Rust sudo-rs still owns cmd:sudo in world.
|
|
"$REPO/scripts/prune-rootfs-packages.sh" "$ROOTFS" world
|
|
if [ ! -f "$ROOTFS/lib/apk/db/installed" ]; then
|
|
# shellcheck disable=SC2086
|
|
apk --root "$ROOTFS" --arch armv7 add --initdb --no-scripts $PKGS >/dev/null
|
|
else
|
|
# An existing rootfs only needs newly added packages, not a full reinstall.
|
|
# shellcheck disable=SC2086
|
|
apk --root "$ROOTFS" --arch armv7 add --no-scripts $PKGS >/dev/null
|
|
fi
|
|
|
|
"$REPO/scripts/prune-rootfs-packages.sh" "$ROOTFS" purge
|
|
|
|
echo "[4/8] Creating system accounts and default credentials..."
|
|
PW_HASH="$(openssl passwd -6 -salt bananarchy "$PASSWORD")"
|
|
python3 - "$ROOTFS" "$PW_HASH" <<'PYEOF'
|
|
import os
|
|
import sys
|
|
|
|
root = sys.argv[1]
|
|
pw_hash = sys.argv[2]
|
|
|
|
|
|
def load(name):
|
|
path = os.path.join(root, "etc", name)
|
|
with open(path, "r") as handle:
|
|
return [line.rstrip("\n") for line in handle if line.strip()]
|
|
|
|
|
|
def store(name, rows):
|
|
path = os.path.join(root, "etc", name)
|
|
with open(path, "w") as handle:
|
|
handle.write("\n".join(rows) + "\n")
|
|
|
|
|
|
passwd = load("passwd")
|
|
group = load("group")
|
|
shadow = load("shadow")
|
|
|
|
system_users = [
|
|
"klogd:x:100:101:klogd:/dev/null:/sbin/nologin",
|
|
"chrony:x:101:102:chrony:/dev/null:/sbin/nologin",
|
|
"messagebus:x:102:103:messagebus:/dev/null:/sbin/nologin",
|
|
"dnsmasq:x:103:104:dnsmasq:/dev/null:/sbin/nologin",
|
|
"geoclue:x:104:105::/var/lib/geoclue:/sbin/nologin",
|
|
"polkitd:x:105:110:polkitd:/var/empty:/sbin/nologin",
|
|
"colord:x:106:111:colord:/var/lib/colord:/sbin/nologin",
|
|
"greetd:x:107:112:greetd:/var/lib/greetd:/sbin/nologin",
|
|
"openvpn:x:108:113:OpenVPN:/dev/null:/sbin/nologin",
|
|
"tor:x:109:114:tor:/var/lib/tor:/sbin/nologin",
|
|
"user:x:10000:10000::/home/user:/bin/ash",
|
|
]
|
|
for entry in system_users:
|
|
name = entry.split(":")[0]
|
|
if not any(row.startswith(name + ":") for row in passwd):
|
|
passwd.append(entry)
|
|
|
|
system_groups = [
|
|
"avahi:x:86:avahi",
|
|
"klogd:x:101:klogd",
|
|
"chrony:x:102:chrony",
|
|
"messagebus:x:103:messagebus",
|
|
"dnsmasq:x:104:dnsmasq",
|
|
"geoclue:x:105:geoclue",
|
|
"plugdev:x:106:user",
|
|
"pipewire:x:107:user",
|
|
"seat:x:108:user",
|
|
"feedbackd:x:109:user",
|
|
"polkitd:x:110:polkitd",
|
|
"colord:x:111:colord",
|
|
"greetd:x:112:greetd",
|
|
"openvpn:x:113:openvpn",
|
|
"tor:x:114:tor",
|
|
"user:x:10000:",
|
|
]
|
|
for entry in system_groups:
|
|
name = entry.split(":")[0]
|
|
if not any(row.startswith(name + ":") for row in group):
|
|
group.append(entry)
|
|
|
|
member_groups = (
|
|
"wheel", "audio", "input", "netdev", "plugdev", "video", "seat",
|
|
"feedbackd", "dialout", "tty", "pipewire",
|
|
)
|
|
for index, row in enumerate(group):
|
|
fields = row.split(":")
|
|
if fields[0] not in member_groups:
|
|
continue
|
|
members = [item for item in fields[3].split(",") if item]
|
|
if "user" not in members:
|
|
members.append("user")
|
|
fields[3] = ",".join(members)
|
|
group[index] = ":".join(fields)
|
|
|
|
for entry in system_users:
|
|
name = entry.split(":")[0]
|
|
if name == "user":
|
|
continue
|
|
if not any(row.startswith(name + ":") for row in shadow):
|
|
shadow.append(name + ":!:::::::")
|
|
|
|
if not any(row.startswith("user:") for row in shadow):
|
|
shadow.append("user:" + pw_hash + ":::::::")
|
|
for index, row in enumerate(shadow):
|
|
if row.startswith("root:"):
|
|
fields = row.split(":")
|
|
if len(fields) > 1 and fields[1] == "":
|
|
fields[1] = pw_hash
|
|
shadow[index] = ":".join(fields)
|
|
|
|
store("passwd", passwd)
|
|
store("group", group)
|
|
store("shadow", shadow)
|
|
PYEOF
|
|
mkdir -p "$ROOTFS/home/user" "$ROOTFS/etc/bananarchy"
|
|
chown -R 10000:10000 "$ROOTFS/home/user"
|
|
chown 0:42 "$ROOTFS/etc/shadow"
|
|
chmod 640 "$ROOTFS/etc/shadow"
|
|
chown 0:0 "$ROOTFS/etc/bananarchy"
|
|
chmod 0700 "$ROOTFS/etc/bananarchy"
|
|
|
|
echo "[5/8] Writing base system configuration..."
|
|
printf '%s\n' "nokia-argon" > "$ROOTFS/etc/hostname"
|
|
cat > "$ROOTFS/etc/hosts" <<EOF
|
|
127.0.0.1 nokia-argon localhost.localdomain localhost
|
|
::1 localhost ipv6-localhost ipv6-loopback
|
|
fe00::0 ipv6-localnet
|
|
ff00::0 ipv6-mcastprefix
|
|
ff02::1 ipv6-allnodes
|
|
ff02::2 ipv6-allrouters
|
|
ff02::3 ipv6-allhosts
|
|
EOF
|
|
printf '%s\n' "LANG=C.UTF-8" > "$ROOTFS/etc/locale.conf"
|
|
if [ -f "$ROOTFS/usr/share/zoneinfo/UTC" ]; then
|
|
cp "$ROOTFS/usr/share/zoneinfo/UTC" "$ROOTFS/etc/localtime"
|
|
touch "$ROOTFS/etc/apk/interactive"
|
|
mkdir -p "$ROOTFS/run/openrc" "$ROOTFS/dev/pts" "$ROOTFS/dev/shm"
|
|
touch "$ROOTFS/run/openrc/shutdowntime"
|
|
# mkinitfs and boot-deploy run in a chroot and need /dev/null; devtmpfs
|
|
# replaces these placeholders on the device at boot time.
|
|
: > "$ROOTFS/dev/null"
|
|
chmod 666 "$ROOTFS/dev/null"
|
|
# mkinitfs expects losetup under /usr/sbin; the util-linux package only
|
|
# installs it under /sbin when package scripts are skipped.
|
|
if [ -e "$ROOTFS/sbin/losetup" ] && [ ! -e "$ROOTFS/usr/sbin/losetup" ]; then
|
|
ln -sf /sbin/losetup "$ROOTFS/usr/sbin/losetup"
|
|
fi
|
|
tr -d '-' < /proc/sys/kernel/random/uuid > "$ROOTFS/etc/machine-id"
|
|
printf '\n' >> "$ROOTFS/etc/machine-id"
|
|
fi
|
|
mkdir -p "$ROOTFS/etc/sysctl.d"
|
|
cat > "$ROOTFS/etc/sysctl.d/90-nokia-argon-lowram.conf" <<EOF
|
|
vm.swappiness = 180
|
|
vm.page-cluster = 0
|
|
vm.vfs_cache_pressure = 150
|
|
vm.min_free_kbytes = 16384
|
|
EOF
|
|
mkdir -p "$ROOTFS/etc/sudoers.d" "$ROOTFS/etc/doas.d"
|
|
cat > "$ROOTFS/etc/sudoers.d/wheel" <<EOF
|
|
%wheel ALL=(ALL:ALL) ALL
|
|
EOF
|
|
chmod 440 "$ROOTFS/etc/sudoers.d/wheel"
|
|
rm -f "$ROOTFS/etc/doas.d/wheel.conf"
|
|
touch "$ROOTFS/etc/apk/interactive"
|
|
mkdir -p "$ROOTFS/run/openrc"
|
|
touch "$ROOTFS/run/openrc/shutdowntime"
|
|
|
|
echo "[6/8] Enabling OpenRC runlevels..."
|
|
mkdir -p "$ROOTFS/etc/runlevels/sysinit" "$ROOTFS/etc/runlevels/boot" \
|
|
"$ROOTFS/etc/runlevels/default" "$ROOTFS/etc/runlevels/shutdown"
|
|
enable_service() {
|
|
runlevel="$1"
|
|
service="$2"
|
|
if [ -e "$ROOTFS/etc/init.d/$service" ]; then
|
|
ln -sf "/etc/init.d/$service" "$ROOTFS/etc/runlevels/$runlevel/$service"
|
|
fi
|
|
}
|
|
for svc in devfs dmesg msm-firmware-loader udev udev-trigger udev-settle; do
|
|
enable_service sysinit "$svc"
|
|
done
|
|
for svc in bootmisc hostname modules msm-firmware-loader-unpack osclock \
|
|
swclock-offset-boot sysctl tmpfs; do
|
|
enable_service boot "$svc"
|
|
done
|
|
for svc in bluetooth cgroups chronyd dbus elogind kill-plymouth local \
|
|
modemmanager msm8909-modem-wwan-port msm-modem-uim-selection networkmanager \
|
|
postmarketos-zram-swap q6voiced rfkill rmtfs sshd tinydm udev-postmount \
|
|
wpa_supplicant; do
|
|
enable_service default "$svc"
|
|
done
|
|
for svc in killprocs mount-ro savecache swclock-offset-shutdown; do
|
|
enable_service shutdown "$svc"
|
|
done
|
|
rm -f "$ROOTFS/etc/runlevels/boot/hwclock"
|
|
|
|
echo "[7/8] Applying the Bananarchy overlay and prebuilt artifacts..."
|
|
"$REPO/scripts/apply-bananarchy-overlay.sh" "$ROOTFS" "$DEVICE"
|
|
depmod -b "$ROOTFS" 6.12.1-msm8916
|
|
|
|
echo "[8/8] Finalizing rootfs ownership and bootstrap marker..."
|
|
printf '%s:%s\n' "$BOOTSTRAP_VERSION" "$PKG_HASH" > "$ROOTFS/etc/bananarchy/rootfs-bootstrap.done"
|
|
chown -R "$HOST_UID:$HOST_GID" "$ROOTFS"
|
|
echo "Bananarchy rootfs bootstrap completed for $DEVICE."
|