Magellan Linux

Annotation of /trunk/mage/usr/lib/mage/mage4.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


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