Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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