source: trunk/dsys/funcINSTALL@ 34

Last change on this file since 34 was 27, checked in by rainer, 19 years ago

Support for server-to-server relay and more user policies

File size: 13.5 KB
RevLine 
[1]1#########################################################################
2#
3# Subroutines for installing
4#
5#########################################################################
[27]6#
7# Copyright Rainer Wichmann (2005)
8#
9# License Information:
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
[1]24
25getconfopts () {
26 fconf="$1"
27
28 if test -f "$fconf"
29 then
30 #
31 # check if readable
32 #
33 cat "$fconf" >/dev/null 2>&1 || return 1
34 #
35 # empty string if no --enable-nocl=..., else password
36 #
37 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%'$%%"`
38 if test x"${is_nocl}" = x
39 then
40 is_nocl="start"
41 else
42 printINFO "Option --enable-nocl=${is_nocl} used."
43 fi
44 #
45 #
46 #
47 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%'$%%"`
48 if test x"${is_xor}" = x
49 then
50 is_xor="no"
51 else
52 printINFO "Option --enable-stealth=${is_xor} used."
53 fi
54 return 0
55 else
56 return 1
57 fi
58}
59
60writerecord () {
61 IDATE=`date +"%Y-%m-%d %H:%M:%S"`
62 echo " <client>"
63 echo " <client_host>${host}</client_host>"
64 echo " <client_os_machine>${arch}</client_os_machine>"
65 echo " <client_install_status>${install_entry}</client_install_status>"
66 echo " <client_install_date>${IDATE}</client_install_date>"
67 echo " <client_install_name>${SH_NAME}</client_install_name>"
68 echo " <client_install_prefix>${SH_PREFIX}</client_install_prefix>"
69 echo " <client_install_version>${src_version}.${realformat}</client_install_version>"
70 echo " </client>"
71}
72
73FTEST=0
74
75set_flag () {
76 case "$line" in
77 *\</client\>*)
78 FTEST=0;
79 return 0;
80 ;;
81
82 *\<client_host\>${host}\</client_host\>*)
83 FTEST=1;
84 return 1;
85 ;;
86
87 *)
88 return ${FTEST};
89 ;;
90 esac
91}
92
93
94#------------------------------------------------------------------------
95# Update client db
96#------------------------------------------------------------------------
97updateDB() {
98
99 if test "x$1" = x
100 then
101 install_entry="D2_installed"
102 else
103 install_entry="$1"
104 fi
105 export install_entry
106
107 if test x"$DATABASE" = x
108 then
109 DATABASE="${basedir}/${defdatabase}"
110 fi
111
[3]112 updlock="${DATABASE}.lockdir"
113 trap "rm -rf ${updlock}" 1 2 13 15
114
115 #
116 # A lockfile will not work, because 'root' can write anyway.
117 # However, 'mkdir' an existing directory will fail even for root
118 #
119 until (umask 222; mkdir "${updlock}") 2>/dev/null # test & set
120 do
121 printINFO "Waiting for lock"
122 sleep 1
123 done
124
125
[1]126 IDATE=`date +"%Y-%m-%d %H:%M:%S"`
127 rm -f "$tmpF"; touch "$tmpF"
128
129 if test -f "$DATABASE"; then
130 rcfile_perm=`ls -l "${DATABASE}" | \
131 awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
132 gsub("-","",u); gsub("-","",g); gsub("-","",o); \
133 print "u=" u ",g=" g ",o=" o; }'`
134 rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
135 rcfile_owner=`ls -l "${DATABASE}" | \
136 awk '{print $3 }'`
137 rcfile_group=`ls -l "${DATABASE}" | \
138 awk '{print $4 }'`
139 else
140 rcfile_perm=640;
141 rcfile_owner=`ls -ld ${basedir} | awk '{print $3 }'`
142 rcfile_group=`ls -ld ${basedir} | awk '{print $4 }'`
143 fi
144
145
146 if test -f "${DATABASE}"
147 then
148 SStr1=`grep '<yule_db>' "${DATABASE}"`
149 if test "x${SStr1}" != "x"
150 then
151
152 SStr2=`grep "<client_host>${host}</client_host>" "${DATABASE}"`
153
154 SStr3=
155
156 if test "x${SStr2}" != "x"
157 then
158 # REPLACE
159
160 printINFO "Replace ${host} in ${DATABASE}"
161
162 exec 3<&0 <"${DATABASE}"
163 while
164 read line
165 do
166 # for some reason, var=xx only works in a function call (why?)
167 #
168 # here we test if we are still in the same client block
169 # (set_flag will return 0 for </client> and following)
170 set_flag "$line"
171
172 if test "x$?" = "x1"
173 then
174 case "$line" in
175 *\<client_os_machine\>*\</client_os_machine\>)
176 echo " <client_os_machine>${arch}</client_os_machine>" >>"${tmpF}"
177 echo " <client_install_status>${install_entry}</client_install_status>" >>"${tmpF}"
178 echo " <client_install_date>${IDATE}</client_install_date>" >>"${tmpF}"
179 echo " <client_install_name>${SH_NAME}</client_install_name>" >>"${tmpF}"
180 echo " <client_install_prefix>${SH_PREFIX}</client_install_prefix>" >>"${tmpF}"
181 echo " <client_install_version>${src_version}.${realformat}</client_install_version>" >>"${tmpF}"
182 ;;
183
184 *\<client_install_status\>*\</client_install_status\>)
185 # echo " <client_install_status>${install_entry}</client_install_status>" >>"${tmpF}"
186 :
187 ;;
188
189 *\<client_install_date\>*\</client_install_date\>)
190 # echo " <client_install_date>${IDATE}</client_install_date>" >>"${tmpF}"
191 :
192 ;;
193
194 *\<client_install_name\>*\</client_install_name\>)
195 # echo " <client_install_name>${SH_NAME}</client_install_name>" >>"${tmpF}"
196 :
197 ;;
198
199 *\<client_install_prefix\>*\</client_install_prefix\>)
200 # echo " <client_install_prefix>${SH_PREFIX}</client_install_prefix>" >>"${tmpF}"
201 :
202 ;;
203
204 *\<client_install_version\>*\</client_install_version\>)
205 # echo " <client_install_version>${src_version}.${realformat}</client_install_version>" >>"${tmpF}"
206 :
207 ;;
208
209 *)
210 echo "$line" >>"${tmpF}"
211 ;;
212
213 esac
214 else
215 echo "$line" >>"${tmpF}"
216 fi
217
218 done
219 exec 0<&3 3<&-
220 cp "${tmpF}" "${DATABASE}"
221 else
222 # WRITE NEW CLIENT RECORD
223
224 printINFO "Write record for ${host} in ${DATABASE}"
225
226 exec 3<&0 <"${DATABASE}"
227 while
228 read line
229 do
230 if test "x$line" = "x<yule_db>"
231 then
232 echo "$line" >>"${tmpF}"
233 writerecord >>"${tmpF}"
234 else
235 echo "$line" >>"${tmpF}"
236 fi
237 done
238 exec 0<&3 3<&-
239 cp "${tmpF}" "${DATABASE}"
240 fi
241 else
242 # COMPLAIN
243 printLOG "File ${DATABASE} exists, but has wrong format";
244 fi
245 else
246 # WRITE XML FROM SCRATCH
247 printINFO "Write ${DATABASE} from scratch"
248 echo '<?xml version="1.0" encoding="ISO-8859-1"?>' >"${tmpF}"
249 echo '<!DOCTYPE yule_db SYSTEM "http://la-samhna.de/yule_db-0.1.dtd">' \
250 >>"${tmpF}"
251 echo "<yule_db>" >>"${tmpF}"
252 writerecord >>"${tmpF}"
253 echo "</yule_db>" >>"${tmpF}"
254 cp "${tmpF}" "${DATABASE}"
255 fi
256
[3]257 chown ${rcfile_owner}:${rcfile_group} "${DATABASE}"
258 if [ $? -ne 0 ]; then
[4]259 rm -rf "${updlock}"
[3]260 printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${DATABASE}"
261 fi
262 chmod ${rcfile_perm} "${DATABASE}"
263 if [ $? -ne 0 ]; then
[4]264 rm -rf "${updlock}"
[3]265 printFATAL "Could not chmod ${rcfile_perm} ${DATABASE}"
266 fi
[1]267
[3]268 rm -rf "${updlock}"
[1]269}
270
271
272ageFILE() {
273 file="$1"
274
275 if test -f "${file}"
276 then
277 test -f "${file}.9" && { rm -f "${file}.9" || printFATAL "rm -f ${file}.9 failed."; }
278 test -f "${file}.8" && { mv "${file}.8" "${file}.9" || printFATAL "mv ${file}.8 ${file}.9 failed."; }
279 test -f "${file}.7" && { mv "${file}.7" "${file}.8" || printFATAL "mv ${file}.7 ${file}.8 failed."; }
280 test -f "${file}.6" && { mv "${file}.6" "${file}.7" || printFATAL "mv ${file}.6 ${file}.7 failed."; }
281 test -f "${file}.5" && { mv "${file}.5" "${file}.6" || printFATAL "mv ${file}.5 ${file}.6 failed."; }
282 test -f "${file}.4" && { mv "${file}.4" "${file}.5" || printFATAL "mv ${file}.4 ${file}.5 failed."; }
283 test -f "${file}.3" && { mv "${file}.3" "${file}.4" || printFATAL "mv ${file}.3 ${file}.4 failed."; }
284 test -f "${file}.2" && { mv "${file}.2" "${file}.3" || printFATAL "mv ${file}.2 ${file}.3 failed."; }
285 test -f "${file}.1" && { mv "${file}.1" "${file}.2" || printFATAL "mv ${file}.1 ${file}.2 failed."; }
286 test -f "${file}" && { mv "${file}" "${file}.1" || printFATAL "mv ${file} ${file}.1 failed."; }
287 fi
288 return 0;
289}
290
291#------------------------------------------------------------------------
292# The path to yule data
293#------------------------------------------------------------------------
294pathYDATA() {
295 if test "x${yule_data}" = x
296 then
297 promptINPUT "Please enter the path to your yule executable"
298 yule_data="$INPUT"; export yule_data
299 fi
300 if test -d "${yule_data}"
301 then
302 :
303 else
304 printFATAL "Path to yule data directory not given."
305 fi
306}
307
308#------------------------------------------------------------------------
309# The path to yule
310#------------------------------------------------------------------------
311pathYULE() {
312
313 if test "x${yule_exec}" = x
314 then
315 findEXE yule
316 if test -n "$EXECUTABLE"
317 then
318 yule_exec="$EXECUTABLE"
319 export yule_exec
320 fi
321 else
322 if test -f "${yule_exec}"
323 then
324 :
325 else
326 yule_exec=""
327 findEXE yule
328 if test -n "$EXECUTABLE"
329 then
330 yule_exec="$EXECUTABLE"
331 export yule_exec
332 fi
333 fi
334 fi
335 if test "x${yule_exec}" = x
336 then
337 promptINPUT "Please enter the path to your yule executable"
338 yule_exec="$INPUT"; export yule_exec
339 fi
340 if test -f "${yule_exec}"
341 then
342 if "${yule_exec}" --help 2>&1 | grep qualified >/dev/null 2>&1
343 then
344 :
345 else
346 printFATAL "${yule_exec} is not Yule, or not executable."
347 fi
348 else
349 printFATAL "Path to yule executable directory not given."
350 fi
351}
352
353#------------------------------------------------------------------------
354# Select operating system
355#------------------------------------------------------------------------
356selbinARCH() {
357 #---------------------------------------------------------------------
358 # Select arch to build
359 #---------------------------------------------------------------------
360 if test x"$arch" = x
361 then
362 if test x"$assumeyes" = x1
363 then
364 printFATAL "No operating system selected, aborting."
365 fi
366 cd "$basedir/archpkg" || printFATAL "Cannot cd to $basedir/archpkg !"
367 LIST=`ls 2>/dev/null`
368 if test x"$LIST" = x
369 then
370 printFATAL "No OS directories found in ${basedir}/archpkg."
371 fi
372
373 n=0
374 command="promptMENU 'Please select operating system of host' "
375 ALIST=""
376 FLIST=""
377 for ff in $LIST
378 do
379 haspkg=`ls $ff/samhain-* 2>/dev/null`
380 if test x"$haspkg" = x
381 then
382 :
383 else
384 n=`expr $n + 1`
385 osp="$ff"
386 ALIST="$ALIST $ff"
387 FLIST="$FLIST $ff"
388 if test $n -lt 8
389 then
390 command="$command '${ff}'"
391 fi
392 fi
393 done
394 if test $n -ge 8
395 then
396 command="$command other"
397 fi
398
399 eval ${command}
400 m=$?
401 if test x$m = x1
402 then
403 (exit 0); exit 0;
404 elif test x$m = "x-1"
405 then
406 printFATAL "Something went wrong !"
407 else
408 arch="$MENU"; export arch
409 if test x"$arch" = xother
410 then
411 promptINPUT "Please select operating system of host from $FLIST"
412 if test x$m = x1
413 then
414 (exit 0); exit 0;
415 elif test x$m = "x-1"
416 then
417 printFATAL "Something went wrong !"
418 else
419 found=`echo $FLIST | sed -n /$INPUT/p 2>/dev/null`
420 if test x"$found" = x
421 then
422 printFATAL "There is no package for $INPUT"
423 fi
424 arch="$INPUT"; export arch
425 fi
426 fi
427 fi
428 fi
429 # arch selected or exited
430}
431
432selbinVERSION() {
433
434 OKVERLIST=""
435
436 #---------------------------------------------------------------------
437 # Select version
438 #---------------------------------------------------------------------
439 if test x"$src_version" = x
440 then
441 if test x"$assumeyes" = x1
442 then
443 printFATAL "No version selected, aborting."
444 fi
445 cd "${basedir}/archpkg/${arch}" || printFATAL "Cannot cd to ${basedir}/archpkg/${arch} !"
446 LIST=`ls samhain-* 2>/dev/null`
447 if test x"$LIST" = x
448 then
449 printFATAL "No binary package found in ${basedir}/archpkg/${arch}."
450 fi
451
452 # --------------------------------------------------
453 # Build a list of ${version}.${format}
454 # --------------------------------------------------
455
456 for ff in $LIST
457 do
458 sh_version=`echo "$ff" | sed 's/samhain\-//g'`
459 if test -f "install-${sh_version}"
460 then
461 OKVERLIST="$OKVERLIST ${sh_version}"
462 fi
463 done
464
465 rm -f "$tmpF" && touch "$tmpF"
466
467 for dd in $OKVERLIST
468 do
469 echo "$dd" >>"$tmpF"
470 done
471
472 OKVERLIST=`cat "$tmpF" | sort -r`
473
474 rm -f "$tmpF" && touch "$tmpF"
475
476 command="promptMENU 'Please select version to install' "
477 for word in $OKVERLIST
478 do
479 command="$command '${word}'"
480 done
481
482 eval ${command}
483 m=$?
484 if test x$m = x1
485 then
486 (exit 0); exit 0;
487 elif test x$m = "x-1"
488 then
489 printFATAL "Something went wrong !"
490 else
491 first_version="$MENU";
492 fi
493
494 src_version=`echo ${first_version} | sed s%\.run%% | sed s%\.rpm%% | sed s%\.deb%% | sed s%\.tbz2%% | sed s%\.depot%% | sed s%\.pkg%%`
495 export src_version
496
497 format=`echo ${first_version} | sed '/^\(.*\)\.\([0-9a-zA-Z]*\)$/{ s//\2/; q; }'`
498 if test "x$format" = xpkg
499 then
500 format="solaris-pkg"
501 fi
502 export format
503
504 fi
505}
Note: See TracBrowser for help on using the repository browser.