source: trunk/dsys/comUNINSTALL@ 19

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

Initial import

File size: 6.3 KB
Line 
1#########################################################################
2#
3# Subroutine for the 'uninstall' command
4#
5#########################################################################
6
7commandUNINSTALL() {
8
9 printINFO "About to run \"$action\" on host \"$host\""
10
11 format=`setupFORMAT ${DB_version}`
12 realformat="$format"
13
14 src_version=`setupVERSION ${DB_version}`
15
16 test -f "${basedir}/archpkg/${DB_arch}/install-${DB_version}" || \
17 printFATAL "Install script ${DB_arch}/install-${DB_version} not found"
18
19 name=`/bin/sh "${basedir}/archpkg/${DB_arch}/install-${DB_version}" '--print-config' 'name'`
20
21 test x"$name" = x"${DB_name}" || \
22 printFATAL "Client database and installer files are inconsistent"
23
24 arch="${DB_arch}"
25
26 #---------------------------------------------------------------------
27 # Uninstall.
28 #---------------------------------------------------------------------
29
30 if test "x$format" = "xrun"; then
31 is_command="./samhain-install.sh --force --express purge"
32 target="uninstall"
33 elif test "x$format" = "xdeb"; then
34 is_command="dpkg --purge"
35 target="${DB_name}"
36 elif test "x$format" = "xrpm"; then
37 is_command="rpm --erase"
38 target="${DB_name}"
39 elif test "x$format" = "xtbz2"; then
40 is_command="emerge unmerge"
41 target="${DB_name}"
42 elif test "x$realformat" = "xpkg"; then
43 is_command="pkgremove"
44 target="${DB_name}"
45 elif test "x$realformat" = "xdepot"; then
46 is_command="/usr/sbin/swremove"
47 target="${DB_name}"
48 else
49 printFATAL "Don't know how to uninstall package format ${format}"
50 fi
51
52 if test x"$silent" = x0
53 then
54 is_rmboot="./samhain-install.sh --force --express uninstall-boot"
55 else
56 is_rmboot="./samhain-install.sh --force --express --verbose uninstall-boot"
57 fi
58
59 #---------------------------------------------------------------------
60 # Create temporary directory on host.
61 #---------------------------------------------------------------------
62
63 tmpdir=`eval echo "/tmp/sh_${src_version}_${arch}_${format}_$$"`
64
65 if test x"$simulate" = x0
66 then
67 ssh -x -l "root" "${host}" '(umask 0077; mkdir "'${tmpdir}'")'
68 else
69 printINFO "ssh -x -l root ${host} (umask 0077; mkdir ${tmpdir})"
70 fi
71 if test x"$?" != x0
72 then
73 printFATAL "Could not create temporary directory ${tmpdir} on host ${host}."
74 else
75 printLOG "Directory ${tmpdir} created on host ${host}."
76 fi
77
78 #---------------------------------------------------------------------
79 # Copy to host.
80 #---------------------------------------------------------------------
81
82 if test -f "${basedir}/configs/${arch}.initscript"
83 then
84 cp "${basedir}/configs/${arch}.initscript" "${tmpD}/initscript" || \
85 printFATAL "Could not copy ${basedir}/configs/${arch}.initscript to ${tmpD}/initscript"
86 is_initscript_full="${tmpD}/initscript"
87 else
88 is_initscript_full="${basedir}/libexec/initscript"
89 fi
90
91 if test x"$simulate" = x0
92 then
93 if test x"$silent" = x0
94 then
95 scp "${is_initscript_full}" "${basedir}/archpkg/${arch}/install-${src_version}.${format}" "root@${host}:${tmpdir}/"
96 else
97 scp -q "${is_initscript_full}" "${basedir}/archpkg/${arch}/install-${src_version}.${format}" "root@${host}:${tmpdir}/"
98 fi
99 else
100 if test x"$silent" = x0
101 then
102 printINFO "scp ${is_initscript_full} ${basedir}/archpkg/${arch}/install-${src_version}.${format} root@${host}:${tmpdir}/"
103 else
104 printINFO "scp -q ${is_initscript_full} ${basedir}/archpkg/${arch}/install-${src_version}.${format} root@${host}:${tmpdir}/"
105 fi
106 fi
107 if test x"$?" != x0
108 then
109 printFATAL "Could not copy uninstall script to host ${host}."
110 else
111 printINFO "Script copied to host ${host}."
112 fi
113
114
115 #---------------------------------------------------------------------
116 # Run uninstall script.
117 #---------------------------------------------------------------------
118 if test x"$simulate" = x0
119 then
120 #
121 # No, this is not a bug; the first 'start' argument to 'initscript'
122 # is a required dummy argument.
123 #
124 if test x"$silent" = x0
125 then
126 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}'")'\'
127 else
128 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'\'
129 fi
130 else
131 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}")"
132 fi
133 if test x"$?" != x0
134 then
135 printFATAL "Could not complete uninstall on host ${host}."
136 else
137 printLOG "Uninstall executed on host ${host}"
138 fi
139
140 #---------------------------------------------------------------------
141 # Clean up.
142 #---------------------------------------------------------------------
143
144 if test x"$simulate" = x0
145 then
146 ssh -x -l "root" "${host}" '(rm -rf "'${tmpdir}'")'
147 else
148 printINFO "ssh -x -l root ${host} (rm -rf ${tmpdir})"
149 fi
150 if test x"$?" != x0
151 then
152 printFATAL "Could not remove temporary directory ${tmpdir} on host ${host}."
153 else
154 printLOG "Directory ${tmpdir} deleted on host ${host}."
155 fi
156
157 #---------------------------------------------------------------------
158 # Write/update client database
159 #---------------------------------------------------------------------
160
161 SH_NAME="$name"; export SH_NAME
162 SH_PREFIX=`/bin/sh ${basedir}/archpkg/${DB_arch}/install-${DB_version} --print-config prefix`; export SH_PREFIX
163
164 if test x"$simulate" = x0
165 then
166 updateDB D2_removed
167 else
168 printINFO "Updating client database."
169 fi
170}
Note: See TracBrowser for help on using the repository browser.