-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·43 lines (36 loc) · 1.36 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·43 lines (36 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#
# Uninstall the AC Caffeinate (accaf) LaunchDaemon. Must be run as root:
#
# sudo ./uninstall.sh # stop & remove daemon + watcher, restore normal sleep
# sudo ./uninstall.sh --purge # additionally delete the log file
#
# Honors the same overrides as install.sh (LABEL, PREFIX, DAEMON_DIR, LOG_FILE).
#
set -euo pipefail
# --- configuration (must match the install) ---
LABEL="${LABEL:-com.howar31.ac-caffeinate}"
PREFIX="${PREFIX:-/usr/local}"
DAEMON_DIR="${DAEMON_DIR:-/Library/LaunchDaemons}"
LOG_FILE="${LOG_FILE:-/var/log/ac-caffeinate.log}"
INSTALL_SCRIPT="$PREFIX/sbin/ac-caffeinate.sh"
PLIST="$DAEMON_DIR/$LABEL.plist"
PURGE=0
[ "${1:-}" = "--purge" ] && PURGE=1
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: must run as root: sudo $0" >&2
exit 1
fi
# Stop & unload (kills the watcher and its pmset child), then remove files.
launchctl bootout system "$PLIST" 2>/dev/null || true
rm -f "$PLIST" "$INSTALL_SCRIPT"
# Restore normal power management. `disablesleep` is a global flag that otherwise stays
# frozen at its last value (likely 1 while on AC), which would keep the Mac awake forever.
pmset -a disablesleep 0
echo "Removed: $LABEL"
echo " restored: disablesleep 0 (normal sleep)"
if [ "$PURGE" -eq 1 ]; then
rm -f "$LOG_FILE" && echo " purged log: $LOG_FILE"
else
echo " log kept: $LOG_FILE (run with --purge to delete it)"
fi