Add IdeaPad Conservation Mode plugin (#20)
* feat: add lux/ideapad-conservation-mode plugin * fix: address review blockers on ideapad-conservation-mode - shell-quote pluginDir/USER before splicing into the sudo/runInTerminal command (shell injection) - declare every external command setup-permissions.sh invokes as a manifest dependency, and document them in README Requirements - drop the hardcoded KERNEL=="VPC2004:00" match from the udev rule so it matches any ideapad_acpi instance, consistent with the dynamic discovery the Luau side already does - add the promised NixOS declarative setup section to README - move all user-visible strings out of conservation_mode.luau into translations/en.json, accessed via noctalia.tr() - add the required README Plugin/Usage sections * Update dependencies in plugin.toml * Update setup script requirements in README.md --------- Co-authored-by: Lemmy <studio@quadbyte.net>
This commit is contained in:
co-authored by
Lemmy
parent
f1a38ca585
commit
2922dd5d40
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-time setup: lets the "lenovoctl" group toggle Lenovo IdeaPad/Legion ACPI
|
||||
# features (currently battery conservation_mode) without root.
|
||||
#
|
||||
# Run via sudo (the plugin invokes this itself, in a terminal, the first time
|
||||
# a write fails). Idempotent -- safe to re-run.
|
||||
#
|
||||
# NOTE: udev's GROUP=/MODE= rule keys only apply to the /dev device node they
|
||||
# create, NOT to arbitrary sysfs ATTR files (see udev(7)) -- a rule matching
|
||||
# ATTR{conservation_mode} with GROUP=/MODE= is a silent no-op here. We use
|
||||
# RUN+= to chmod/chgrp the resolved sysfs path directly instead.
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Run this with sudo." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_USER="${SUDO_USER:-${1:-}}"
|
||||
if [ -z "$TARGET_USER" ]; then
|
||||
echo "No target user specified (expected \$SUDO_USER or \$1)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GROUP_NAME=lenovoctl
|
||||
RULE_FILE=/etc/udev/rules.d/99-ideapad-conservation-mode.rules
|
||||
|
||||
if [ ! -w "$(dirname "$RULE_FILE")" ]; then
|
||||
echo "Cannot write to $(dirname "$RULE_FILE") -- this looks like an immutable" >&2
|
||||
echo "/etc (e.g. NixOS, where udev rules are generated from system config)." >&2
|
||||
echo "See this plugin's README.md for the declarative NixOS setup instead." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CHGRP_BIN="$(command -v chgrp)"
|
||||
CHMOD_BIN="$(command -v chmod)"
|
||||
|
||||
echo "Creating group '$GROUP_NAME' (if missing) and adding $TARGET_USER..."
|
||||
getent group "$GROUP_NAME" >/dev/null || groupadd "$GROUP_NAME"
|
||||
usermod -aG "$GROUP_NAME" "$TARGET_USER"
|
||||
|
||||
echo "Writing $RULE_FILE..."
|
||||
cat >"$RULE_FILE" <<EOF
|
||||
ACTION=="add|change", SUBSYSTEM=="platform", DRIVER=="ideapad_acpi", RUN+="$CHGRP_BIN $GROUP_NAME /sys%p/conservation_mode", RUN+="$CHMOD_BIN 664 /sys%p/conservation_mode"
|
||||
EOF
|
||||
|
||||
echo "Reloading udev rules..."
|
||||
udevadm control --reload-rules
|
||||
udevadm trigger --subsystem-match=platform
|
||||
|
||||
echo "Done."
|
||||
Reference in New Issue
Block a user