Files
Arch-R/scripts/archr-sleep
Douglas Teles 06dc2d16f3 Add system scripts, services, and boot splash
System daemons: hotkeys (volume/brightness), automount, bluetooth agent,
memory manager, sleep/suspend, USB gadget mode, save-config persistence.

Boot splash: initramfs SVG renderer (fbsplash + svg_parser) for 0.7s splash.

Panel tools: generate-panel-dtbos.sh rewrite, convert-panel.py for ROCKNIX
panel data extraction, archr-dtbo.py for runtime overlay management.

Input: archr-gptokeyb.c gamepad-to-keyboard mapper via uinput.

Launch wrappers: emulationstation.sh and retroarch-launch.sh updated for
KMS/DRM + Mesa 26 Panfrost environment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 17:22:30 -03:00

97 lines
2.7 KiB
Bash

#!/bin/bash
# Arch R — System Sleep Hook
# Installed to /usr/lib/systemd/system-sleep/archr-sleep
# Called by systemd before suspend (pre) and after wake (post).
#
# Pre-suspend: saves governors, sets powersave, unloads problem modules
# Post-wake: reloads modules, restores governors
MODULES_BAD="/etc/archr/modules.bad"
SAVED_MODULES="/tmp/archr-sleep-modules"
SAVED_CPU_GOV="/tmp/archr-sleep-cpu-gov"
SAVED_GPU_GOV="/tmp/archr-sleep-gpu-gov"
CPU_GOV="/sys/devices/system/cpu/cpufreq/policy0/scaling_governor"
GPU_GOV="/sys/devices/platform/ff400000.gpu/devfreq/ff400000.gpu/governor"
DMC_GOV="/sys/devices/platform/dmc/devfreq/dmc/governor"
log() { logger -t archr-sleep "$1"; }
pre_suspend() {
log "Pre-suspend: saving state..."
# Save current governors
cat "$CPU_GOV" > "$SAVED_CPU_GOV" 2>/dev/null
cat "$GPU_GOV" > "$SAVED_GPU_GOV" 2>/dev/null
# Set powersave governors
echo powersave > "$CPU_GOV" 2>/dev/null
echo powersave > "$GPU_GOV" 2>/dev/null
echo powersave > "$DMC_GOV" 2>/dev/null
# Unload problem modules (USB, WiFi)
if [ -f "$MODULES_BAD" ]; then
rm -f "$SAVED_MODULES"
while read -r line; do
# Skip comments and empty lines
[ -z "$line" ] && continue
[[ "$line" == \#* ]] && continue
for mod in $line; do
if lsmod | grep -q "^${mod} "; then
echo "$mod" >> "$SAVED_MODULES"
modprobe -r "$mod" 2>/dev/null
log "Unloaded module: $mod"
fi
done
done < "$MODULES_BAD"
fi
# Stop services that conflict with suspend
systemctl stop archr-hotkeys.service 2>/dev/null
systemctl stop battery-led.service 2>/dev/null
log "Pre-suspend: done"
}
post_wake() {
log "Post-wake: restoring state..."
# Reload modules
if [ -f "$SAVED_MODULES" ]; then
tac "$SAVED_MODULES" | while read -r mod; do
modprobe "$mod" 2>/dev/null
log "Reloaded module: $mod"
done
rm -f "$SAVED_MODULES"
fi
# Restore governors
if [ -f "$SAVED_CPU_GOV" ]; then
cat "$SAVED_CPU_GOV" > "$CPU_GOV" 2>/dev/null
rm -f "$SAVED_CPU_GOV"
else
echo schedutil > "$CPU_GOV" 2>/dev/null
fi
if [ -f "$SAVED_GPU_GOV" ]; then
cat "$SAVED_GPU_GOV" > "$GPU_GOV" 2>/dev/null
rm -f "$SAVED_GPU_GOV"
else
echo simple_ondemand > "$GPU_GOV" 2>/dev/null
fi
echo simple_ondemand > "$DMC_GOV" 2>/dev/null
# Restart services
systemctl start archr-hotkeys.service 2>/dev/null
systemctl start battery-led.service 2>/dev/null
log "Post-wake: done"
}
case "$1" in
pre) pre_suspend ;;
post) post_wake ;;
esac