source: trunk/dsys/funcINSTALL@ 2

Last change on this file since 2 was 1, checked in by katerina, 19 years ago

Initial import

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