Skip to content

Instantly share code, notes, and snippets.

@WinkelCode
WinkelCode / user-battery-notify.service
Created May 2, 2023 13:53
Put in `~/.config/systemd/user/user-battery-notify.service`, enable with `systemctl --user enable --now user-battery-notify.service`. Change variables as required for your system.
[Unit]
Description=Battery Level Notifier
[Service]
Environment=BATT_PATH=/sys/class/power_supply/BAT1/capacity
Environment=MIN_BATT_PCT=35
Environment=BATT_REFRESH_SECS=5
ExecStart=bash -c 'set -e; snooze=false; while true; do [ "$(cat "${BATT_PATH}")" -le "${MIN_BATT_PCT}" ] && [ "$snooze" != "true" ] && { notify-send --urgency=critical "Battery is at or below ${MIN_BATT_PCT}%"; snooze=true; }; [ "$(cat "${BATT_PATH}")" -gt "${MIN_BATT_PCT}" ] && [ "$snooze" == "true" ] && snooze=false; sleep "${BATT_REFRESH_SECS}"; done'
Restart=always
@WinkelCode
WinkelCode / install_portmaster_to_var.sh
Last active April 12, 2024 14:01
Work in progress
#!/usr/bin/env bash
set -e # Exit on error
if [ "$EUID" -ne 0 ]; then
echo "To ensure correct permissions, this script must be run as root."
exit 1
fi
install_location="/var/lib/safing-portmaster" # Must not include trailing slash