-
Notifications
You must be signed in to change notification settings - Fork 0
/
RADsnapshot.command
executable file
·439 lines (369 loc) · 13.6 KB
/
RADsnapshot.command
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
#
# Do an initial scan of the system in order to prime the client transcripts
#
#
#
# Mark J Swift
GLB_VERSTAG="1.0.10"
[ 1 -eq 1 ];GLB_TRUE=$?
[ 1 -ne 1 ];GLB_FALSE=$?
# Full souce of this script
GLB_MYSOURCE="${0}"
# Path to this script
GLB_MYPATH="$(dirname "${GLB_MYSOURCE}")"
# Filename of this script
GLB_MYSCRIPT="$(basename "${GLB_MYSOURCE}")"
# Filename without extension
GLB_MYNAME="$(basename "${GLB_MYSOURCE}" | sed "s/\.[^\.]*$//g")"
# Get user name
GLB_USERNAME="$(whoami)"
# Get system info
GLB_SystemVersionStampAsString=$(sw_vers -productVersion)
GLB_SystemVersionStampAsNumber=0
for num in $(echo ${GLB_SystemVersionStampAsString}".0.0.0.0" | cut -d"." -f1-4 | tr "." "\n")
do
GLB_SystemVersionStampAsNumber=$((${GLB_SystemVersionStampAsNumber}*256+${num}))
done
GLB_SystemMajorVersion=$(echo ${GLB_SystemVersionStampAsString}".0.0.0.0" | cut -d"." -f1-2)
if [ ${GLB_SystemVersionStampAsNumber} -lt 168099840 ]
then
GLB_DSdefaultLocalNode="/NetInfo/DefaultLocalNode"
else
GLB_DSdefaultLocalNode="."
fi
# Check if user is an admin (returns "yes" or "no")
GLB_ISADMIN=$(dseditgroup -o checkmember -m "${GLB_USERNAME}" -n "${GLB_DSdefaultLocalNode}" admin | cut -d" " -f1)
# change directory to where this script is running
cd "${GLB_MYPATH}"
# here we go...
echo "${GLB_MYNAME} version ${GLB_VERSTAG}"
if [ ${GLB_ISADMIN} = "no" ]
then
echo "Sorry, this script can only be run as an administrator."
exit 0
fi
# path to Radmind support files
GLB_RADPATH="/private/var/radmind"
GLB_RADCMDPATH="${GLB_MYPATH}"/bin
if ! test -f "${GLB_RADCMDPATH}"/fsdiff
then
GLB_RADCMDPATH="/usr/local/bin"
fi
ln -sf "${GLB_RADCMDPATH}" /tmp/radcmdpath
GLB_RADCMDPATH="/tmp/radcmdpath"
if ! test -f "${GLB_RADCMDPATH}"/fsdiff
then
if [ ${GLB_SystemVersionStampAsNumber} -lt 168165376 ]
then
echo "Please download and install version 1.13.0 of the Radmind tools from: "
echo "http://sourceforge.net/projects/radmind/files/radmind/radmind-1.13.0/"
else
echo "Please download and install the Radmind tools from: "
echo "http://sourceforge.net/projects/radmind/"
fi
exit 0
fi
# Get radtools version
GLB_RADTOOLSVERSTR=$("${GLB_RADCMDPATH}"/fsdiff -V | head -n1)
GLB_RADTOOLSVERNUM=0
if test -n "${GLB_RADTOOLSVERSTR}"
then
for num in $(echo ${GLB_RADTOOLSVERSTR}".0.0.0.0" | cut -d"." -f1-4 | tr "." "\n")
do
GLB_RADTOOLSVERNUM=$((${GLB_RADTOOLSVERNUM}*256+${num}))
done
fi
if [ ${GLB_RADTOOLSVERNUM} -eq 0 ] || ( [ ${GLB_SystemVersionStampAsNumber} -lt 168165376 ] && [ ${GLB_RADTOOLSVERNUM} -gt 17629184 ] )
then
echo "The installed version of Radmind tools doesn't work on this OS."
if [ ${GLB_SystemVersionStampAsNumber} -lt 168165376 ]
then
echo "Please download and install version 1.13.0 from:"
echo "http://sourceforge.net/projects/radmind/files/radmind/radmind-1.13.0/"
fi
printf "Do you want to remove the installed version of RadmindTools? (Y/n):"
read GLB_YN
if [ "${GLB_YN}" = "Y" ]
then
# Execute everything within HEREDOC_SU2 with escalated privs.
# It's quoted. You can create new vars, but vars from outside are not available.
sudo su root <<'HEREDOC_SU0'
while read LCL_RADTOOLFILE
do
if test -e ${LCL_RADTOOLFILE}
then
# delete the installed radmind tools
if test -d ${LCL_RADTOOLFILE}
then
rm -d ${LCL_RADTOOLFILE}
else
rm -f ${LCL_RADTOOLFILE}
fi
fi
done << HEREDOCRADTOOLS0
/usr/local/share/man8/radmind.8
/usr/local/share/man8
/usr/local/share/man5/applefile.5
/usr/local/share/man5
/usr/local/share/man1/twhich.1
/usr/local/share/man1/repo.1
/usr/local/share/man1/rash.1
/usr/local/share/man1/lsort.1
/usr/local/share/man1/lmerge.1
/usr/local/share/man1/lfdiff.1
/usr/local/share/man1/lcreate.1
/usr/local/share/man1/lcksum.1
/usr/local/share/man1/lapply.1
/usr/local/share/man1/ktcheck.1
/usr/local/share/man1/fsdiff.1
/usr/local/share/man1
/usr/local/share/man/man8/radmind.8
/usr/local/share/man/man8
/usr/local/share/man/man5/applefile.5
/usr/local/share/man/man5
/usr/local/share/man/man1/twhich.1
/usr/local/share/man/man1/repo.1
/usr/local/share/man/man1/rash.1
/usr/local/share/man/man1/lsort.1
/usr/local/share/man/man1/lmerge.1
/usr/local/share/man/man1/lfdiff.1
/usr/local/share/man/man1/lcreate.1
/usr/local/share/man/man1/lcksum.1
/usr/local/share/man/man1/lapply.1
/usr/local/share/man/man1/ktcheck.1
/usr/local/share/man/man1/fsdiff.1
/usr/local/share/man/man1
/usr/local/share/man
/usr/local/share
/usr/local/sbin/radmind
/usr/local/sbin
/usr/local/bin/twhich
/usr/local/bin/repo
/usr/local/bin/ra.sh
/usr/local/bin/lsort
/usr/local/bin/lmerge
/usr/local/bin/lfdiff
/usr/local/bin/lcreate
/usr/local/bin/lcksum
/usr/local/bin/lapply
/usr/local/bin/ktcheck
/usr/local/bin/fsdiff
/usr/local/bin
/usr/local
/private/var/radmind/preapply
/private/var/radmind/postapply
/private/var/radmind/client
/private/var/radmind/cert
/private/var/radmind
/private/var/db/receipts/edu.umich.radmind.plist
/private/var/db/receipts/edu.umich.radmind.bom
HEREDOCRADTOOLS0
if test -e "/Library/Receipts"
then
find /Library/Receipts -depth 1 -iname "RadmindTools*" -prune -exec rm -fR "{}" \;
fi
HEREDOC_SU0
fi
exit 0
fi
echo "Creating a known state snapshot of this workstation..."
GLB_START_EPOCH=$(date -u "+%s")
# info about this workstation
GLB_ARCH=$(arch)
# formulate a name for the base transcript
GLB_BASETRANSCRIPT="os-Apple-OSX-"$(echo ${GLB_SystemVersionStampAsString}".0.0.0" | cut -d"." -f1-3 | tr "." "v")"v"$(date -r ${GLB_START_EPOCH} "+%Y%m%d%H%M")"-"$(echo ${GLB_SystemVersionStampAsString}".0.0.0" | cut -d"." -f1-2 | tr "." "v")"-"${GLB_ARCH}".T"
# Execute everything within HEREDOC_SU1 with escalated privs.
# It's not quoted. You can't create new vars, but vars from outside are available.
sudo su root <<HEREDOC_SU1
mkdir -p ${GLB_RADPATH}/cert
mkdir -p ${GLB_RADPATH}/client
mkdir -p ${GLB_RADPATH}/client/labwarden/exc
mkdir -p ${GLB_RADPATH}/postapply
mkdir -p ${GLB_RADPATH}/preapply
# Copy the general negative and exclude files in place
cp "${GLB_MYPATH}"/Resources/radmind/transcript/*.T ${GLB_RADPATH}/client/
cp "${GLB_MYPATH}"/Resources/radmind/command/labwarden/exc/*.K ${GLB_RADPATH}/client/labwarden/exc
HEREDOC_SU1
# Execute everything within HEREDOC_SU2 with escalated privs.
# It's quoted. You can create new vars, but vars from outside are not available.
sudo su root <<'HEREDOC_SU2'
LCL_START_EPOCH=$(date -u "+%s")
# path to Radmind support files
LCL_RADPATH="/private/var/radmind"
LCL_RADCMDPATH="/tmp/radcmdpath"
# should we backup the existing command file?
if test -f ${LCL_RADPATH}/client/command.K
then
if test -z "$(cat ${LCL_RADPATH}/client/command.K | grep "RADsnapshot command file")"
then
cp ${LCL_RADPATH}/client/command.K ${LCL_RADPATH}/client/command-backup-$(date -r ${LCL_START_EPOCH} "+%Y%m%d%H%M").K
fi
fi
# Work out the correct neg and exc files for the OS
LCL_NEGT=""
LCL_EXCK=""
LCL_COUNT=0
while [ $LCL_COUNT -le $(sw_vers -productVersion | cut -d"." -f2) ]; do
os_name="10v${LCL_COUNT}"
# get latest neg transcript version for this OS
sw_name="neg-Apple-OSX"
sw_ver=$(ls -1 "${LCL_RADPATH}"/client | grep -E "^$sw_name-" | grep -E ".*-$os_name-i386.T$" | grep -oE "([0-9]{1,}(v[0-9]{1,})*(v[0-9A-Za-uw-z]{1,})*)-([0-9]{1,}v[0-9]{1,})-i386.T$" | cut -d"-" -f1 | tr "v" " " | sort -n -t" " -k1 -k2 -k3 -k4 -k5 -k6 | tr " " "v" | tail -n1)
if test -n "$sw_ver"
then
LCL_NEGT=$sw_name-$sw_ver-$os_name-i386.T
fi
# get the exclude command name for this OS (if any)
command_name=$( ls -1 "${LCL_RADPATH}"/client/labwarden/exc | grep -E "^exc-Apple-OSX-"${os_name}"-i386.K$" )
if test -n "$command_name"
then
LCL_EXCK=$command_name
fi
LCL_COUNT=$((${LCL_COUNT}+1))
done
# Create a minimum workstation command file (manifest)
cat << HEREDOC_FILE1 > ${LCL_RADPATH}/client/command.K
# RADsnapshot command file
n ${LCL_NEGT}
k labwarden/exc/${LCL_EXCK}
HEREDOC_FILE1
# -- Create a radmind tools transcript --
LCL_RADTOOLSVERSTR=$("${LCL_RADCMDPATH}"/fsdiff -V | head -n1 | tr "." "v")
LCL_RADTOOLSNAMET="app-UMich-RadmindTools-${LCL_RADTOOLSVERSTR}-10v0-i386.T"
# create radtools transcript
rm -f ${LCL_RADPATH}/client/${LCL_RADTOOLSNAMET}
while read LCL_RADTOOLFILE
do
if test -e ${LCL_RADTOOLFILE}
then
"${LCL_RADCMDPATH}"/fsdiff -1 -I ${LCL_RADTOOLFILE} >>${LCL_RADPATH}/client/${LCL_RADTOOLSNAMET}
fi
done << HEREDOCRADTOOLS1
/Library/Receipts/RadmindTools-1.13.0.pkg
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Archive.bom
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Info.plist
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/PkgInfo
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/background.tiff
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/en.lproj
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/en.lproj/Description.plist
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/License.rtf
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/package_version
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/ReadMe.rtf
/Library/Receipts/RadmindTools-1.13.0.pkg/Contents/Resources/Welcome.rtf
/private/var/db/receipts/edu.umich.radmind.bom
/private/var/db/receipts/edu.umich.radmind.plist
/private/var/radmind
/private/var/radmind/cert
/private/var/radmind/postapply
/private/var/radmind/preapply
/usr/local
/usr/local/bin
/usr/local/bin/fsdiff
/usr/local/bin/ktcheck
/usr/local/bin/lapply
/usr/local/bin/lcksum
/usr/local/bin/lcreate
/usr/local/bin/lfdiff
/usr/local/bin/lmerge
/usr/local/bin/lsort
/usr/local/bin/ra.sh
/usr/local/bin/repo
/usr/local/bin/twhich
/usr/local/sbin
/usr/local/sbin/radmind
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man1/fsdiff.1
/usr/local/share/man/man1/ktcheck.1
/usr/local/share/man/man1/lapply.1
/usr/local/share/man/man1/lcksum.1
/usr/local/share/man/man1/lcreate.1
/usr/local/share/man/man1/lfdiff.1
/usr/local/share/man/man1/lmerge.1
/usr/local/share/man/man1/lsort.1
/usr/local/share/man/man1/rash.1
/usr/local/share/man/man1/repo.1
/usr/local/share/man/man1/twhich.1
/usr/local/share/man/man5
/usr/local/share/man/man5/applefile.5
/usr/local/share/man/man8
/usr/local/share/man/man8/radmind.8
/usr/local/share/man1
/usr/local/share/man1/fsdiff.1
/usr/local/share/man1/ktcheck.1
/usr/local/share/man1/lapply.1
/usr/local/share/man1/lcksum.1
/usr/local/share/man1/lcreate.1
/usr/local/share/man1/lfdiff.1
/usr/local/share/man1/lmerge.1
/usr/local/share/man1/lsort.1
/usr/local/share/man1/rash.1
/usr/local/share/man1/repo.1
/usr/local/share/man1/twhich.1
/usr/local/share/man5
/usr/local/share/man5/applefile.5
/usr/local/share/man8
/usr/local/share/man8/radmind.8
HEREDOCRADTOOLS1
HEREDOC_SU2
# Execute everything within HEREDOC_SU2 with escalated privs.
# It's quoted. You can create new vars, but vars from outside are not available.
sudo su root <<'HEREDOC_SU3'
# path to Radmind support files
LCL_RADPATH="/private/var/radmind"
LCL_RADCMDPATH="/tmp/radcmdpath"
LCL_RADTOOLSVERSTR=$("${LCL_RADCMDPATH}"/fsdiff -V | head -n1 | tr "." "v")
LCL_RADTOOLSNAMET="app-UMich-RadmindTools-${LCL_RADTOOLSVERSTR}-10v0-i386.T"
echo "p ${LCL_RADTOOLSNAMET}" >> ${LCL_RADPATH}/client/command.K
# -- Create a new localised negative transcript --
LCL_TEMPFILE=$(mktemp /tmp/RADsnapshot.XXXXXX)
mount | sed -E 's/^.* on //;s/ \([^(]*\)$//' | grep -v '^/$' | while read LCL_MOUNTPOINT
do
if test -z "$(${LCL_RADCMDPATH}/twhich -Ir "${LCL_MOUNTPOINT}" | grep -E "^# Negative$")"
then
"${LCL_RADCMDPATH}"/fsdiff -1 -I -csha1 "${LCL_MOUNTPOINT}" >> ${LCL_TEMPFILE}
fi
done
rm -f ${LCL_RADPATH}/client/neg-Workstation-LocalFS-1v0v0-10v0-i386.T
if test -s ${LCL_TEMPFILE}
then
cat << HEREDOC_FILE2 > ${LCL_RADPATH}/client/neg-Workstation-LocalFS-1v0v0-10v0-i386.T
# Negative transcript - local workstation specific.
# - This file should be generated on the workstation, prior to any filesystem
# - checks (fsdiff). It should contain negative items specific to the workstation.
# - Specifically, it should contain unusual mount points that you do not want to
# - be traversed during the filesystem check.
#
HEREDOC_FILE2
"${LCL_RADCMDPATH}"/lsort -I ${LCL_TEMPFILE} >>${LCL_RADPATH}/client/neg-Workstation-LocalFS-1v0v0-10v0-i386.T
fi
rm -f ${LCL_TEMPFILE}
HEREDOC_SU3
# -- Create the base transcript --
GLB_TEMPFILE=$(mktemp /tmp/tempfile.XXXXXX)
# Execute everything within HEREDOC_SU4 with escalated privs.
# It's not quoted. You can't create new vars, but vars from outside are available.
sudo su root <<HEREDOC_SU4
if test -e ${GLB_RADPATH}/client/neg-Workstation-LocalFS-1v0v0-10v0-i386.T
then
# Add the local negative transcript to the command file
echo "n neg-Workstation-LocalFS-1v0v0-10v0-i386.T" > ${GLB_TEMPFILE}
cat ${GLB_RADPATH}/client/command.K | grep -v "neg-Workstation-LocalFS-" >> ${GLB_TEMPFILE}
cp ${GLB_TEMPFILE} ${GLB_RADPATH}/client/command.K
rm -f ${GLB_TEMPFILE}
fi
# Create the base transcript (file payload)
# If you want to enable fsdiff checksums, add the option -csha1
#"${GLB_RADCMDPATH}"/fsdiff -I -C -o${GLB_RADPATH}/client/${GLB_BASETRANSCRIPT} -% /
"${GLB_RADCMDPATH}"/fsdiff -I -C -o${GLB_TEMPFILE} -% /
cat ${GLB_TEMPFILE} | grep -Ev "^- " >${GLB_RADPATH}/client/${GLB_BASETRANSCRIPT}
rm -f ${GLB_TEMPFILE}
# Add the base transcript to the command file
echo "p ${GLB_BASETRANSCRIPT}" >> ${GLB_RADPATH}/client/command.K
HEREDOC_SU4
echo "Snapshot created in "$(($(date -u "+%s")-${GLB_START_EPOCH}))" seconds:"
echo ${GLB_RADPATH}/client/${GLB_BASETRANSCRIPT}
rm -f "/tmp/radcmdpath"