[1] | 1 | #########################################################################
|
---|
| 2 | #
|
---|
| 3 | # Subroutine for the 'uninstall' command
|
---|
| 4 | #
|
---|
| 5 | #########################################################################
|
---|
[27] | 6 | #
|
---|
| 7 | # Copyright Rainer Wichmann (2005)
|
---|
| 8 | #
|
---|
| 9 | # License Information:
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
[1] | 24 |
|
---|
| 25 | commandUNINSTALL() {
|
---|
| 26 |
|
---|
| 27 | printINFO "About to run \"$action\" on host \"$host\""
|
---|
| 28 |
|
---|
| 29 | format=`setupFORMAT ${DB_version}`
|
---|
| 30 | realformat="$format"
|
---|
| 31 |
|
---|
| 32 | src_version=`setupVERSION ${DB_version}`
|
---|
| 33 |
|
---|
| 34 | test -f "${basedir}/archpkg/${DB_arch}/install-${DB_version}" || \
|
---|
| 35 | printFATAL "Install script ${DB_arch}/install-${DB_version} not found"
|
---|
| 36 |
|
---|
| 37 | name=`/bin/sh "${basedir}/archpkg/${DB_arch}/install-${DB_version}" '--print-config' 'name'`
|
---|
| 38 |
|
---|
| 39 | test x"$name" = x"${DB_name}" || \
|
---|
| 40 | printFATAL "Client database and installer files are inconsistent"
|
---|
| 41 |
|
---|
| 42 | arch="${DB_arch}"
|
---|
| 43 |
|
---|
| 44 | #---------------------------------------------------------------------
|
---|
| 45 | # Uninstall.
|
---|
| 46 | #---------------------------------------------------------------------
|
---|
| 47 |
|
---|
| 48 | if test "x$format" = "xrun"; then
|
---|
| 49 | is_command="./samhain-install.sh --force --express purge"
|
---|
| 50 | target="uninstall"
|
---|
| 51 | elif test "x$format" = "xdeb"; then
|
---|
| 52 | is_command="dpkg --purge"
|
---|
| 53 | target="${DB_name}"
|
---|
| 54 | elif test "x$format" = "xrpm"; then
|
---|
| 55 | is_command="rpm --erase"
|
---|
| 56 | target="${DB_name}"
|
---|
| 57 | elif test "x$format" = "xtbz2"; then
|
---|
| 58 | is_command="emerge unmerge"
|
---|
| 59 | target="${DB_name}"
|
---|
| 60 | elif test "x$realformat" = "xpkg"; then
|
---|
| 61 | is_command="pkgremove"
|
---|
| 62 | target="${DB_name}"
|
---|
| 63 | elif test "x$realformat" = "xdepot"; then
|
---|
| 64 | is_command="/usr/sbin/swremove"
|
---|
| 65 | target="${DB_name}"
|
---|
| 66 | else
|
---|
| 67 | printFATAL "Don't know how to uninstall package format ${format}"
|
---|
| 68 | fi
|
---|
| 69 |
|
---|
| 70 | if test x"$silent" = x0
|
---|
| 71 | then
|
---|
| 72 | is_rmboot="./samhain-install.sh --force --express uninstall-boot"
|
---|
| 73 | else
|
---|
| 74 | is_rmboot="./samhain-install.sh --force --express --verbose uninstall-boot"
|
---|
| 75 | fi
|
---|
| 76 |
|
---|
| 77 | #---------------------------------------------------------------------
|
---|
| 78 | # Create temporary directory on host.
|
---|
| 79 | #---------------------------------------------------------------------
|
---|
| 80 |
|
---|
[308] | 81 | tmpdir=`eval echo "${temp_dir}/sh_${src_version}_${arch}_${format}_$$"`
|
---|
[1] | 82 |
|
---|
| 83 | if test x"$simulate" = x0
|
---|
| 84 | then
|
---|
| 85 | ssh -x -l "root" "${host}" '(umask 0077; mkdir "'${tmpdir}'")'
|
---|
| 86 | else
|
---|
| 87 | printINFO "ssh -x -l root ${host} (umask 0077; mkdir ${tmpdir})"
|
---|
| 88 | fi
|
---|
| 89 | if test x"$?" != x0
|
---|
| 90 | then
|
---|
| 91 | printFATAL "Could not create temporary directory ${tmpdir} on host ${host}."
|
---|
| 92 | else
|
---|
| 93 | printLOG "Directory ${tmpdir} created on host ${host}."
|
---|
| 94 | fi
|
---|
| 95 |
|
---|
| 96 | #---------------------------------------------------------------------
|
---|
| 97 | # Copy to host.
|
---|
| 98 | #---------------------------------------------------------------------
|
---|
| 99 |
|
---|
| 100 | if test -f "${basedir}/configs/${arch}.initscript"
|
---|
| 101 | then
|
---|
| 102 | cp "${basedir}/configs/${arch}.initscript" "${tmpD}/initscript" || \
|
---|
| 103 | printFATAL "Could not copy ${basedir}/configs/${arch}.initscript to ${tmpD}/initscript"
|
---|
| 104 | is_initscript_full="${tmpD}/initscript"
|
---|
| 105 | else
|
---|
| 106 | is_initscript_full="${basedir}/libexec/initscript"
|
---|
| 107 | fi
|
---|
| 108 |
|
---|
| 109 | if test x"$simulate" = x0
|
---|
| 110 | then
|
---|
| 111 | if test x"$silent" = x0
|
---|
| 112 | then
|
---|
| 113 | scp "${is_initscript_full}" "${basedir}/archpkg/${arch}/install-${src_version}.${format}" "root@${host}:${tmpdir}/"
|
---|
| 114 | else
|
---|
| 115 | scp -q "${is_initscript_full}" "${basedir}/archpkg/${arch}/install-${src_version}.${format}" "root@${host}:${tmpdir}/"
|
---|
| 116 | fi
|
---|
| 117 | else
|
---|
| 118 | if test x"$silent" = x0
|
---|
| 119 | then
|
---|
| 120 | printINFO "scp ${is_initscript_full} ${basedir}/archpkg/${arch}/install-${src_version}.${format} root@${host}:${tmpdir}/"
|
---|
| 121 | else
|
---|
| 122 | printINFO "scp -q ${is_initscript_full} ${basedir}/archpkg/${arch}/install-${src_version}.${format} root@${host}:${tmpdir}/"
|
---|
| 123 | fi
|
---|
| 124 | fi
|
---|
| 125 | if test x"$?" != x0
|
---|
| 126 | then
|
---|
| 127 | printFATAL "Could not copy uninstall script to host ${host}."
|
---|
| 128 | else
|
---|
| 129 | printINFO "Script copied to host ${host}."
|
---|
| 130 | fi
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | #---------------------------------------------------------------------
|
---|
| 134 | # Run uninstall script.
|
---|
| 135 | #---------------------------------------------------------------------
|
---|
| 136 | if test x"$simulate" = x0
|
---|
| 137 | then
|
---|
| 138 | #
|
---|
| 139 | # No, this is not a bug; the first 'start' argument to 'initscript'
|
---|
| 140 | # is a required dummy argument.
|
---|
| 141 | #
|
---|
| 142 | if test x"$silent" = x0
|
---|
| 143 | then
|
---|
| 144 | ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH'" && export PATH && cp "'install-${src_version}.${format}'" samhain-install.sh && chmod +x samhain-install.sh && chmod +x initscript && ./initscript start stop; eval "'${is_command}'" "'${target}'"; eval "'${is_rmboot}'")'\'
|
---|
| 145 | else
|
---|
| 146 | ssh -x -l "root" "${host}" /bin/sh -c \''(cd "'${tmpdir}'" && PATH="'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH'" && export PATH && cp "'install-${src_version}.${format}'" samhain-install.sh && chmod +x samhain-install.sh && chmod +x initscript && ./initscript start stop; eval "'${is_command}'" "'${target}'"; eval "'${is_rmboot}'") >/dev/null'\'
|
---|
| 147 | fi
|
---|
| 148 | else
|
---|
| 149 | printINFO "ssh -x -l root ${host} (cd ${tmpdir} && && PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:\$PATH && export PATH cp install-${src_version}.${realformat} samhain-install.sh && chmod +x samhain-install.sh && chmod +x initscript && ./initscript start stop; eval "${is_command}" "${target}"; eval "${is_rmboot}")"
|
---|
| 150 | fi
|
---|
| 151 | if test x"$?" != x0
|
---|
| 152 | then
|
---|
| 153 | printFATAL "Could not complete uninstall on host ${host}."
|
---|
| 154 | else
|
---|
| 155 | printLOG "Uninstall executed on host ${host}"
|
---|
| 156 | fi
|
---|
| 157 |
|
---|
| 158 | #---------------------------------------------------------------------
|
---|
| 159 | # Clean up.
|
---|
| 160 | #---------------------------------------------------------------------
|
---|
| 161 |
|
---|
| 162 | if test x"$simulate" = x0
|
---|
| 163 | then
|
---|
| 164 | ssh -x -l "root" "${host}" '(rm -rf "'${tmpdir}'")'
|
---|
| 165 | else
|
---|
| 166 | printINFO "ssh -x -l root ${host} (rm -rf ${tmpdir})"
|
---|
| 167 | fi
|
---|
| 168 | if test x"$?" != x0
|
---|
| 169 | then
|
---|
| 170 | printFATAL "Could not remove temporary directory ${tmpdir} on host ${host}."
|
---|
| 171 | else
|
---|
| 172 | printLOG "Directory ${tmpdir} deleted on host ${host}."
|
---|
| 173 | fi
|
---|
| 174 |
|
---|
| 175 | #---------------------------------------------------------------------
|
---|
| 176 | # Write/update client database
|
---|
| 177 | #---------------------------------------------------------------------
|
---|
| 178 |
|
---|
| 179 | SH_NAME="$name"; export SH_NAME
|
---|
| 180 | SH_PREFIX=`/bin/sh ${basedir}/archpkg/${DB_arch}/install-${DB_version} --print-config prefix`; export SH_PREFIX
|
---|
| 181 |
|
---|
| 182 | if test x"$simulate" = x0
|
---|
| 183 | then
|
---|
| 184 | updateDB D2_removed
|
---|
| 185 | else
|
---|
| 186 | printINFO "Updating client database."
|
---|
| 187 | fi
|
---|
| 188 | }
|
---|