Annotation of /trunk/mage/usr/lib/mage/mage4.functions.sh
Parent Directory | Revision Log
Revision 892 -
(hide annotations)
(download)
(as text)
Tue Aug 4 19:52:16 2009 UTC (15 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 66163 byte(s)
Tue Aug 4 19:52:16 2009 UTC (15 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 66163 byte(s)
-support both blacklist types
1 | niro | 226 | #!/bin/bash |
2 | # Magellan Linux Installer Functions (mage.functions.sh) | ||
3 | niro | 776 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $ |
4 | niro | 226 | |
5 | mage_setup() | ||
6 | { | ||
7 | [ ! -d ${MROOT}${INSTALLDB} ] && \ | ||
8 | install -d ${MROOT}${INSTALLDB} | ||
9 | [ ! -f ${MROOT}${VIRTUALDB_FILE} ] && \ | ||
10 | touch ${MROOT}${VIRTUALDB_FILE} | ||
11 | [ ! -d ${PKGDIR} ] && install -d ${PKGDIR} | ||
12 | [ ! -d ${BUILDDIR} ] && install -d ${BUILDDIR} | ||
13 | [ ! -d ${MAGEDIR} ] && install -d ${MAGEDIR} | ||
14 | |||
15 | return 0 | ||
16 | } | ||
17 | |||
18 | unpack_packages() | ||
19 | { | ||
20 | local list="$@" | ||
21 | local magefile | ||
22 | local pkg | ||
23 | local pkgtype | ||
24 | local count_current | ||
25 | local count_total | ||
26 | |||
27 | # get count of total packages | ||
28 | declare -i count_current=0 | ||
29 | declare -i count_total=0 | ||
30 | |||
31 | for i in ${list}; do (( count_total++ )); done | ||
32 | |||
33 | for magefile in ${list} | ||
34 | do | ||
35 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
36 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
37 | |||
38 | (( count_current++ )) | ||
39 | xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]" | ||
40 | |||
41 | # abort on virtual pkg | ||
42 | if [[ ${pkgtype} = virtual ]] | ||
43 | then | ||
44 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
45 | echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
46 | continue | ||
47 | fi | ||
48 | |||
49 | # abort on sources pkg | ||
50 | if [[ ${pkgtype} = sources ]] | ||
51 | then | ||
52 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
53 | echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
54 | continue | ||
55 | fi | ||
56 | |||
57 | echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... " | ||
58 | tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}" | ||
59 | done | ||
60 | |||
61 | # add a crlf for a better view | ||
62 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
63 | } | ||
64 | |||
65 | |||
66 | # fix_mtime path/to/$mtime/reffile $pathto/file | ||
67 | # creates a given reference file and fixes given file | ||
68 | # returns new mtime | ||
69 | fix_mtime() | ||
70 | { | ||
71 | local reference="$1" | ||
72 | local pathto="$2" | ||
73 | local mtime | ||
74 | |||
75 | mtime=$(stat -c %Y "${reference}") | ||
76 | touch \ | ||
77 | --no-create \ | ||
78 | --time=mtime \ | ||
79 | --reference "${reference}" \ | ||
80 | "${pathto}" | ||
81 | |||
82 | echo "${mtime}" | ||
83 | } | ||
84 | |||
85 | # fix_descriptor pkgname/.dir "foo1" "foo2" | ||
86 | fix_descriptor() | ||
87 | { | ||
88 | local descriptor="$1" | ||
89 | local output | ||
90 | local i | ||
91 | shift | ||
92 | |||
93 | for i in $@ | ||
94 | do | ||
95 | if [[ -z ${output} ]] | ||
96 | then | ||
97 | output="${i}" | ||
98 | else | ||
99 | output="${output}§${i}" | ||
100 | fi | ||
101 | done | ||
102 | |||
103 | echo "${output}" >> ${BUILDDIR}/${descriptor}_fixed | ||
104 | } | ||
105 | |||
106 | ################################################### | ||
107 | # function install_direcories # | ||
108 | # install_direcories $PKGNAME # | ||
109 | ################################################### | ||
110 | install_directories() | ||
111 | { | ||
112 | local pkgname="$1" | ||
113 | local pathto | ||
114 | local posix | ||
115 | local user | ||
116 | local group | ||
117 | local IFS | ||
118 | |||
119 | # sanity checks; abort if not given | ||
120 | [ -z "${pkgname}" ] && die "install_directories() \$pkgname not given." | ||
121 | |||
122 | # check needed global vars | ||
123 | [ -z "${BUILDDIR}" ] && die "install_directories() \$BUILDDIR not set." | ||
124 | |||
125 | [ ! -f ${BUILDDIR}/${pkgname}/.dirs ] && die "install_directories() .dirs not found" | ||
126 | |||
127 | # sets fieldseperator to "§" instead of " " | ||
128 | IFS=§ | ||
129 | |||
130 | while read pathto posix user group | ||
131 | do | ||
132 | [ -z "${pathto}" ] && continue | ||
133 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR: ${MROOT}${pathto}" | ||
134 | |||
135 | |||
136 | # monitors /etc/env.d -> env-rebuild | ||
137 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true | ||
138 | |||
139 | # monitors /usr/share/info -> info-rebuild | ||
140 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true | ||
141 | |||
142 | install -m "${posix}" -o "${user}" -g "${group}" -d "${MROOT}${pathto}" | ||
143 | done < ${BUILDDIR}/${pkgname}/.dirs | ||
144 | |||
145 | # very important: unsetting the '§' fieldseperator | ||
146 | IFS=$'\n' | ||
147 | } | ||
148 | |||
149 | |||
150 | ################################################### | ||
151 | # function install_files # | ||
152 | # install_files $PKGNAME # | ||
153 | ################################################### | ||
154 | install_files() | ||
155 | { | ||
156 | |||
157 | local pkgname="$1" | ||
158 | local pathto | ||
159 | local posix | ||
160 | local user | ||
161 | local group | ||
162 | local mtime | ||
163 | local md5sum | ||
164 | |||
165 | local retval | ||
166 | local counter | ||
167 | local filename | ||
168 | local dest_dirname | ||
169 | local dest_protected | ||
170 | local IFS | ||
171 | |||
172 | # sanity checks; abort if not given | ||
173 | [ -z "${pkgname}" ] && die "install_files() \$pkgname not given." | ||
174 | |||
175 | # check needed global vars | ||
176 | [ -z "${BUILDDIR}" ] && die "install_files() \$BUILDDIR not set." | ||
177 | |||
178 | [ ! -f ${BUILDDIR}/${pkgname}/.files ] && die "install_files() .files not found" | ||
179 | |||
180 | # delete old files | ||
181 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && rm ${BUILDDIR}/${pkgname}/.files_fixed | ||
182 | |||
183 | # sets fieldseperator to "§" instead of " " | ||
184 | IFS=§ | ||
185 | |||
186 | while read pathto posix user group mtime md5sum | ||
187 | do | ||
188 | [ -z "${pathto}" ] && continue | ||
189 | |||
190 | # final destination dir of file ${pathto} | ||
191 | dest_dirname="$(dirname "${MROOT}${pathto}")" | ||
192 | |||
193 | ### small hotfix fix ### | ||
194 | [ ! -d "${dest_dirname}" ] && install -d "${dest_dirname}" | ||
195 | |||
196 | # check if the file is config_protected | ||
197 | # ${MROOT} will automatically added if set !! | ||
198 | is_config_protected "${pathto}" | ||
199 | retval="$?" | ||
200 | |||
201 | # 0 - not protected # | ||
202 | # 1 - error # | ||
203 | # 2 - protected # | ||
204 | # 3 - protected but masked # | ||
205 | |||
206 | case ${retval} in | ||
207 | # file is not protected - (over)write it | ||
208 | 0|3) | ||
209 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}" | ||
210 | install -m "${posix}" -o "${user}" -g "${group}" \ | ||
211 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ | ||
212 | "${MROOT}${pathto}" | ||
213 | |||
214 | # fix mtime and db | ||
215 | fix_descriptor ${pkgname}/.files \ | ||
216 | "${pathto}" \ | ||
217 | "${posix}" \ | ||
218 | "${user}" \ | ||
219 | "${group}" \ | ||
220 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
221 | "${MROOT}${pathto}")" \ | ||
222 | "${md5sum}" | ||
223 | ;; | ||
224 | |||
225 | # file is protected, write backup file | ||
226 | 2) | ||
227 | if [[ ${VERBOSE} = on ]] | ||
228 | then | ||
229 | echo -en "${COLRED}" | ||
230 | echo -n "! prot " | ||
231 | echo -en "${COLDEFAULT}" | ||
232 | echo " === FILE: ${MROOT}${pathto}" | ||
233 | fi | ||
234 | filename="$(basename "${pathto}")" | ||
235 | counter=$(count_protected_files "${pathto}") | ||
236 | dest_protected="${dest_dirname}/._cfg${counter}_${filename}" | ||
237 | install -m "${posix}" -o "${user}" -g "${group}" \ | ||
238 | ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \ | ||
239 | "${dest_protected}" | ||
240 | |||
241 | # fix mtime and db | ||
242 | fix_descriptor ${pkgname}/.files \ | ||
243 | "${pathto}" \ | ||
244 | "${posix}" \ | ||
245 | "${user}" \ | ||
246 | "${group}" \ | ||
247 | "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
248 | "${dest_protected}")" \ | ||
249 | "${md5sum}" | ||
250 | |||
251 | # update global MAGE_PROTECT_COUNTER | ||
252 | (( MAGE_PROTECT_COUNTER++ )) | ||
253 | export MAGE_PROTECT_COUNTER | ||
254 | ;; | ||
255 | esac | ||
256 | done < ${BUILDDIR}/${pkgname}/.files | ||
257 | |||
258 | # now copy the fixed file over the old one | ||
259 | [ -f ${BUILDDIR}/${pkgname}/.files_fixed ] && \ | ||
260 | cp ${BUILDDIR}/${pkgname}/.files{_fixed,} | ||
261 | |||
262 | # very important: unsetting the '§' fieldseperator | ||
263 | IFS=$'\n' | ||
264 | } | ||
265 | |||
266 | |||
267 | ################################################### | ||
268 | # function install_symlinks # | ||
269 | # install_symlinks $PKGNAME # | ||
270 | ################################################### | ||
271 | install_symlinks() | ||
272 | { | ||
273 | local pkgname="$1" | ||
274 | local pathto | ||
275 | local posix | ||
276 | local link | ||
277 | local mtime | ||
278 | local IFS | ||
279 | |||
280 | # sanity checks; abort if not given | ||
281 | [ -z "${pkgname}" ] && die "install_symlinks() \$pkgname not given." | ||
282 | |||
283 | # check needed global vars | ||
284 | [ -z "${BUILDDIR}" ] && die "install_symlinks() \$BUILDDIR not set." | ||
285 | |||
286 | [ ! -f ${BUILDDIR}/${pkgname}/.symlinks ] && die "install_symlinks() .symlinks not found" | ||
287 | |||
288 | # delete old files | ||
289 | [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && rm ${BUILDDIR}/${pkgname}/.symlinks_fixed | ||
290 | |||
291 | # sets fieldseperator to "§" instead of " " | ||
292 | IFS=§ | ||
293 | |||
294 | while read pathto posix link mtime | ||
295 | do | ||
296 | [ -z "${pathto}" ] && continue | ||
297 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}" | ||
298 | |||
299 | ln -snf "${link}" "${MROOT}${pathto}" | ||
300 | |||
301 | niro | 858 | # # fix mtime and db |
302 | # fix_descriptor ${pkgname}/.symlinks \ | ||
303 | # "${pathto}" \ | ||
304 | # "${posix}" \ | ||
305 | # "${link}" \ | ||
306 | # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ | ||
307 | # "${MROOT}${pathto}")" | ||
308 | niro | 226 | |
309 | done < ${BUILDDIR}/${pkgname}/.symlinks | ||
310 | |||
311 | niro | 858 | # # now copy the fixed file over the old one |
312 | # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ | ||
313 | # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} | ||
314 | niro | 226 | |
315 | # very important: unsetting the '§' fieldseperator | ||
316 | IFS=$'\n' | ||
317 | } | ||
318 | |||
319 | |||
320 | ################################################### | ||
321 | # function install_blockdevices # | ||
322 | # install_blockdevices $PKGNAME # | ||
323 | ################################################### | ||
324 | install_blockdevices() | ||
325 | { | ||
326 | local pkgname="$1" | ||
327 | local pathto | ||
328 | local posix | ||
329 | local IFS | ||
330 | |||
331 | # sanity checks; abort if not given | ||
332 | [ -z "${pkgname}" ] && die "install_blockdevices() \$pkgname not given." | ||
333 | |||
334 | # check needed global vars | ||
335 | [ -z "${BUILDDIR}" ] && die "install_blockdevices() \$BUILDDIR not set." | ||
336 | |||
337 | [ ! -f ${BUILDDIR}/${pkgname}/.pipes ] && die "install_blockdevices() .pipes not found" | ||
338 | |||
339 | # sets fieldseperator to "§" instead of " " | ||
340 | IFS=§ | ||
341 | |||
342 | while read pathto posix | ||
343 | do | ||
344 | [ -z "${pathto}" ] && continue | ||
345 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}" | ||
346 | |||
347 | mkfifo -m "${posix}" "${MROOT}$pathto" | ||
348 | done < ${BUILDDIR}/${pkgname}/.pipes | ||
349 | |||
350 | # very important: unsetting the '§' fieldseperator | ||
351 | IFS=$'\n' | ||
352 | } | ||
353 | |||
354 | |||
355 | ################################################### | ||
356 | # function install_characterdevices # | ||
357 | # install_characterdevices $PKGNAME # | ||
358 | ################################################### | ||
359 | install_characterdevices() | ||
360 | { | ||
361 | local pkgname="$1" | ||
362 | local pathto | ||
363 | local posix | ||
364 | niro | 312 | local major |
365 | local minor | ||
366 | niro | 226 | local IFS |
367 | |||
368 | # sanity checks; abort if not given | ||
369 | [ -z "${pkgname}" ] && die "install_characterdevices() \$pkgname not given." | ||
370 | |||
371 | # check needed global vars | ||
372 | [ -z "${BUILDDIR}" ] && die "install_characterdevices() \$BUILDDIR not set." | ||
373 | |||
374 | [ ! -f ${BUILDDIR}/${pkgname}/.char ] && die "install_characterdevices() .char not found" | ||
375 | |||
376 | # sets fieldseperator to "§" instead of " " | ||
377 | IFS=§ | ||
378 | |||
379 | niro | 312 | while read pathto posix major minor |
380 | niro | 226 | do |
381 | [ -z "${pathto}" ] && continue | ||
382 | [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" | ||
383 | |||
384 | niro | 314 | mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} |
385 | niro | 226 | done < ${BUILDDIR}/${pkgname}/.char |
386 | |||
387 | # very important: unsetting the '§' fieldseperator | ||
388 | IFS=$'\n' | ||
389 | } | ||
390 | |||
391 | |||
392 | ################################################### | ||
393 | # function build_doinstall # | ||
394 | # build_doinstall $PKGNAME # | ||
395 | # NOTE: this is an wrapper do install packages # | ||
396 | ################################################### | ||
397 | build_doinstall() | ||
398 | { | ||
399 | local pkgname="$1" | ||
400 | |||
401 | # sanity checks; abort if not given | ||
402 | [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given." | ||
403 | |||
404 | # this is only a wrapper | ||
405 | |||
406 | # NOTE: | ||
407 | # !! we use § as field seperator !! | ||
408 | # doing so prevent us to get errors by filenames with spaces | ||
409 | |||
410 | # create a new mtime reference file | ||
411 | touch ${BUILDDIR}/${pkgname}/.mtime | ||
412 | |||
413 | install_directories ${pkgname} || die "install directories ${pkgname}" | ||
414 | install_files ${pkgname} || die "install files ${pkgname}" | ||
415 | install_symlinks ${pkgname} || die "install symlinks ${pkgname}" | ||
416 | install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}" | ||
417 | install_characterdevices ${pkgname} || die "install chardevices ${pkgname}" | ||
418 | } | ||
419 | |||
420 | |||
421 | ################################################### | ||
422 | # function install_database_entry # | ||
423 | # install_database_entry $PKGNAME $PKGTYPE # | ||
424 | # PKGTYPE can be "virtual", "sources" or nothing # | ||
425 | ################################################### | ||
426 | install_database_entry() | ||
427 | { | ||
428 | local pcat | ||
429 | local pname | ||
430 | local pver | ||
431 | local pbuild | ||
432 | local pkgtype | ||
433 | local pkgname | ||
434 | local magefile | ||
435 | local dbrecorddir | ||
436 | local provide | ||
437 | niro | 273 | local i |
438 | niro | 226 | |
439 | # very basic getops | ||
440 | for i in $* | ||
441 | do | ||
442 | case $1 in | ||
443 | --pcat|-c) shift; pcat="$1" ;; | ||
444 | --pname|-n) shift; pname="$1" ;; | ||
445 | --pver|-v) shift; pver="$1" ;; | ||
446 | --pbuild|-b) shift; pbuild="$1" ;; | ||
447 | --pkgname|-a) shift; pkgname="$1" ;; | ||
448 | --pkgtype|-t) shift; pkgtype="$1" ;; | ||
449 | esac | ||
450 | shift | ||
451 | done | ||
452 | |||
453 | # sanity checks; abort if not given | ||
454 | [ -z "${pcat}" ] && die "install_database_entry() \$pcat not given." | ||
455 | [ -z "${pname}" ] && die "install_database_entry() \$pname not given." | ||
456 | [ -z "${pver}" ] && die "install_database_entry() \$pver not given." | ||
457 | [ -z "${pbuild}" ] && die "install_database_entry() \$pbuild not given." | ||
458 | [ -z "${pkgname}" ] && die "install_database_entry() \$pkgname not given." | ||
459 | |||
460 | # check needed global vars | ||
461 | [ -z "${MAGEDIR}" ] && die "install_database_entry() \$MAGEDIR not set." | ||
462 | [ -z "${INSTALLDB}" ] && die "install_database_entry() \$INSTALLDB not set." | ||
463 | |||
464 | # set needed vars | ||
465 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" | ||
466 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" | ||
467 | |||
468 | # abort if mage file not exists | ||
469 | [ ! -f ${magefile} ] && die "install_database_entry() ${magefile} not exist." | ||
470 | |||
471 | # add package to database | ||
472 | install -d ${dbrecorddir} | ||
473 | |||
474 | # install mage-file to database | ||
475 | install -m 0644 -o root -g root ${magefile} ${dbrecorddir} | ||
476 | |||
477 | # create fake file descriptors | ||
478 | # used by virtual and source packages | ||
479 | for i in .dirs .symlinks .files .pipes .char | ||
480 | do | ||
481 | touch ${dbrecorddir}/${i} | ||
482 | done | ||
483 | |||
484 | # put the category to database | ||
485 | echo ${pcat} > ${dbrecorddir}/.categorie | ||
486 | |||
487 | # now install PKGTYPE specific files | ||
488 | case ${pkgtype} in | ||
489 | virtual) touch ${dbrecorddir}/.virtual ;; | ||
490 | sources) touch ${dbrecorddir}/.sources ;; | ||
491 | *) | ||
492 | # !move! .mtime to database (only mv modifies not the mtime!!) | ||
493 | mv ${BUILDDIR}/${pkgname}/.mtime ${dbrecorddir}/.mtime | ||
494 | |||
495 | # normal packages needs these files | ||
496 | local i | ||
497 | for i in .char .dirs .files .pipes .symlinks | ||
498 | do | ||
499 | install -m 0644 ${BUILDDIR}/${pkgname}/${i} \ | ||
500 | ${dbrecorddir}/${i} | ||
501 | done | ||
502 | ;; | ||
503 | esac | ||
504 | |||
505 | # last but not least register virtuals | ||
506 | provide="$(get_value_from_magefile PROVIDE ${magefile})" | ||
507 | if [ -n "${provide}" ] | ||
508 | then | ||
509 | niro | 273 | for i in ${provide} |
510 | do | ||
511 | virtuals_add "${i}" "${pcat}/${pname}" | ||
512 | done | ||
513 | niro | 226 | fi |
514 | } | ||
515 | |||
516 | |||
517 | ################################################### | ||
518 | # function remove_database_entry # | ||
519 | # remove_database_entry $PKGNAME $PKGTYPE # | ||
520 | # PKGTYPE can be "virtual", "sources" or nothing # | ||
521 | ################################################### | ||
522 | remove_database_entry() | ||
523 | { | ||
524 | local pcat | ||
525 | local pname | ||
526 | local pver | ||
527 | local pbuild | ||
528 | local magefile | ||
529 | local dbrecorddir | ||
530 | local provide | ||
531 | niro | 273 | local i |
532 | niro | 226 | |
533 | # very basic getops | ||
534 | for i in $* | ||
535 | do | ||
536 | case $1 in | ||
537 | --pcat|-c) shift; pcat="$1" ;; | ||
538 | --pname|-n) shift; pname="$1" ;; | ||
539 | --pver|-v) shift; pver="$1" ;; | ||
540 | --pbuild|-b) shift; pbuild="$1" ;; | ||
541 | esac | ||
542 | shift | ||
543 | done | ||
544 | |||
545 | # sanity checks; abort if not given | ||
546 | [ -z "${pcat}" ] && die "remove_database_entry() \$pcat not given." | ||
547 | [ -z "${pname}" ] && die "remove_database_entry() \$pname not given." | ||
548 | [ -z "${pver}" ] && die "remove_database_entry() \$pver not given." | ||
549 | [ -z "${pbuild}" ] && die "remove_database_entry() \$pbuild not given." | ||
550 | |||
551 | # check needed global vars | ||
552 | [ -z "${INSTALLDB}" ] && die "remove_database_entry() \$INSTALLDB not set." | ||
553 | |||
554 | # set needed vars | ||
555 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" | ||
556 | dbrecorddir="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}" | ||
557 | |||
558 | # abort if mage file not exists | ||
559 | [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." | ||
560 | |||
561 | niro | 294 | # remove virtuals only if no other exist |
562 | if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] | ||
563 | niro | 226 | then |
564 | niro | 294 | # first unregister virtuals |
565 | provide="$(get_value_from_magefile PROVIDE ${magefile})" | ||
566 | if [ -n "${provide}" ] | ||
567 | then | ||
568 | for i in ${provide} | ||
569 | do | ||
570 | virtuals_del "${i}" "${pcat}/${pname}" | ||
571 | done | ||
572 | fi | ||
573 | niro | 226 | fi |
574 | |||
575 | # removes database entry | ||
576 | if [ -d ${dbrecorddir} ] | ||
577 | then | ||
578 | rm -rf ${dbrecorddir} | ||
579 | fi | ||
580 | } | ||
581 | |||
582 | niro | 294 | # get the number of installed packages |
583 | count_installed_pkgs() | ||
584 | { | ||
585 | local pcat | ||
586 | local pname | ||
587 | local pkg | ||
588 | local i | ||
589 | niro | 226 | |
590 | niro | 294 | # very basic getops |
591 | for i in $* | ||
592 | do | ||
593 | case $1 in | ||
594 | --pcat|-c) shift; pcat="$1" ;; | ||
595 | --pname|-n) shift; pname="$1" ;; | ||
596 | esac | ||
597 | shift | ||
598 | done | ||
599 | |||
600 | # sanity checks; abort if not given | ||
601 | [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." | ||
602 | [ -z "${pname}" ] && die "pkg_count() \$pname not given." | ||
603 | |||
604 | declare -i i=0 | ||
605 | for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) | ||
606 | do | ||
607 | (( i++ )) | ||
608 | #echo "$i ${pkg}" | ||
609 | done | ||
610 | |||
611 | # return the value | ||
612 | echo "${i}" | ||
613 | } | ||
614 | |||
615 | |||
616 | niro | 226 | ################################################### |
617 | # function compare_mtime # | ||
618 | # compare_mtime $pcat/$PKGNAME /path/to/file # | ||
619 | # # | ||
620 | # returns: # | ||
621 | # 0=delete me # | ||
622 | # 1=keep me # | ||
623 | # # | ||
624 | # compares mtime of given files in packages # | ||
625 | ################################################### | ||
626 | compare_mtime() | ||
627 | { | ||
628 | local pfull="$1" | ||
629 | local pathto="$2" | ||
630 | local mtime | ||
631 | local pcat | ||
632 | local x | ||
633 | |||
634 | mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)" | ||
635 | |||
636 | # if $pathto is a symlink than compare linked binary | ||
637 | if [ -L "${MROOT}${pathto}" ] | ||
638 | then | ||
639 | # readlink -f resolves full path of linked file | ||
640 | x="$(readlink -f "${MROOT}${pathto}")" | ||
641 | |||
642 | # abort if target does not exists | ||
643 | # we keep safe here, theoretically the link can removed | ||
644 | [ ! -e "${x}" ] && return 1 | ||
645 | |||
646 | x=$(stat -c %Y "${x}") | ||
647 | else | ||
648 | x=$(stat -c %Y "${MROOT}${pathto}") | ||
649 | fi | ||
650 | |||
651 | [[ ${mtime} = ${x} ]] && return 0 | ||
652 | |||
653 | # echo "keep me : ${pathto}" | ||
654 | return 1 | ||
655 | } | ||
656 | |||
657 | |||
658 | ################################################### | ||
659 | # function remove_symlinks # | ||
660 | # remove_symlinks $PKGNAME # | ||
661 | ################################################### | ||
662 | remove_symlinks() | ||
663 | { | ||
664 | local pathto | ||
665 | local posix | ||
666 | local link | ||
667 | local mtime | ||
668 | local IFS | ||
669 | local retval | ||
670 | local pcat | ||
671 | local pname | ||
672 | local pver | ||
673 | local pbuild | ||
674 | local i | ||
675 | local pfull | ||
676 | |||
677 | IFS=$'\n' | ||
678 | |||
679 | # very basic getops | ||
680 | for i in $* | ||
681 | do | ||
682 | case $1 in | ||
683 | --pcat|-c) shift; pcat="$1" ;; | ||
684 | --pname|-n) shift; pname="$1" ;; | ||
685 | --pver|-v) shift; pver="$1" ;; | ||
686 | --pbuild|-b) shift; pbuild="$1" ;; | ||
687 | esac | ||
688 | shift | ||
689 | done | ||
690 | |||
691 | # sanity checks; abort if not given | ||
692 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
693 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
694 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
695 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
696 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
697 | |||
698 | # check needed global vars | ||
699 | [ -z "${BUILDDIR}" ] && die "remove_symlinks() \$BUILDDIR not set." | ||
700 | |||
701 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.symlinks ] && die "remove_symlinks() .symlinks not found" | ||
702 | |||
703 | # sets fieldseperator to "§" instead of " " | ||
704 | IFS=§ | ||
705 | |||
706 | while read pathto posix link mtime | ||
707 | do | ||
708 | [ -z "${pathto}" ] && continue | ||
709 | if [ ! -L "${MROOT}${pathto}" ] | ||
710 | then | ||
711 | [[ ${VERBOSE} = on ]] && \ | ||
712 | echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}" | ||
713 | continue | ||
714 | fi | ||
715 | |||
716 | # *no* ${MROOT}, will be set internal | ||
717 | compare_mtime "${pfull}" "${pathto}" | ||
718 | retval=$? | ||
719 | # 0=delete me # | ||
720 | # 1=keep me # | ||
721 | case ${retval} in | ||
722 | 0) | ||
723 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}" | ||
724 | rm "${MROOT}${pathto}" | ||
725 | ;; | ||
726 | |||
727 | 1) | ||
728 | [[ ${VERBOSE} = on ]] && \ | ||
729 | echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}" | ||
730 | ;; | ||
731 | esac | ||
732 | done < ${MROOT}${INSTALLDB}/${pfull}/.symlinks | ||
733 | |||
734 | # very important: unsetting the '§' fieldseperator | ||
735 | IFS=$'\n' | ||
736 | } | ||
737 | |||
738 | |||
739 | ################################################### | ||
740 | # function remove_files # | ||
741 | # remove_files $PKGNAME # | ||
742 | ################################################### | ||
743 | remove_files() | ||
744 | { | ||
745 | local pathto | ||
746 | local posix | ||
747 | local user | ||
748 | local group | ||
749 | local mtime | ||
750 | local md5sum | ||
751 | local IFS | ||
752 | local retval | ||
753 | local pcat | ||
754 | local pname | ||
755 | local pver | ||
756 | local pbuild | ||
757 | local i | ||
758 | local pfull | ||
759 | |||
760 | IFS=$'\n' | ||
761 | |||
762 | # very basic getops | ||
763 | for i in $* | ||
764 | do | ||
765 | case $1 in | ||
766 | --pcat|-c) shift; pcat="$1" ;; | ||
767 | --pname|-n) shift; pname="$1" ;; | ||
768 | --pver|-v) shift; pver="$1" ;; | ||
769 | --pbuild|-b) shift; pbuild="$1" ;; | ||
770 | esac | ||
771 | shift | ||
772 | done | ||
773 | |||
774 | # sanity checks; abort if not given | ||
775 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
776 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
777 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
778 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
779 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
780 | |||
781 | # check needed global vars | ||
782 | [ -z "${BUILDDIR}" ] && die "remove_files() \$BUILDDIR not set." | ||
783 | |||
784 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.files ] && die "remove_files() .files not found" | ||
785 | |||
786 | # sets fieldseperator to "§" instead of " " | ||
787 | IFS=§ | ||
788 | |||
789 | while read pathto posix user group mtime md5sum | ||
790 | do | ||
791 | [ -z "${pathto}" ] && continue | ||
792 | |||
793 | niro | 240 | if [ ! -e "${MROOT}${pathto}" ] |
794 | niro | 226 | then |
795 | [[ ${VERBOSE} = on ]] && \ | ||
796 | echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" | ||
797 | continue | ||
798 | fi | ||
799 | |||
800 | # *no* ${MROOT}, will be set internal | ||
801 | compare_mtime "${pfull}" "${pathto}" | ||
802 | retval=$? | ||
803 | # 0=delete me # | ||
804 | # 1=keep me # | ||
805 | case ${retval} in | ||
806 | 0) | ||
807 | niro | 280 | # check if the file is config_protected |
808 | # ${MROOT} will automatically added if set !! | ||
809 | is_config_protected "${pathto}" | ||
810 | retval="$?" | ||
811 | |||
812 | # 0 - not protected # | ||
813 | # 1 - error # | ||
814 | # 2 - protected # | ||
815 | # 3 - protected but masked # | ||
816 | |||
817 | case ${retval} in | ||
818 | # file is not protected - delete it | ||
819 | 0|3) | ||
820 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" | ||
821 | rm "${MROOT}${pathto}" | ||
822 | ;; | ||
823 | |||
824 | # file is protected, do not delete | ||
825 | 2) | ||
826 | if [[ ${VERBOSE} = on ]] | ||
827 | then | ||
828 | echo -en "${COLRED}" | ||
829 | echo -n "! prot " | ||
830 | echo -en "${COLDEFAULT}" | ||
831 | echo " === FILE: ${MROOT}${pathto}" | ||
832 | fi | ||
833 | ;; | ||
834 | esac | ||
835 | niro | 226 | ;; |
836 | 1) | ||
837 | [[ ${VERBOSE} = on ]] && \ | ||
838 | echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" | ||
839 | ;; | ||
840 | esac | ||
841 | done < ${MROOT}${INSTALLDB}/${pfull}/.files | ||
842 | |||
843 | # very important: unsetting the '§' fieldseperator | ||
844 | IFS=$'\n' | ||
845 | } | ||
846 | |||
847 | |||
848 | ################################################### | ||
849 | # function remove_blockdevices # | ||
850 | # remove_blockdevices $PKGNAME # | ||
851 | ################################################### | ||
852 | remove_blockdevices() | ||
853 | { | ||
854 | local pathto | ||
855 | local posix | ||
856 | local IFS | ||
857 | local pcat | ||
858 | local pname | ||
859 | local pver | ||
860 | local pbuild | ||
861 | local i | ||
862 | local pfull | ||
863 | |||
864 | IFS=$'\n' | ||
865 | |||
866 | # very basic getops | ||
867 | for i in $* | ||
868 | do | ||
869 | case $1 in | ||
870 | --pcat|-c) shift; pcat="$1" ;; | ||
871 | --pname|-n) shift; pname="$1" ;; | ||
872 | --pver|-v) shift; pver="$1" ;; | ||
873 | --pbuild|-b) shift; pbuild="$1" ;; | ||
874 | esac | ||
875 | shift | ||
876 | done | ||
877 | |||
878 | # sanity checks; abort if not given | ||
879 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
880 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
881 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
882 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
883 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
884 | |||
885 | # check needed global vars | ||
886 | [ -z "${BUILDDIR}" ] && die "remove_blockdevices() \$BUILDDIR not set." | ||
887 | |||
888 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.pipes ] && die "remove_blockdevices() .pipes not found" | ||
889 | |||
890 | # sets fieldseperator to "§" instead of " " | ||
891 | IFS=§ | ||
892 | |||
893 | while read pathto posix | ||
894 | do | ||
895 | [ -z "${pathto}" ] && continue | ||
896 | |||
897 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}" | ||
898 | rm "${MROOT}${pathto}" | ||
899 | done < ${MROOT}${INSTALLDB}/${pfull}/.pipes | ||
900 | |||
901 | # very important: unsetting the '§' fieldseperator | ||
902 | IFS=$'\n' | ||
903 | } | ||
904 | |||
905 | |||
906 | ################################################### | ||
907 | # function remove_characterdevices # | ||
908 | # remove_characterdevices $PKGNAME # | ||
909 | ################################################### | ||
910 | remove_characterdevices() | ||
911 | { | ||
912 | local pathto | ||
913 | local posix | ||
914 | local IFS | ||
915 | local pcat | ||
916 | local pname | ||
917 | local pver | ||
918 | local pbuild | ||
919 | local i | ||
920 | local pfull | ||
921 | |||
922 | IFS=$'\n' | ||
923 | |||
924 | # very basic getops | ||
925 | for i in $* | ||
926 | do | ||
927 | case $1 in | ||
928 | --pcat|-c) shift; pcat="$1" ;; | ||
929 | --pname|-n) shift; pname="$1" ;; | ||
930 | --pver|-v) shift; pver="$1" ;; | ||
931 | --pbuild|-b) shift; pbuild="$1" ;; | ||
932 | esac | ||
933 | shift | ||
934 | done | ||
935 | |||
936 | # sanity checks; abort if not given | ||
937 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
938 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
939 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
940 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
941 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
942 | |||
943 | # check needed global vars | ||
944 | [ -z "${BUILDDIR}" ] && die "remove_characterdevices() \$BUILDDIR not set." | ||
945 | |||
946 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_characterdevices() .char not found" | ||
947 | |||
948 | # sets fieldseperator to "§" instead of " " | ||
949 | IFS=§ | ||
950 | |||
951 | while read pathto posix | ||
952 | do | ||
953 | [ -z "${pathto}" ] && continue | ||
954 | |||
955 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}" | ||
956 | rm "${MROOT}${pathto}" | ||
957 | done < ${MROOT}${INSTALLDB}/${pfull}/.char | ||
958 | |||
959 | # very important: unsetting the '§' fieldseperator | ||
960 | IFS=$'\n' | ||
961 | } | ||
962 | |||
963 | |||
964 | ################################################### | ||
965 | # function remove_direcories # | ||
966 | # remove_direcories $PKGNAME # | ||
967 | ################################################### | ||
968 | remove_directories() | ||
969 | { | ||
970 | local pathto | ||
971 | local posix | ||
972 | local IFS | ||
973 | local pcat | ||
974 | local pname | ||
975 | local pver | ||
976 | local pbuild | ||
977 | local i | ||
978 | local pfull | ||
979 | |||
980 | IFS=$'\n' | ||
981 | |||
982 | # very basic getops | ||
983 | for i in $* | ||
984 | do | ||
985 | case $1 in | ||
986 | --pcat|-c) shift; pcat="$1" ;; | ||
987 | --pname|-n) shift; pname="$1" ;; | ||
988 | --pver|-v) shift; pver="$1" ;; | ||
989 | --pbuild|-b) shift; pbuild="$1" ;; | ||
990 | esac | ||
991 | shift | ||
992 | done | ||
993 | |||
994 | # sanity checks; abort if not given | ||
995 | [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given." | ||
996 | [ -z "${pname}" ] && die "remove_symlinks() \$pname not given." | ||
997 | [ -z "${pver}" ] && die "remove_symlinks() \$pver not given." | ||
998 | [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given." | ||
999 | pfull="${pcat}/${pname}-${pver}-${pbuild}" | ||
1000 | |||
1001 | # check needed global vars | ||
1002 | [ -z "${BUILDDIR}" ] && die "remove_directories() \$BUILDDIR not set." | ||
1003 | |||
1004 | [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" | ||
1005 | |||
1006 | # sets fieldseperator to "§" instead of " " | ||
1007 | IFS=§ | ||
1008 | |||
1009 | niro | 240 | # reversed order is mandatory ! |
1010 | tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix | ||
1011 | niro | 226 | do |
1012 | [ -z "${pathto}" ] && continue | ||
1013 | |||
1014 | if [ ! -d "${MROOT}${pathto}" ] | ||
1015 | then | ||
1016 | [[ ${VERBOSE} = on ]] && \ | ||
1017 | echo -e "${COLRED}! exist${COLDEFAULT} === DIR: ${MROOT}${pathto}" | ||
1018 | continue | ||
1019 | fi | ||
1020 | |||
1021 | # exclude .keep directories | ||
1022 | if [ -f "${MROOT}${pathto}/.keep" ] | ||
1023 | then | ||
1024 | [[ ${VERBOSE} = on ]] && \ | ||
1025 | niro | 240 | echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" |
1026 | niro | 226 | continue |
1027 | fi | ||
1028 | |||
1029 | # monitors /etc/env.d -> env-rebuild | ||
1030 | [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true | ||
1031 | |||
1032 | # monitors /usr/share/info -> info-rebuild | ||
1033 | [[ ${pathto} = /usr/share/info ]] && export MAGE_INFO_REBUILD=true | ||
1034 | |||
1035 | if rmdir "${MROOT}${pathto}" &> /dev/null | ||
1036 | then | ||
1037 | [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR: ${MROOT}${pathto}" | ||
1038 | else | ||
1039 | [[ ${VERBOSE} = on ]] && \ | ||
1040 | echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" | ||
1041 | fi | ||
1042 | niro | 240 | done |
1043 | niro | 226 | |
1044 | # very important: unsetting the '§' fieldseperator | ||
1045 | IFS=$'\n' | ||
1046 | } | ||
1047 | |||
1048 | |||
1049 | ################################################### | ||
1050 | # function build_douninstall # | ||
1051 | # build_douninstall $PKGNAME # | ||
1052 | # NOTE: this is an wrapper do remove packages # | ||
1053 | ################################################### | ||
1054 | build_douninstall() | ||
1055 | { | ||
1056 | local pcat | ||
1057 | local pname | ||
1058 | local pver | ||
1059 | local pbuild | ||
1060 | local i | ||
1061 | |||
1062 | # very basic getops | ||
1063 | for i in $* | ||
1064 | do | ||
1065 | case $1 in | ||
1066 | --pcat|-c) shift; pcat="$1" ;; | ||
1067 | --pname|-n) shift; pname="$1" ;; | ||
1068 | --pver|-v) shift; pver="$1" ;; | ||
1069 | --pbuild|-b) shift; pbuild="$1" ;; | ||
1070 | esac | ||
1071 | shift | ||
1072 | done | ||
1073 | |||
1074 | # sanity checks; abort if not given | ||
1075 | [ -z "${pcat}" ] && die "build_douninstall() \$pcat not given." | ||
1076 | [ -z "${pname}" ] && die "build_douninstall() \$pname not given." | ||
1077 | [ -z "${pver}" ] && die "build_douninstall() \$pver not given." | ||
1078 | [ -z "${pbuild}" ] && die "build_douninstall() \$pbuild not given." | ||
1079 | |||
1080 | # this is only a wrapper | ||
1081 | |||
1082 | # NOTE: | ||
1083 | # !! we use § as field seperator !! | ||
1084 | # doing so prevent us to get errors by filenames with spaces | ||
1085 | |||
1086 | for i in symlinks files blockdevices characterdevices directories | ||
1087 | do | ||
1088 | remove_${i} \ | ||
1089 | --pcat "${pcat}" \ | ||
1090 | --pname "${pname}" \ | ||
1091 | --pver "${pver}" \ | ||
1092 | --pbuild "${pbuild}" \ | ||
1093 | || die "remove ${i} ${pcat}/${pname}-${pver}-${pbuild}" | ||
1094 | done | ||
1095 | } | ||
1096 | |||
1097 | # fetch_packages /path/to/mage/file1 /path/to/mage/file2 | ||
1098 | fetch_packages() | ||
1099 | { | ||
1100 | local list="$@" | ||
1101 | local pkg | ||
1102 | local mirr | ||
1103 | local magefile | ||
1104 | local md5file | ||
1105 | local opt | ||
1106 | local count_current | ||
1107 | local count_total | ||
1108 | |||
1109 | niro | 419 | [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." |
1110 | niro | 226 | |
1111 | # get count of total packages | ||
1112 | declare -i count_current=0 | ||
1113 | declare -i count_total=0 | ||
1114 | |||
1115 | for i in ${list}; do (( count_total++ )); done | ||
1116 | |||
1117 | for magefile in ${list} | ||
1118 | do | ||
1119 | pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
1120 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
1121 | |||
1122 | (( count_current++ )) | ||
1123 | xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]" | ||
1124 | |||
1125 | # abort on virtual pkg | ||
1126 | if [[ ${pkgtype} = virtual ]] | ||
1127 | then | ||
1128 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
1129 | echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
1130 | continue | ||
1131 | fi | ||
1132 | |||
1133 | # abort on sources pkg | ||
1134 | if [[ ${pkgtype} = sources ]] | ||
1135 | then | ||
1136 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
1137 | echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... " | ||
1138 | continue | ||
1139 | fi | ||
1140 | |||
1141 | # abort if already exist | ||
1142 | if [ -f ${PKGDIR}/${pkg} ] | ||
1143 | then | ||
1144 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
1145 | echo " fetch complete (${count_current}/${count_total}): ${pkg} ... " | ||
1146 | continue | ||
1147 | fi | ||
1148 | |||
1149 | for mirr in ${MIRRORS} | ||
1150 | do | ||
1151 | echo -ne " ${COLBLUE}***${COLDEFAULT}" | ||
1152 | #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... " | ||
1153 | echo -e " fetching (${count_current}/${count_total}): ${pkg} ... " | ||
1154 | [[ ${VERBOSE} = off ]] && opt="--quiet" | ||
1155 | wget \ | ||
1156 | --passive-ftp \ | ||
1157 | --tries 3 \ | ||
1158 | --continue \ | ||
1159 | --progress bar \ | ||
1160 | --directory-prefix=${PKGDIR} \ | ||
1161 | niro | 286 | ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} |
1162 | niro | 226 | if [[ $? = 0 ]] |
1163 | then | ||
1164 | break | ||
1165 | else | ||
1166 | continue | ||
1167 | fi | ||
1168 | done | ||
1169 | |||
1170 | if [ ! -f ${PKGDIR}/${pkg} ] | ||
1171 | then | ||
1172 | die "Could not download ${pkg}" | ||
1173 | fi | ||
1174 | done | ||
1175 | |||
1176 | # add a crlf for a better view | ||
1177 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
1178 | } | ||
1179 | |||
1180 | syncmage() | ||
1181 | { | ||
1182 | if [ -z "${RSYNC}" ] | ||
1183 | then | ||
1184 | niro | 419 | die "You have no rsync-mirrors defined. Please edit your ${MAGERC}." |
1185 | niro | 226 | fi |
1186 | |||
1187 | local i | ||
1188 | for i in ${RSYNC} | ||
1189 | do | ||
1190 | niro | 386 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} |
1191 | niro | 226 | if [[ $? = 0 ]] |
1192 | then | ||
1193 | break | ||
1194 | else | ||
1195 | continue | ||
1196 | fi | ||
1197 | done | ||
1198 | |||
1199 | # clean up backup files (foo~) | ||
1200 | find ${MAGEDIR} -name *~ -exec rm '{}' ';' | ||
1201 | |||
1202 | # check if an newer mage version is available | ||
1203 | is_newer_mage_version_available | ||
1204 | } | ||
1205 | |||
1206 | niro | 739 | syncmage_tarball() |
1207 | { | ||
1208 | local latest_tarball | ||
1209 | local temp="$(mktemp -d)" | ||
1210 | local mirr mymirr | ||
1211 | |||
1212 | # try to get the tarball marked as latest on the server | ||
1213 | latest_tarball="mage-latest.tar.bz2" | ||
1214 | |||
1215 | for mirr in ${MIRRORS} | ||
1216 | do | ||
1217 | # path without distribution | ||
1218 | mymirr="${mirr%/*}" | ||
1219 | |||
1220 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1221 | echo "fetching latest tarball from ${mymirr} ..." | ||
1222 | |||
1223 | wget \ | ||
1224 | --passive-ftp \ | ||
1225 | --tries 3 \ | ||
1226 | --continue \ | ||
1227 | --progress bar \ | ||
1228 | --directory-prefix=${temp} \ | ||
1229 | ${mymirr}/rsync/tarballs/${latest_tarball} | ||
1230 | if [[ $? = 0 ]] | ||
1231 | then | ||
1232 | break | ||
1233 | else | ||
1234 | continue | ||
1235 | fi | ||
1236 | done | ||
1237 | |||
1238 | if [[ -f ${temp}/${latest_tarball} ]] | ||
1239 | then | ||
1240 | if [[ -d ${MAGEDIR} ]] | ||
1241 | then | ||
1242 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1243 | echo "cleaning old mage-tree ${MAGEDIR}..." | ||
1244 | rm -rf ${MAGEDIR} | ||
1245 | fi | ||
1246 | |||
1247 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1248 | echo "updating mage-tree from tarball ..." | ||
1249 | # unpack in dirname of MAGEDIR, as the tarball has already the mage | ||
1250 | tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" | ||
1251 | |||
1252 | if [[ -d ${temp} ]] | ||
1253 | then | ||
1254 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1255 | echo "clenaing temp-files ..." | ||
1256 | rm -rf ${temp} | ||
1257 | fi | ||
1258 | else | ||
1259 | die "Could not fetch the latest tarball ... aborting" | ||
1260 | fi | ||
1261 | } | ||
1262 | |||
1263 | niro | 226 | cleanpkg() |
1264 | { | ||
1265 | if [ -d "${PKGDIR}" ] | ||
1266 | then | ||
1267 | echo -n "Removing downloaded packages... " | ||
1268 | rm -rf ${PKGDIR}/* | ||
1269 | echo "done." | ||
1270 | fi | ||
1271 | } | ||
1272 | |||
1273 | xtitle() | ||
1274 | { | ||
1275 | if [[ ${TERM} = xterm ]] | ||
1276 | then | ||
1277 | echo -ne "\033]0;Mage: $1\007" | ||
1278 | fi | ||
1279 | return 0 | ||
1280 | } | ||
1281 | |||
1282 | |||
1283 | xtitleclean() | ||
1284 | { | ||
1285 | if [[ ${TERM} = xterm ]] | ||
1286 | then | ||
1287 | echo -ne "\033]0;\007" | ||
1288 | fi | ||
1289 | return 0 | ||
1290 | } | ||
1291 | |||
1292 | |||
1293 | # cuts full pathnames or versioniezed names down to basename | ||
1294 | choppkgname() | ||
1295 | { | ||
1296 | #we want this only if full name was used | ||
1297 | if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] | ||
1298 | then | ||
1299 | #cuts ARCH and PBUILD | ||
1300 | niro | 419 | #ARCH comes from ${MAGERC} |
1301 | niro | 226 | MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") |
1302 | |||
1303 | #cuts version number | ||
1304 | MAGENAME=$(basename ${MAGENAME%-*} .mage) | ||
1305 | fi | ||
1306 | } | ||
1307 | |||
1308 | # get_categorie $PNAME, returns CATEGORIE | ||
1309 | # $1=pname | ||
1310 | # ret 0=ok, 1=not_found | ||
1311 | pname2pcat() | ||
1312 | { | ||
1313 | local pname="$1" | ||
1314 | local repo="$2" | ||
1315 | local pcat | ||
1316 | local categorie | ||
1317 | |||
1318 | for pcat in ${MAGEDIR}/* | ||
1319 | do | ||
1320 | if [ -d ${pcat}/${pname} ] | ||
1321 | then | ||
1322 | categorie=$(basename ${pcat}) | ||
1323 | fi | ||
1324 | done | ||
1325 | |||
1326 | echo "${categorie}" | ||
1327 | } | ||
1328 | |||
1329 | # check_stable_package /path/to/foo.mage | ||
1330 | # returns 0=stable 1=unstable | ||
1331 | check_stable_package() | ||
1332 | { | ||
1333 | niro | 370 | # first check if this magefile is not blacklisted |
1334 | blacklisted "$1" || return 1 | ||
1335 | |||
1336 | niro | 226 | local STATE |
1337 | STATE="$(get_value_from_magefile STATE "$1")" | ||
1338 | |||
1339 | # state testing | ||
1340 | niro | 286 | if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] |
1341 | niro | 226 | then |
1342 | case ${STATE} in | ||
1343 | testing|stable) return 0 ;; | ||
1344 | *) return 1 ;; | ||
1345 | esac | ||
1346 | fi | ||
1347 | |||
1348 | # state unstable | ||
1349 | niro | 286 | if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] |
1350 | niro | 226 | then |
1351 | case ${STATE} in | ||
1352 | unstable|testing|stable) return 0 ;; | ||
1353 | *) return 1 ;; | ||
1354 | esac | ||
1355 | fi | ||
1356 | |||
1357 | # no use_state given = stable | ||
1358 | case ${STATE} in | ||
1359 | stable) return 0 ;; | ||
1360 | *) return 1 ;; | ||
1361 | esac | ||
1362 | } | ||
1363 | |||
1364 | |||
1365 | # get_highest_magefile ${PCAT} ${PNAME} | ||
1366 | # fake at moment returns only stable pkgs (must set to be one) | ||
1367 | # return $HIGHEST_MAGEFILE | ||
1368 | get_highest_magefile() | ||
1369 | { | ||
1370 | local HIGHEST_MAGEFILE | ||
1371 | local PCAT="$1" | ||
1372 | local PNAME="$2" | ||
1373 | local magefile | ||
1374 | |||
1375 | niro | 676 | # do not list the content of a directory, only the name (-d) |
1376 | for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*) | ||
1377 | niro | 226 | do |
1378 | niro | 676 | [[ -z ${magefile} ]] && continue |
1379 | niro | 226 | # we exclude subdirs (for stuff like a md5sum dir) |
1380 | niro | 676 | [[ -d ${magefile} ]] && continue |
1381 | niro | 226 | if check_stable_package ${magefile} |
1382 | then | ||
1383 | HIGHEST_MAGEFILE=${magefile} | ||
1384 | #for debug only | ||
1385 | [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" | ||
1386 | fi | ||
1387 | done | ||
1388 | |||
1389 | niro | 370 | # do not so anything |
1390 | # # stop here if HIGHEST_MAGEFILE is zero | ||
1391 | # # this package must be unstable or old | ||
1392 | # if [ -z "${HIGHEST_MAGEFILE}" ] | ||
1393 | # then | ||
1394 | # echo | ||
1395 | # echo -n "All packages named " | ||
1396 | # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} | ||
1397 | # echo -n " are marked " | ||
1398 | # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} | ||
1399 | # echo "." | ||
1400 | # echo "You need to declare USE_UNSTABLE=true to install this." | ||
1401 | # echo | ||
1402 | # echo "Example:" | ||
1403 | # echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" | ||
1404 | # echo | ||
1405 | # echo "Be warned that these packages are not stable and may cause serious problems." | ||
1406 | # echo "You should know what you are doing, so don't complain about any damage." | ||
1407 | # echo | ||
1408 | # return 1 | ||
1409 | # fi | ||
1410 | niro | 226 | |
1411 | echo "${HIGHEST_MAGEFILE}" | ||
1412 | return 0 | ||
1413 | } | ||
1414 | |||
1415 | |||
1416 | ################################################### | ||
1417 | # function is_config_protected # | ||
1418 | # is_config_protected /path/to/file # | ||
1419 | # # | ||
1420 | # returns: # | ||
1421 | # 0 - not protected # | ||
1422 | # 1 - error # | ||
1423 | # 2 - protected # | ||
1424 | # 3 - protected but masked # | ||
1425 | # # | ||
1426 | ################################################### | ||
1427 | is_config_protected() | ||
1428 | { | ||
1429 | local EXPFILE | ||
1430 | local TEST | ||
1431 | local PROTECTED | ||
1432 | local IFS | ||
1433 | |||
1434 | EXPFILE="${MROOT}$1" | ||
1435 | |||
1436 | # file does not exist; it can be written | ||
1437 | niro | 451 | [[ ! -e ${EXPFILE} ]] && return 0 |
1438 | niro | 226 | |
1439 | # to be safe; it may be '§' | ||
1440 | IFS=' ' | ||
1441 | |||
1442 | # check ob in config protect | ||
1443 | for i in ${CONFIG_PROTECT} | ||
1444 | do | ||
1445 | # ersetzen von $i nur wenn am anfang der variable | ||
1446 | TEST="${EXPFILE/#${MROOT}${i}/Protected}" | ||
1447 | niro | 451 | if [[ ${TEST} != ${EXPFILE} ]] |
1448 | niro | 226 | then |
1449 | # setzen das es protected ist | ||
1450 | PROTECTED=TRUE | ||
1451 | |||
1452 | # check ob nicht doch maskiert | ||
1453 | for x in ${CONFIG_PROTECT_MASK} | ||
1454 | do | ||
1455 | TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" | ||
1456 | niro | 451 | if [[ ${TEST} != ${EXPFILE} ]] |
1457 | niro | 226 | then |
1458 | PROTECTED=MASKED | ||
1459 | fi | ||
1460 | done | ||
1461 | fi | ||
1462 | done | ||
1463 | |||
1464 | unset IFS | ||
1465 | |||
1466 | case ${PROTECTED} in | ||
1467 | TRUE) | ||
1468 | #echo "I'm protected" | ||
1469 | return 2 | ||
1470 | ;; | ||
1471 | MASKED) | ||
1472 | #echo "I'm protected, but masked - delete me" | ||
1473 | return 3 | ||
1474 | ;; | ||
1475 | *) | ||
1476 | #echo "delete me" | ||
1477 | return 0 | ||
1478 | ;; | ||
1479 | esac | ||
1480 | } | ||
1481 | |||
1482 | |||
1483 | ################################################### | ||
1484 | # function count_protected_files # | ||
1485 | # count_protected_files /path/to/file # | ||
1486 | # # | ||
1487 | # note: prints number of protected files # | ||
1488 | # exp: 0012 # | ||
1489 | ################################################### | ||
1490 | count_protected_files() | ||
1491 | { | ||
1492 | niro | 603 | local file="$1" |
1493 | local dirname="${file%/*}" | ||
1494 | local filename="${file##*/}" | ||
1495 | local count | ||
1496 | local output | ||
1497 | local i | ||
1498 | |||
1499 | declare -i count=0 | ||
1500 | |||
1501 | # check if there are already protected files | ||
1502 | for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | | ||
1503 | sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | | ||
1504 | sort -t'%' -k3 -k2 | cut -f1 -d'%') | ||
1505 | do | ||
1506 | count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") | ||
1507 | done | ||
1508 | (( count ++ )) | ||
1509 | |||
1510 | # fill output up with zeros | ||
1511 | for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done | ||
1512 | output="${output}${count}" | ||
1513 | |||
1514 | echo "${output}" | ||
1515 | niro | 226 | } |
1516 | |||
1517 | # call with | ||
1518 | # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME' | ||
1519 | # returns /path/to/magefile(s) | ||
1520 | get_uninstall_candidates() | ||
1521 | { | ||
1522 | local search_pname | ||
1523 | local pkg | ||
1524 | local pcat | ||
1525 | local pname | ||
1526 | local pver | ||
1527 | local pbuild | ||
1528 | local list | ||
1529 | local pcatdir | ||
1530 | local protected | ||
1531 | niro | 449 | local i |
1532 | niro | 226 | |
1533 | # very basic getops | ||
1534 | for i in $* | ||
1535 | do | ||
1536 | case $1 in | ||
1537 | --pcat|-c) shift; pcatdir="$1" ;; | ||
1538 | --pname|-n) shift; search_pname="$1" ;; | ||
1539 | --protected|-p) shift; protected="$1" ;; | ||
1540 | esac | ||
1541 | shift | ||
1542 | done | ||
1543 | |||
1544 | niro | 329 | # it's not good to complain here about empty pnames; better to continue later anyway |
1545 | # # sanity checks; abort if not given | ||
1546 | # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." | ||
1547 | niro | 226 | |
1548 | |||
1549 | # check needed global vars | ||
1550 | [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." | ||
1551 | |||
1552 | # set pcatdir to '*' if empty | ||
1553 | niro | 329 | [ -z "${pcatdir}" ] && pcatdir='*' |
1554 | niro | 226 | |
1555 | for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* | ||
1556 | do | ||
1557 | # abort if not a dir | ||
1558 | [ ! -d ${pkg} ] && continue | ||
1559 | |||
1560 | pname="$(magename2pname ${pkg})" | ||
1561 | |||
1562 | if [[ ${search_pname} = ${pname} ]] | ||
1563 | then | ||
1564 | pcat="$(magename2pcat ${pkg} installdb)" | ||
1565 | pver="$(magename2pver ${pkg})" | ||
1566 | pbuild="$(magename2pbuild ${pkg})" | ||
1567 | |||
1568 | # exclude proteced | ||
1569 | [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue | ||
1570 | |||
1571 | list="${list} ${pcat}/${pname}-${pver}-${pbuild}" | ||
1572 | fi | ||
1573 | done | ||
1574 | |||
1575 | echo "${list}" | ||
1576 | } | ||
1577 | |||
1578 | # reads virtualdb file | ||
1579 | #$1 = virtualname; $2 commands: showpkgs, showline | ||
1580 | #return 0 == installed -> shows installed pkg as well | ||
1581 | #return 1 == not installed | ||
1582 | virtuals_read() | ||
1583 | { | ||
1584 | local virtualname="$1" | ||
1585 | local command="$2" | ||
1586 | local virtline | ||
1587 | local line x i | ||
1588 | |||
1589 | # parse file to get virtual_name line | ||
1590 | IFS=$'\n' | ||
1591 | for line in $(< ${MROOT}${VIRTUALDB_FILE}) | ||
1592 | do | ||
1593 | IFS=$' ' | ||
1594 | for x in ${line} | ||
1595 | do | ||
1596 | if [[ ${x} = ${virtualname} ]] | ||
1597 | then | ||
1598 | virtline="${line}" | ||
1599 | [[ ${command} = showline ]] && echo "${line}" | ||
1600 | fi | ||
1601 | done | ||
1602 | IFS=$'\n' | ||
1603 | done | ||
1604 | |||
1605 | unset IFS | ||
1606 | |||
1607 | # now read the packages linked to VIRTUAL_NAME and output them | ||
1608 | if [ -n "${virtline}" ] | ||
1609 | then | ||
1610 | if [[ ${command} = showpkgs ]] | ||
1611 | then | ||
1612 | declare -i x=0 | ||
1613 | for i in ${virtline} | ||
1614 | do | ||
1615 | if [ ${x} -ge 1 ] | ||
1616 | then | ||
1617 | echo "${i}" | ||
1618 | fi | ||
1619 | ((x++)) | ||
1620 | done | ||
1621 | fi | ||
1622 | return 0 | ||
1623 | fi | ||
1624 | return 1 | ||
1625 | } | ||
1626 | |||
1627 | |||
1628 | #add pkg to virtualdb | ||
1629 | # $1 == virtualname $2= pkgname | ||
1630 | # retvals: 0=ok,added; 1=error; 3=pkg already in virtual | ||
1631 | virtuals_add() | ||
1632 | { | ||
1633 | local virtualname="$1" | ||
1634 | local pkgname="$2" | ||
1635 | local oldline | ||
1636 | local line i | ||
1637 | local installed_file | ||
1638 | niro | 273 | local OLDIFS |
1639 | niro | 226 | |
1640 | if virtuals_read ${virtualname} | ||
1641 | then | ||
1642 | niro | 329 | # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already |
1643 | niro | 226 | for i in $(virtuals_read ${virtualname} showpkgs) |
1644 | do | ||
1645 | if [[ ${i} = ${pkgname} ]] | ||
1646 | then | ||
1647 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
1648 | echo "${pkgname} already linked as ${virtualname} ..." | ||
1649 | #return 3 | ||
1650 | return 0 | ||
1651 | fi | ||
1652 | done | ||
1653 | |||
1654 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
1655 | echo "updating ${virtualname} entry with ${pkgname} ..." | ||
1656 | oldline="$(virtuals_read ${virtualname} showline)" | ||
1657 | |||
1658 | # make a backup | ||
1659 | mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old | ||
1660 | |||
1661 | niro | 273 | OLDIFS="${IFS}" |
1662 | niro | 226 | IFS=$'\n' |
1663 | for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) | ||
1664 | do | ||
1665 | # if the right line, append ${pkgname}, else do nothing | ||
1666 | if [[ ${line} = ${oldline} ]] | ||
1667 | then | ||
1668 | echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1669 | else | ||
1670 | echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1671 | fi | ||
1672 | done | ||
1673 | niro | 273 | # unset IFS |
1674 | IFS="${OLDIFS}" | ||
1675 | niro | 226 | else |
1676 | niro | 273 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" |
1677 | niro | 226 | echo "register ${pkgname} as ${virtualname} ..." |
1678 | echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} | ||
1679 | fi | ||
1680 | |||
1681 | return 0 | ||
1682 | } | ||
1683 | |||
1684 | #deletes pakages from virtual database | ||
1685 | #$1 virtualname; $2 pkgname | ||
1686 | virtuals_del() { | ||
1687 | |||
1688 | niro | 273 | local virtualname="$1" |
1689 | local pkgname="$2" | ||
1690 | local oldline | ||
1691 | local method | ||
1692 | local line i x | ||
1693 | local pkg_installed | ||
1694 | local OLDIFS | ||
1695 | |||
1696 | # first check if exists | ||
1697 | if virtuals_read ${virtualname} | ||
1698 | niro | 226 | then |
1699 | niro | 273 | # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME} |
1700 | niro | 226 | declare -i x=0 |
1701 | niro | 273 | for i in $(virtuals_read ${virtualname} showpkgs) |
1702 | niro | 226 | do |
1703 | niro | 273 | if [[ ${i} = ${pkgname} ]] |
1704 | niro | 226 | then |
1705 | niro | 273 | pkg_installed=true |
1706 | niro | 226 | fi |
1707 | ((x++)) | ||
1708 | done | ||
1709 | niro | 273 | |
1710 | # abort if not installed | ||
1711 | if [[ ${pkg_installed} != true ]] | ||
1712 | niro | 226 | then |
1713 | niro | 273 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1714 | echo "${pkgname} does not exists in ${virtualname}." | ||
1715 | niro | 226 | return 0 |
1716 | fi | ||
1717 | niro | 273 | |
1718 | niro | 226 | if [ ${x} -ge 2 ] |
1719 | then | ||
1720 | niro | 273 | method=update |
1721 | niro | 226 | else |
1722 | niro | 273 | method=delall |
1723 | niro | 226 | fi |
1724 | niro | 273 | |
1725 | # get the complete line | ||
1726 | oldline="$(virtuals_read ${virtualname} showline)" | ||
1727 | |||
1728 | # make a backup of the db | ||
1729 | niro | 226 | mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old |
1730 | niro | 273 | |
1731 | # parse virtualdb | ||
1732 | OLDIFS="${IFS}" | ||
1733 | niro | 226 | IFS=$'\n' |
1734 | for line in $(< ${VIRTUALDB_FILE}.old) | ||
1735 | do | ||
1736 | niro | 273 | if [[ ${line} = ${oldline} ]] |
1737 | niro | 226 | then |
1738 | #delall or update? | ||
1739 | niro | 273 | case ${method} in |
1740 | niro | 226 | update) |
1741 | niro | 273 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" |
1742 | echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." | ||
1743 | # del PKG_NAME from line | ||
1744 | echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} | ||
1745 | niro | 226 | ;; |
1746 | delall) | ||
1747 | niro | 273 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" |
1748 | echo "Deleting ${virtualname} in virtual database ..." | ||
1749 | # continue; do not write anything | ||
1750 | niro | 226 | continue |
1751 | ;; | ||
1752 | esac | ||
1753 | else | ||
1754 | echo "${line}" >> ${VIRTUALDB_FILE} | ||
1755 | fi | ||
1756 | done | ||
1757 | niro | 273 | # unset IFS |
1758 | IFS="${OLDIFS}" | ||
1759 | niro | 226 | else |
1760 | niro | 273 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" |
1761 | echo "${virtualname} does not exists in virtual database." | ||
1762 | niro | 226 | fi |
1763 | } | ||
1764 | |||
1765 | # gets real pkgname from virtuals.default | ||
1766 | #$1=VIRTUAL_NAME; returns PKG_NAME | ||
1767 | default_virtualname_to_pkgname() | ||
1768 | { | ||
1769 | local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname | ||
1770 | |||
1771 | VIRTUAL_NAME=$1 | ||
1772 | |||
1773 | while read db_virtualname db_pkgname | ||
1774 | do | ||
1775 | if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ] | ||
1776 | then | ||
1777 | PKG_NAME="${db_pkgname}" | ||
1778 | fi | ||
1779 | done << EOF | ||
1780 | $(< ${VIRTUALDB_DEFAULTS}) | ||
1781 | EOF | ||
1782 | |||
1783 | if [ -n "${PKG_NAME}" ] | ||
1784 | then | ||
1785 | echo "${PKG_NAME}" | ||
1786 | fi | ||
1787 | } | ||
1788 | |||
1789 | minclude() | ||
1790 | { | ||
1791 | local i | ||
1792 | |||
1793 | niro | 437 | if [[ -n $* ]] |
1794 | niro | 226 | then |
1795 | niro | 437 | for i in $* |
1796 | niro | 226 | do |
1797 | [[ ${MAGEDEBUG} = on ]] && \ | ||
1798 | echo "--- Including ${MAGEDIR}/include/${i}.minc" | ||
1799 | source ${MAGEDIR}/include/${i}.minc | ||
1800 | done | ||
1801 | [[ ${MAGEDEBUG} = on ]] && echo | ||
1802 | fi | ||
1803 | } | ||
1804 | |||
1805 | sminclude() | ||
1806 | { | ||
1807 | local i | ||
1808 | |||
1809 | niro | 437 | if [[ -n $* ]] |
1810 | niro | 226 | then |
1811 | niro | 437 | for i in $* |
1812 | niro | 226 | do |
1813 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" | ||
1814 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc | ||
1815 | done | ||
1816 | echo | ||
1817 | fi | ||
1818 | } | ||
1819 | |||
1820 | # checks if an newer mage version is available | ||
1821 | is_newer_mage_version_available() | ||
1822 | { | ||
1823 | local newest_mage | ||
1824 | local installed_mage | ||
1825 | |||
1826 | niro | 252 | newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" |
1827 | niro | 226 | installed_mage="$(magequery -n mage | cut -d' ' -f5)" |
1828 | |||
1829 | if [[ ${newest_mage} > ${installed_mage} ]] | ||
1830 | then | ||
1831 | echo | ||
1832 | echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} | ||
1833 | echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} | ||
1834 | echo "It is recommened to install this newer version" | ||
1835 | niro | 373 | echo "or your current system installation may break." |
1836 | niro | 226 | echo |
1837 | echo -en "Please update mage by running " | ||
1838 | echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} | ||
1839 | echo | ||
1840 | fi | ||
1841 | } | ||
1842 | |||
1843 | |||
1844 | # returns pname from pkgname | ||
1845 | # pkgname2pname $PKGNAME | ||
1846 | pkgname2pname() | ||
1847 | { | ||
1848 | local pname | ||
1849 | |||
1850 | pname="${1%-*-*-*}" | ||
1851 | echo "${pname}" | ||
1852 | } | ||
1853 | |||
1854 | # returns pver from pkgname | ||
1855 | # pkgname2pver $PKGNAME | ||
1856 | pkgname2pver() | ||
1857 | { | ||
1858 | local i pver | ||
1859 | |||
1860 | i="${1/$(pkgname2pname $1)-/}" | ||
1861 | pver="${i%-*-*}" | ||
1862 | echo "${pver}" | ||
1863 | } | ||
1864 | |||
1865 | # returns pbuild from pkgname | ||
1866 | # pkgname2pbuild $PKGNAME | ||
1867 | pkgname2pbuild() | ||
1868 | { | ||
1869 | local pbuild | ||
1870 | |||
1871 | pbuild="${1##*-}" | ||
1872 | echo "${pbuild}" | ||
1873 | } | ||
1874 | |||
1875 | # returns parch from pkgname | ||
1876 | # pkgname2parch $PKGNAME | ||
1877 | pkgname2parch() | ||
1878 | { | ||
1879 | local i x parch | ||
1880 | |||
1881 | i="${1%-*-*}-" | ||
1882 | x="${1%-*}" | ||
1883 | parch="${x/${i}/}" | ||
1884 | echo "${parch}" | ||
1885 | } | ||
1886 | |||
1887 | # returns pname from magename | ||
1888 | # magename2pname /PATH/TO/MAGE/FILE | ||
1889 | magename2pname() | ||
1890 | { | ||
1891 | local i pname | ||
1892 | |||
1893 | i="$(basename $1 .mage)" | ||
1894 | pname="${i%-*-*}" | ||
1895 | echo "${pname}" | ||
1896 | } | ||
1897 | |||
1898 | # returns pver from magename | ||
1899 | # magename2pver /PATH/TO/MAGE/FILE | ||
1900 | magename2pver() | ||
1901 | { | ||
1902 | local i pver | ||
1903 | |||
1904 | i="$(basename $1 .mage)" | ||
1905 | i="${i/$(magename2pname $1)-/}" | ||
1906 | pver="${i%-*}" | ||
1907 | echo "${pver}" | ||
1908 | } | ||
1909 | |||
1910 | # returns pbuild from magename | ||
1911 | # magename2pbuild /PATH/TO/MAGE/FILE | ||
1912 | magename2pbuild() | ||
1913 | { | ||
1914 | local i pbuild | ||
1915 | |||
1916 | i="$(basename $1 .mage)" | ||
1917 | pbuild="${i##*-}" | ||
1918 | echo "${pbuild}" | ||
1919 | } | ||
1920 | |||
1921 | # returns pcat from magename | ||
1922 | # magename2pcat /PATH/TO/MAGE/FILE | ||
1923 | magename2pcat() | ||
1924 | { | ||
1925 | local i pcat | ||
1926 | |||
1927 | if [[ ${2} = installdb ]] | ||
1928 | then | ||
1929 | # go 1 dir back | ||
1930 | i="${1%/*}" | ||
1931 | else | ||
1932 | # go 2 dirs back | ||
1933 | i="${1%/*/*}" | ||
1934 | fi | ||
1935 | |||
1936 | # get basename | ||
1937 | pcat="${i##*/}" | ||
1938 | echo "${pcat}" | ||
1939 | } | ||
1940 | |||
1941 | # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION) | ||
1942 | # dep2pcat DEPEND | ||
1943 | dep2pcat() | ||
1944 | { | ||
1945 | local pcat | ||
1946 | |||
1947 | pcat="${1%/*}" | ||
1948 | echo "${pcat}" | ||
1949 | } | ||
1950 | |||
1951 | # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION) | ||
1952 | # $2=virtual is used to resolv VDEPEND from virtual packages | ||
1953 | # dep2pcat DEPEND (virtual) | ||
1954 | dep2pname() | ||
1955 | { | ||
1956 | local pname | ||
1957 | |||
1958 | pname="${1##*/}" | ||
1959 | |||
1960 | # cut version only if not virtual or it will cut the name | ||
1961 | if [[ $(dep2pcat $1) != virtual ]] && \ | ||
1962 | [[ $2 != virtual ]] | ||
1963 | then | ||
1964 | pname="${pname%-*}" | ||
1965 | fi | ||
1966 | |||
1967 | echo "${pname}" | ||
1968 | } | ||
1969 | |||
1970 | dep2highest_magefile() | ||
1971 | { | ||
1972 | local pcat | ||
1973 | local pname | ||
1974 | local magefile | ||
1975 | local installed_virtuals | ||
1976 | |||
1977 | pcat="$(dep2pcat $1)" | ||
1978 | pname="$(dep2pname $1)" | ||
1979 | |||
1980 | if [[ ${pcat} = virtual ]] | ||
1981 | then | ||
1982 | # first check if virtual is already installed | ||
1983 | installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)" | ||
1984 | if [ -n "${installed_virtuals}" ] | ||
1985 | then | ||
1986 | for vpkg in ${installed_virtuals} | ||
1987 | do | ||
1988 | realpkgname="${vpkg}" | ||
1989 | virtualpkgname="${pcat}/${pname}" | ||
1990 | pcat="$(dep2pcat ${realpkgname})" | ||
1991 | pname="$(dep2pname ${realpkgname} virtual)" | ||
1992 | done | ||
1993 | else | ||
1994 | # choose one from virtualdb defaults (virtuals.defaults) | ||
1995 | realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})" | ||
1996 | virtualpkgname="${pcat}/${pname}" | ||
1997 | pcat="$(dep2pcat ${realpkgname})" | ||
1998 | pname="$(dep2pname ${realpkgname} virtual)" | ||
1999 | fi | ||
2000 | fi | ||
2001 | |||
2002 | magefile="$(get_highest_magefile ${pcat} ${pname})" | ||
2003 | echo "${magefile}" | ||
2004 | } | ||
2005 | |||
2006 | # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD} | ||
2007 | is_installed() | ||
2008 | { | ||
2009 | local fullpkgname="$1" | ||
2010 | |||
2011 | # return 0 if installed | ||
2012 | [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0 | ||
2013 | |||
2014 | return 1 | ||
2015 | } | ||
2016 | |||
2017 | install_packages() | ||
2018 | { | ||
2019 | local list="$@" | ||
2020 | local pkg | ||
2021 | local pcat | ||
2022 | local pname | ||
2023 | local pver | ||
2024 | local pbuild | ||
2025 | local total_pkgs | ||
2026 | local current_pkg | ||
2027 | local src_install | ||
2028 | local uninstall_list | ||
2029 | |||
2030 | # check for --src-install | ||
2031 | if [[ $1 = --src-install ]] | ||
2032 | then | ||
2033 | # remove --src-install from list | ||
2034 | list=${list/--src-install/} | ||
2035 | # enable src-install | ||
2036 | src_install="--src-install" | ||
2037 | fi | ||
2038 | |||
2039 | # reset MAGE_PROTECT_COUNTER | ||
2040 | declare -i MAGE_PROTECT_COUNTER=0 | ||
2041 | export MAGE_PROTECT_COUNTER | ||
2042 | |||
2043 | # get count of total packages | ||
2044 | declare -i total_pkgs=0 | ||
2045 | declare -i current_pkg=0 | ||
2046 | for i in ${list}; do (( total_pkgs++ )); done | ||
2047 | |||
2048 | echo | ||
2049 | |||
2050 | if [[ -n ${MROOT} ]] | ||
2051 | then | ||
2052 | echo -ne ${COLRED} | ||
2053 | echo "!! installing in MROOT=${MROOT}" | ||
2054 | echo -ne ${COLDEFAULT} | ||
2055 | echo | ||
2056 | fi | ||
2057 | |||
2058 | for pkg in ${list} | ||
2059 | do | ||
2060 | (( current_pkg++ )) | ||
2061 | pcat=$(magename2pcat ${pkg}) | ||
2062 | pname=$(magename2pname ${pkg}) | ||
2063 | pver=$(magename2pver ${pkg}) | ||
2064 | pbuild=$(magename2pbuild ${pkg}) | ||
2065 | |||
2066 | mage_install \ | ||
2067 | --pcat ${pcat} \ | ||
2068 | --pname ${pname} \ | ||
2069 | --pver ${pver} \ | ||
2070 | --pbuild ${pbuild} \ | ||
2071 | --count-total ${total_pkgs} \ | ||
2072 | --count-current ${current_pkg} \ | ||
2073 | ${src_install} | ||
2074 | |||
2075 | # check for allready installed packages and remove them | ||
2076 | # except the package we have installed | ||
2077 | uninstall_list="$(get_uninstall_candidates \ | ||
2078 | --pcat "${pcat}" \ | ||
2079 | --pname "${pname}" \ | ||
2080 | --protected ${pcat}/${pname}-${pver}-${pbuild})" | ||
2081 | |||
2082 | # uninstall all packges in uninstall_list if not empty | ||
2083 | if [ -n "${uninstall_list}" ] | ||
2084 | then | ||
2085 | echo | ||
2086 | uninstall_packages ${uninstall_list} \ | ||
2087 | || die "install_packges() uninstalling not-needed." | ||
2088 | fi | ||
2089 | |||
2090 | # crlf for better view in VERBOSE mode | ||
2091 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
2092 | echo | ||
2093 | done | ||
2094 | |||
2095 | #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}" | ||
2096 | show_etc_update_mesg | ||
2097 | } | ||
2098 | |||
2099 | # get_value_from_magefile VARIABLE | ||
2100 | # returns the content of this VAR | ||
2101 | get_value_from_magefile() | ||
2102 | { | ||
2103 | local var="$1" | ||
2104 | local magefile="$2" | ||
2105 | local value | ||
2106 | |||
2107 | niro | 370 | [[ -z ${var} ]] && return 1 |
2108 | [[ -z ${magefile} ]] && return 1 | ||
2109 | |||
2110 | niro | 226 | # local all possible vars of a mage file |
2111 | # to prevent bad issues | ||
2112 | local PKGNAME | ||
2113 | local STATE | ||
2114 | local DESCRIPTION | ||
2115 | local HOMEPAGE | ||
2116 | local DEPEND | ||
2117 | local SDEPEND | ||
2118 | local PROVIDE | ||
2119 | local PKGTYPE | ||
2120 | local preinstall | ||
2121 | local postinstall | ||
2122 | niro | 248 | local preremove |
2123 | local postremove | ||
2124 | niro | 226 | |
2125 | # sanity checks | ||
2126 | [ -f ${magefile} ] && source ${magefile} || \ | ||
2127 | die "get_value_from_magefile: ${magefile} not found." | ||
2128 | [ -z "${var}" ] && die "get_value_from_magefile: \$var not given." | ||
2129 | |||
2130 | source ${magefile} | ||
2131 | eval value=\$$(echo ${var}) | ||
2132 | echo "${value}" | ||
2133 | niro | 248 | |
2134 | niro | 258 | # unset these functions |
2135 | unset -f preinstall | ||
2136 | unset -f postinstall | ||
2137 | unset -f preremove | ||
2138 | unset -f postremove | ||
2139 | niro | 226 | } |
2140 | |||
2141 | mage_install() | ||
2142 | { | ||
2143 | # local all possible vars of a mage file | ||
2144 | # to prevent bad issues | ||
2145 | local PKGNAME | ||
2146 | local STATE | ||
2147 | local DESCRIPTION | ||
2148 | local HOMEPAGE | ||
2149 | local DEPEND | ||
2150 | local SDEPEND | ||
2151 | local PROVIDE | ||
2152 | local PKGTYPE | ||
2153 | local preinstall | ||
2154 | local postinstall | ||
2155 | niro | 248 | local preremove |
2156 | local postremove | ||
2157 | niro | 226 | |
2158 | local pcat | ||
2159 | local pname | ||
2160 | local pver | ||
2161 | local pbuild | ||
2162 | local count_total | ||
2163 | local count_current | ||
2164 | local magefile | ||
2165 | local src_install | ||
2166 | niro | 876 | local i |
2167 | niro | 226 | |
2168 | # very basic getops | ||
2169 | for i in $* | ||
2170 | do | ||
2171 | case $1 in | ||
2172 | --pcat|-c) shift; pcat="$1" ;; | ||
2173 | --pname|-n) shift; pname="$1" ;; | ||
2174 | --pver|-v) shift; pver="$1" ;; | ||
2175 | --pbuild|-b) shift; pbuild="$1" ;; | ||
2176 | --count-total) shift; count_total="$1" ;; | ||
2177 | --count-current) shift; count_current="$1" ;; | ||
2178 | --src-install|-s) shift; src_install=true ;; | ||
2179 | esac | ||
2180 | shift | ||
2181 | done | ||
2182 | |||
2183 | # sanity checks; abort if not given | ||
2184 | [ -z "${pcat}" ] && die "mage_install() \$pcat not given." | ||
2185 | [ -z "${pname}" ] && die "mage_install() \$pname not given." | ||
2186 | [ -z "${pver}" ] && die "mage_install() \$pver not given." | ||
2187 | [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given." | ||
2188 | |||
2189 | # check needed global vars | ||
2190 | [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set." | ||
2191 | [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set." | ||
2192 | [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set." | ||
2193 | |||
2194 | xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]" | ||
2195 | echo -ne "${COLBLUE} >>> ${COLDEFAULT}" | ||
2196 | echo -n "installing (${count_current}/${count_total}): " | ||
2197 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2198 | echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" | ||
2199 | |||
2200 | magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" | ||
2201 | source ${magefile} | ||
2202 | |||
2203 | # abort on sources if no srcinstall | ||
2204 | if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]] | ||
2205 | then | ||
2206 | echo | ||
2207 | echo -e "This Package is a Source Package." | ||
2208 | echo | ||
2209 | echo -e "Only 'srcinstall' works with this type of packages" | ||
2210 | echo -en "If you have done a srcinstall before, " | ||
2211 | echo -e "you will find the files in /usr/src." | ||
2212 | echo | ||
2213 | exit 1 | ||
2214 | fi | ||
2215 | |||
2216 | ## preinstall scripts | ||
2217 | if [ -n "$(typeset -f preinstall)" ] | ||
2218 | then | ||
2219 | echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... " | ||
2220 | preinstall | ||
2221 | unset preinstall | ||
2222 | fi | ||
2223 | |||
2224 | if [[ ${src_install} = true ]] | ||
2225 | then | ||
2226 | local smage2file | ||
2227 | # check needed global vars | ||
2228 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set." | ||
2229 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set." | ||
2230 | [ -z "${BINDIR}" ] && die "\$BINDIR not set." | ||
2231 | |||
2232 | # build the package first | ||
2233 | if [[ ${MAGEDEBUG} = on ]] | ||
2234 | then | ||
2235 | echo M:${pname} | ||
2236 | echo V:${pver} | ||
2237 | echo B:${pbuild} | ||
2238 | fi | ||
2239 | |||
2240 | niro | 675 | if [[ -z ${MAGE_TARGETS} ]] |
2241 | then | ||
2242 | niro | 876 | # basic svn compat |
2243 | if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] | ||
2244 | then | ||
2245 | for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 | ||
2246 | do | ||
2247 | smage2file="${i}" | ||
2248 | done | ||
2249 | else | ||
2250 | smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 | ||
2251 | fi | ||
2252 | niro | 675 | else |
2253 | niro | 876 | # basic svn compat |
2254 | if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] | ||
2255 | then | ||
2256 | for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 | ||
2257 | do | ||
2258 | smage2file="${i}" | ||
2259 | done | ||
2260 | else | ||
2261 | smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 | ||
2262 | fi | ||
2263 | niro | 675 | fi |
2264 | niro | 226 | if [ -f "${smage2file}" ] |
2265 | then | ||
2266 | niro | 385 | echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " |
2267 | niro | 226 | smage2 ${smage2file} || die "compile failed" |
2268 | else | ||
2269 | echo | ||
2270 | echo "$(basename ${SMAGEFILE}) not found." | ||
2271 | echo "update your smage-tree and try it again." | ||
2272 | echo | ||
2273 | die | ||
2274 | fi | ||
2275 | fi | ||
2276 | |||
2277 | if [[ ${PKGTYPE} != virtual ]] && \ | ||
2278 | [[ ${PKGTYPE} != sources ]] | ||
2279 | then | ||
2280 | niro | 385 | echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " |
2281 | niro | 226 | build_doinstall ${PKGNAME} |
2282 | fi | ||
2283 | |||
2284 | ## postinstall scripts | ||
2285 | if [ -n "$(typeset -f postinstall)" ] | ||
2286 | then | ||
2287 | echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... " | ||
2288 | postinstall | ||
2289 | unset postinstall | ||
2290 | fi | ||
2291 | |||
2292 | # install a database entry | ||
2293 | install_database_entry \ | ||
2294 | --pcat "${pcat}" \ | ||
2295 | --pname "${pname}" \ | ||
2296 | --pver "${pver}" \ | ||
2297 | --pbuild "${pbuild}" \ | ||
2298 | --pkgname "${PKGNAME}" \ | ||
2299 | --pkgtype "${PKGTYPE}" \ | ||
2300 | || die "error in mage_install() running install_database_entry()." | ||
2301 | |||
2302 | # remove the package dir now | ||
2303 | if [ -d ${BUILDDIR}/${PKGNAME} ] | ||
2304 | then | ||
2305 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
2306 | fi | ||
2307 | |||
2308 | # rebuilds toplevel info node | ||
2309 | if [[ ${MAGE_INFO_REBUILD} = true ]] | ||
2310 | then | ||
2311 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2312 | echo -n "rebuilding top-level info node ... " | ||
2313 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ | ||
2314 | > ${MROOT}/usr/share/info/dir && \ | ||
2315 | echo "done." || echo "failure." | ||
2316 | unset MAGE_INFO_REBUILD | ||
2317 | fi | ||
2318 | |||
2319 | # rebuilds the enviroment with the content of /etc/env.d | ||
2320 | if [[ ${MAGE_ENV_REBUILD} = true ]] | ||
2321 | then | ||
2322 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2323 | echo -n "rebuilding environment ... " | ||
2324 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ | ||
2325 | echo "done." || echo "failure." | ||
2326 | unset MAGE_ENV_REBUILD | ||
2327 | fi | ||
2328 | |||
2329 | xtitleclean | ||
2330 | |||
2331 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2332 | echo -n "package " | ||
2333 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2334 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " | ||
2335 | echo "successfully installed." | ||
2336 | niro | 248 | |
2337 | niro | 258 | # unset these functions |
2338 | unset -f preinstall | ||
2339 | unset -f postinstall | ||
2340 | unset -f preremove | ||
2341 | unset -f postremove | ||
2342 | niro | 226 | } |
2343 | |||
2344 | md5sum_packages() | ||
2345 | { | ||
2346 | local list="$@" | ||
2347 | local magefile | ||
2348 | local pcat | ||
2349 | local pname | ||
2350 | local pkgname | ||
2351 | local pkgfile | ||
2352 | local pkgtype | ||
2353 | local count_current | ||
2354 | local count_total | ||
2355 | |||
2356 | # get count of total packages | ||
2357 | declare -i count_current=0 | ||
2358 | declare -i count_total=0 | ||
2359 | |||
2360 | for i in ${list}; do (( count_total++ )); done | ||
2361 | |||
2362 | for magefile in ${list} | ||
2363 | do | ||
2364 | pcat=$(magename2pcat ${magefile}) | ||
2365 | pname=$(magename2pname ${magefile}) | ||
2366 | pkgname="$(get_value_from_magefile PKGNAME ${magefile})" | ||
2367 | md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5" | ||
2368 | pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}" | ||
2369 | pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})" | ||
2370 | |||
2371 | (( count_current++ )) | ||
2372 | xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]" | ||
2373 | |||
2374 | # abort on virtual pkg | ||
2375 | if [[ ${pkgtype} = virtual ]] | ||
2376 | then | ||
2377 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
2378 | echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
2379 | continue | ||
2380 | fi | ||
2381 | |||
2382 | # abort on sources pkg | ||
2383 | if [[ ${pkgtype} = sources ]] | ||
2384 | then | ||
2385 | echo -ne " ${COLBLUE}---${COLDEFAULT}" | ||
2386 | echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... " | ||
2387 | continue | ||
2388 | fi | ||
2389 | |||
2390 | if [ -f "${md5file}" ] | ||
2391 | then | ||
2392 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2393 | echo -ne "checking md5sum (${count_current}/${count_total}): " | ||
2394 | ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed" | ||
2395 | else | ||
2396 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2397 | echo -e "!! no md5sum file found for ${pkgfile} :(" | ||
2398 | fi | ||
2399 | done | ||
2400 | |||
2401 | # add a crlf for a better view | ||
2402 | if [ ${count_total} -gt 1 ]; then echo; fi | ||
2403 | } | ||
2404 | |||
2405 | ## uninstall_packages ulist | ||
2406 | uninstall_packages() | ||
2407 | { | ||
2408 | local list="$@" | ||
2409 | local pcat | ||
2410 | local pname | ||
2411 | local pver | ||
2412 | local pbuild | ||
2413 | local can_pcat | ||
2414 | local can_pname | ||
2415 | local can_ver_list | ||
2416 | |||
2417 | if [[ -n ${MROOT} ]] | ||
2418 | then | ||
2419 | echo -ne ${COLRED} | ||
2420 | echo "!! uninstalling from MROOT=${MROOT}" | ||
2421 | echo -ne ${COLDEFAULT} | ||
2422 | echo | ||
2423 | fi | ||
2424 | |||
2425 | # generate a candidates list | ||
2426 | for pkg in ${list} | ||
2427 | do | ||
2428 | pcat=$(dep2pcat ${pkg}) | ||
2429 | pname=$(magename2pname ${pkg}) | ||
2430 | pver=$(magename2pver ${pkg}) | ||
2431 | pbuild=$(magename2pbuild ${pkg}) | ||
2432 | can_pcat="${pcat}" | ||
2433 | can_pname="${pname}" | ||
2434 | |||
2435 | if [ -z "${can_ver_list}" ] | ||
2436 | then | ||
2437 | can_ver_list=" ${pver}-${pbuild}" | ||
2438 | else | ||
2439 | can_ver_list="${can_ver_list}, ${pver}-${pbuild}" | ||
2440 | fi | ||
2441 | done | ||
2442 | |||
2443 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2444 | echo "following candidate(s) will be removed:" | ||
2445 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2446 | niro | 240 | echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" |
2447 | niro | 226 | echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" |
2448 | niro | 501 | echo |
2449 | niro | 240 | if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] |
2450 | then | ||
2451 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2452 | echo "( Press [CTRL+C] to abort )" | ||
2453 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2454 | echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." | ||
2455 | for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) | ||
2456 | do | ||
2457 | echo -ne "${COLRED} ${i}${COLDEFAULT}" | ||
2458 | sleep 1 | ||
2459 | done | ||
2460 | echo | ||
2461 | echo | ||
2462 | fi | ||
2463 | niro | 226 | |
2464 | for pkg in ${list} | ||
2465 | do | ||
2466 | pcat=$(dep2pcat ${pkg}) | ||
2467 | pname=$(magename2pname ${pkg}) | ||
2468 | pver=$(magename2pver ${pkg}) | ||
2469 | pbuild=$(magename2pbuild ${pkg}) | ||
2470 | |||
2471 | mage_uninstall \ | ||
2472 | --pcat ${pcat} \ | ||
2473 | --pname ${pname} \ | ||
2474 | --pver ${pver} \ | ||
2475 | --pbuild ${pbuild} \ | ||
2476 | --count-total ${total_pkgs} \ | ||
2477 | --count-current ${current_pkg} \ | ||
2478 | ${src_install} | ||
2479 | |||
2480 | # crlf for better view in VERBOSE mode | ||
2481 | #if [[ ${VERBOSE} = on ]]; then echo; fi | ||
2482 | echo | ||
2483 | done | ||
2484 | } | ||
2485 | |||
2486 | mage_uninstall() | ||
2487 | { | ||
2488 | # local all possible vars of a mage file | ||
2489 | # to prevent bad issues | ||
2490 | local PKGNAME | ||
2491 | local STATE | ||
2492 | local DESCRIPTION | ||
2493 | local HOMEPAGE | ||
2494 | local DEPEND | ||
2495 | local SDEPEND | ||
2496 | local PROVIDE | ||
2497 | local PKGTYPE | ||
2498 | local preinstall | ||
2499 | local postinstall | ||
2500 | niro | 248 | local preremove |
2501 | local postremove | ||
2502 | niro | 226 | |
2503 | local pcat | ||
2504 | local pname | ||
2505 | local pver | ||
2506 | local pbuild | ||
2507 | local magefile | ||
2508 | local i | ||
2509 | |||
2510 | # very basic getops | ||
2511 | for i in $* | ||
2512 | do | ||
2513 | case $1 in | ||
2514 | niro | 501 | --pcat|-c) shift; pcat="$1" ;; |
2515 | niro | 226 | --pname|-n) shift; pname="$1" ;; |
2516 | --pver|-v) shift; pver="$1" ;; | ||
2517 | niro | 501 | --pbuild|-b) shift; pbuild="$1" ;; |
2518 | niro | 226 | esac |
2519 | shift | ||
2520 | niro | 501 | done |
2521 | niro | 226 | |
2522 | # sanity checks; abort if not given | ||
2523 | niro | 501 | [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given." |
2524 | niro | 226 | [ -z "${pname}" ] && die "mage_uninstall() \$pname not given." |
2525 | [ -z "${pver}" ] && die "mage_uninstall() \$pver not given." | ||
2526 | niro | 501 | [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given." |
2527 | niro | 226 | |
2528 | # check needed global vars | ||
2529 | [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set." | ||
2530 | [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set." | ||
2531 | [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set." | ||
2532 | |||
2533 | xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]" | ||
2534 | echo -ne "${COLBLUE} <<< ${COLDEFAULT}" | ||
2535 | echo -n "removing: " | ||
2536 | echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2537 | niro | 416 | echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}" |
2538 | niro | 226 | |
2539 | niro | 499 | magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" |
2540 | niro | 226 | source ${magefile} |
2541 | |||
2542 | ## preremove scripts | ||
2543 | if [ -n "$(typeset -f preremove)" ] | ||
2544 | then | ||
2545 | echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... " | ||
2546 | preremove | ||
2547 | unset preremove | ||
2548 | fi | ||
2549 | |||
2550 | # runs uninstall | ||
2551 | build_douninstall \ | ||
2552 | --pcat "${pcat}" \ | ||
2553 | --pname "${pname}" \ | ||
2554 | --pver "${pver}" \ | ||
2555 | --pbuild "${pbuild}" | ||
2556 | |||
2557 | ## postremove scripts | ||
2558 | if [ -n "$(typeset -f postremove)" ] | ||
2559 | then | ||
2560 | echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... " | ||
2561 | postremove | ||
2562 | unset postremove | ||
2563 | fi | ||
2564 | |||
2565 | # removes the database entry | ||
2566 | remove_database_entry \ | ||
2567 | --pcat "${pcat}" \ | ||
2568 | --pname "${pname}" \ | ||
2569 | --pver "${pver}" \ | ||
2570 | --pbuild "${pbuild}" \ | ||
2571 | || die "error in mage_uninstall() running remove_database_entry()." | ||
2572 | |||
2573 | # rebuilds toplevel info node | ||
2574 | if [[ ${MAGE_INFO_REBUILD} = true ]] | ||
2575 | then | ||
2576 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2577 | echo -n "rebuilding top-level info node ... " | ||
2578 | ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \ | ||
2579 | > ${MROOT}/usr/share/info/dir && \ | ||
2580 | echo "done." || echo "failure." | ||
2581 | unset MAGE_INFO_REBUILD | ||
2582 | fi | ||
2583 | |||
2584 | # rebuilds the enviroment with the content of /etc/env.d | ||
2585 | if [[ ${MAGE_ENV_REBUILD} = true ]] | ||
2586 | then | ||
2587 | echo -ne "${COLBLUE} *** ${COLDEFAULT}" | ||
2588 | echo -n "rebuilding environment ... " | ||
2589 | ${MLIBDIR}/env-rebuild.sh > /dev/null && \ | ||
2590 | echo "done." || echo "failure." | ||
2591 | unset MAGE_ENV_REBUILD | ||
2592 | fi | ||
2593 | |||
2594 | echo -ne "${COLBLUE} --- ${COLDEFAULT}" | ||
2595 | echo -n "package " | ||
2596 | # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" | ||
2597 | # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " | ||
2598 | echo "successfully removed." | ||
2599 | niro | 248 | |
2600 | niro | 258 | # unset these functions |
2601 | unset -f preinstall | ||
2602 | unset -f postinstall | ||
2603 | unset -f preremove | ||
2604 | unset -f postremove | ||
2605 | niro | 226 | } |
2606 | |||
2607 | show_etc_update_mesg() { | ||
2608 | [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0 | ||
2609 | |||
2610 | echo | ||
2611 | echo -ne "${COLRED}" | ||
2612 | echo "Important:" | ||
2613 | echo -ne ${COLDEFAULT} | ||
2614 | echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed." | ||
2615 | echo | ||
2616 | echo "Please run 'etc-update' to update your configuration files." | ||
2617 | echo | ||
2618 | } | ||
2619 | niro | 237 | |
2620 | pkgsearch() | ||
2621 | { | ||
2622 | local string="$1" | ||
2623 | local result | ||
2624 | local pkg | ||
2625 | local pcat | ||
2626 | local pname | ||
2627 | local magefile | ||
2628 | local pver | ||
2629 | local pbuild | ||
2630 | local state | ||
2631 | local descriptiom | ||
2632 | local homepage | ||
2633 | local i | ||
2634 | local all_installed | ||
2635 | local ipver | ||
2636 | local ipbuild | ||
2637 | niro | 445 | local latest_available |
2638 | niro | 458 | local depsfull |
2639 | local sdepsfull | ||
2640 | local deps | ||
2641 | local sdeps | ||
2642 | local dep | ||
2643 | local sign | ||
2644 | niro | 237 | |
2645 | # only names no versions | ||
2646 | niro | 391 | result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" |
2647 | niro | 328 | #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)" |
2648 | niro | 237 | |
2649 | # nothing found | ||
2650 | [[ -z ${result} ]] && die "No package found containing '${string}' in the name." | ||
2651 | |||
2652 | for pkg in ${result} | ||
2653 | do | ||
2654 | # dirty, but does the job | ||
2655 | pcat="$(magename2pcat ${pkg}/foo)" | ||
2656 | pname="$(magename2pname ${pkg}-foo-foo)" | ||
2657 | |||
2658 | # get highest version available | ||
2659 | magefile=$(get_highest_magefile ${pcat} ${pname}) | ||
2660 | |||
2661 | niro | 445 | if [[ ! -z ${magefile} ]] |
2662 | then | ||
2663 | # now get all needed infos to print a nice output | ||
2664 | pver="$(magename2pver ${magefile})" | ||
2665 | pbuild="$(magename2pbuild ${magefile})" | ||
2666 | state="$(get_value_from_magefile STATE ${magefile})" | ||
2667 | description="$(get_value_from_magefile DESCRIPTION ${magefile})" | ||
2668 | homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" | ||
2669 | |||
2670 | # all installed | ||
2671 | for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) | ||
2672 | do | ||
2673 | ipver="$(magename2pver ${i})" | ||
2674 | ipbuild="$(magename2pbuild ${i})" | ||
2675 | |||
2676 | if [[ -z ${all_installed} ]] | ||
2677 | then | ||
2678 | all_installed="${ipver}-${ipbuild}" | ||
2679 | else | ||
2680 | all_installed="${all_installed} ${ipver}-${ipbuild}" | ||
2681 | fi | ||
2682 | done | ||
2683 | [[ -z ${all_installed} ]] && all_installed="none" | ||
2684 | |||
2685 | case ${state} in | ||
2686 | stable) state=${COLGREEN}"[s] ";; | ||
2687 | testing) state=${COLYELLOW}"[t] ";; | ||
2688 | unstable) state=${COLRED}"[u] ";; | ||
2689 | old) state=${COLGRAY}"[o] ";; | ||
2690 | esac | ||
2691 | niro | 237 | |
2692 | niro | 445 | latest_available="${pver}-${pbuild}" |
2693 | else | ||
2694 | # package is masked | ||
2695 | state="${COLRED}[m] " | ||
2696 | latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" | ||
2697 | fi | ||
2698 | niro | 237 | |
2699 | niro | 458 | depsfull="$(get_value_from_magefile DEPEND ${magefile})" |
2700 | sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" | ||
2701 | |||
2702 | while read sign dep | ||
2703 | do | ||
2704 | case ${dep} in | ||
2705 | "") continue;; | ||
2706 | esac | ||
2707 | |||
2708 | deps="${deps} $(basename ${dep%-*})" | ||
2709 | done << EOF | ||
2710 | ${depsfull} | ||
2711 | EOF | ||
2712 | |||
2713 | while read sign dep | ||
2714 | do | ||
2715 | case ${dep} in | ||
2716 | "") continue;; | ||
2717 | esac | ||
2718 | |||
2719 | sdeps="${sdeps} $(basename ${dep%-*})" | ||
2720 | done << EOF | ||
2721 | ${sdepsfull} | ||
2722 | EOF | ||
2723 | |||
2724 | niro | 237 | echo -e "${state}${pcat}/${pname}"${COLDEFAULT} |
2725 | niro | 445 | echo -e " Latest available: ${latest_available}" |
2726 | niro | 237 | echo " Installed versions: ${all_installed}" |
2727 | echo " Description: ${description}" | ||
2728 | echo " Homepage: ${homepage}" | ||
2729 | niro | 458 | echo " Depends: ${deps}" |
2730 | echo " SDepends: ${sdeps}" | ||
2731 | niro | 237 | echo |
2732 | |||
2733 | unset pcat | ||
2734 | unset pname | ||
2735 | unset magefile | ||
2736 | unset pver | ||
2737 | unset pbuild | ||
2738 | unset state | ||
2739 | unset descriptiom | ||
2740 | unset homepage | ||
2741 | unset all_installed | ||
2742 | unset ipver | ||
2743 | unset ipbuild | ||
2744 | niro | 458 | unset depsfull |
2745 | unset sdepsfull | ||
2746 | unset deps | ||
2747 | unset sdeps | ||
2748 | unset dep | ||
2749 | unset sign | ||
2750 | niro | 237 | done |
2751 | } | ||
2752 | niro | 249 | |
2753 | export_inherits() | ||
2754 | { | ||
2755 | local include="$1" | ||
2756 | shift | ||
2757 | |||
2758 | while [ "$1" ] | ||
2759 | do | ||
2760 | local functions="$1" | ||
2761 | |||
2762 | # sanity checks | ||
2763 | [ -z "${include}" ] && die "export_inherits(): \$include not given." | ||
2764 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." | ||
2765 | |||
2766 | eval "${functions}() { ${include}_${functions} ; }" | ||
2767 | |||
2768 | # debug | ||
2769 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" | ||
2770 | |||
2771 | shift | ||
2772 | done | ||
2773 | } | ||
2774 | niro | 350 | |
2775 | mlibdir() | ||
2776 | { | ||
2777 | local libdir=lib | ||
2778 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 | ||
2779 | |||
2780 | echo "${libdir}" | ||
2781 | } | ||
2782 | niro | 370 | |
2783 | ## blacklisted ${magefile} | ||
2784 | blacklisted() | ||
2785 | { | ||
2786 | [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable | ||
2787 | |||
2788 | # compat | ||
2789 | [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable | ||
2790 | [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing | ||
2791 | |||
2792 | niro | 892 | # support both types for the moment |
2793 | if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]] | ||
2794 | then | ||
2795 | local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" | ||
2796 | else | ||
2797 | local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}" | ||
2798 | fi | ||
2799 | niro | 370 | |
2800 | # return 0 if the list not exist; nothin is masked | ||
2801 | [[ ! -f ${EXCLUDED} ]] && return 0 | ||
2802 | |||
2803 | local MAGEFILE="$1" | ||
2804 | |||
2805 | local PCAT="$(magename2pcat ${MAGEFILE})" | ||
2806 | local PNAME="$(magename2pname ${MAGEFILE})" | ||
2807 | local PVER="$(magename2pver ${MAGEFILE})" | ||
2808 | local PBUILD="$(magename2pbuild ${MAGEFILE})" | ||
2809 | |||
2810 | local EXPCAT EXPNAME EXPVER EXPBUILD | ||
2811 | while read EXPCAT EXPNAME EXPVER EXPBUILD | ||
2812 | do | ||
2813 | # ignore spaces and comments | ||
2814 | case "${EXPCAT}" in | ||
2815 | \#*|"") continue ;; | ||
2816 | esac | ||
2817 | |||
2818 | # exclude full pver | ||
2819 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && | ||
2820 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && | ||
2821 | [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && | ||
2822 | [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] | ||
2823 | then | ||
2824 | [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 | ||
2825 | fi | ||
2826 | |||
2827 | # exclude pcat/pname only | ||
2828 | if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && | ||
2829 | [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && | ||
2830 | [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] | ||
2831 | then | ||
2832 | [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 | ||
2833 | fi | ||
2834 | done << EOF | ||
2835 | $( cat ${EXCLUDED}; echo) | ||
2836 | EOF | ||
2837 | |||
2838 | return 0 | ||
2839 | } | ||
2840 |