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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
|
#########################################################################
#
# Subroutines for installing
#
#########################################################################
#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
getconfopts () {
fconf="$1"
if test -f "$fconf"
then
#
# check if readable
#
cat "$fconf" >/dev/null 2>&1 || return 1
#
# empty string if no --enable-nocl=..., else password
#
is_nocl=`cat "$fconf" | tr -d '\n' | egrep "^ *'?--enable-nocl=" | sed -e "s%^ *%%" | sed -e "s%^'%%" | sed -e "s%^--enable-nocl=%%" | sed -e "s% *$%%" | sed -e "s%'$%%"`
if test x"${is_nocl}" = x
then
is_nocl="start"
else
printINFO "Option --enable-nocl=${is_nocl} used."
fi
#
#
#
is_xor=`cat "$fconf" | tr -d '\n' | egrep "^ *'?--enable-stealth=" | sed -e "s%^ *%%" | sed -e "s%^'%%" | sed -e "s%^--enable-nocl=%%" | sed -e "s% *$%%" | sed -e "s%'$%%"`
if test x"${is_xor}" = x
then
is_xor="no"
else
printINFO "Option --enable-stealth=${is_xor} used."
fi
return 0
else
return 1
fi
}
writerecord () {
IDATE=`date +"%Y-%m-%d %H:%M:%S"`
echo " <client>"
echo " <client_host>${host}</client_host>"
echo " <client_group>${hostgroup}</client_group>"
echo " <client_os_machine>${arch}</client_os_machine>"
echo " <client_install_status>${install_entry}</client_install_status>"
echo " <client_install_date>${IDATE}</client_install_date>"
echo " <client_install_name>${SH_NAME}</client_install_name>"
echo " <client_install_prefix>${SH_PREFIX}</client_install_prefix>"
echo " <client_install_version>${src_version}.${realformat}</client_install_version>"
echo " </client>"
}
FTEST=0
set_flag () {
case "$line" in
*\</client\>*)
FTEST=0;
return 0;
;;
*\<client_host\>${host}\</client_host\>*)
FTEST=1;
return 1;
;;
*)
return ${FTEST};
;;
esac
}
#------------------------------------------------------------------------
# Update client db
#------------------------------------------------------------------------
updateDB() {
if test "x$1" = x
then
install_entry="D2_installed"
else
install_entry="$1"
fi
export install_entry
if test x"$DATABASE" = x
then
DATABASE="${basedir}/${defdatabase}"
fi
updlock="${DATABASE}.lockdir"
trap "rm -rf ${updlock}" 1 2 13 15
#
# A lockfile will not work, because 'root' can write anyway.
# However, 'mkdir' an existing directory will fail even for root
#
until (umask 222; mkdir "${updlock}") 2>/dev/null # test & set
do
printINFO "Waiting for lock"
sleep 1
done
IDATE=`date +"%Y-%m-%d %H:%M:%S"`
rm -f "$tmpF"; touch "$tmpF"
if test -f "$DATABASE"; then
rcfile_perm=`ls -l "${DATABASE}" | \
awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
gsub("-","",u); gsub("-","",g); gsub("-","",o); \
print "u=" u ",g=" g ",o=" o; }'`
rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
rcfile_owner=`ls -l "${DATABASE}" | \
awk '{print $3 }'`
rcfile_group=`ls -l "${DATABASE}" | \
awk '{print $4 }'`
else
rcfile_perm=640;
rcfile_owner=`ls -ld ${basedir} | awk '{print $3 }'`
rcfile_group=`ls -ld ${basedir} | awk '{print $4 }'`
fi
if test -f "${DATABASE}"
then
SStr1=`grep '<yule_db>' "${DATABASE}"`
if test "x${SStr1}" != "x"
then
SStr2=`grep "<client_host>${host}</client_host>" "${DATABASE}"`
SStr3=
if test "x${SStr2}" != "x"
then
# REPLACE
printINFO "Replace ${host} in ${DATABASE}"
exec 3<&0 <"${DATABASE}"
while
read line
do
# for some reason, var=xx only works in a function call (why?)
#
# here we test if we are still in the same client block
# (set_flag will return 0 for </client> and following)
set_flag "$line"
if test "x$?" = "x1"
then
#
# Write the full entry when client_os_machine is found
#
case "$line" in
*\<client_os_machine\>*\</client_os_machine\>)
echo " <client_group>${hostgroup}</client_group>" >>"${tmpF}"
echo " <client_os_machine>${arch}</client_os_machine>" >>"${tmpF}"
echo " <client_install_status>${install_entry}</client_install_status>" >>"${tmpF}"
echo " <client_install_date>${IDATE}</client_install_date>" >>"${tmpF}"
echo " <client_install_name>${SH_NAME}</client_install_name>" >>"${tmpF}"
echo " <client_install_prefix>${SH_PREFIX}</client_install_prefix>" >>"${tmpF}"
echo " <client_install_version>${src_version}.${realformat}</client_install_version>" >>"${tmpF}"
;;
*\<client_group\>*\</client_group\>)
:
;;
*\<client_install_status\>*\</client_install_status\>)
:
;;
*\<client_install_date\>*\</client_install_date\>)
:
;;
*\<client_install_name\>*\</client_install_name\>)
:
;;
*\<client_install_prefix\>*\</client_install_prefix\>)
:
;;
*\<client_install_version\>*\</client_install_version\>)
:
;;
*)
echo "$line" >>"${tmpF}"
;;
esac
else
echo "$line" >>"${tmpF}"
fi
done
exec 0<&3 3<&-
cp "${tmpF}" "${DATABASE}"
else
# WRITE NEW CLIENT RECORD
printINFO "Write record for ${host} in ${DATABASE}"
exec 3<&0 <"${DATABASE}"
while
read line
do
if test "x$line" = "x<yule_db>"
then
echo "$line" >>"${tmpF}"
writerecord >>"${tmpF}"
else
echo "$line" >>"${tmpF}"
fi
done
exec 0<&3 3<&-
cp "${tmpF}" "${DATABASE}"
fi
else
# COMPLAIN
printLOG "File ${DATABASE} exists, but has wrong format";
fi
else
# WRITE XML FROM SCRATCH
printINFO "Write ${DATABASE} from scratch"
echo '<?xml version="1.0" encoding="ISO-8859-1"?>' >"${tmpF}"
echo '<!DOCTYPE yule_db SYSTEM "http://la-samhna.de/yule_db-0.2.dtd">' \
>>"${tmpF}"
echo "<yule_db>" >>"${tmpF}"
writerecord >>"${tmpF}"
echo "</yule_db>" >>"${tmpF}"
cp "${tmpF}" "${DATABASE}"
fi
chown ${rcfile_owner}:${rcfile_group} "${DATABASE}"
if [ $? -ne 0 ]; then
rm -rf "${updlock}"
printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${DATABASE}"
fi
chmod ${rcfile_perm} "${DATABASE}"
if [ $? -ne 0 ]; then
rm -rf "${updlock}"
printFATAL "Could not chmod ${rcfile_perm} ${DATABASE}"
fi
rm -rf "${updlock}"
}
ageFILE() {
file="$1"
if test -f "${file}"
then
test -f "${file}.9" && { rm -f "${file}.9" || printFATAL "rm -f ${file}.9 failed."; }
test -f "${file}.8" && { mv "${file}.8" "${file}.9" || printFATAL "mv ${file}.8 ${file}.9 failed."; }
test -f "${file}.7" && { mv "${file}.7" "${file}.8" || printFATAL "mv ${file}.7 ${file}.8 failed."; }
test -f "${file}.6" && { mv "${file}.6" "${file}.7" || printFATAL "mv ${file}.6 ${file}.7 failed."; }
test -f "${file}.5" && { mv "${file}.5" "${file}.6" || printFATAL "mv ${file}.5 ${file}.6 failed."; }
test -f "${file}.4" && { mv "${file}.4" "${file}.5" || printFATAL "mv ${file}.4 ${file}.5 failed."; }
test -f "${file}.3" && { mv "${file}.3" "${file}.4" || printFATAL "mv ${file}.3 ${file}.4 failed."; }
test -f "${file}.2" && { mv "${file}.2" "${file}.3" || printFATAL "mv ${file}.2 ${file}.3 failed."; }
test -f "${file}.1" && { mv "${file}.1" "${file}.2" || printFATAL "mv ${file}.1 ${file}.2 failed."; }
test -f "${file}" && { mv "${file}" "${file}.1" || printFATAL "mv ${file} ${file}.1 failed."; }
fi
return 0;
}
#------------------------------------------------------------------------
# The path to yule data
#------------------------------------------------------------------------
pathYDATA() {
if test "x${yule_data}" = x
then
promptINPUT "Please enter the path to your yule executable"
yule_data="$INPUT"; export yule_data
fi
if test -d "${yule_data}"
then
:
else
printFATAL "Path to yule data directory not given."
fi
}
#------------------------------------------------------------------------
# The path to yule
#------------------------------------------------------------------------
pathYULE() {
if test "x${yule_exec}" = x
then
findEXE yule
if test -n "$EXECUTABLE"
then
yule_exec="$EXECUTABLE"
export yule_exec
fi
else
if test -f "${yule_exec}"
then
:
else
yule_exec=""
findEXE yule
if test -n "$EXECUTABLE"
then
yule_exec="$EXECUTABLE"
export yule_exec
fi
fi
fi
if test "x${yule_exec}" = x
then
promptINPUT "Please enter the path to your yule executable"
yule_exec="$INPUT"; export yule_exec
fi
if test -f "${yule_exec}"
then
if "${yule_exec}" --help 2>&1 | grep qualified >/dev/null 2>&1
then
:
else
printFATAL "${yule_exec} is not Yule, or not executable."
fi
else
printFATAL "Path to yule executable directory not given."
fi
}
#------------------------------------------------------------------------
# Select operating system
#------------------------------------------------------------------------
selbinARCH() {
#---------------------------------------------------------------------
# Select arch to build
#---------------------------------------------------------------------
if test x"$arch" = x
then
if test x"$assumeyes" = x1
then
printFATAL "No operating system selected, aborting."
fi
cd "$basedir/archpkg" || printFATAL "Cannot cd to $basedir/archpkg !"
LIST=`ls 2>/dev/null`
if test x"$LIST" = x
then
printFATAL "No OS directories found in ${basedir}/archpkg."
fi
n=0
command="promptMENU 'Please select operating system of host' "
ALIST=""
FLIST=""
for ff in $LIST
do
haspkg=`ls $ff/samhain-* 2>/dev/null`
if test x"$haspkg" = x
then
:
else
n=`expr $n + 1`
osp="$ff"
ALIST="$ALIST $ff"
FLIST="$FLIST $ff"
if test $n -lt 8
then
command="$command '${ff}'"
fi
fi
done
if test $n -ge 8
then
command="$command other"
fi
if test $n -eq 0
then
printFATAL "No binary packages built yet !"
fi
eval ${command}
m=$?
if test x$m = x1
then
(exit 0); exit 0;
elif test x$m = "x-1"
then
printFATAL "Something went wrong !"
else
arch="$MENU"; export arch
if test x"$arch" = xother
then
promptINPUT "Please select operating system of host from $FLIST"
if test x$m = x1
then
(exit 0); exit 0;
elif test x$m = "x-1"
then
printFATAL "Something went wrong !"
else
found=`echo $FLIST | sed -n /$INPUT/p 2>/dev/null`
if test x"$found" = x
then
printFATAL "There is no package for $INPUT"
fi
arch="$INPUT"; export arch
fi
fi
fi
fi
# arch selected or exited
}
selbinVERSION() {
OKVERLIST=""
#---------------------------------------------------------------------
# Select version
#---------------------------------------------------------------------
if test x"$src_version" = x
then
if test x"$assumeyes" = x1
then
printFATAL "No version selected, aborting."
fi
cd "${basedir}/archpkg/${arch}" || printFATAL "Cannot cd to ${basedir}/archpkg/${arch} !"
LIST=`ls samhain-* 2>/dev/null`
if test x"$LIST" = x
then
printFATAL "No binary package found in ${basedir}/archpkg/${arch}."
fi
# --------------------------------------------------
# Build a list of ${version}.${format}
# --------------------------------------------------
for ff in $LIST
do
sh_version=`echo "$ff" | sed 's/samhain\-//g'`
if test -f "install-${sh_version}"
then
OKVERLIST="$OKVERLIST ${sh_version}"
fi
done
rm -f "$tmpF" && touch "$tmpF"
for dd in $OKVERLIST
do
echo "$dd" >>"$tmpF"
done
OKVERLIST=`cat "$tmpF" | sort -r`
rm -f "$tmpF" && touch "$tmpF"
command="promptMENU 'Please select version to install' "
for word in $OKVERLIST
do
command="$command '${word}'"
done
eval ${command}
m=$?
if test x$m = x1
then
(exit 0); exit 0;
elif test x$m = "x-1"
then
printFATAL "Something went wrong !"
else
first_version="$MENU";
fi
src_version=`echo ${first_version} | sed s%\.run%% | sed s%\.rpm%% | sed s%\.deb%% | sed s%\.tbz2%% | sed s%\.depot%% | sed s%\.pkg%%`
export src_version
format=`echo ${first_version} | sed '/^\(.*\)\.\([0-9a-zA-Z]*\)$/{ s//\2/; q; }'`
if test "x$format" = xpkg
then
format="solaris-pkg"
fi
export format
fi
}
|