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