Magellan Linux

Annotation of /branches/mage-next/src/mage4.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


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