Files
steamify-cachyos-live-iso/archiso/airootfs/usr/local/bin/steamify-install
T

45 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# steamify-install <target root> <user> <choice>: runs Steamify's setup for
# the new user inside the installed system (Calamares, after the users and
# services steps), as chosen on the installer's Steamify page: <choice> is the
# ids that are on, comma-separated, plus "boot" for Boot into Desktop, or
# "none" (packagechooser_steamifypage). Steamify refuses root and asks sudo
# per command, so the
# user gets a NOPASSWD rule for this run only, named to be read last: sudo
# takes the last matching rule, and a later %wheel rule would ask again. Never fails the install: a
# problem leaves the log and Steamify can be run again from the desktop.
root="$1" user="$2" choice="${3:-}"
# Not filled in by Calamares (empty, or the literal ${gs[...]}): the page's
# default, everything on.
[[ -z "$choice" || "$choice" == *'${'* ]] && choice=gaming,theme,glyphs,single,launcher,notify,vram,cec,machine,poweroff
boot=gamescope options=""
for id in ${choice//,/ }; do
case "$id" in
boot) boot=desktop ;;
none) ;;
*) options+="${options:+,}$id" ;;
esac
done
# systemd-boot: cachyos-installer runs `bootctl install` in a chroot, and bootctl leaves the EFI
# variables alone there: no "Linux Boot Manager" boot entry, so the firmware tries the network and
# its other entries first and finds the disk's fallback path last (or never). Register it now.
if [[ -n "$root" && -f "$root/boot/EFI/systemd/systemd-bootx64.efi" && -d /sys/firmware/efi/efivars ]]; then
arch-chroot "$root" bootctl --esp-path=/boot --variables=yes install > "$root/var/log/steamify-bootentry.log" 2>&1
arch-chroot "$root" efibootmgr >> "$root/var/log/steamify-bootentry.log" 2>&1
fi
log="$root/var/log/steamify-install.log"
rule="$root/etc/sudoers.d/zz-steamify-install"
[[ -d "$root" && -n "$user" ]] || exit 0
# Everything switched off on the page: nothing to set up.
[[ -n "$options" ]] || { echo "Nothing chosen on the Steamify page." > "$log"; exit 0; }
install -Dm755 /usr/local/share/steamify/steamify.sh "$root/var/tmp/steamify.sh"
printf '%s ALL=(ALL) NOPASSWD: ALL\n' "$user" > "$rule"
chmod 440 "$rule"
arch-chroot "$root" runuser -u "$user" -- env -i HOME="/home/$user" USER="$user" LOGNAME="$user" \
PATH=/usr/local/bin:/usr/bin TERM=dumb LANG=C.UTF-8 \
bash -c 'cd ~ && bash /var/tmp/steamify.sh --defaults --options "$0" --boot "$1" < /dev/null' "$options" "$boot" > "$log" 2>&1
echo "exit: $?" >> "$log"
rm -f "$rule" "$root/var/tmp/steamify.sh"
exit 0