Files
arch-i3/scripts/40-services.sh
T

107 lines
3.5 KiB
Bash
Raw Normal View History

2026-09-14 15:31:20 -05:00
#!/usr/bin/env bash
# Stage 40 — enable system services, user services and groups.
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
log "Services & system integration"
require_arch
require_not_root
require_sudo
enable_system() {
local unit="$1"
if ! systemctl list-unit-files --no-legend | grep -q "^${unit}"; then
skip "$unit not present"
return 0
fi
if systemctl is-enabled --quiet "$unit" 2>/dev/null; then
skip "$unit already enabled"
else
step "enabling $unit"
run sudo systemctl enable --now "$unit"
fi
}
enable_user() {
local unit="$1"
if ! systemctl --user list-unit-files | grep -q "^${unit}"; then
skip "user unit $unit not present"
return 0
fi
if systemctl --user is-enabled --quiet "$unit" 2>/dev/null; then
skip "user unit $unit already enabled"
else
step "enabling user unit $unit"
run systemctl --user enable "$unit"
fi
}
# --- system services -------------------------------------------------------
enable_system NetworkManager.service
enable_system bluetooth.service
enable_system systemd-timesyncd.service
# --- user services ---------------------------------------------------------
# pipewire is socket-activated; enabling the sockets is enough.
enable_user pipewire.socket
enable_user pipewire-pulse.socket
enable_user wireplumber.service
# --- betterlockscreen on suspend ------------------------------------------
# xss-lock (started from the i3 config) already handles lid-close and suspend.
# The systemd unit below is the belt-and-braces version for logind-initiated
# sleeps that happen outside the X session.
if have betterlockscreen; then
step "installing betterlockscreen@.service hook"
if [[ "$DRY_RUN" != "1" ]]; then
sudo tee /etc/systemd/system/betterlockscreen@.service >/dev/null <<UNIT
[Unit]
Description=Lock the screen with betterlockscreen before sleep
Before=sleep.target
[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/betterlockscreen --lock dimblur
TimeoutSec=infinity
[Install]
WantedBy=sleep.target
UNIT
sudo systemctl daemon-reload
sudo systemctl enable "betterlockscreen@${USER}.service"
fi
ok "betterlockscreen sleep hook enabled"
fi
# --- groups ----------------------------------------------------------------
for grp in video input audio storage; do
if getent group "$grp" >/dev/null && ! id -nG "$USER" | tr ' ' '\n' | grep -qx "$grp"; then
step "adding $USER to group '$grp'"
run sudo usermod -aG "$grp" "$USER"
fi
done
# --- font cache ------------------------------------------------------------
step "rebuilding the font cache"
run fc-cache -f >/dev/null
if fc-list | grep -qi 'inconsolata.*nerd'; then
ok "Inconsolata Nerd Font is available to X clients"
else
warn "Inconsolata Nerd Font not found by fontconfig — check that ttf-inconsolata-nerd installed"
fi
# --- lock screen cache -----------------------------------------------------
if have betterlockscreen; then
wall="$(cat "${XDG_STATE_HOME:-$HOME/.local/state}/current-wallpaper" 2>/dev/null || true)"
[[ -z "$wall" ]] && wall="$(find "$WALLPAPER_DIR" -maxdepth 1 -type f 2>/dev/null | sort | head -n1 || true)"
if [[ -n "$wall" && -f "$wall" ]]; then
step "building the betterlockscreen image cache (this takes a moment)"
run betterlockscreen --update "$wall" --blur 0.5 >/dev/null 2>&1 \
|| warn "betterlockscreen cache build failed; run 'betterlockscreen -u <image>' by hand"
else
skip "no wallpaper available yet — run 'betterlockscreen -u <image>' after first login"
fi
fi
ok "services configured"