Last active
April 21, 2025 12:44
-
-
Save HackingGate/ff63228a8d1e368d5703f02e7b1d04e9 to your computer and use it in GitHub Desktop.
Installs and configures acpid to lock the session on a short power‑button press (Ubuntu 24.04).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# 1) Install acpid if missing | |
if ! dpkg -s acpid >/dev/null 2>&1; then | |
apt-get update | |
DEBIAN_FRONTEND=noninteractive apt-get install -y acpid | |
fi | |
# 2) Enable/start it if needed | |
if ! systemctl is-enabled acpid >/dev/null; then | |
systemctl enable acpid | |
fi | |
if ! systemctl is-active acpid >/dev/null; then | |
systemctl start acpid | |
fi | |
# 3) Ensure logging is set | |
DEFAULTS=/etc/default/acpid | |
if ! grep -q -- '--logevents' "$DEFAULTS"; then | |
cat >"$DEFAULTS" <<'EOF' | |
OPTIONS="--logevents" | |
EOF | |
fi | |
# 4) Drop in the event rule | |
RULE=/etc/acpi/events/powerbtn-lock | |
if ! grep -q 'lock-sessions' "$RULE"; then | |
mkdir -p /etc/acpi/events | |
cat >"$RULE" <<'EOF' | |
event=button/power.*PBTN.* | |
action=/usr/bin/loginctl lock-sessions | |
EOF | |
fi | |
# 5) Reload | |
systemctl restart acpid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on Surface Go 2 (Ubuntu 25.04, default GNOME 48, Wayland)