-
Notifications
You must be signed in to change notification settings - Fork 3
/
rmOffice2016
377 lines (350 loc) · 11.2 KB
/
rmOffice2016
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/bin/bash
## USAGE:
## _script_ [-r|-t|-m <path>] [-u|-a|-U <username>] [-q] [-h]
##
## DESCRIPTION:
## Script to remove/show/move (to a path) MS Office 2016 from macOS
## Copyright (C) 2017, Tony Liu
## Version 0.1.1
##
## WHERE:
## Actions:
## -r to remove, need root privilege
## -t to show the processed files, this is the default action if no action assigned
## -m <path> move all to the specific <path>, need root privilege
##
## User choice:
## do not evaluate user configurations by default
## -u current user
## -U <username> specify which <username>
## -a all local users
##
## Options:
## -q quiet mode
## -h show this help
##
## EXAMPLES:
## -rq
## remove all quietly
##
## -m /Users/Shared/Office2016
## Move all to folder /Users/Shared/Office2016
##
## -ra
## remove all global and all users local configurations
##
## -tu
## test and display apps, all global and current user's local configurations
##
# ----------------------------------------------------------------------------------------
# Remove Office 2016 for Mac totally
# Remove apps, related global and user(s)' library data
# ----------------------------------------------------------------------------------------
sUsage()
{
# scName=$(basename "$0" .sh)
[ "$*" ] && echo "$0: $*"
sed -n -e "s/_script_/$(basename "$0" .sh)/" -e "/^##/,/^$/s/^## \{0,1\}//p" "$0"
}
declare -a LibPrefs=(\
"com.microsoft.autoupdate*" \
"com.microsoft.office*" \
"com.microsoft.excel*" \
"com.microsoft.onenote*" \
"com.microsoft.outlook*" \
"com.microsoft.powerpoint*" \
"com.microsoft.word*" \
"Microsoft/uls")
cmd="echo "
mod=0
mvPath=""
username=""
userMode=0
# userMode=0 : do not touch user settings
# userMode=1 : current user
# userMode=1 : specific user, use username
# userMode=-1 : all users
# check if run as root
if ! [ $(id -u) = 0 ]; then
echo "Please run me as root!"
exit 1
fi
# Remove all Office apps.
# Printf "Removing all MS Office apps in /Applications folder...\n"
# ----------------------------------------------------------------------------------------
# Description: it use the appropriate command to do the real work.
# Arguments:
# $1 = the destination file
# Dependence:
# Global: cmd, mvPath
# ----------------------------------------------------------------------------------------
goProcess()
{
if [ -e "$1" ]; then
case $cmd in
R)
[[ $mod > 0 ]] && rm -fr "$1" &>/dev/null || rm -fr "$1"
;;
T)
[[ $mod > 0 ]] && echo "-> delete $1" &>/dev/null || echo " -> delete $1"
;;
M)
[[ $mod > 0 ]] && mv "$1" "$mvPath" &>/dev/null || mv "$1" "$mvPath"
;;
esac
fi
}
# ----------------------------------------------------------------------------------------
# Description: It traverse array to retrieve each element pass to goProcess.
# Arguments:
# $1 = the array
# Dependence: N/A
# ----------------------------------------------------------------------------------------
process1Array()
{
declare -a argAry=("${!1}")
for each in ${argAry[*]}; do
# echo " -debug: goProcess -> $each"
goProcess "$each"
done
}
# ----------------------------------------------------------------------------------------
declare -a OfficeApps=("Excel.app" "OneNote.app" "Outlook.app" "PowerPoint.app" "Word.app")
# ----------------------------------------------------------------------------------------
# Description: It deal with the Office applications from the Office Application array.
# Arguments: N/A
# Dependence:
# Global: OfficeApps
# ----------------------------------------------------------------------------------------
pOfficeApps ()
{
for each in ${OfficeApps[@]}; do
goProcess "/Applications/Microsoft $each"
done
}
# ----------------------------------------------------------------------------------------
# Description: Use pkgutil to forget all the packages.
# Arguments: N/A
# Dependence:
# Global: OfficeApps
# ----------------------------------------------------------------------------------------
pForgetPKG()
{
case $cmd in
R)
pkgutil --forget com.microsoft.pkg.licensing.volume &>/dev/null
pkgutil --forget com.microsoft.package.Proofing_Tools &>/dev/null
pkgutil --forget com.microsoft.pkg.licensing &>/dev/null
pkgutil --forget com.microsoft.package.Fonts &>/dev/null
pkgutil --forget com.microsoft.package.Frameworks &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_AutoUpdate.app &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_Excel.app &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_OneNote.app &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_Outlook.app &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_PowerPoint.app &>/dev/null
pkgutil --forget com.microsoft.package.Microsoft_Word.app &>/dev/null
;;
*)
echo " -> forget package com.microsoft.pkg.licensing.volume"
echo " -> forget package com.microsoft.package.Proofing_Tools"
echo " -> forget package com.microsoft.pkg.licensing"
echo " -> forget package com.microsoft.package.Fonts"
echo " -> forget package com.microsoft.package.Frameworks"
echo " -> forget package com.microsoft.package.Microsoft_AutoUpdate.app"
echo " -> forget package com.microsoft.package.Microsoft_Excel.app"
echo " -> forget package com.microsoft.package.Microsoft_OneNote.app"
echo " -> forget package com.microsoft.package.Microsoft_Outlook.app"
echo " -> forget package com.microsoft.package.Microsoft_PowerPoint.app"
echo " -> forget package com.microsoft.package.Microsoft_Word.app"
;;
esac
}
# ----------------------------------------------------------------------------------------
declare -a sLibPLaunch=(\
"/Library/LaunchDaemons/com.microsoft.office.licensingV2.helper.plist" \
"/Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist")
declare -a sLibPrivs=(\
"/Library/PrivilegedHelperTools/com.microsoft.office.licensingV2.helper" \
"/Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper")
declare -a sLibAppSupt=(\
"/Library/Application\ Support/Microsoft/MAU2.0" \
"/Library/Application\ Support/Microsoft/MERP*" \
"/Library/Preferences/com.microsoft.office.licensingV2.plist")
# ----------------------------------------------------------------------------------------
# Description: It deal with the system level Library from System Library arrays.
# Arguments: N/A
# Dependence:
# Global: sLibPLaunch, sLibPrivs and sLibAppSupt
# ----------------------------------------------------------------------------------------
pSysLibrary ()
{
# Launchd
process1Array sLibPLaunch[@]
#PrivilegedHelperTools
process1Array sLibPrivs[@]
# Application Support
process1Array [@]
for each in ${sLibAppSupt[@]}; do
for file in "${user}/Library/Preferences/${each}"; do goProcess "$file"; done
done
# Preferences
for each in ${LibPrefs[@]}; do
for file in "/Library/Preferences/$each"; do goProcess "$file"; done
done
}
# ----------------------------------------------------------------------------------------
declare -a uLibContainers=(\
"/Library/Containers/com.microsoft.errorreporting" \
"/Library/Containers/com.microsoft.Excel" \
"/Library/Containers/com.microsoft.netlib.shipassertprocess" \
"/Library/Containers/com.microsoft.Office365ServiceV2" \
"/Library/Containers/com.microsoft.Outlook" \
"/Library/Containers/com.microsoft.Powerpoint" \
"/Library/Containers/com.microsoft.RMS-XPCService" \
"/Library/Containers/com.microsoft.Word" \
"/Library/Containers/com.microsoft.onenote.mac")
declare -a uLibGContainers=(\
"UBF8T346G9.OfficeOsfWebHost" \
"UBF8T346G9.Office" \
"UBF8T346G9.ms")
declare -a uLibAppScripts=(\
"com.microsoft.Office365ServiceV2" \
"com.microsoft.Excel" \
"com.microsoft.onenote.mac" \
"com.microsoft.Outlook" \
"com.microsoft.PowerPoint" \
"com.microsoft.Word")
# ----------------------------------------------------------------------------------------
# Description: It deal with the user level Library from user global arrays.
# Arguments:
# $1 = the user homepath
# Dependence:
# Global: LibPrefs, uLibContainers, uLibGContainers
# ----------------------------------------------------------------------------------------
pUserLibrary()
{
user="$1"
# echo " -debug: $user/Library"
if [ -d "$user/Library" ]; then
# Preferences, ByHost, Caches, Application Support
for each in ${LibPrefs[@]}; do
#echo " -debug:$each; ${user}/Library/Preferences/${each}"
for sFile in ${user}/Library/Preferences/${each}; do goProcess "$sFile"; done
for sFile in ${user}/Library/Preferences/ByHost/${each}; do goProcess "$sFile"; done
for sFile in ${user}/Library/Caches/${each}; do goProcess "$sFile"; done
done
for sFile in ${user}/Library/Application\ Support/Microsoft/Office*; do goProcess "$sFile"; done
# Containers
for each in ${uLibContainers[@]}; do goProcess "${user}/$each"; done
# Group Containers
for each in ${uLibGContainers[@]}; do goProcess "${user}/Library/Group Containers/$each"; done
# ~/Library/Application Scripts/ folder
for sFile in ${uLibAppScripts[@]}; do goProcess "${user}/Library/Application Scripts/$sFile"; done
# Keychains
# Microsoft Office Identities Cache 2
# Microsoft Office Identities Settings 2
fi
}
# ----------------------------------------------------------------------------------------
# Description: Get the given user home directory and process it.
# Arguments:
# $1 = username
# Dependence: N/A
# ----------------------------------------------------------------------------------------
pUserSingle()
{
home=`dscl . read /Users/"$1" NFSHomeDirectory | awk '{print $2}'`
# echo " --> Single User=$1; Home=$home"
pUserLibrary "$home"
}
# ----------------------------------------------------------------------------------------
# Description: Get all local host none-system users and pass to pUserSingle to process.
# Arguments: N/A
# Dependence: N/A
# ----------------------------------------------------------------------------------------
pUserAll()
{
allUsers=`dscl . list /Users UniqueID | awk '$2 > 500 {print $1}'`
for user in $allUsers; do
pUserSingle $user
done
}
# ----------------------------------------------------------------------------------------
# Description: Start with user mode.
# Arguments: N/A
# Dependence:
# Global: userMode, destUser
# ----------------------------------------------------------------------------------------
pUserMode()
{
case $userMode in
0)
pUserSingle "$(users)"
;;
1)
pUserSingle "$destUser"
;;
-1)
pUserAll
;;
esac
}
# ----------------------------------------------------------------------------------------
while getopts ":rqtm:uU:ah" opt; do
case $opt in
r)
#echo "-r to remove!"
cmd="R"
;;
t)
#echo "-t test mode."
cmd="T"
;;
m)
#echo "-m to move!"
cmd="M"
mvPath="$OPTARG"
if [ ! -e "$mvPath" ]; then mkdir -p "$mvPath"; fi
;;
u)
#echo "-u to current user!"
destUser=$(users)
userMode=0
;;
U)
#echo "-U to specific user!"
destUser="$OPTARG"
userMode=1
;;
a)
#echo "-a all users!"
destUser=""
userMode=-1
;;
q)
#echo "-q verbose mode."
mod=1
;;
:)
#echo "Option -$OPTARG requires an argument." >&2
sUsage >&2
#echo "$usage" >&2
exit 2
;;
\?)
#echo "Invalid option: -$OPTARG" >&2
sUsage >&2
#echo "$usage" >&2
;;
h)
sUsage
#echo "$usage"
exit 1
;;
esac
done
pForgetPKG
pOfficeApps
pSysLibrary
pUserMode
exit 0