#!/bin/sh # Installs the AGS greeter for greetd. # # Usage: sudo ./greeter/install.sh # # This replaces /etc/greetd/config.toml (a .bak copy is kept) and copies the # greeter into /etc/greetd/ags so the `greeter` user can read it. set -eu if [ "$(id -u)" -ne 0 ]; then echo "Run this script with sudo." >&2 exit 1 fi SRC=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) TARGET_USER=${SUDO_USER:-pascal} for bin in cage sass dbus-run-session; do if ! command -v "$bin" >/dev/null 2>&1; then echo "Missing dependency: $bin" >&2 case "$bin" in cage) echo "Install it with: pacman -S cage" >&2 ;; sass) echo "Install it with: pacman -S dart-sass" >&2 ;; esac exit 1 fi done if ! id greeter >/dev/null 2>&1; then echo "The 'greeter' user does not exist. Create it with:" >&2 echo " useradd -M -G video greeter" >&2 exit 1 fi install -d -m 755 /etc/greetd/ags install -d -o greeter -g greeter -m 700 \ /var/lib/greetd /var/lib/greetd/run /var/lib/greetd/.cache install -m 644 -o root -g root "$SRC/greeter.tsx" /etc/greetd/ags/greeter.tsx install -m 644 -o root -g root "$SRC/style.scss" /etc/greetd/ags/style.scss install -m 755 -o root -g root "$SRC/start-greeter.sh" /etc/greetd/ags/start-greeter.sh rm -f /etc/greetd/ags/*.map printf '%s\n' "$TARGET_USER" > /etc/greetd/ags/default-user chmod 644 /etc/greetd/ags/default-user # Compile a fallback theme in case the shell has never exported one. # /tmp is sticky and fs.protected_regular is enabled, so root cannot # overwrite an existing user-owned file there. Remove it first and give it # back to the user at the end so theme switching keeps working. rm -f /tmp/ags-colors.scss cat > /tmp/ags-colors.scss <<'EOF' $wallpaper: ""; $background: #1e1e1e; $foreground: #d4d4d4; $cursor: #d4d4d4; $color0: #1e1e1e; $color1: #f44747; $color2: #6a9955; $color3: #d7ba7d; $color4: #569cd6; $color5: #c586c0; $color6: #4ec9b0; $color7: #d4d4d4; $color8: #808080; $color9: #f44747; $color10: #6a9955; $color11: #d7ba7d; $color12: #569cd6; $color13: #c586c0; $color14: #4ec9b0; $color15: #d4d4d4; EOF sass --no-source-map /etc/greetd/ags/style.scss /etc/greetd/ags/fallback.css chmod 644 /etc/greetd/ags/fallback.css # Seed the greeter theme from the user's current pywal state. USER_HOME=$(getent passwd "$TARGET_USER" | cut -d: -f6 || true) if [ -n "${USER_HOME:-}" ] && [ -f "$USER_HOME/.cache/wal/colors.scss" ]; then install -d -m 755 -o "$TARGET_USER" -g "$TARGET_USER" /var/tmp/ags-greeter rm -f /var/tmp/ags-greeter/greeter.css \ /var/tmp/ags-greeter/greeter.css.map /var/tmp/ags-greeter/wallpaper.jpg cp "$USER_HOME/.cache/wal/colors.scss" /tmp/ags-colors.scss sass --no-source-map /etc/greetd/ags/style.scss \ /var/tmp/ags-greeter/greeter.css if [ -f "$USER_HOME/.cache/current_wallpaper.jpg" ]; then cp "$USER_HOME/.cache/current_wallpaper.jpg" \ /var/tmp/ags-greeter/wallpaper.jpg fi chown "$TARGET_USER:$TARGET_USER" \ /var/tmp/ags-greeter/greeter.css /var/tmp/ags-greeter/wallpaper.jpg \ 2>/dev/null || true fi if [ -f /etc/greetd/config.toml ]; then cp /etc/greetd/config.toml /etc/greetd/config.toml.bak fi chown "$TARGET_USER:$TARGET_USER" /tmp/ags-colors.scss 2>/dev/null || true cat > /etc/greetd/config.toml <<'EOF' [terminal] vt = 1 [default_session] # greetd prefixes the command with `exec`, so it must be a single executable. # start-greeter.sh sets HOME/XDG dirs, starts cage, then AGS. command = "/etc/greetd/ags/start-greeter.sh" user = "greeter" EOF # Allow the greeter user to power off/reboot without an auth agent. if [ ! -d /etc/polkit-1/rules.d ]; then install -d -m 755 /etc/polkit-1/rules.d fi cat > /etc/polkit-1/rules.d/49-greetd-greeter.rules <<'EOF' polkit.addRule(function(action, subject) { if (subject.user !== "greeter") return null; const allowed = [ "org.freedesktop.login1.power-off", "org.freedesktop.login1.power-off-multiple-sessions", "org.freedesktop.login1.reboot", "org.freedesktop.login1.reboot-multiple-sessions", ]; if (allowed.indexOf(action.id) !== -1) return polkit.Result.YES; return null; }); EOF chmod 644 /etc/polkit-1/rules.d/49-greetd-greeter.rules cat <