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