-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNudge-Reset.sh
71 lines (59 loc) · 2.18 KB
/
Nudge-Reset.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# get the currently logged in user
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
# global check if there is a user logged in
if [ -z "$currentUser" -o "$currentUser" = "loginwindow" ]; then
echo "no user logged in, cannot proceed"
exit 1
fi
# now we know a user is logged in
# Killing the process
/usr/bin/killall Nudge
/usr/bin/pgrep -i Nudge | /usr/bin/xargs kill
# get the current user's UID
uid=$(id -u "$currentUser")
# convenience function to run a command as the current user
# usage:
# runAsUser command arguments...
runAsUser() {
if [ "$currentUser" != "loginwindow" ]; then
launchctl asuser "$uid" sudo -u "$currentUser" "$@"
else
echo "no user logged in"
exit 1
fi
}
# variables
locationLaunchAgent="/Library/LaunchAgents/com.github.macadmins.Nudge.plist"
locationLaunchDaemon="/Library/LaunchDaemons/com.github.macadmins.Nudge.logger.plist"
locationApp="/Applications/Utilities/Nudge.app"
launchAgentPlistRunning=$(runAsUser /bin/launchctl list | grep "com.github.macadmins.Nudge")
launchDaemonPlistRunning=$(/bin/launchctl list | grep "com.github.macadmins.Nudge.Logger")
# check if the launchAgent is Running and if so, unload it.
if [[ -z $launchAgentPlistRunning ]]; then
echo "Nudge launchAgent is not loaded"
elif [[ ! -z $launchAgentPlistRunning ]]; then
echo "Nudge launchAgent is loaded, need to unload"
runAsUser /bin/launchctl unload "$locationLaunchAgent"
fi
# check if the launchDaemon is Running and if so, unload it.
if [[ -z $launchDaemonPlistRunning ]]; then
echo "Nudge Logger launchDaemon is not loaded"
elif [[ ! -z $launchDaemonPlistRunning ]]; then
echo "Nudge Logger launchDaemon is loaded, need to unload"
/bin/launchctl unload "$locationLaunchDaemon"
fi
# removal of files and the Nudge app:
if [[ -e "$locationLaunchAgent" ]]; then
echo "$locationLaunchAgent found, need to remove"
/bin/rm "$locationLaunchAgent"
fi
if [[ -e "$locationLaunchDaemon" ]]; then
echo "$locationLaunchDaemon found, need to remove"
/bin/rm "$locationLaunchDaemon"
fi
if [[ -e "$locationApp" ]]; then
echo "$locationApp found, need to remove"
/bin/rm -r "$locationApp"
fi