Gentoo Archives: gentoo-commits

From: "Alfredo Tupone (tupone)" <tupone@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-admin/zprod-manager/files/0.3.2: zprod-manager
Date: Tue, 06 May 2008 21:53:51
Message-Id: E1JtV6Z-0000AZ-TM@stork.gentoo.org
1 tupone 08/05/06 21:53:47
2
3 Added: zprod-manager
4 Log:
5 New version. Bug #220311 by me
6 (Portage version: 2.1.4.4)
7 (Signed Manifest commit)
8
9 Revision Changes Path
10 1.1 app-admin/zprod-manager/files/0.3.2/zprod-manager
11
12 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/zprod-manager/files/0.3.2/zprod-manager?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/zprod-manager/files/0.3.2/zprod-manager?rev=1.1&content-type=text/plain
14
15 Index: zprod-manager
16 ===================================================================
17 #!/bin/bash
18 # Gentoo Zope Product selection tool.
19 # Copyright 2003 Jason Shoemaker <kutsuya@g.o>
20 # Distributed under GPL v2
21 # $Header: /var/cvsroot/gentoo-x86/app-admin/zprod-manager/files/0.3.2/zprod-manager,v 1.1 2008/05/06 21:53:47 tupone Exp $
22
23 VERSION="0.3.1"
24 COMMAND_LIST="add del"
25 ZS_DIR="/usr/share/zope/"
26 ZI_DIR="/var/lib/zope/"
27 ZPROD_DIR="/usr/share/zproduct/"
28
29 ZINST_DEFAULT=".default"
30 ZPROD_FLIST_FNAME=".zfolder.lst"
31 ZPROD_LLIST_FNAME=".zlfolder.lst"
32 ZPROD_PLIST_FNAME=".zproduct.lst"
33
34 # Assume the standard dialog return codes
35 #DIALOG_CANCEL=1
36 #DIALOG_ERROR=-1
37 #DIALOG_ESC=-255
38 #DIALOG_OK=0
39 #DIALOG_ERROR may equal #DIALOG_ESC
40
41 # Return codes used in this program:
42 E_SUCCESS=0
43 E_FAILURE=1
44
45 E_ZPLIST=20
46 E_ZILIST=22
47 E_COMMAND=24
48 E_OVERWRITE=26
49
50 ## copied from zope-config
51
52 zinst_dir_get()
53 {
54 local RESULT=${E_FAILURE}
55 local LIST=$(ls ${ZI_DIR})
56 local LIST_CNT=$(echo ${LIST} | wc -w)
57 local DLIST=
58
59 if [ ${LIST_CNT} -eq 1 ] ; then
60 ZINST_DIR=${LIST}
61 RESULT=${E_SUCCESS}
62 elif [ ${LIST_CNT} -ne 0 ] ; then
63 for N in ${LIST} ; do
64 DLIST="${DLIST} $N -"
65 done
66 ZINST_DIR=$(dialog --stdout \
67 --title "Zope Instance List" \
68 --menu "Select desired zinstance:" 0 0 ${LIST_CNT} ${DLIST})
69 RESULT=$?
70 else
71 RESULT=${E_ZILIST} # There are no zinstances
72 fi
73 ZINST_DIR="${ZI_DIR}${ZINST_DIR}"
74 return ${RESULT}
75 }
76
77 # params: none
78 # TODO: Maybe try to break this function down some more.
79 # TODO: verify items in ZP_PLIST and ZI_PLIST
80
81 mode_interactive()
82 {
83 local RESULT=
84 if [ $(is_command "${COMMAND_LIST}" ${1})${?} -ne 0 ] ; then
85 RESULT=${?}
86 return ${RESULT}
87 fi
88 ZP_PLIST=$(ls ${ZPROD_DIR})
89 if [ "${ZP_PLIST}" ] ; then
90 zinst_dir_get
91 RESULT=$?
92 if [ ${RESULT} -eq 0 ] ; then
93 ZI_PLIST=$(cat ${ZINST_DIR}/${ZPROD_PLIST_FNAME})
94 # Create CLIST for --menu
95 if [ "${ZI_PLIST}" ] ; then
96 for N in ${ZP_PLIST} ; do
97 echo ${ZI_PLIST} |grep ${N} >/dev/null
98 if [ $? -eq 0 ] ; then
99 STATUS=ON
100 else
101 STATUS=OFF
102 fi
103 CLIST="${CLIST} ${N} - ${STATUS}"
104 done
105 CTAGS=$(dialog --stdout \
106 --backtitle "Select the zproducts you want installed for zinstance(${ZINST_DIR})." \
107 --checklist "Select:" 0 0 0 ${CLIST})
108 RESULT=$?
109 CTAGS=$(echo ${CTAGS} | sed -e "s:\"::g")
110 # Prepare to add and delete zproducts installed in zinstance
111 if [[ ${RESULT} -eq 0 && "${CTAGS}" ]] ; then
112 for N in ${ZI_PLIST} ; do
113 echo "$CTAGS" |grep ${N} >/dev/null
114 if [ $? -ne 0 ] ; then
115 prod_del ${ZPROD_DIR}/${N} ${ZINST_DIR}
116 fi
117 done
118 for N in ${CTAGS} ; do
119 echo ${ZI_PLIST} |grep ${N} >/dev/null
120 if [ $? -ne 0 ] ; then
121 prod_add ${ZPROD_DIR}/${N} ${ZINST_DIR}
122 fi
123 done
124 RESULT=$?
125 elif [ ${RESULT} -eq 0 ] ; then # $CTAGS is empty
126 for N in ${ZI_PLIST} ; do
127 prod_del ${ZPROD_DIR}/${N} ${ZINST_DIR}
128 done
129 RESULT=$?
130 fi
131 else # ZI_PLIST is empty
132 for N in ${ZP_PLIST} ; do
133 CLIST="${CLIST} ${N} - 0"
134 done
135 CTAGS=$(dialog --stdout \
136 --backtitle "Select the zproducts you want installed for zinstance(${ZINST_DIR})." \
137 --checklist "Select:" 0 0 0 ${CLIST})
138 RESULT=$?
139 CTAGS=$(echo "${CTAGS}" | sed -e "s:\"::g")
140 if [[ ${RESULT} -eq 0 && "${CTAGS}" ]] ; then
141 for N in ${CTAGS} ; do
142 # as this is empty Products directory in instance if-case, we can safely ignore
143 # RESULT returned from prod_add in case of overwrite error. It can not happen
144 # when ZI_PLIST is empty, right? ;) <radek@g.o>
145 prod_add ${ZPROD_DIR}/${N} ${ZINST_DIR}
146 done
147 fi
148 fi
149 fi
150 else # ZP_PLIST is empty
151 RESULT=${E_ZPLIST}
152 fi
153 return ${RESULT}
154 }
155
156
157 # Parameters:
158 # $1 = command list
159 # $2 = command received
160 # Returns:
161 # true or false
162
163 is_command()
164 {
165 local RESULT=${E_COMMAND}
166 local N=
167
168 echo ${1} |grep ${2} >/dev/null
169 if [ $? -eq 0 ] ; then
170 RESULT=0
171 fi
172
173 return ${RESULT}
174 }
175
176 # Parameters:
177 # $1 = /path/to/zinstance
178 # Returns:
179 # true or false
180
181 is_zinstanceDir()
182 {
183 local RESULT=${E_ZILIST}
184 # If can't find these, probably not a zinstance.
185 if [[ -d "${1}/Products" && -d "${1}/var" && -d "${1}/import" && -d "${1}/Extensions" ]] ; then
186 RESULT=0
187 fi
188 return ${RESULT}
189 }
190
191 # Parameters:
192 # $1 = /path/to/zproduct
193 # Returns:
194 # true or false
195
196 is_zproductDir()
197 {
198 local RESULT=${E_ZPLIST}
199 # look for something in .zproduct.lst in $1, if we can't find that...
200 if [ -s "${1}/${ZPROD_FLIST_FNAME}" ] ; then
201 RESULT=0
202 fi
203 return ${RESULT}
204 }
205
206 # Parameters:
207 # $1 = /path/to/zinst_dir
208 # Returns:
209 # stdout = name of defautl zinstance, if any.
210
211 zinst_default_get()
212 {
213 if [ -s ${1}/${ZINST_DEFAULT} ] ; then
214 cat ${1}/${ZINST_DEFAULT}
215 fi
216 }
217
218 # Parameters:
219 # $1 = /path/to/zproduct
220 # $2 = /path/to/zinstance
221
222 # be warned, using this function you have to immediately fail if functionss returns error.
223
224 prod_add()
225 {
226 local RESULT=
227 local N=
228
229 # checks if some products components are already installed,
230 # if yes, we have to break with error, as overwrites are DANGEROUS!
231 for N in $(cat "${1}/${ZPROD_FLIST_FNAME}")
232 do
233 if [ -d ${2}/Products/${N} ]
234 then
235 echo "ZPROD-MANAGER WARNING: Overwrite possiblity detected at ${N}"
236 return ${E_OVERWRITE}
237 fi
238 done
239 for N in $(cat "${1}/${ZPROD_LLIST_FNAME}")
240 do
241 if [ -d ${2}/lib/python/${N} ]
242 then
243 echo "ZPROD-MANAGER WARNING: Overwrite possiblity detected at ${N}"
244 return ${E_OVERWRITE}
245 fi
246 done
247
248 if [ -e ${1}/Products ] ; then
249 for N in $(cat "${1}/${ZPROD_FLIST_FNAME}") ; do
250 # we do copy instead of link, because its much safer, and zope-development-way compliant
251 cp -Ra ${1}/Products/${N} ${2}/Products
252 done
253 else
254 for N in $(cat "${1}/${ZPROD_FLIST_FNAME}") ; do
255 # we do copy instead of link, because its much safer, and zope-development-way compliant
256 cp -Ra ${1}/${N} ${2}/Products
257 done
258 fi
259 for N in $(cat "${1}/${ZPROD_LLIST_FNAME}") ; do
260 # we do copy instead of link, because its much safer, and zope-development-way compliant
261 cp -Ra ${1}/lib/python/${N} ${2}/lib/python
262 done
263 RESULT=$?
264 if [ ${RESULT} -eq 0 ] ; then
265 # basically adding ${PF} to .zproduct.lst
266 echo $(basename $1) >> ${2}/${ZPROD_PLIST_FNAME}
267 sort -u ${2}/${ZPROD_PLIST_FNAME} > ${2}/.tmp
268 mv -f ${2}/.tmp ${2}/${ZPROD_PLIST_FNAME}
269 RESULT=$?
270
271 for N in $(cat "${1}/${ZPROD_FLIST_FNAME}") ; do
272 # setting owner and group as in Products folder, so we can compile
273 # python scripts with the zope user
274
275 chown -R `stat -c %U:%G ${2}/Products` ${2}/Products/${N}
276
277 # gives group writing perms (very often need in development teams)
278 # takes all perms from others to comply with 770 instance policy
279 chmod -R g+rwX,o-rwx ${2}/Products/${N}
280 done
281 for N in $(cat "${1}/${ZPROD_LLIST_FNAME}") ; do
282 # setting owner and group as in Products folder, so we can compile
283 # python scripts with the zope user
284
285 chown -R `stat -c %U:%G ${2}/Products` ${2}/lib/python/${N}
286
287 # gives group writing perms (very often need in development teams)
288 # takes all perms from others to comply with 770 instance policy
289 chmod -R g+rwX,o-rwx ${2}/lib/python/${N}
290 done
291 fi
292
293 return ${RESULT}
294 }
295
296 # Parameters:
297 # $1 = /path/to/zproduct
298 # $2 = /path/to/zinstance
299
300 prod_del()
301 {
302 local RESULT=
303 local N=
304 local PF=$(basename $1)
305
306 grep "${PF}" "${2}/${ZPROD_PLIST_FNAME}" >/dev/null
307 RESULT=$?
308 if [ ${RESULT} -eq 0 ] ; then
309 for N in $(cat ${1}/${ZPROD_FLIST_FNAME}) ; do
310 rm -rf ${2}/Products/${N}
311 done
312 for N in $(cat ${1}/${ZPROD_LLIST_FNAME}) ; do
313 rm -rf ${2}/lib/python/${N}
314 done
315 # remove zproduct from .zproduct.lst
316 sed -i -e "s/${PF}$//" -e "/^$/d" ${2}/${ZPROD_PLIST_FNAME}
317 RESULT=$?
318 fi
319 return ${RESULT}
320 }
321
322 # Parameters:
323 # $1 = (optional) error message
324
325 mode_help()
326 {
327 echo "$(basename $0) version ${VERSION}"
328 echo "A Gentoo Zope Product selection tool."
329 echo
330 echo "Interactive usage:"
331 echo -e "\t$(basename $0) [add | del]"
332 echo "Default zinstance usage:"
333 echo -e "\t$(basename $0) [add |del] /path/of/zproduct"
334 echo "Non-interactive usage:"
335 echo -e "\t$(basename $0) [add | del] /path/of/zproduct /path/of/zinstance/"
336 }
337
338 # Parameters:
339 # $1 = command
340 # $2 = /path/to/zproductDir
341
342 mode_defaultZinst()
343 {
344 local DEFAULT_ZINST=$(zinst_default_get ${ZI_DIR})
345 local RESULT=$?
346 if [ -n "${DEFAULT_ZINST}" ] ; then
347 mode_explicit ${1} ${2} ${ZI_DIR}/${DEFAULT_ZINST}
348 RESULT=${?}
349 fi
350 return ${RESULT}
351 }
352
353 # Parameters:
354 # $1 = command
355 # $2 = /path/to/zproduct
356 # $3 = /path/to/zinstance
357
358 mode_explicit()
359 {
360 local RESULT=
361 if [[ $(is_command "${COMMAND_LIST}" ${1})${?} -eq 0 && \
362 $(is_zproductDir ${2})${?} -eq 0 && \
363 $(is_zinstanceDir ${3})${?} -eq 0 ]] ; then
364 if [ ${1} = "add" ] ; then
365 prod_add ${2} ${3}
366 RESULT=$?
367 elif [ ${1} = "del" ] ; then
368 prod_del ${2} ${3}
369 RESULT=$?
370 else
371 RESULT=${E_COMMAND}
372 fi
373 fi
374 return ${RESULT}
375 }
376
377 ### MAIN
378
379 if [ ${!#} = "--help" ] ; then
380 mode_help
381 else
382 case "${#}" in
383 0) mode_help ;;
384 1) mode_interactive ${1} ;;
385 2) mode_defaultZinst ${1} ${2} ;;
386 3) mode_explicit ${1} ${2} ${3} ;;
387 *) mode_help "Error: Too many parameters" ;;
388 esac
389 fi
390
391 RESULT=$?
392
393 if [ ${RESULT} -ne 0 ] ; then
394 echo "ERROR ${?}"
395 fi
396
397
398 # vim:ts=8
399
400
401
402 --
403 gentoo-commits@l.g.o mailing list