-
Notifications
You must be signed in to change notification settings - Fork 0
/
RADdiff.command
executable file
·285 lines (237 loc) · 8.24 KB
/
RADdiff.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
#!/bin/bash
#
# Compare current filesystem to the initial snapshot and create a diff transcript
#
#
#
# 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
# check if snapshot file exists
if ! ( test -r "${GLB_RADPATH}/client/command.K" )
then
echo "Snapshot file not found - please run RADsnapshot.command first."
exit 0
fi
echo "Checking for differences compared to the snapshot file. "
GLB_START_EPOCH=$(date -u "+%s")
# -- Create a new localised negative transcript --
# 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'
# start afresh
rm -f ${LCL_RADPATH}/client/neg-Workstation-LocalFS-1v0v0-10v0-i386.T
# path to Radmind support files
LCL_RADPATH="/private/var/radmind"
LCL_RADCMDPATH="/tmp/radcmdpath"
LCL_TEMPFILE=$(mktemp /tmp/RADdiff.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
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_SU2
GLB_TEMPFILE=$(mktemp /tmp/tempfile.XXXXXX)
# Execute everything within HEREDOC_SU3 with escalated privs.
# It's not quoted. You can't create new vars, but vars from outside are available.
sudo su root <<HEREDOC_SU3
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
# If you want to enable fsdiff checksums, add the option -csha1
#"${GLB_RADCMDPATH}"/fsdiff -I -C -o"${GLB_MYPATH}"/snapshotdiff.T -% /
# Create the diff file
"${GLB_RADCMDPATH}"/fsdiff -I -C -o${GLB_TEMPFILE} -% /
# I'm not interested in negative changes
cat ${GLB_TEMPFILE} | grep -Ev "^- " >"${GLB_MYPATH}"/snapshotdiff.T
rm -f ${GLB_TEMPFILE}
# If the SIP fixer script is available, use it
if test -e "${GLB_MYPATH}"/bin/RadmindTfix4SIP.sh
then
"${GLB_MYPATH}"/bin/RadmindTfix4SIP.sh "${GLB_MYPATH}"/snapshotdiff.T
fi
chown ${GLB_USERNAME} "${GLB_MYPATH}"/snapshotdiff.T
HEREDOC_SU3
echo "Diff created in "$(($(date -u "+%s")-${GLB_START_EPOCH}))" seconds:"
echo "${GLB_MYPATH}"/snapshotdiff.T
rm -f /tmp/radcmdpath