[1] | 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 | Replace=`"${yule_exec}" -P "${is_passwd}" | sed s%HOSTNAME%${host}%g`
|
---|
| 343 | if test "x$Replace" = x
|
---|
| 344 | then
|
---|
| 345 | printFATAL "Could not execute ${yule_exec} -P ${is_passwd}."
|
---|
| 346 | fi
|
---|
| 347 | SearchString="Client=${host}@"
|
---|
| 348 | Seen=n
|
---|
| 349 | echo >"$tmpF" || printFATAL "Cannot write new server configuration."
|
---|
| 350 | while read line
|
---|
| 351 | do
|
---|
| 352 | if test "x$Seen" = xn
|
---|
| 353 | then
|
---|
| 354 | echo "$line" >>"$tmpF"
|
---|
| 355 | if test -n "`echo $line | awk '/^\[Clients\]/'`"
|
---|
| 356 | then
|
---|
| 357 | Seen=y
|
---|
| 358 | echo "$Replace" >>"$tmpF" || printFATAL "Cannot write new server configuration."
|
---|
| 359 | fi
|
---|
| 360 | else
|
---|
| 361 | if test -n "`echo $line | awk '/^'${SearchString}'/'`"
|
---|
| 362 | then
|
---|
| 363 | :
|
---|
| 364 | else
|
---|
| 365 | echo "$line" >>"$tmpF" || printFATAL "Cannot write new server configuration."
|
---|
| 366 | fi
|
---|
| 367 | fi
|
---|
| 368 | done <"${yule_conf}"
|
---|
| 369 |
|
---|
| 370 | rcfile_perm=`ls -l "${yule_conf}" | \
|
---|
| 371 | awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
|
---|
| 372 | gsub("-","",u); gsub("-","",g); gsub("-","",o); \
|
---|
| 373 | print "u=" u ",g=" g ",o=" o; }'`
|
---|
| 374 | rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
|
---|
| 375 | rcfile_owner=`ls -l "${yule_conf}" | \
|
---|
| 376 | awk '{print $3 }'`
|
---|
| 377 | rcfile_group=`ls -l "${yule_conf}" | \
|
---|
| 378 | awk '{print $4 }'`
|
---|
| 379 |
|
---|
| 380 | if test x"$simulate" = x0
|
---|
| 381 | then
|
---|
| 382 | ageFILE "${yule_conf}" || printFATAL "Could not backup ${yule_conf}."
|
---|
| 383 | rm -f "${yule_conf}" && { cp "$tmpF" "${yule_conf}" || printFATAL "Could not write new server config. Backup is ${yule_conf}.1"; }
|
---|
| 384 | chown ${rcfile_owner}:${rcfile_group} "${yule_conf}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_conf}"
|
---|
| 385 | chmod ${rcfile_perm} "${yule_conf}" || printFATAL "Could not chmod ${rcfile_perm} ${yule_conf}"
|
---|
| 386 | else
|
---|
| 387 | printINFO "Backup and update ${yule_conf}"
|
---|
| 388 | fi
|
---|
| 389 |
|
---|
| 390 | if test "x${local_command}" = x
|
---|
| 391 | then
|
---|
| 392 | :
|
---|
| 393 | else
|
---|
| 394 | if test x"$simulate" = x0
|
---|
| 395 | then
|
---|
| 396 | eval "${local_command}" "${host}" "${arch}" "${basedir}" "${yule_data}" "first"
|
---|
| 397 | else
|
---|
| 398 | printINFO "eval ${local_command} ${host} ${arch} ${basedir} ${yule_data} first"
|
---|
| 399 | fi
|
---|
| 400 | fi
|
---|
| 401 |
|
---|
| 402 | yule_name=`basename "${yule_exec}"`
|
---|
| 403 |
|
---|
| 404 | if test x"$simulate" = x0
|
---|
| 405 | then
|
---|
| 406 | if test -f "/etc/init.d/${yule_name}"
|
---|
| 407 | then
|
---|
| 408 | eval "/etc/init.d/${yule_name}" reload
|
---|
| 409 | if test x"$?" != x0
|
---|
| 410 | then
|
---|
| 411 | printWARNING "Could not reload server using: /etc/init.d/${yule_name} reload."
|
---|
| 412 | fi
|
---|
| 413 | else
|
---|
| 414 | eval "${yule_exec}" reload
|
---|
| 415 | if test x"$?" != x0
|
---|
| 416 | then
|
---|
| 417 | printWARNING "Could not reload server using: ${yule_exec} reload."
|
---|
| 418 | fi
|
---|
| 419 | fi
|
---|
| 420 | #
|
---|
| 421 | # wait for the server to pick up the new configuration
|
---|
| 422 | #
|
---|
| 423 | sleep 5
|
---|
| 424 | #
|
---|
| 425 | else
|
---|
| 426 | printINFO "Reloading server configuration."
|
---|
| 427 | fi
|
---|
| 428 |
|
---|
| 429 | printLOG "Server configuration updated and reloaded."
|
---|
| 430 |
|
---|
| 431 | #---------------------------------------------------------------------
|
---|
| 432 | # Write/update client database
|
---|
| 433 | #---------------------------------------------------------------------
|
---|
| 434 |
|
---|
| 435 | SH_NAME=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config name`; export SH_NAME
|
---|
| 436 | SH_PREFIX=`/bin/sh ${basedir}/archpkg/${arch}/install-${src_version}.${realformat} --print-config prefix`; export SH_PREFIX
|
---|
| 437 |
|
---|
| 438 | if test x"$simulate" = x0
|
---|
| 439 | then
|
---|
| 440 | updateDB
|
---|
| 441 | else
|
---|
| 442 | printINFO "Updating client database."
|
---|
| 443 | fi
|
---|
| 444 |
|
---|
| 445 | #---------------------------------------------------------------------
|
---|
| 446 | # Initialize and fetch database
|
---|
| 447 | #---------------------------------------------------------------------
|
---|
| 448 |
|
---|
| 449 | if test "x${is_init}" = xy
|
---|
| 450 | then
|
---|
| 451 | if test x"$simulate" = x0
|
---|
| 452 | then
|
---|
| 453 | if test x"$silent" != x0
|
---|
| 454 | then
|
---|
| 455 | ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && chmod +x initscript && ./initscript ${is_nocl} >/dev/null 2>&1 )'\'
|
---|
| 456 | else
|
---|
| 457 | ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && chmod +x initscript && ./initscript ${is_nocl} >/dev/null 2>&1 )'\'
|
---|
| 458 | fi
|
---|
| 459 | if test x"$?" != x0
|
---|
| 460 | then
|
---|
| 461 | printFATAL "Could not initialize database on host ${host}."
|
---|
| 462 | else
|
---|
| 463 | printLOG "Database initialized on host ${host}"
|
---|
| 464 | fi
|
---|
| 465 | scp -q "root@${host}:${tmpdir}/data" "$tmpD" || \
|
---|
| 466 | printFATAL "Could not retrieve database file root@${host}:${tmpdir}/data"
|
---|
| 467 | else
|
---|
| 468 | printINFO "ssh -x -l root ${host} /bin/sh -c '(cd ${tmpdir} && chmod +x initscript && ./initscript ${is_nocl})'"
|
---|
| 469 | printLOG "Database initialized on host ${host}"
|
---|
| 470 | printINFO "scp -q root@${host}:${tmpdir}/data $tmpD"
|
---|
| 471 | fi
|
---|
| 472 |
|
---|
| 473 | mytest_file=`ls -1 "${yule_data}/file*" 2>/dev/null | tail -n 1 2>/dev/null`
|
---|
| 474 | if test "x$mytest_file" = x; then
|
---|
| 475 | rcfile_perm=640;
|
---|
| 476 | rcfile_owner=`ls -ld ${yule_data} | awk '{print $3 }'`
|
---|
| 477 | rcfile_group=`ls -ld ${yule_data} | awk '{print $4 }'`
|
---|
| 478 | else
|
---|
| 479 | mytest_file=`basename $mytest_file`
|
---|
| 480 | rcfile_perm=`ls -l "${yule_data}/${mytest_file}" | \
|
---|
| 481 | awk '{ u= substr($1,2,3); g=substr($1,5,3); o=substr($1,8,3); \
|
---|
| 482 | gsub("-","",u); gsub("-","",g); gsub("-","",o); \
|
---|
| 483 | print "u=" u ",g=" g ",o=" o; }'`
|
---|
| 484 | rcfile_perm=`echo ${rcfile_perm} | sed s%g=,%g-rwx,% | sed s%,o=$%,o-rwx%`
|
---|
| 485 | rcfile_owner=`ls -l "${yule_data}/${mytest_file}" | \
|
---|
| 486 | awk '{print $3 }'`
|
---|
| 487 | rcfile_group=`ls -l "${yule_data}/${mytest_file}" | \
|
---|
| 488 | awk '{print $4 }'`
|
---|
| 489 | fi
|
---|
| 490 |
|
---|
| 491 | if test x"$simulate" = x0
|
---|
| 492 | then
|
---|
| 493 | if test -f "$tmpD/data"
|
---|
| 494 | then
|
---|
| 495 | ageFILE "${yule_data}/file.${host}" || printFATAL "Could not backup ${yule_conf}."
|
---|
| 496 | mv "$tmpD/data" "${yule_data}/file.${host}" || printFATAL "Could not move database file to ${yule_data}/file.${host}"
|
---|
| 497 | chown ${rcfile_owner}:${rcfile_group} "${yule_data}/file.${host}" || printFATAL "Could not chown ${rcfile_owner}:${rcfile_group} ${yule_data}/file.${host}"
|
---|
| 498 | chmod ${rcfile_perm} "${yule_data}/file.${host}" || printFATAL "Could not chmod ${rcfile_perm} ${yule_data}/file.${host}"
|
---|
| 499 | else
|
---|
| 500 | printFATAL "Database file not downloaded from host ${host}"
|
---|
| 501 | fi
|
---|
| 502 | else
|
---|
| 503 | printINFO "Backup and replace ${yule_data}/file.${host}"
|
---|
| 504 | fi
|
---|
| 505 | fi
|
---|
| 506 |
|
---|
| 507 | #---------------------------------------------------------------------
|
---|
| 508 | # Start up.
|
---|
| 509 | #---------------------------------------------------------------------
|
---|
| 510 |
|
---|
| 511 | if test "x${local_command}" = x
|
---|
| 512 | then
|
---|
| 513 | :
|
---|
| 514 | else
|
---|
| 515 | if test x"$simulate" = x0
|
---|
| 516 | then
|
---|
| 517 | eval "${local_command}" "${host}" "${arch}" "${basedir}" "${yule_data}" "second"
|
---|
| 518 | else
|
---|
| 519 | printINFO "eval ${local_command} ${host} ${arch} ${basedir} ${yule_data} second"
|
---|
| 520 | fi
|
---|
| 521 | fi
|
---|
| 522 |
|
---|
| 523 | if test "x${is_startup}" = xy
|
---|
| 524 | then
|
---|
| 525 | if test x"$simulate" = x0
|
---|
| 526 | then
|
---|
| 527 | ssh -x -l "root" "${host}" '(cd "'${tmpdir}'" && chmod +x initscript && eval "'./initscript ${is_nocl} start'")'
|
---|
| 528 | else
|
---|
| 529 | printINFO "Starting remote client now."
|
---|
| 530 | fi
|
---|
| 531 | if test x"$?" != x0
|
---|
| 532 | then
|
---|
| 533 | printFATAL "Could not start client on host ${host}."
|
---|
| 534 | else
|
---|
| 535 | printLOG "Client started on host ${host}."
|
---|
| 536 | fi
|
---|
| 537 | fi
|
---|
| 538 |
|
---|
| 539 | #---------------------------------------------------------------------
|
---|
| 540 | # Clean up.
|
---|
| 541 | #---------------------------------------------------------------------
|
---|
| 542 |
|
---|
| 543 | if test x"$simulate" = x0
|
---|
| 544 | then
|
---|
| 545 | ssh -x -l "root" "${host}" '(rm -rf "'${tmpdir}'")'
|
---|
| 546 | else
|
---|
| 547 | printINFO "ssh -x -l root ${host} (rm -rf ${tmpdir})"
|
---|
| 548 | fi
|
---|
| 549 | if test x"$?" != x0
|
---|
| 550 | then
|
---|
| 551 | printFATAL "Could not remove temporary directory ${tmpdir} on host ${host}."
|
---|
| 552 | else
|
---|
| 553 | printLOG "Directory ${tmpdir} deleted on host ${host}."
|
---|
| 554 | fi
|
---|
| 555 |
|
---|
| 556 | }
|
---|
| 557 |
|
---|