source: trunk/dsys/funcDB@ 22

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

Initial import

File size: 6.6 KB
RevLine 
[1]1#########################################################################
2#
3# More subroutines for client DB
4#
5#########################################################################
6
7DBFTEST=0
8
9dbSETFLAG() {
10 case "$line" in
11 *\</client\>*)
12 DBFTEST=0;
13 return 0;
14 ;;
15
16 *\<client_host\>${DB_host}\</client_host\>*)
17 DBFTEST=1;
18 return 1;
19 ;;
20
21 *)
22 return ${DBFTEST};
23 ;;
24 esac
25}
26
27
28DB_arch=""; export DB_arch;
29DB_status=""; export DB_status;
30DB_version=""; export DB_version;
31DB_date=""; export DB_date;
32DB_name=""; export DB_name;
33
34dbINFO() {
35
36 if test "x$1" = x
37 then
38 printFATAL "No host specified, aborting"
39 else
40 DB_host="$1"
41 fi
42
43 DB_arch=""; export DB_arch;
44 DB_status=""; export DB_status;
45 DB_version=""; export DB_version;
46 DB_date=""; export DB_date;
47 DB_name=""; export DB_name;
48
49 if test x"$DATABASE" = x
50 then
51 DATABASE="${basedir}/${defdatabase}"
52 fi
53
54 if test -f "${DATABASE}"
55 then
56 SStr1=`grep '<yule_db>' "${DATABASE}"`
57 if test "x${SStr1}" != "x"
58 then
59
60 SStr2=`grep "<client_host>${DB_host}</client_host>" "${DATABASE}"`
61
62 SStr3=
63
64 if test "x${SStr2}" != "x"
65 then
66 exec 3<&0 <"${DATABASE}"
67 while
68 read line
69 do
70 # for some reason, var=xx only works in a function call (why?)
71 #
72 # here we test if we are still in the same client block
73 # (set_flag will return 0 for </client> and following)
74 dbSETFLAG "$line"
75
76 if test "x$?" = "x1"
77 then
78 case "$line" in
79 *\<client_os_machine\>*\</client_os_machine\>)
80 DB_arch=`echo "$line" | sed '/^\(.*\)<client_os_machine>\([0-9a-zA-Z_-]*\)<\/client_os_machine>\(.*\)$/{ s//\2/; q; }'`
81 export DB_arch
82 ;;
83
84 *\<client_install_status\>*\</client_install_status\>)
85 DB_status=`echo "$line" | sed '/^\(.*\)<client_install_status>\([0-9a-zA-Z_-]*\)<\/client_install_status>\(.*\)$/{ s//\2/; q; }'`
86 export DB_status
87 ;;
88
89 *\<client_install_date\>*\</client_install_date\>)
90 DB_date=`echo "$line" | sed '/^\(.*\)<client_install_date>\([ 0-9a-zA-Z_.:,-]*\)<\/client_install_date>\(.*\)$/{ s//\2/; q; }'`
91 export DB_date
92 ;;
93
94 *\<client_install_name\>*\</client_install_name\>)
95 DB_name=`echo "$line" | sed '/^\(.*\)<client_install_name>\([0-9a-zA-Z_-]*\)<\/client_install_name>\(.*\)$/{ s//\2/; q; }'`
96 export DB_name
97 ;;
98
99 *\<client_install_prefix\>*\</client_install_prefix\>)
100 ;;
101
102 *\<client_install_version\>*\</client_install_version\>)
103 DB_version=`echo "$line" | sed '/^\(.*\)<client_install_version>\([0-9a-zA-Z_.-]*\)<\/client_install_version>\(.*\)$/{ s//\2/; q; }'`
104 export DB_version
105 ;;
106
107 *)
108 ;;
109
110 esac
111 else
112 :
113 fi
114 done
115 exec 0<&3 3<&-
116 return 0
117 else
118 printINFO "Host ${DB_host} not found in client database"
119 return 1
120 fi
121 else
122 printINFO "Client database ${DATABASE} in bad shape"
123 return 1
124 fi
125 else
126 printINFO "Client database ${DATABASE} not available"
127 return 1
128 fi
129}
130
131DB_hostlist=""; export DB_hostlist
132
133dbHOSTLIST() {
134
135 DB_hostlist=""; export DB_hostlist
136
137 if test x"$DATABASE" = x
138 then
139 DATABASE="${basedir}/${defdatabase}"
140 fi
141
142 if test -f "${DATABASE}"
143 then
144 DB_hostlist=`cat "${DATABASE}" | grep 'client_host' | sed '/^\(.*\)<client_host>\([0-9a-zA-Z.-]*\)<\/client_host>\(.*\)$/{ s//\2/; }' | sort`
145 export DB_hostlist
146 return 0
147 else
148 printINFO "Client database ${DATABASE} not available"
149 return 1
150 fi
151}
152
153dbSHOWHOSTS() {
154
155 if test "x$1" = x
156 then
157 dbHOSTLIST
158 else
159 DB_hostlist="$1"
160 fi
161
162 if test "x$?" = x1
163 then
164 printLOG "No known hosts - database unavailable"
165 fi
166 if test "x${DB_hostlist}" = x
167 then
168 printLOG "No known hosts - database unavailable, empty, or corrupt"
169 fi
170
171 for ff in ${DB_hostlist}
172 do
173 dbINFO "$ff"
174
175
176 if test "x$?" = x1
177 then
178 :
179 else
180 test -z "${DB_date}" && DB_date="INDEF"
181 test -z "${DB_arch}" && DB_arch="INDEF"
182 test -z "${DB_version}" && DB_version="INDEF"
183
184 tmp_status="-"
185 if test "x$DB_status" = xinstalled
186 then
187 tmp_status="o"
188 elif test "x$DB_status" = xD2_installed
189 then
190 tmp_status="i"
191 elif test "x$DB_status" = xD2_removed
192 then
193 tmp_status="u"
194 fi
195 out=`echo | awk '{ printf "%1s %14s %-11s %19s %s\n", "'"${tmp_status}"'", "'"${DB_arch}"'", "'"${DB_version}"'", "'"${DB_date}"'", "'"${ff}"'" }'`
196 printINFO "${out}"
197 fi
198 done
199}
200
201
202dbSHOWPKG() {
203
204 delete=no
205 show=no
206
207 if test x"$1" = xshow
208 then
209 show=yes
210 fi
211 if test x"$2" = xdelete
212 then
213 delete=yes
214 fi
215
216 cd "${basedir}/archpkg" || printFATAL "Cannot cd to ${basedir}/archpkg"
217
218 dbHOSTLIST
219
220 if test x"$DATABASE" = x
221 then
222 DATABASE="${basedir}/${defdatabase}"
223 fi
224
225 LIST=`ls`
226 this_dir=`pwd`
227
228 for dd in $LIST
229 do
230 if test -d "$dd"
231 then
232 cd "$dd"
233
234 PKGLIST=`ls samhain-* 2>/dev/null`
235
236 for ff in $PKGLIST
237 do
238 if test -f "$ff"
239 then
240 version=`echo "$ff" | sed -e 's%samhain-%%'`
241
242 tmp_status="-"
243
244 grep "$version" "${DATABASE}" >/dev/null 2>&1
245 if test "x$?" = x0
246 then
247 for hh in ${DB_hostlist}
248 do
249 dbINFO "$hh"
250 if test x"${DB_arch}" = x"${dd}" && \
251 test x"${DB_version}" = x"${version}"
252 then
253 tmp_status="-"
254 if test "x$DB_status" = xinstalled
255 then
256 tmp_status="o"
257 elif test "x$DB_status" = xD2_installed
258 then
259 tmp_status="i"
260 fi
261 break
262 fi
263 done
264 else
265 tmp_status="-"
266 fi
267
268 if test x"${show}" = xyes
269 then
270 printINFO "${tmp_status} ${dd}/${version}"
271 fi
272
273 if test x"${delete}" = xyes && test x"${tmp_status}" = "x-"
274 then
275 printLOG "REMOVE ${dd}/${version}"
276
277 if test x"$simulate" = x0
278 then
279 rm -f "samhain-${version}"
280 rm -f "install-${version}"
281 rm -f "configure-${version}"
282 else
283 printINFO "rm -f ${dd}/samhain-${version}"
284 printINFO "rm -f ${dd}/install-${version}"
285 printINFO "rm -f ${dd}/configure-${version}"
286 fi
287 fi
288 fi
289 done
290 cd "${this_dir}"
291 fi
292 done
293}
Note: See TracBrowser for help on using the repository browser.