* feat(battery-threshold): add translations and rule file * feat(battery-threshold): add setup script * feat(battery-threshold): add plugin manifest * feat(battery-threshold): implement battery-threshold service * feat(battery-threshold): implement battery-threshold widget * feat(battery-threshold): implement battery-threshold panel * feat(battery-threshold): add readme * chore(battery-threshold): add dependencies field * chore(battery-threshold): add thumbnail * docs(battery-threshold): add thumbnail to readme * fix(battery-threshold): add thumbnail from generator * chore(battery-threshold): add license and icon fields to plugin.toml * style(battery-threshold): replace tabs with spaces * style(battery-threshold): unflatten translation files * refactor(battery-threshold): use translations for widget tooltip * chore(battery-threshold): replace raw strings with translations * chore(battery-threshold): remove panel ipc event * chore(battery-threshold): check error on file read * chore(battery-threshold): remove `setUpdateInterval` calls * style(battery-threshold): fix formatting * chore(battery-threshold): remove tags capital letters * Update plugin.toml * chore(battery-threshold): remove de fr and tr translations * chore(battery-threshold): update thumbnail * fix(battery-threshold): add shell quoting for runAsync * chore(battery-threshold): embed rule file content in setup script * chore(battery-threshold): update manifest * refactor(battery-threshold): use noctalia.pluginDataDir, log read/write errors * docs(battery-threshold): update README to match template * chore(battery-threshold): add missing dependencies to manifest --------- Co-authored-by: Lemmy <studio@quadbyte.net>
55 lines
1.6 KiB
Bash
Executable File
55 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# ------------------------------
|
|
# Battery Threshold Udev Setup
|
|
# ------------------------------
|
|
# This script sets up udev rules to allow a non-root user to write to
|
|
# /sys/class/power_supply/BAT0/charge_control_end_threshold.
|
|
# It creates a group 'battery_ctl' and adds the target user to this group.
|
|
#
|
|
# Usage:
|
|
# $ sudo ./setup_rules.sh # uses SUDO_USER (with sudo)
|
|
# $ ./setup_rules.sh username # use provided username (if ran as root)
|
|
# ------------------------------
|
|
set -e
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Error: This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
# Determine target user
|
|
TARGET_USER=${SUDO_USER:-$1}
|
|
|
|
if [ -z "$TARGET_USER" ]; then
|
|
echo "Error: No target user specified." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! getent group battery_ctl >/dev/null; then
|
|
echo "Creating battery_ctl group..."
|
|
groupadd battery_ctl
|
|
fi
|
|
|
|
echo "Adding $TARGET_USER to battery_ctl group..."
|
|
usermod -aG battery_ctl "$TARGET_USER"
|
|
|
|
echo "Writing udev rule to /etc/udev/rules.d/99-battery-threshold.rules..."
|
|
|
|
cat <<'EOF' >/etc/udev/rules.d/99-battery-threshold.rules
|
|
# Battery Threshold Control - udev rule
|
|
# Grants write access to charge_control_end_threshold for users in the
|
|
# 'battery_ctl' group.
|
|
SUBSYSTEM=="power_supply", KERNEL=="BAT*", \
|
|
RUN+="/bin/chgrp battery_ctl /sys$devpath/charge_control_end_threshold", \
|
|
RUN+="/bin/chmod g+w /sys$devpath/charge_control_end_threshold"
|
|
EOF
|
|
|
|
echo "Reloading rules..."
|
|
|
|
udevadm control --reload-rules && udevadm trigger
|
|
|
|
echo "You may need a reboot for the plugin's write access to take effect"
|
|
echo "Done!"
|