source: trunk/dsys/comINSTALL@ 298

Last change on this file since 298 was 65, checked in by rainer, 18 years ago

Fix some minor bugs.

File size: 23.7 KB
Line 
1#########################################################################
2#
3# Subroutine for the 'install' command
4#
5#########################################################################
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#
24
25commandINSTALL() {
26
27 printINFO "About to run \"$action\" on host \"$host\""
28 #
29 # configuration options we should know about
30 #
31 is_packed=0
32 is_nocl="start"
33 is_xor="no"
34
35
36 if test -f "${basedir}/configs/${arch}.configure"
37 then
38 :
39 else
40 printFATAL "Configure options ${basedir}/configs/${arch}.configure missing."
41 fi
42
43 if test -f "${basedir}/configs/${arch}.samhainrc"
44 then
45 :
46 else
47 printFATAL "Configuration file ${basedir}/configs/${arch}.samhainrc missing."
48 fi
49
50 realformat=`echo $format | sed s,solaris-,,`; export realformat
51
52 if test -f "${basedir}/archpkg/${arch}/samhain-${src_version}.${realformat}"
53 then
54 :
55 else
56 printFATAL "Binary package OS: ${arch}, version: ${src_version}, format ${format} does not exist."
57 fi
58
59 if test -f "${basedir}/archpkg/${arch}/install-${src_version}.${realformat}"
60 then
61 :
62 else
63 printFATAL "Binary package OS: ${arch}, version: ${src_version}, format ${format} is incomplete and cannot be installed."
64 fi
65
66
67 if test -f "${basedir}/archpkg/${arch}/PASSWD-${src_version}.${realformat}"
68 then
69 printINFO "Binary package OS: ${arch}, version: ${src_version}, format ${format} is packed."
70 is_packed=1
71 is_passwd=`cat "${basedir}/archpkg/${arch}/PASSWD-${src_version}.${realformat}" | tr -d '\n'`
72 else
73 is_passwd=`eval "${yule_exec}" -G`
74 if test x$? != x0
75 then
76 printFATAL "Could not generate password. Is yule in your PATH ?"
77 fi
78 fi
79
80 if test -f "${basedir}/configs/${arch}.preinstall"
81 then
82 cp "${basedir}/configs/${arch}.preinstall" "${tmpD}/preinstall" || \
83 printFATAL "Could not copy ${basedir}/configs/${arch}.preinstall to ${tmpD}/preinstall"
84 is_preinstall_full="${tmpD}/preinstall"
85 else
86 is_preinstall_full="${basedir}/libexec/preinstall"
87 fi
88
89 if test -f "${basedir}/configs/${arch}.postinstall"
90 then
91 cp "${basedir}/configs/${arch}.postinstall" "${tmpD}/postinstall" || \
92 printFATAL "Could not copy ${basedir}/configs/${arch}.postinstall to ${tmpD}/postinstall"
93 is_postinstall_full="${tmpD}/postinstall"
94 else
95 is_postinstall_full="${basedir}/libexec/postinstall"
96 fi
97
98 if test -f "${basedir}/configs/${arch}.initscript"
99 then
100 cp "${basedir}/configs/${arch}.initscript" "${tmpD}/initscript" || \
101 printFATAL "Could not copy ${basedir}/configs/${arch}.initscript to ${tmpD}/initscript"
102 is_initscript_full="${tmpD}/initscript"
103 else
104 is_initscript_full="${basedir}/libexec/initscript"
105 fi
106
107 #---------------------------------------------------------------------
108 # Get important configuration options.
109 #---------------------------------------------------------------------
110
111 getconfopts "${basedir}/archpkg/${arch}/configure-${src_version}.${realformat}" || printFATAL "Could not check config file ${basedir}/archpkg/${arch}/configure-${src_version}.${realformat}"
112
113
114 #---------------------------------------------------------------------
115 # Prepare the configuration file
116 #---------------------------------------------------------------------
117
118 if test -f "${basedir}/hosts/${host}/${arch}.samhainrc"
119 then
120 hostconfig="${basedir}/hosts/${host}/${arch}.samhainrc"
121 elif test -f "${basedir}/hosts/${host}/samhainrc"
122 then
123 hostconfig="${basedir}/hosts/${host}/samhainrc"
124 else
125 hostconfig="${basedir}/configs/${arch}.samhainrc"
126 fi
127
128 test -f "${hostconfig}" || printFATAL "Configuration file ${hostconfig} missing."
129
130 # Handle the '--enable-stealth' option
131 #
132 if test x"${is_xor}" = xno
133 then
134 :
135 else
136 test -f "${basedir}/private/stealth_template.ps" || \
137 printFATAL "${basedir}/private/stealth_template.ps not available."
138 ${basedir}/libexec/samhain_stealth -o "${hostconfig}" >/dev/null ||\
139 printFATAL "Problem reading ${hostconfig}".
140 ccount=`${basedir}/libexec/samhain_stealth -o "${hostconfig}" 2>&1 | awk '{ print $1 }'`
141 ${basedir}/libexec/samhain_stealth -i "${basedir}/private/stealth_template.ps" >/dev/null || \
142 printFATAL "Problem reading ${basedir}/private/stealth_template.ps"
143 mcount=`${basedir}/libexec/samhain_stealth -i "${basedir}/private/stealth_template.ps" 2>&1 | awk '{ print $7 }'`
144
145 if test ${mcount} -lt ${ccount}
146 then
147 printFATAL "Configuration file ${hostconfig} too big."
148 fi
149
150 cp "${basedir}/private/stealth_template.ps" "$tmpD" || \
151 printFATAL "Could not copy ${basedir}/private/stealth_template.ps to ${tmpD}/"
152 ${basedir}/libexec/samhain_stealth -s "${tmpD}/stealth_template.ps" "${hostconfig}" >/dev/null
153 if test "x$?" = x0
154 then
155 printINFO "Configuration file hidden into stealth_template.ps"
156 hostconfig="${tmpD}/stealth_template.ps"
157 else
158 printFATAL "Could not run ${basedir}/libexec/samhain_stealth -s ${tmpD}/stealth_template.ps ${hostconfig}"
159 fi
160 fi
161
162 rm -f "${tmpD}/prepared_samhainrc"
163 cp "${hostconfig}" "${tmpD}/prepared_samhainrc" || \
164 printFATAL "Could not copy ${hostconfig} to ${tmpD}/prepared_samhainrc"
165 hostconfig="${tmpD}/prepared_samhainrc"
166
167 #---------------------------------------------------------------------
168 # Create temporary directory on host.
169 #---------------------------------------------------------------------
170
171 tmpdir=`eval echo "/tmp/sh_${src_version}_${arch}_${format}_$$"`
172
173 if test x"$simulate" = x0
174 then
175 ssh -x -l "root" "${host}" '(umask 0077; mkdir "'${tmpdir}'")'
176 else
177 printINFO "ssh -x -l root ${host} (umask 0077; mkdir ${tmpdir})"
178 fi
179 if test x"$?" != x0
180 then
181 printFATAL "Could not create temporary directory ${tmpdir} on host ${host}."
182 else
183 printLOG "Directory ${tmpdir} created on host ${host}."
184 fi
185
186 #---------------------------------------------------------------------
187 # Copy to host.
188 #---------------------------------------------------------------------
189 if test x"$simulate" = x0
190 then
191 if test x"$silent" = x0
192 then
193 scp "${is_initscript_full}" "${is_preinstall_full}" "${is_postinstall_full}" "${hostconfig}" "${basedir}/archpkg/${arch}/samhain-${src_version}.${realformat}" "${basedir}/archpkg/${arch}/install-${src_version}.${realformat}" "root@${host}:${tmpdir}/"
194 else
195 scp -q "${is_initscript_full}" "${is_preinstall_full}" "${is_postinstall_full}" "${hostconfig}" "${basedir}/archpkg/${arch}/samhain-${src_version}.${realformat}" "${basedir}/archpkg/${arch}/install-${src_version}.${realformat}" "root@${host}:${tmpdir}/"
196 fi
197 else
198 if test x"$silent" = x0
199 then
200 printINFO "scp ${is_initscript_full} ${is_preinstall_full} ${is_postinstall_full} ${hostconfig} ${basedir}/archpkg/${arch}/samhain-${src_version}.${realformat} ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} root@${host}:${tmpdir}/"
201 else
202 printINFO "scp -q ${is_initscript_full} ${is_preinstall_full} ${is_postinstall_full} ${hostconfig} ${basedir}/archpkg/${arch}/samhain-${src_version}.${realformat} ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} root@${host}:${tmpdir}/"
203 fi
204 fi
205 if test x"$?" != x0
206 then
207 printFATAL "Could not copy package to host ${host}."
208 else
209 printINFO "Package copied to host ${host}."
210 fi
211
212 #---------------------------------------------------------------------
213 # Run preinstall script.
214 #---------------------------------------------------------------------
215 if test x"$simulate" = x0
216 then
217 ssh -x -l "root" "${host}" '(cd "'${tmpdir}'" && cp "'install-${src_version}.${realformat}'" samhain-install.sh && chmod +x samhain-install.sh && chmod +x preinstall && ./preinstall)'
218 else
219 printINFO "ssh -x -l root ${host} (cd ${tmpdir} && cp install-${src_version}.${realformat} samhain-install.sh && chmod +x samhain-install.sh && chmod +x preinstall && ./preinstall)"
220 fi
221 if test x"$?" != x0
222 then
223 printFATAL "Could not run preinstall script on host ${host}."
224 else
225 printLOG "Preinstall script executed on host ${host}"
226 fi
227
228 #---------------------------------------------------------------------
229 # Install.
230 #---------------------------------------------------------------------
231
232 if test "x$format" = "xrun"; then
233 is_command="/bin/sh"
234 elif test "x$format" = "xdeb"; then
235 is_command="dpkg --install --force-downgrade --force-confnew"
236 elif test "x$format" = "xrpm"; then
237 is_command="rpm --upgrade --quiet --oldpackage"
238 elif test "x$format" = "xtbz2"; then
239 is_command="emerge -K"
240 elif test "x$format" = "xsolaris-pkg"; then
241 is_command="pkgadd -n -d"
242 elif test "x$format" = "xdepot"; then
243 is_command="/usr/sbin/swinstall -x fix_explicit_directories=false -v -s "
244 else
245 printFATAL "Don't know how to install package format ${format}"
246 fi
247
248 if test "x$format" = "xdepot"
249 then
250 tmp_iname=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config name`
251 if test x"$simulate" = x0
252 then
253 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/sbin:/usr/sbin:/sbin:$PATH'" && export PATH && eval "'${is_command}'" "'${tmpdir}/samhain-${src_version}.${realformat}'" "'${tmp_iname}'") >/dev/null '\'
254 else
255 printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && eval ${is_command} ${tmpdir}/samhain-${src_version}.${realformat} ${tmp_iname})'"
256 fi
257 elif test "x$format" = "xsolaris-pkg"
258 then
259 if test x"$simulate" = x0
260 then
261 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH'" && export PATH && eval "'${is_command}'" "'samhain-${src_version}.${realformat} all'") >/dev/null '\'
262 else
263 printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && eval ${is_command} samhain-${src_version}.${realformat}) all'"
264 fi
265 elif test "x$format" = "xtbz2"
266 then
267 # Gentoo is a PITA
268 #
269 tmp_iname=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config name`
270 if test x"$simulate" = x0
271 then
272 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH'" && export PATH && cp "'samhain-${src_version}.${realformat}'" "'/usr/portage/packages/All/${tmp_iname}-${src_version}.tbz2'" && eval "'${is_command}'" "'${tmp_iname}-${src_version}.${realformat}'") >/dev/null '\'
273 else
274 printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && cp samhain-${src_version}.${realformat} /usr/portage/packages/${tmp_iname}-${src_version}.tbz2 && eval ${is_command} ${tmp_iname}-${src_version}.${realformat})'"
275 fi
276 else
277 if test x"$simulate" = x0
278 then
279 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH'" && export PATH && eval "'${is_command}'" "'samhain-${src_version}.${realformat}'") >/dev/null '\'
280 else
281 printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && eval ${is_command} samhain-${src_version}.${realformat})'"
282 fi
283 fi
284
285 if test x"$?" != x0
286 then
287 printFATAL "Could not install package on host ${host}."
288 else
289 printLOG "Package installed on host ${host}"
290 fi
291
292
293 #---------------------------------------------------------------------
294 # Run postinstall script to fix the client password.
295 #---------------------------------------------------------------------
296 if test x"$simulate" = x0
297 then
298 if test "x${is_packed}" = "x0"
299 then
300 ssh -x -l "root" "${host}" '(cd "'${tmpdir}'" && chmod +x postinstall && ./postinstall "'${is_passwd}'") >/dev/null'
301 else
302 # Dummy argument
303 ssh -x -l "root" "${host}" '(cd "'${tmpdir}'" && chmod +x postinstall && ./postinstall DUMMY ) >/dev/null'
304 fi
305 else
306 if test "x${is_packed}" = "x0"
307 then
308 printINFO "ssh -x -l root ${host} (cd ${tmpdir} && chmod +x postinstall && ./postinstall ${is_passwd})"
309 else
310 # Dummy argument
311 printINFO "ssh -x -l root ${host} (cd ${tmpdir} && chmod +x postinstall && ./postinstall DUMMY )"
312 fi
313 fi
314
315 if test x"$?" != x0
316 then
317 printFATAL "Could not run postinstall script on host ${host}."
318 else
319 printLOG "Postinstall script executed on host ${host}"
320 fi
321
322 #---------------------------------------------------------------------
323 # Update the rc file
324 #---------------------------------------------------------------------
325
326 if test "x${is_rcfile}" = xy
327 then
328 mytest_file=`ls -1 "${yule_data}/rc*" 2>/dev/null | tail -n 1 2>/dev/null`
329 if test "x$mytest_file" = x; then
330 rcfile_perm=640;
331 xgid=`(cat /etc/group; ypcat group) 2>/dev/null |\
332 grep "^samhain:" | awk -F: '{ print $3; }'`
333 if test "x$xgid" = x; then
334 rcfile_owner=`ls -ld ${yule_data} | awk '{print $3 }'`
335 rcfile_group=`ls -ld ${yule_data} | awk '{print $4 }'`
336 else
337 rcfile_owner=`ls -ld ${yule_data} | awk '{print $3 }'`
338 rcfile_group=samhain
339 fi
340 else
341 mytest_file=`basename $mytest_file`
342 rcfile_perm=`ls -l "${yule_data}/${mytest_file}" | \
343 awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
344 gsub("-","",u); gsub("-","",g); gsub("-","",o); \
345 print "u=" u ",g=" g ",o=" o; }'`
346 rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
347 rcfile_owner=`ls -l "${yule_data}/${mytest_file}" | \
348 awk '{print $3 }'`
349 rcfile_group=`ls -l "${yule_data}/${mytest_file}" | \
350 awk '{print $4 }'`
351 fi
352
353 if test -f "${hostconfig}"
354 then
355 if test x"$simulate" = x0
356 then
357 ageFILE "${yule_data}/rc.${host}" || printFATAL "Could not backup ${yule_data}/rc.${host}."
358 cp "${hostconfig}" "${yule_data}/rc.${host}" || printFATAL "Could not copy ${hostconfig} to ${yule_data}/rc.${host}"
359 chown ${rcfile_owner}:${rcfile_group} "${yule_data}/rc.${host}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_data}/rc.${host}"
360 chmod ${rcfile_perm} "${yule_data}/rc.${host}" || printFATAL "Could not chmod ${rcfile_perm} ${yule_data}/rc.${host}"
361 else
362 printINFO "Backup existing ${yule_data}/rc.${host}"
363 printINFO "Copy ${hostconfig} to ${yule_data}/rc.${host}"
364 fi
365 else
366 printFATAL "${hostconfig} is missing."
367 fi
368 printLOG "Server-side config file ${yule_data}/rc.${host} copied from ${hostconfig}."
369 fi
370
371 #---------------------------------------------------------------------
372 # Server entry and restart
373 #---------------------------------------------------------------------
374
375 instlock="${yule_conf}.lockdir";
376 trap "rm -rf ${instlock}" 1 2 13 15
377
378 if test x"$simulate" = x0
379 then
380 #
381 # A lockfile will not work, because 'root' can write anyway.
382 # However, 'mkdir' an existing directory will fail even for root
383 #
384 until (umask 222; mkdir "${instlock}") 2>/dev/null # test & set
385 do
386 printINFO "Waiting for lock"
387 sleep 1
388 done
389 fi
390
391 Replace=`"${yule_exec}" -P "${is_passwd}" | sed s%HOSTNAME%${host}%g`
392 if test "x$Replace" = x
393 then
394 rm -rf "${instlock}"
395 printFATAL "Could not execute ${yule_exec} -P ${is_passwd}."
396 fi
397 SearchString="Client=${host}@"
398 Seen=n
399 echo >"$tmpF" || printFATAL "Cannot write new server configuration."
400 while read line
401 do
402 if test "x$Seen" = xn
403 then
404 echo "$line" >>"$tmpF"
405 if test -n "`echo $line | awk '/^\[Clients\]/'`"
406 then
407 Seen=y
408 echo "$Replace" >>"$tmpF"
409 if [ $? -ne 0 ]; then
410 rm -rf "${instlock}"
411 printFATAL "Cannot write new server configuration."
412 fi
413 fi
414 else
415 if test -n "`echo $line | awk '/^'${SearchString}'/'`"
416 then
417 :
418 else
419 echo "$line" >>"$tmpF"
420 if [ $? -ne 0 ]; then
421 rm -rf "${instlock}"
422 printFATAL "Cannot write new server configuration."
423 fi
424 fi
425 fi
426 done <"${yule_conf}"
427
428 rcfile_perm=`ls -l "${yule_conf}" | \
429 awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
430 gsub("-","",u); gsub("-","",g); gsub("-","",o); \
431 print "u=" u ",g=" g ",o=" o; }'`
432 rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
433 rcfile_owner=`ls -l "${yule_conf}" | \
434 awk '{print $3 }'`
435 rcfile_group=`ls -l "${yule_conf}" | \
436 awk '{print $4 }'`
437
438 if test x"$simulate" = x0
439 then
440 ageFILE "${yule_conf}"
441 if [ $? -ne 0 ]; then
442 rm -rf "${instlock}"
443 printFATAL "Could not backup ${yule_conf}"
444 fi
445
446 rm -f "${yule_conf}" && cp "$tmpF" "${yule_conf}"
447 if [ $? -ne 0 ]; then
448 rm -rf "${instlock}"
449 printFATAL "Could not write new server config. Backup is ${yule_conf}.1"
450 fi
451
452 chown ${rcfile_owner}:${rcfile_group} "${yule_conf}"
453 if [ $? -ne 0 ]; then
454 rm -rf "${instlock}"
455 printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_conf}"
456 fi
457
458 chmod ${rcfile_perm} "${yule_conf}"
459 if [ $? -ne 0 ]; then
460 rm -rf "${instlock}"
461 printFATAL "Could not chmod ${rcfile_perm} ${yule_conf}"
462 fi
463 else
464 printINFO "Backup and update ${yule_conf}"
465 fi
466
467 if test "x${local_command}" = x
468 then
469 :
470 else
471 if test x"$simulate" = x0
472 then
473 eval "${local_command}" "${host}" "${arch}" "${basedir}" "${yule_data}" "first"
474 else
475 printINFO "eval ${local_command} ${host} ${arch} ${basedir} ${yule_data} first"
476 fi
477 fi
478
479 yule_name=`basename "${yule_exec}"`
480
481 if test x"$simulate" = x0
482 then
483 if test -f "/etc/init.d/${yule_name}"
484 then
485 eval "/etc/init.d/${yule_name}" reload
486 if test x"$?" != x0
487 then
488 printWARNING "Could not reload server using: /etc/init.d/${yule_name} reload."
489 fi
490 else
491 eval "${yule_exec}" reload
492 if test x"$?" != x0
493 then
494 printWARNING "Could not reload server using: ${yule_exec} reload."
495 fi
496 fi
497 #
498 # wait for the server to pick up the new configuration
499 #
500 sleep 5
501 #
502 rm -rf "${instlock}"
503 else
504 printINFO "Reloading server configuration."
505 fi
506
507 printLOG "Server configuration updated and reloaded."
508
509
510 #---------------------------------------------------------------------
511 # Write/update client database
512 #---------------------------------------------------------------------
513
514 SH_NAME=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config name`; export SH_NAME
515 SH_PREFIX=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config prefix`; export SH_PREFIX
516
517 if test x"$simulate" = x0
518 then
519 updateDB
520 else
521 printINFO "Updating client database."
522 fi
523
524 #---------------------------------------------------------------------
525 # Initialize and fetch database
526 #---------------------------------------------------------------------
527
528 if test "x${is_init}" = xy
529 then
530 if test x"$simulate" = x0
531 then
532 if test x"$silent" != x0
533 then
534 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && chmod +x initscript && ./initscript ${is_nocl} >/dev/null 2>&1 )'\'
535 else
536 ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && chmod +x initscript && ./initscript ${is_nocl} >/dev/null 2>&1 )'\'
537 fi
538 if test x"$?" != x0
539 then
540 printFATAL "Could not initialize database on host ${host}."
541 else
542 printLOG "Database initialized on host ${host}"
543 fi
544 scp -q "root@${host}:${tmpdir}/data" "$tmpD" || \
545 printFATAL "Could not retrieve database file root@${host}:${tmpdir}/data"
546 else
547 printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && chmod +x initscript && ./initscript ${is_nocl})'"
548 printLOG "Database initialized on host ${host}"
549 printINFO "scp -q root@${host}:${tmpdir}/data $tmpD"
550 fi
551
552 mytest_file=`ls -1 "${yule_data}/file*" 2>/dev/null | tail -n 1 2>/dev/null`
553 if test "x$mytest_file" = x; then
554 rcfile_perm=640;
555 xgid=`(cat /etc/group; ypcat group) 2>/dev/null |\
556 grep "^samhain:" | awk -F: '{ print $3; }'`
557 if test "x$xgid" = x; then
558 rcfile_owner=`ls -ld ${yule_data} | awk '{print $3 }'`
559 rcfile_group=`ls -ld ${yule_data} | awk '{print $4 }'`
560 else
561 rcfile_owner=`ls -ld ${yule_data} | awk '{print $3 }'`
562 rcfile_group=samhain
563 fi
564 else
565 mytest_file=`basename $mytest_file`
566 rcfile_perm=`ls -l "${yule_data}/${mytest_file}" | \
567 awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
568 gsub("-","",u); gsub("-","",g); gsub("-","",o); \
569 print "u=" u ",g=" g ",o=" o; }'`
570 rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
571 rcfile_owner=`ls -l "${yule_data}/${mytest_file}" | \
572 awk '{print $3 }'`
573 rcfile_group=`ls -l "${yule_data}/${mytest_file}" | \
574 awk '{print $4 }'`
575 fi
576
577 if test x"$simulate" = x0
578 then
579 if test -f "$tmpD/data"
580 then
581 ageFILE "${yule_data}/file.${host}" || printFATAL "Could not backup ${yule_conf}."
582 mv "$tmpD/data" "${yule_data}/file.${host}" || printFATAL "Could not move database file to ${yule_data}/file.${host}"
583 chown ${rcfile_owner}:${rcfile_group} "${yule_data}/file.${host}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_data}/file.${host}"
584 chmod ${rcfile_perm} "${yule_data}/file.${host}" || printFATAL "Could not chmod ${rcfile_perm} ${yule_data}/file.${host}"
585 else
586 printFATAL "Database file not downloaded from host ${host}"
587 fi
588 else
589 printINFO "Backup and replace ${yule_data}/file.${host}"
590 fi
591 fi
592
593 #---------------------------------------------------------------------
594 # Start up.
595 #---------------------------------------------------------------------
596
597 if test "x${local_command}" = x
598 then
599 :
600 else
601 if test x"$simulate" = x0
602 then
603 eval "${local_command}" "${host}" "${arch}" "${basedir}" "${yule_data}" "second"
604 else
605 printINFO "eval ${local_command} ${host} ${arch} ${basedir} ${yule_data} second"
606 fi
607 fi
608
609 if test "x${is_startup}" = xy
610 then
611 if test x"$simulate" = x0
612 then
613 ssh -x -l "root" "${host}" '(cd "'${tmpdir}'" && chmod +x initscript && eval "'./initscript ${is_nocl} start'")'
614 else
615 printINFO "Starting remote client now."
616 fi
617 if test x"$?" != x0
618 then
619 printFATAL "Could not start client on host ${host}."
620 else
621 printLOG "Client started on host ${host}."
622 fi
623 fi
624
625 #---------------------------------------------------------------------
626 # Clean up.
627 #---------------------------------------------------------------------
628
629 if test x"$simulate" = x0
630 then
631 ssh -x -l "root" "${host}" '(rm -rf "'${tmpdir}'")'
632 else
633 printINFO "ssh -x -l root ${host} (rm -rf ${tmpdir})"
634 fi
635 if test x"$?" != x0
636 then
637 printFATAL "Could not remove temporary directory ${tmpdir} on host ${host}."
638 else
639 printLOG "Directory ${tmpdir} deleted on host ${host}."
640 fi
641
642}
643
Note: See TracBrowser for help on using the repository browser.