Merge pull request #5 from Shivox/fix-firstboot-cachyos

fix first-boot flow for CachyOS
This commit is contained in:
Dan
2026-05-14 18:55:39 +02:00
committed by GitHub
2 changed files with 92 additions and 51 deletions

View File

@@ -1,11 +1,8 @@
#!/bin/bash #!/bin/bash
# First-boot interactive setup for CachyOS PS5 image. # First-boot: dialog wizard on tty1 (timezone, steam password, hostname).
# Sets the password for the 'steam' user and optionally the hostname, # Defaults: UTC, ps5, keep image password (steam:steam). Skips on Cancel use defaults.
# then creates a sentinel so this script never runs again. set -euo pipefail
set -e
# Keep interactive prompts readable on tty1 by suppressing kernel console noise
# during setup. Restore the previous setting before exiting.
ORIG_PRINTK="$(cat /proc/sys/kernel/printk 2>/dev/null || true)" ORIG_PRINTK="$(cat /proc/sys/kernel/printk 2>/dev/null || true)"
if [ -n "$ORIG_PRINTK" ]; then if [ -n "$ORIG_PRINTK" ]; then
echo "1 4 1 7" > /proc/sys/kernel/printk || true echo "1 4 1 7" > /proc/sys/kernel/printk || true
@@ -17,57 +14,93 @@ cleanup_printk() {
} }
trap cleanup_printk EXIT trap cleanup_printk EXIT
clear export TERM="${TERM:-linux}"
echo "=================================================="
echo " Welcome to CachyOS on PS5!"
echo "=================================================="
echo
echo "User: steam (fixed — used for both Gaming Mode and Desktop)"
echo
# --- Password --- apply_timezone() {
while true; do local tz="${1:-UTC}"
read -rsp "Set a password for 'steam': " PASSWORD; echo timedatectl set-timezone "$tz" 2>/dev/null || ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime
read -rsp "Confirm password: " PASSWORD2; echo }
if [[ -z "$PASSWORD" ]]; then
echo "Password cannot be empty." apply_hostname() {
elif [[ "$PASSWORD" != "$PASSWORD2" ]]; then local hn="${1:-ps5}"
echo "Passwords do not match. Try again." hostnamectl set-hostname "$hn" 2>/dev/null || echo "$hn" > /etc/hostname
if grep -q '^127\.0\.1\.1' /etc/hosts; then
sed -i "s/^127\.0\.1\.1.*/127.0.1.1 $hn/" /etc/hosts
else else
break echo "127.0.1.1 $hn" >> /etc/hosts
fi fi
}
main() {
if ! command -v dialog >/dev/null 2>&1; then
echo "first-boot-setup: dialog not installed" >&2
exit 1
fi
clear
local choice
choice="$(dialog --stdout --clear --menu \
"Welcome to CachyOS on PS5\nUser: steam (Gaming Mode + Desktop)" \
17 64 4 \
defaults "Use defaults (UTC, hostname ps5, keep password)" \
custom "Customize timezone, password, hostname" )" \
|| choice="defaults"
if [[ "$choice" == "defaults" ]]; then
apply_timezone UTC
apply_hostname ps5
else
local zones
mapfile -t zones < <(timedatectl list-timezones 2>/dev/null | LC_ALL=C sort -u)
local -a menu_args=()
local z
for z in "${zones[@]}"; do
menu_args+=("$z" "$z")
done done
# --- Hostname --- local tz_pick
read -rp "Hostname [ps5]: " HOSTNAME if ((${#menu_args[@]} == 0)); then
HOSTNAME="${HOSTNAME:-ps5}" apply_timezone UTC
elif tz_pick="$(dialog --stdout --clear --menu "Select timezone (Cancel = UTC)" 22 70 15 \
echo "${menu_args[@]}")"; then
echo "Applying settings..." apply_timezone "$tz_pick"
echo "steam:$PASSWORD" | chpasswd
hostnamectl set-hostname "$HOSTNAME" 2>/dev/null || echo "$HOSTNAME" > /etc/hostname
# Update /etc/hosts if a 127.0.1.1 line exists, otherwise append one.
if grep -q '^127\.0\.1\.1' /etc/hosts; then
sed -i "s/^127\.0\.1\.1.*/127.0.1.1 $HOSTNAME/" /etc/hosts
else else
echo "127.0.1.1 $HOSTNAME" >> /etc/hosts apply_timezone UTC
fi
if dialog --clear --yesno "Change password for user steam?" 8 55; then
local p1 p2
while true; do
p1="$(dialog --stdout --clear --insecure --passwordbox "New password (empty = skip)" 9 55)" \
|| break
p2="$(dialog --stdout --clear --insecure --passwordbox "Confirm password" 9 55)" \
|| break
if [[ -z "$p1" ]]; then
dialog --clear --msgbox "Password unchanged (empty)." 7 44
break
fi
if [[ "$p1" != "$p2" ]]; then
dialog --clear --msgbox "Passwords do not match. Try again." 7 50
continue
fi
echo "steam:$p1" | chpasswd
break
done
fi
local hn
hn="$(dialog --stdout --clear --inputbox "Hostname (empty = ps5)" 9 50 "ps5")" \
|| hn="ps5"
hn="${hn:-ps5}"
apply_hostname "$hn"
fi fi
# Sentinel — prevents this service from running on subsequent boots.
touch /etc/ps5-first-boot-done touch /etc/ps5-first-boot-done
echo dialog --clear --msgbox \
echo "==================================================" "Setup complete.\n\nYou will log in on tty1 (Steam Gaming Mode).\n\nDesktop: Steam > Power > Switch to KDE\nReturn: double-click the desktop shortcut." \
echo " Setup complete!" 14 62
echo "==================================================" }
echo
echo "The system will log in on tty1 and start Steam Gaming Mode (Gamescope)." main "$@"
echo "(No display manager — same pattern as the Arch Sway image in this repo.)"
echo
echo "Tips:"
echo " In Steam: Power > Switch to Desktop → KDE Plasma (X11)"
echo " In KDE: Double-click 'Return to Gaming Mode' on the desktop"
echo
sleep 3

View File

@@ -59,6 +59,11 @@ packages:
# Networking # Networking
- networkmanager - networkmanager
- linux-firmware - linux-firmware
# GIO module libgiognutls.so (KDE/Konsole, GVfs, etc.): needs gnutls → nettle (libhogweed).
# Explicit install avoids a sparse dependency tree under distrobuilder cleanup: true.
- gnutls
- nettle
- glib-networking
# System # System
- base - base
@@ -75,6 +80,7 @@ packages:
- dbus - dbus
- kexec-tools - kexec-tools
- curl - curl
- dialog
# Fonts (Steam UI + KDE) — CJK + emoji avoid "tofu" boxes in Steam Big Picture language list # Fonts (Steam UI + KDE) — CJK + emoji avoid "tofu" boxes in Steam Big Picture language list
- ttf-dejavu - ttf-dejavu
@@ -241,6 +247,8 @@ actions:
touch /etc/ps5-use-tty-sessions touch /etc/ps5-use-tty-sessions
ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
ln -sf /dev/null /etc/systemd/system/sddm.service ln -sf /dev/null /etc/systemd/system/sddm.service
# First-boot wizard handles timezone/password/hostname; avoid duplicate prompts.
ln -sf /dev/null /etc/systemd/system/systemd-firstboot.service
mkdir -p /etc/systemd/system/getty@tty1.service.d mkdir -p /etc/systemd/system/getty@tty1.service.d
printf '%s\n' '[Service]' 'ExecStart=' 'ExecStart=-/sbin/agetty --autologin steam --noclear %I $TERM' \ printf '%s\n' '[Service]' 'ExecStart=' 'ExecStart=-/sbin/agetty --autologin steam --noclear %I $TERM' \