-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.sh
executable file
·171 lines (143 loc) · 5.93 KB
/
uninstall.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
#set -e
#set -vx
# Moving things to the right places :)
# Being super verbose and as careful as can be with "rm"
CURRENTDIR="$(pwd)"
SCRIPT_NAME=$(basename "$0")
function timenow {
date "+%Y%m%dT%H%M%S%z"
}
echo "PS: Running PanSift: $SCRIPT_NAME at $(timenow) with..."
echo "PS: Current Directory: $CURRENTDIR"
echo "PS: Parent process USER: $USER"
# Figure out how they are trying to run the script?
if [[ "$1" == "-s" ]]; then
echo "PS: Doing a silent uninstall as the -s switch was passed to the script."
else
read -n 1 -s -r -p "PS: Press any key to continue or Ctrl+C to stop."
fi
echo
echo "PS: Getting user password if required:"
sudo true
#currentUser=$(stat -f '%Su' /dev/console)
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
userHomeFolder=$(dscl . -read /users/${currentUser} NFSHomeDirectory | cut -d " " -f 2)
echo "PS: Running parts of script as logged in user: $currentUser"
echo "PS: User's home folder: $userHomeFolder"
# First, shut down the processes and stop PanSift from restarting if they continue.
echo "PS: Shutting down main PanSift.app and telegraf processes..."
sudo pkill -9 -f Pansift/telegraf
sudo pkill -9 -f Pansift.app
sudo pkill -9 -f Scripts/Pansift
echo "PS: Remove PanSift defaults if they exist..."
sudo defaults delete com.pansift.p3bar
# We are not going to source any more as we might be root versus user
install_path="/Applications/Pansift.app"
preferences="$install_path"/Contents/Resources/Preferences/pansift.conf
if test -f "$preferences"; then
echo "PS: Found original /Applications based pansift.conf preferences file..."
true
# source "$preferences"
else
echo "PS: Can not find original /Applications based pansift.conf preferences file..."
# We could exit but they have signalled their intent so let's continue.
# exit 1
fi
sudo -H -u $currentUser userHomeFolder=$userHomeFolder /bin/bash <<'END'
pansift_uuid_file="$userHomeFolder"/Library/Preferences/Pansift/pansift_uuid.conf
if test -f "$pansift_uuid_file"; then
echo "PS: pansift_uuid_file path: $pansift_uuid_file"
line=$(head -n 1 $pansift_uuid_file)
uuid=$(echo -n "$line" | xargs)
fi
pansift_token_file="$userHomeFolder"/Library/Preferences/Pansift/pansift_token.conf
if test -f "$pansift_token_file"; then
echo "PS: pansift_token_file path: $pansift_token_file"
line=$(head -n 1 $pansift_token_file)
token=$(echo -n "$line" | xargs)
fi
pansift_ingest_file="$userHomeFolder"/Library/Preferences/Pansift/pansift_ingest.conf
if test -f "$pansift_ingest_file"; then
echo "PS: pansift_ingest_file path: $pansift_ingest_file"
line=$(head -n 1 $pansift_ingest_file)
ingest=$(echo -n "$line" | xargs)
fi
echo "PS: =========================================================="
echo "PS: Strongly recommend making a note of your Pansift settings"
echo "PS: Bucket UUID: ${uuid}"
echo "PS: Write Token: ${token}"
echo "PS: Ingest URL: ${ingest}"
echo "PS: =========================================================="
END
PANSIFT_PREFERENCES="$userHomeFolder"/Library/Preferences/Pansift
PANSIFT_SCRIPTS="$userHomeFolder"/Library/Application\ Scripts/Pansift
PANSIFT_LOGS="$userHomeFolder"/Library/Logs/Pansift
PANSIFT_SUPPORT="$userHomeFolder"/Library/Application\ Support/Pansift
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "Not supported on Linux yet"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
# /Applications
if [[ -d "/Applications/Pansift.app" ]]; then
cd /Applications
sudo rm -rf ./Pansift.app
fi
# Sudoers Entry
if [[ -f "/etc/sudoers.d/pansift" ]]; then
cd /etc/sudoers.d/ && sudo rm pansift
fi
# sudo -H -u $currentUser PANSIFT_PREFERENCES="$PANSIFT_PREFERENCES" PANSIFT_SCRIPTS="$PANSIFT_SCRIPTS" PANSIFT_LOGS="$PANSIFT_LOGS" PANSIFT_SUPPORT="$PANSIFT_SUPPORT" /bin/bash <<'END'
# Scripts to Trash
if [[ -d "$PANSIFT_SCRIPTS" ]]; then
cd "$PANSIFT_SCRIPTS" && sudo rm -rf ../Pansift/*
cd .. && sudo rmdir ./Pansift
fi
# Conf files
if [[ -d "$PANSIFT_PREFERENCES" ]]; then
if [[ -f "$PANSIFT_PREFERENCES"/pansift_token.conf ]]; then
sudo rm "$PANSIFT_PREFERENCES"/pansift_token.conf
fi
cd "$PANSIFT_PREFERENCES" && sudo rm -rf ../Pansift/*
cd .. && sudo rmdir ./Pansift
fi
# Logs
if [[ -d "$PANSIFT_LOGS" ]]; then
cd "$PANSIFT_LOGS" && sudo rm -rf ../Pansift/*
cd .. && sudo rmdir ./Pansift
fi
# Telegraf Support
if [[ -d "$PANSIFT_SUPPORT" ]]; then
cd "$PANSIFT_SUPPORT" && sudo rm -rf ../Pansift/*
cd .. && sudo rmdir ./Pansift
fi
# END
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
echo "Not supported on Cygwin yet"
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
echo "Not supported on MinGW yet."
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
echo "Not supported on Windows yet"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo "Not supported on FreeBSD yet."
# ...
else
echo "Not supported on this platform yet"
fi
sudo pkgutil --forget com.pansift.p3bar
#launchctl unload -w ~/Library/LaunchAgents/com.pansift.p3bar
# Need to find where the launchagent went in Big Sur?
echo "PS: =========================================================="
echo "PS: Check Applications and move Pansift to Trash if requried."
echo "PS: Log in to https://pansift.com to request data deletion, "
echo "PS: or ask your administrator / managed service provider."
echo "PS: Note: Only Pansift admins can request web data deletions!"
echo "PS: =========================================================="
# TODO: Need a better way to do the below as it looks for permissions from installer/terminal + unknown TCC/PPPC profile?
# echo "PS: Tell System Events to delete login item Pansift..."
# sudo osascript -e 'tell application "System Events" to delete login item "Pansift"' || echo "PS: Failed to remove Login Item" && exit 0
launchctl unload -w "$userHomeFolder"/Library/LaunchAgents/com.pansift.p3bar.agent.plist || true
exit