Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1083 - (hide annotations) (download) (as text)
Mon Jun 28 18:07:29 2010 UTC (13 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 68213 byte(s)
-added support for md5sum in update-tarball
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     --passive-ftp \
1183     --tries 3 \
1184     --continue \
1185     --progress bar \
1186     --directory-prefix=${PKGDIR} \
1187 niro 286 ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1188 niro 226 if [[ $? = 0 ]]
1189     then
1190     break
1191     else
1192     continue
1193     fi
1194     done
1195    
1196     if [ ! -f ${PKGDIR}/${pkg} ]
1197     then
1198     die "Could not download ${pkg}"
1199     fi
1200     done
1201    
1202     # add a crlf for a better view
1203     if [ ${count_total} -gt 1 ]; then echo; fi
1204     }
1205    
1206     syncmage()
1207     {
1208     if [ -z "${RSYNC}" ]
1209     then
1210 niro 419 die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1211 niro 226 fi
1212    
1213     local i
1214     for i in ${RSYNC}
1215     do
1216 niro 386 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
1217 niro 226 if [[ $? = 0 ]]
1218     then
1219     break
1220     else
1221     continue
1222     fi
1223     done
1224    
1225     # clean up backup files (foo~)
1226     find ${MAGEDIR} -name *~ -exec rm '{}' ';'
1227    
1228 niro 966 # check if a newer mage version is available
1229 niro 226 is_newer_mage_version_available
1230     }
1231    
1232 niro 739 syncmage_tarball()
1233     {
1234     local latest_tarball
1235 niro 1083 local latest_md5
1236 niro 739 local temp="$(mktemp -d)"
1237     local mirr mymirr
1238    
1239 niro 1083 # try to get the md5 marked as latest on the server
1240     latest_md5="mage-latest.md5"
1241    
1242 niro 739 # try to get the tarball marked as latest on the server
1243     latest_tarball="mage-latest.tar.bz2"
1244    
1245     for mirr in ${MIRRORS}
1246     do
1247     # path without distribution
1248     mymirr="${mirr%/*}"
1249    
1250     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1251 niro 1083 echo "fetching latest md5 from ${mymirr} ..."
1252     wget \
1253     --passive-ftp \
1254     --tries 3 \
1255     --continue \
1256     --progress bar \
1257     --directory-prefix=${temp} \
1258     ${mymirr}/rsync/tarballs/${latest_md5}
1259    
1260     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1261 niro 739 echo "fetching latest tarball from ${mymirr} ..."
1262    
1263     wget \
1264     --passive-ftp \
1265     --tries 3 \
1266     --continue \
1267     --progress bar \
1268     --directory-prefix=${temp} \
1269     ${mymirr}/rsync/tarballs/${latest_tarball}
1270     if [[ $? = 0 ]]
1271     then
1272     break
1273     else
1274     continue
1275     fi
1276     done
1277    
1278     if [[ -f ${temp}/${latest_tarball} ]]
1279     then
1280 niro 1083 # check md5
1281     if [[ ! -f ${temp}/${latest_md5} ]]
1282     then
1283     die "md5 is missing ... aborting"
1284     else
1285     ( cd ${temp}; md5sum --check ${lastest_md5} ) || die "md5 for ${lastest_tarball} failed"
1286     fi
1287    
1288 niro 739 if [[ -d ${MAGEDIR} ]]
1289     then
1290     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1291     echo "cleaning old mage-tree ${MAGEDIR}..."
1292     rm -rf ${MAGEDIR}
1293     fi
1294    
1295     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1296     echo "updating mage-tree from tarball ..."
1297     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1298     tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1299    
1300     if [[ -d ${temp} ]]
1301     then
1302     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1303 niro 972 echo "cleaning temp-files ..."
1304 niro 739 rm -rf ${temp}
1305     fi
1306 niro 966
1307     # check if a newer mage version is available
1308     is_newer_mage_version_available
1309 niro 739 else
1310     die "Could not fetch the latest tarball ... aborting"
1311     fi
1312     }
1313    
1314 niro 226 cleanpkg()
1315     {
1316     if [ -d "${PKGDIR}" ]
1317     then
1318     echo -n "Removing downloaded packages... "
1319     rm -rf ${PKGDIR}/*
1320     echo "done."
1321     fi
1322     }
1323    
1324     xtitle()
1325     {
1326     if [[ ${TERM} = xterm ]]
1327     then
1328     echo -ne "\033]0;Mage: $1\007"
1329     fi
1330     return 0
1331     }
1332    
1333    
1334     xtitleclean()
1335     {
1336     if [[ ${TERM} = xterm ]]
1337     then
1338     echo -ne "\033]0;\007"
1339     fi
1340     return 0
1341     }
1342    
1343    
1344     # cuts full pathnames or versioniezed names down to basename
1345     choppkgname()
1346     {
1347     #we want this only if full name was used
1348     if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1349     then
1350     #cuts ARCH and PBUILD
1351 niro 419 #ARCH comes from ${MAGERC}
1352 niro 226 MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1353    
1354     #cuts version number
1355     MAGENAME=$(basename ${MAGENAME%-*} .mage)
1356     fi
1357     }
1358    
1359     # get_categorie $PNAME, returns CATEGORIE
1360     # $1=pname
1361     # ret 0=ok, 1=not_found
1362     pname2pcat()
1363     {
1364     local pname="$1"
1365     local repo="$2"
1366     local pcat
1367     local categorie
1368    
1369     for pcat in ${MAGEDIR}/*
1370     do
1371     if [ -d ${pcat}/${pname} ]
1372     then
1373     categorie=$(basename ${pcat})
1374     fi
1375     done
1376    
1377     echo "${categorie}"
1378     }
1379    
1380     # check_stable_package /path/to/foo.mage
1381     # returns 0=stable 1=unstable
1382     check_stable_package()
1383     {
1384 niro 370 # first check if this magefile is not blacklisted
1385     blacklisted "$1" || return 1
1386    
1387 niro 226 local STATE
1388     STATE="$(get_value_from_magefile STATE "$1")"
1389    
1390     # state testing
1391 niro 286 if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1392 niro 226 then
1393     case ${STATE} in
1394     testing|stable) return 0 ;;
1395     *) return 1 ;;
1396     esac
1397     fi
1398    
1399     # state unstable
1400 niro 286 if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1401 niro 226 then
1402     case ${STATE} in
1403     unstable|testing|stable) return 0 ;;
1404     *) return 1 ;;
1405     esac
1406     fi
1407    
1408     # no use_state given = stable
1409     case ${STATE} in
1410     stable) return 0 ;;
1411     *) return 1 ;;
1412     esac
1413     }
1414    
1415    
1416     # get_highest_magefile ${PCAT} ${PNAME}
1417     # fake at moment returns only stable pkgs (must set to be one)
1418     # return $HIGHEST_MAGEFILE
1419     get_highest_magefile()
1420     {
1421     local HIGHEST_MAGEFILE
1422     local PCAT="$1"
1423     local PNAME="$2"
1424     local magefile
1425    
1426 niro 676 # do not list the content of a directory, only the name (-d)
1427     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)
1428 niro 226 do
1429 niro 676 [[ -z ${magefile} ]] && continue
1430 niro 226 # we exclude subdirs (for stuff like a md5sum dir)
1431 niro 676 [[ -d ${magefile} ]] && continue
1432 niro 226 if check_stable_package ${magefile}
1433     then
1434     HIGHEST_MAGEFILE=${magefile}
1435     #for debug only
1436     [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1437     fi
1438     done
1439    
1440 niro 370 # do not so anything
1441     # # stop here if HIGHEST_MAGEFILE is zero
1442     # # this package must be unstable or old
1443     # if [ -z "${HIGHEST_MAGEFILE}" ]
1444     # then
1445     # echo
1446     # echo -n "All packages named "
1447     # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1448     # echo -n " are marked "
1449     # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1450     # echo "."
1451     # echo "You need to declare USE_UNSTABLE=true to install this."
1452     # echo
1453     # echo "Example:"
1454     # echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1455     # echo
1456     # echo "Be warned that these packages are not stable and may cause serious problems."
1457     # echo "You should know what you are doing, so don't complain about any damage."
1458     # echo
1459     # return 1
1460     # fi
1461 niro 226
1462     echo "${HIGHEST_MAGEFILE}"
1463     return 0
1464     }
1465    
1466    
1467     ###################################################
1468     # function is_config_protected #
1469     # is_config_protected /path/to/file #
1470     # #
1471     # returns: #
1472     # 0 - not protected #
1473     # 1 - error #
1474     # 2 - protected #
1475     # 3 - protected but masked #
1476 niro 942 # 4 - protected but ignored #
1477 niro 226 # #
1478     ###################################################
1479     is_config_protected()
1480     {
1481     local EXPFILE
1482     local TEST
1483     local PROTECTED
1484     local IFS
1485 niro 942 local i
1486     local x
1487 niro 226
1488     EXPFILE="${MROOT}$1"
1489    
1490     # file does not exist; it can be written
1491 niro 451 [[ ! -e ${EXPFILE} ]] && return 0
1492 niro 226
1493     # to be safe; it may be '§'
1494     IFS=' '
1495    
1496 niro 942 # check if config protected
1497 niro 226 for i in ${CONFIG_PROTECT}
1498     do
1499 niro 942 # only replace $i in the beginning of the variable
1500 niro 226 TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1501 niro 451 if [[ ${TEST} != ${EXPFILE} ]]
1502 niro 226 then
1503 niro 942 # file is config proteced
1504 niro 226 PROTECTED=TRUE
1505    
1506 niro 942 # check if not masked
1507 niro 226 for x in ${CONFIG_PROTECT_MASK}
1508     do
1509     TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1510 niro 451 if [[ ${TEST} != ${EXPFILE} ]]
1511 niro 226 then
1512     PROTECTED=MASKED
1513     fi
1514     done
1515 niro 942
1516     # check if not ignored
1517     for x in ${CONFIG_PROTECT_IGNORE}
1518     do
1519     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1520     if [[ ${TEST} != ${EXPFILE} ]]
1521     then
1522     PROTECTED=IGNORED
1523     fi
1524     done
1525 niro 226 fi
1526     done
1527    
1528     unset IFS
1529    
1530     case ${PROTECTED} in
1531     TRUE)
1532     #echo "I'm protected"
1533     return 2
1534     ;;
1535     MASKED)
1536     #echo "I'm protected, but masked - delete me"
1537     return 3
1538     ;;
1539 niro 942 IGNORED)
1540     #echo "I'm protected, but ignored - keep me, del update"
1541     return 4
1542     ;;
1543 niro 226 *)
1544     #echo "delete me"
1545     return 0
1546     ;;
1547     esac
1548     }
1549    
1550    
1551     ###################################################
1552     # function count_protected_files #
1553     # count_protected_files /path/to/file #
1554     # #
1555     # note: prints number of protected files #
1556     # exp: 0012 #
1557     ###################################################
1558     count_protected_files()
1559     {
1560 niro 603 local file="$1"
1561     local dirname="${file%/*}"
1562     local filename="${file##*/}"
1563     local count
1564     local output
1565     local i
1566    
1567     declare -i count=0
1568    
1569     # check if there are already protected files
1570     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1571     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1572     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1573     do
1574     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1575     done
1576     (( count ++ ))
1577    
1578     # fill output up with zeros
1579     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1580     output="${output}${count}"
1581    
1582     echo "${output}"
1583 niro 226 }
1584    
1585     # call with
1586     # 'get_uninstall_candidates (--pcat cat --protected pcat/pfull) --pname PNAME'
1587     # returns /path/to/magefile(s)
1588     get_uninstall_candidates()
1589     {
1590     local search_pname
1591     local pkg
1592     local pcat
1593     local pname
1594     local pver
1595     local pbuild
1596     local list
1597     local pcatdir
1598     local protected
1599 niro 449 local i
1600 niro 226
1601     # very basic getops
1602     for i in $*
1603     do
1604     case $1 in
1605     --pcat|-c) shift; pcatdir="$1" ;;
1606     --pname|-n) shift; search_pname="$1" ;;
1607     --protected|-p) shift; protected="$1" ;;
1608     esac
1609     shift
1610     done
1611    
1612 niro 329 # it's not good to complain here about empty pnames; better to continue later anyway
1613     # # sanity checks; abort if not given
1614     # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1615 niro 226
1616    
1617     # check needed global vars
1618     [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1619    
1620     # set pcatdir to '*' if empty
1621 niro 329 [ -z "${pcatdir}" ] && pcatdir='*'
1622 niro 226
1623     for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1624     do
1625     # abort if not a dir
1626     [ ! -d ${pkg} ] && continue
1627    
1628     pname="$(magename2pname ${pkg})"
1629    
1630     if [[ ${search_pname} = ${pname} ]]
1631     then
1632     pcat="$(magename2pcat ${pkg} installdb)"
1633     pver="$(magename2pver ${pkg})"
1634     pbuild="$(magename2pbuild ${pkg})"
1635    
1636     # exclude proteced
1637     [[ ${protected} = ${pcat}/${pname}-${pver}-${pbuild} ]] && continue
1638    
1639     list="${list} ${pcat}/${pname}-${pver}-${pbuild}"
1640     fi
1641     done
1642    
1643     echo "${list}"
1644     }
1645    
1646     # reads virtualdb file
1647     #$1 = virtualname; $2 commands: showpkgs, showline
1648     #return 0 == installed -> shows installed pkg as well
1649     #return 1 == not installed
1650     virtuals_read()
1651     {
1652     local virtualname="$1"
1653     local command="$2"
1654     local virtline
1655     local line x i
1656    
1657     # parse file to get virtual_name line
1658     IFS=$'\n'
1659     for line in $(< ${MROOT}${VIRTUALDB_FILE})
1660     do
1661     IFS=$' '
1662     for x in ${line}
1663     do
1664     if [[ ${x} = ${virtualname} ]]
1665     then
1666     virtline="${line}"
1667     [[ ${command} = showline ]] && echo "${line}"
1668     fi
1669     done
1670     IFS=$'\n'
1671     done
1672    
1673     unset IFS
1674    
1675     # now read the packages linked to VIRTUAL_NAME and output them
1676     if [ -n "${virtline}" ]
1677     then
1678     if [[ ${command} = showpkgs ]]
1679     then
1680     declare -i x=0
1681     for i in ${virtline}
1682     do
1683     if [ ${x} -ge 1 ]
1684     then
1685     echo "${i}"
1686     fi
1687     ((x++))
1688     done
1689     fi
1690     return 0
1691     fi
1692     return 1
1693     }
1694    
1695    
1696     #add pkg to virtualdb
1697     # $1 == virtualname $2= pkgname
1698     # retvals: 0=ok,added; 1=error; 3=pkg already in virtual
1699     virtuals_add()
1700     {
1701     local virtualname="$1"
1702     local pkgname="$2"
1703     local oldline
1704     local line i
1705     local installed_file
1706 niro 273 local OLDIFS
1707 niro 226
1708     if virtuals_read ${virtualname}
1709     then
1710 niro 329 # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1711 niro 226 for i in $(virtuals_read ${virtualname} showpkgs)
1712     do
1713     if [[ ${i} = ${pkgname} ]]
1714     then
1715     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1716     echo "${pkgname} already linked as ${virtualname} ..."
1717     #return 3
1718     return 0
1719     fi
1720     done
1721    
1722     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1723     echo "updating ${virtualname} entry with ${pkgname} ..."
1724     oldline="$(virtuals_read ${virtualname} showline)"
1725    
1726     # make a backup
1727     mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1728    
1729 niro 273 OLDIFS="${IFS}"
1730 niro 226 IFS=$'\n'
1731     for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1732     do
1733     # if the right line, append ${pkgname}, else do nothing
1734     if [[ ${line} = ${oldline} ]]
1735     then
1736     echo "${line} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1737     else
1738     echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1739     fi
1740     done
1741 niro 273 # unset IFS
1742     IFS="${OLDIFS}"
1743 niro 226 else
1744 niro 273 echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1745 niro 226 echo "register ${pkgname} as ${virtualname} ..."
1746     echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1747     fi
1748    
1749     return 0
1750     }
1751    
1752     #deletes pakages from virtual database
1753     #$1 virtualname; $2 pkgname
1754     virtuals_del() {
1755    
1756 niro 273 local virtualname="$1"
1757     local pkgname="$2"
1758     local oldline
1759     local method
1760     local line i x
1761     local pkg_installed
1762     local OLDIFS
1763    
1764     # first check if exists
1765     if virtuals_read ${virtualname}
1766 niro 226 then
1767 niro 273 # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
1768 niro 226 declare -i x=0
1769 niro 273 for i in $(virtuals_read ${virtualname} showpkgs)
1770 niro 226 do
1771 niro 273 if [[ ${i} = ${pkgname} ]]
1772 niro 226 then
1773 niro 273 pkg_installed=true
1774 niro 226 fi
1775     ((x++))
1776     done
1777 niro 273
1778     # abort if not installed
1779     if [[ ${pkg_installed} != true ]]
1780 niro 226 then
1781 niro 273 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1782     echo "${pkgname} does not exists in ${virtualname}."
1783 niro 226 return 0
1784     fi
1785 niro 273
1786 niro 226 if [ ${x} -ge 2 ]
1787     then
1788 niro 273 method=update
1789 niro 226 else
1790 niro 273 method=delall
1791 niro 226 fi
1792 niro 273
1793     # get the complete line
1794     oldline="$(virtuals_read ${virtualname} showline)"
1795    
1796     # make a backup of the db
1797 niro 226 mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1798 niro 273
1799     # parse virtualdb
1800     OLDIFS="${IFS}"
1801 niro 226 IFS=$'\n'
1802     for line in $(< ${VIRTUALDB_FILE}.old)
1803     do
1804 niro 273 if [[ ${line} = ${oldline} ]]
1805 niro 226 then
1806     #delall or update?
1807 niro 273 case ${method} in
1808 niro 226 update)
1809 niro 273 echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1810     echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1811     # del PKG_NAME from line
1812     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1813 niro 226 ;;
1814     delall)
1815 niro 273 echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1816     echo "Deleting ${virtualname} in virtual database ..."
1817     # continue; do not write anything
1818 niro 226 continue
1819     ;;
1820     esac
1821     else
1822     echo "${line}" >> ${VIRTUALDB_FILE}
1823     fi
1824     done
1825 niro 273 # unset IFS
1826     IFS="${OLDIFS}"
1827 niro 226 else
1828 niro 273 echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1829     echo "${virtualname} does not exists in virtual database."
1830 niro 226 fi
1831     }
1832    
1833     # gets real pkgname from virtuals.default
1834     #$1=VIRTUAL_NAME; returns PKG_NAME
1835     default_virtualname_to_pkgname()
1836     {
1837     local VIRTUAL_NAME PKG_NAME db_virtualname db_pkgname
1838    
1839     VIRTUAL_NAME=$1
1840    
1841     while read db_virtualname db_pkgname
1842     do
1843     if [ "${db_virtualname}" == "${VIRTUAL_NAME}" ]
1844     then
1845     PKG_NAME="${db_pkgname}"
1846     fi
1847     done << EOF
1848     $(< ${VIRTUALDB_DEFAULTS})
1849     EOF
1850    
1851     if [ -n "${PKG_NAME}" ]
1852     then
1853     echo "${PKG_NAME}"
1854     fi
1855     }
1856    
1857     minclude()
1858     {
1859     local i
1860    
1861 niro 437 if [[ -n $* ]]
1862 niro 226 then
1863 niro 437 for i in $*
1864 niro 226 do
1865     [[ ${MAGEDEBUG} = on ]] && \
1866     echo "--- Including ${MAGEDIR}/include/${i}.minc"
1867     source ${MAGEDIR}/include/${i}.minc
1868     done
1869     [[ ${MAGEDEBUG} = on ]] && echo
1870     fi
1871     }
1872    
1873     sminclude()
1874     {
1875     local i
1876    
1877 niro 437 if [[ -n $* ]]
1878 niro 226 then
1879 niro 437 for i in $*
1880 niro 226 do
1881     echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1882     source ${SMAGESCRIPTSDIR}/include/${i}.sminc
1883     done
1884     echo
1885     fi
1886     }
1887    
1888     # checks if an newer mage version is available
1889     is_newer_mage_version_available()
1890     {
1891     local newest_mage
1892     local installed_mage
1893    
1894 niro 252 newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1895 niro 226 installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1896    
1897     if [[ ${newest_mage} > ${installed_mage} ]]
1898     then
1899     echo
1900     echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1901     echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1902     echo "It is recommened to install this newer version"
1903 niro 373 echo "or your current system installation may break."
1904 niro 226 echo
1905     echo -en "Please update mage by running "
1906     echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
1907     echo
1908     fi
1909     }
1910    
1911    
1912     # returns pname from pkgname
1913     # pkgname2pname $PKGNAME
1914     pkgname2pname()
1915     {
1916     local pname
1917    
1918     pname="${1%-*-*-*}"
1919     echo "${pname}"
1920     }
1921    
1922     # returns pver from pkgname
1923     # pkgname2pver $PKGNAME
1924     pkgname2pver()
1925     {
1926     local i pver
1927    
1928     i="${1/$(pkgname2pname $1)-/}"
1929     pver="${i%-*-*}"
1930     echo "${pver}"
1931     }
1932    
1933     # returns pbuild from pkgname
1934     # pkgname2pbuild $PKGNAME
1935     pkgname2pbuild()
1936     {
1937     local pbuild
1938    
1939     pbuild="${1##*-}"
1940     echo "${pbuild}"
1941     }
1942    
1943     # returns parch from pkgname
1944     # pkgname2parch $PKGNAME
1945     pkgname2parch()
1946     {
1947     local i x parch
1948    
1949     i="${1%-*-*}-"
1950     x="${1%-*}"
1951     parch="${x/${i}/}"
1952     echo "${parch}"
1953     }
1954    
1955     # returns pname from magename
1956     # magename2pname /PATH/TO/MAGE/FILE
1957     magename2pname()
1958     {
1959     local i pname
1960    
1961     i="$(basename $1 .mage)"
1962     pname="${i%-*-*}"
1963     echo "${pname}"
1964     }
1965    
1966     # returns pver from magename
1967     # magename2pver /PATH/TO/MAGE/FILE
1968     magename2pver()
1969     {
1970     local i pver
1971    
1972     i="$(basename $1 .mage)"
1973     i="${i/$(magename2pname $1)-/}"
1974     pver="${i%-*}"
1975     echo "${pver}"
1976     }
1977    
1978     # returns pbuild from magename
1979     # magename2pbuild /PATH/TO/MAGE/FILE
1980     magename2pbuild()
1981     {
1982     local i pbuild
1983    
1984     i="$(basename $1 .mage)"
1985     pbuild="${i##*-}"
1986     echo "${pbuild}"
1987     }
1988    
1989     # returns pcat from magename
1990     # magename2pcat /PATH/TO/MAGE/FILE
1991     magename2pcat()
1992     {
1993     local i pcat
1994    
1995     if [[ ${2} = installdb ]]
1996     then
1997     # go 1 dir back
1998     i="${1%/*}"
1999     else
2000     # go 2 dirs back
2001     i="${1%/*/*}"
2002     fi
2003    
2004     # get basename
2005     pcat="${i##*/}"
2006     echo "${pcat}"
2007     }
2008    
2009     # returns pcat from DEPEND (without operand ! PCAT/PNAME-VERSION)
2010     # dep2pcat DEPEND
2011     dep2pcat()
2012     {
2013     local pcat
2014    
2015     pcat="${1%/*}"
2016     echo "${pcat}"
2017     }
2018    
2019     # returns pname from DEPEND (without operand ! PCAT/PNAME-VERSION)
2020     # $2=virtual is used to resolv VDEPEND from virtual packages
2021     # dep2pcat DEPEND (virtual)
2022     dep2pname()
2023     {
2024     local pname
2025    
2026     pname="${1##*/}"
2027    
2028     # cut version only if not virtual or it will cut the name
2029     if [[ $(dep2pcat $1) != virtual ]] && \
2030     [[ $2 != virtual ]]
2031     then
2032     pname="${pname%-*}"
2033     fi
2034    
2035     echo "${pname}"
2036     }
2037    
2038     dep2highest_magefile()
2039     {
2040     local pcat
2041     local pname
2042     local magefile
2043     local installed_virtuals
2044    
2045     pcat="$(dep2pcat $1)"
2046     pname="$(dep2pname $1)"
2047    
2048     if [[ ${pcat} = virtual ]]
2049     then
2050     # first check if virtual is already installed
2051     installed_virtuals="$(virtuals_read ${pcat}/${pname} showpkgs)"
2052     if [ -n "${installed_virtuals}" ]
2053     then
2054     for vpkg in ${installed_virtuals}
2055     do
2056     realpkgname="${vpkg}"
2057     virtualpkgname="${pcat}/${pname}"
2058     pcat="$(dep2pcat ${realpkgname})"
2059     pname="$(dep2pname ${realpkgname} virtual)"
2060     done
2061     else
2062     # choose one from virtualdb defaults (virtuals.defaults)
2063     realpkgname="$(default_virtualname_to_pkgname ${pcat}/${pname})"
2064     virtualpkgname="${pcat}/${pname}"
2065     pcat="$(dep2pcat ${realpkgname})"
2066     pname="$(dep2pname ${realpkgname} virtual)"
2067     fi
2068     fi
2069    
2070     magefile="$(get_highest_magefile ${pcat} ${pname})"
2071     echo "${magefile}"
2072     }
2073    
2074     # is_installed ${PCAT}/${PNAME}-${PVER}-${PBUILD}
2075     is_installed()
2076     {
2077     local fullpkgname="$1"
2078    
2079     # return 0 if installed
2080     [ -d ${MROOT}${INSTALLDB}/${fullpkgname} ] && return 0
2081    
2082     return 1
2083     }
2084    
2085     install_packages()
2086     {
2087     local list="$@"
2088     local pkg
2089     local pcat
2090     local pname
2091     local pver
2092     local pbuild
2093     local total_pkgs
2094     local current_pkg
2095     local src_install
2096     local uninstall_list
2097    
2098     # check for --src-install
2099     if [[ $1 = --src-install ]]
2100     then
2101     # remove --src-install from list
2102     list=${list/--src-install/}
2103     # enable src-install
2104     src_install="--src-install"
2105     fi
2106    
2107     # reset MAGE_PROTECT_COUNTER
2108     declare -i MAGE_PROTECT_COUNTER=0
2109     export MAGE_PROTECT_COUNTER
2110    
2111     # get count of total packages
2112     declare -i total_pkgs=0
2113     declare -i current_pkg=0
2114     for i in ${list}; do (( total_pkgs++ )); done
2115    
2116     echo
2117    
2118     if [[ -n ${MROOT} ]]
2119     then
2120     echo -ne ${COLRED}
2121     echo "!! installing in MROOT=${MROOT}"
2122     echo -ne ${COLDEFAULT}
2123     echo
2124     fi
2125    
2126     for pkg in ${list}
2127     do
2128     (( current_pkg++ ))
2129     pcat=$(magename2pcat ${pkg})
2130     pname=$(magename2pname ${pkg})
2131     pver=$(magename2pver ${pkg})
2132     pbuild=$(magename2pbuild ${pkg})
2133    
2134     mage_install \
2135     --pcat ${pcat} \
2136     --pname ${pname} \
2137     --pver ${pver} \
2138     --pbuild ${pbuild} \
2139     --count-total ${total_pkgs} \
2140     --count-current ${current_pkg} \
2141     ${src_install}
2142    
2143     # check for allready installed packages and remove them
2144     # except the package we have installed
2145     uninstall_list="$(get_uninstall_candidates \
2146     --pcat "${pcat}" \
2147     --pname "${pname}" \
2148     --protected ${pcat}/${pname}-${pver}-${pbuild})"
2149    
2150     # uninstall all packges in uninstall_list if not empty
2151     if [ -n "${uninstall_list}" ]
2152     then
2153     echo
2154     uninstall_packages ${uninstall_list} \
2155     || die "install_packges() uninstalling not-needed."
2156     fi
2157    
2158     # crlf for better view in VERBOSE mode
2159     #if [[ ${VERBOSE} = on ]]; then echo; fi
2160     echo
2161     done
2162    
2163     #echo "DEBUG MAGE_PROTECT_COUNTER=${MAGE_PROTECT_COUNTER}"
2164     show_etc_update_mesg
2165     }
2166    
2167     # get_value_from_magefile VARIABLE
2168     # returns the content of this VAR
2169     get_value_from_magefile()
2170     {
2171     local var="$1"
2172     local magefile="$2"
2173     local value
2174    
2175 niro 370 [[ -z ${var} ]] && return 1
2176     [[ -z ${magefile} ]] && return 1
2177    
2178 niro 226 # local all possible vars of a mage file
2179     # to prevent bad issues
2180     local PKGNAME
2181     local STATE
2182     local DESCRIPTION
2183     local HOMEPAGE
2184     local DEPEND
2185     local SDEPEND
2186     local PROVIDE
2187     local PKGTYPE
2188 niro 943 local MAGE_TARGETS
2189     local SPLIT_PACKAGE_BASE
2190 niro 226 local preinstall
2191     local postinstall
2192 niro 248 local preremove
2193     local postremove
2194 niro 226
2195     # sanity checks
2196     [ -f ${magefile} ] && source ${magefile} || \
2197     die "get_value_from_magefile: ${magefile} not found."
2198     [ -z "${var}" ] && die "get_value_from_magefile: \$var not given."
2199    
2200     source ${magefile}
2201     eval value=\$$(echo ${var})
2202     echo "${value}"
2203 niro 248
2204 niro 258 # unset these functions
2205     unset -f preinstall
2206     unset -f postinstall
2207     unset -f preremove
2208     unset -f postremove
2209 niro 226 }
2210    
2211     mage_install()
2212     {
2213     # local all possible vars of a mage file
2214     # to prevent bad issues
2215     local PKGNAME
2216     local STATE
2217     local DESCRIPTION
2218     local HOMEPAGE
2219     local DEPEND
2220     local SDEPEND
2221     local PROVIDE
2222     local PKGTYPE
2223     local preinstall
2224     local postinstall
2225 niro 248 local preremove
2226     local postremove
2227 niro 226
2228     local pcat
2229     local pname
2230     local pver
2231     local pbuild
2232     local count_total
2233     local count_current
2234     local magefile
2235     local src_install
2236 niro 876 local i
2237 niro 226
2238     # very basic getops
2239     for i in $*
2240     do
2241     case $1 in
2242     --pcat|-c) shift; pcat="$1" ;;
2243     --pname|-n) shift; pname="$1" ;;
2244     --pver|-v) shift; pver="$1" ;;
2245     --pbuild|-b) shift; pbuild="$1" ;;
2246     --count-total) shift; count_total="$1" ;;
2247     --count-current) shift; count_current="$1" ;;
2248     --src-install|-s) shift; src_install=true ;;
2249     esac
2250     shift
2251     done
2252    
2253     # sanity checks; abort if not given
2254     [ -z "${pcat}" ] && die "mage_install() \$pcat not given."
2255     [ -z "${pname}" ] && die "mage_install() \$pname not given."
2256     [ -z "${pver}" ] && die "mage_install() \$pver not given."
2257     [ -z "${pbuild}" ] && die "mage_install() \$pbuild not given."
2258    
2259     # check needed global vars
2260     [ -z "${MAGEDIR}" ] && die "mage_install() \$MAGEDIR not set."
2261     [ -z "${INSTALLDB}" ] && die "mage_install() \$INSTALLDB not set."
2262     [ -z "${BUILDDIR}" ] && die "mage_install() \$BUILDDIR not set."
2263    
2264     xtitle "[ (${count_current}/${count_total}) Installing ${pcat}/${pname}-${pver}-${pbuild} ]"
2265     echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2266     echo -n "installing (${count_current}/${count_total}): "
2267     echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2268     echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2269    
2270     magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"
2271     source ${magefile}
2272    
2273     # abort on sources if no srcinstall
2274     if [[ ${PKGTYPE} = sources ]] && [[ ${src_install} != true ]]
2275     then
2276     echo
2277     echo -e "This Package is a Source Package."
2278     echo
2279     echo -e "Only 'srcinstall' works with this type of packages"
2280     echo -en "If you have done a srcinstall before, "
2281     echo -e "you will find the files in /usr/src."
2282     echo
2283     exit 1
2284     fi
2285    
2286     ## preinstall scripts
2287     if [ -n "$(typeset -f preinstall)" ]
2288     then
2289     echo -e " ${COLBLUE}***${COLDEFAULT} running preinstall ... "
2290     preinstall
2291     unset preinstall
2292     fi
2293    
2294     if [[ ${src_install} = true ]]
2295     then
2296     local smage2file
2297     # check needed global vars
2298     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not set."
2299     [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not set."
2300     [ -z "${BINDIR}" ] && die "\$BINDIR not set."
2301    
2302     # build the package first
2303     if [[ ${MAGEDEBUG} = on ]]
2304     then
2305     echo M:${pname}
2306     echo V:${pver}
2307     echo B:${pbuild}
2308     fi
2309    
2310 niro 943 if [[ -n ${MAGE_TARGETS} ]]
2311 niro 675 then
2312 niro 876 # basic svn compat
2313     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2314     then
2315 niro 943 for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2316 niro 876 do
2317     smage2file="${i}"
2318     done
2319     else
2320 niro 943 smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2321 niro 876 fi
2322 niro 943
2323     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2324     then
2325     # basic svn compat
2326     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2327     then
2328     for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2329     do
2330     smage2file="${i}"
2331     done
2332     else
2333     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2334     fi
2335    
2336 niro 675 else
2337 niro 876 # basic svn compat
2338     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2339     then
2340 niro 943 for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2341 niro 876 do
2342     smage2file="${i}"
2343     done
2344     else
2345 niro 943 smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2346 niro 876 fi
2347 niro 675 fi
2348 niro 943
2349 niro 226 if [ -f "${smage2file}" ]
2350     then
2351 niro 385 echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2352 niro 226 smage2 ${smage2file} || die "compile failed"
2353     else
2354     echo
2355     echo "$(basename ${SMAGEFILE}) not found."
2356     echo "update your smage-tree and try it again."
2357     echo
2358     die
2359     fi
2360     fi
2361    
2362     if [[ ${PKGTYPE} != virtual ]] && \
2363     [[ ${PKGTYPE} != sources ]]
2364     then
2365 niro 385 echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2366 niro 226 build_doinstall ${PKGNAME}
2367     fi
2368    
2369     ## postinstall scripts
2370     if [ -n "$(typeset -f postinstall)" ]
2371     then
2372     echo -e " ${COLBLUE}***${COLDEFAULT} running postinstall ... "
2373     postinstall
2374     unset postinstall
2375     fi
2376    
2377     # install a database entry
2378     install_database_entry \
2379     --pcat "${pcat}" \
2380     --pname "${pname}" \
2381     --pver "${pver}" \
2382     --pbuild "${pbuild}" \
2383     --pkgname "${PKGNAME}" \
2384     --pkgtype "${PKGTYPE}" \
2385     || die "error in mage_install() running install_database_entry()."
2386    
2387     # remove the package dir now
2388     if [ -d ${BUILDDIR}/${PKGNAME} ]
2389     then
2390     rm -rf ${BUILDDIR}/${PKGNAME}
2391     fi
2392    
2393     # rebuilds toplevel info node
2394     if [[ ${MAGE_INFO_REBUILD} = true ]]
2395     then
2396     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2397     echo -n "rebuilding top-level info node ... "
2398     ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \
2399     > ${MROOT}/usr/share/info/dir && \
2400     echo "done." || echo "failure."
2401     unset MAGE_INFO_REBUILD
2402     fi
2403    
2404     # rebuilds the enviroment with the content of /etc/env.d
2405     if [[ ${MAGE_ENV_REBUILD} = true ]]
2406     then
2407     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2408     echo -n "rebuilding environment ... "
2409     ${MLIBDIR}/env-rebuild.sh > /dev/null && \
2410     echo "done." || echo "failure."
2411     unset MAGE_ENV_REBUILD
2412     fi
2413    
2414     xtitleclean
2415    
2416     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2417     echo -n "package "
2418     # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2419     # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2420     echo "successfully installed."
2421 niro 248
2422 niro 258 # unset these functions
2423     unset -f preinstall
2424     unset -f postinstall
2425     unset -f preremove
2426     unset -f postremove
2427 niro 226 }
2428    
2429     md5sum_packages()
2430     {
2431     local list="$@"
2432     local magefile
2433     local pcat
2434     local pname
2435     local pkgname
2436     local pkgfile
2437     local pkgtype
2438     local count_current
2439     local count_total
2440    
2441     # get count of total packages
2442     declare -i count_current=0
2443     declare -i count_total=0
2444    
2445     for i in ${list}; do (( count_total++ )); done
2446    
2447     for magefile in ${list}
2448     do
2449     pcat=$(magename2pcat ${magefile})
2450     pname=$(magename2pname ${magefile})
2451     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2452     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2453     pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
2454     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2455    
2456     (( count_current++ ))
2457     xtitle "[ (${count_current}/${count_total}) MD5SUM: ${pkgfile} ]"
2458    
2459     # abort on virtual pkg
2460     if [[ ${pkgtype} = virtual ]]
2461     then
2462     echo -ne " ${COLBLUE}---${COLDEFAULT}"
2463     echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2464     continue
2465     fi
2466    
2467     # abort on sources pkg
2468     if [[ ${pkgtype} = sources ]]
2469     then
2470     echo -ne " ${COLBLUE}---${COLDEFAULT}"
2471     echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "
2472     continue
2473     fi
2474    
2475     if [ -f "${md5file}" ]
2476     then
2477     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2478     echo -ne "checking md5sum (${count_current}/${count_total}): "
2479     ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"
2480     else
2481     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2482     echo -e "!! no md5sum file found for ${pkgfile} :("
2483     fi
2484     done
2485    
2486     # add a crlf for a better view
2487     if [ ${count_total} -gt 1 ]; then echo; fi
2488     }
2489    
2490     ## uninstall_packages ulist
2491     uninstall_packages()
2492     {
2493     local list="$@"
2494     local pcat
2495     local pname
2496     local pver
2497     local pbuild
2498     local can_pcat
2499     local can_pname
2500     local can_ver_list
2501    
2502     if [[ -n ${MROOT} ]]
2503     then
2504     echo -ne ${COLRED}
2505     echo "!! uninstalling from MROOT=${MROOT}"
2506     echo -ne ${COLDEFAULT}
2507     echo
2508     fi
2509    
2510     # generate a candidates list
2511     for pkg in ${list}
2512     do
2513     pcat=$(dep2pcat ${pkg})
2514     pname=$(magename2pname ${pkg})
2515     pver=$(magename2pver ${pkg})
2516     pbuild=$(magename2pbuild ${pkg})
2517     can_pcat="${pcat}"
2518     can_pname="${pname}"
2519    
2520     if [ -z "${can_ver_list}" ]
2521     then
2522     can_ver_list=" ${pver}-${pbuild}"
2523     else
2524     can_ver_list="${can_ver_list}, ${pver}-${pbuild}"
2525     fi
2526     done
2527    
2528     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2529     echo "following candidate(s) will be removed:"
2530     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2531 niro 240 echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2532 niro 226 echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2533 niro 501 echo
2534 niro 240 if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2535     then
2536     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2537     echo "( Press [CTRL+C] to abort )"
2538     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2539     echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2540     for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2541     do
2542     echo -ne "${COLRED} ${i}${COLDEFAULT}"
2543     sleep 1
2544     done
2545     echo
2546     echo
2547     fi
2548 niro 226
2549     for pkg in ${list}
2550     do
2551     pcat=$(dep2pcat ${pkg})
2552     pname=$(magename2pname ${pkg})
2553     pver=$(magename2pver ${pkg})
2554     pbuild=$(magename2pbuild ${pkg})
2555    
2556     mage_uninstall \
2557     --pcat ${pcat} \
2558     --pname ${pname} \
2559     --pver ${pver} \
2560     --pbuild ${pbuild} \
2561     --count-total ${total_pkgs} \
2562     --count-current ${current_pkg} \
2563     ${src_install}
2564    
2565     # crlf for better view in VERBOSE mode
2566     #if [[ ${VERBOSE} = on ]]; then echo; fi
2567     echo
2568     done
2569     }
2570    
2571     mage_uninstall()
2572     {
2573     # local all possible vars of a mage file
2574     # to prevent bad issues
2575     local PKGNAME
2576     local STATE
2577     local DESCRIPTION
2578     local HOMEPAGE
2579     local DEPEND
2580     local SDEPEND
2581     local PROVIDE
2582     local PKGTYPE
2583     local preinstall
2584     local postinstall
2585 niro 248 local preremove
2586     local postremove
2587 niro 226
2588     local pcat
2589     local pname
2590     local pver
2591     local pbuild
2592     local magefile
2593     local i
2594    
2595     # very basic getops
2596     for i in $*
2597     do
2598     case $1 in
2599 niro 501 --pcat|-c) shift; pcat="$1" ;;
2600 niro 226 --pname|-n) shift; pname="$1" ;;
2601     --pver|-v) shift; pver="$1" ;;
2602 niro 501 --pbuild|-b) shift; pbuild="$1" ;;
2603 niro 226 esac
2604     shift
2605 niro 501 done
2606 niro 226
2607     # sanity checks; abort if not given
2608 niro 501 [ -z "${pcat}" ] && die "mage_uninstall() \$pcat not given."
2609 niro 226 [ -z "${pname}" ] && die "mage_uninstall() \$pname not given."
2610     [ -z "${pver}" ] && die "mage_uninstall() \$pver not given."
2611 niro 501 [ -z "${pbuild}" ] && die "mage_uninstall() \$pbuild not given."
2612 niro 226
2613     # check needed global vars
2614     [ -z "${MAGEDIR}" ] && die "mage_uninstall() \$MAGEDIR not set."
2615     [ -z "${INSTALLDB}" ] && die "mage_uninstall() \$INSTALLDB not set."
2616     [ -z "${BUILDDIR}" ] && die "mage_uninstall() \$BUILDDIR not set."
2617    
2618     xtitle "[ (${count_current}/${count_total}) Removing ${pcat}/${pname}-${pver}-${pbuild} ]"
2619     echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2620     echo -n "removing: "
2621     echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2622 niro 416 echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2623 niro 226
2624 niro 499 magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2625 niro 226 source ${magefile}
2626    
2627     ## preremove scripts
2628     if [ -n "$(typeset -f preremove)" ]
2629     then
2630     echo -e " ${COLBLUE}***${COLDEFAULT} running preremove ... "
2631     preremove
2632     unset preremove
2633     fi
2634    
2635     # runs uninstall
2636     build_douninstall \
2637     --pcat "${pcat}" \
2638     --pname "${pname}" \
2639     --pver "${pver}" \
2640     --pbuild "${pbuild}"
2641    
2642     ## postremove scripts
2643     if [ -n "$(typeset -f postremove)" ]
2644     then
2645     echo -e " ${COLBLUE}***${COLDEFAULT} running postremove ... "
2646     postremove
2647     unset postremove
2648     fi
2649    
2650     # removes the database entry
2651     remove_database_entry \
2652     --pcat "${pcat}" \
2653     --pname "${pname}" \
2654     --pver "${pver}" \
2655     --pbuild "${pbuild}" \
2656     || die "error in mage_uninstall() running remove_database_entry()."
2657    
2658     # rebuilds toplevel info node
2659     if [[ ${MAGE_INFO_REBUILD} = true ]]
2660     then
2661     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2662     echo -n "rebuilding top-level info node ... "
2663     ${MLIBDIR}/mkinfodir ${MROOT}/usr/share/info \
2664     > ${MROOT}/usr/share/info/dir && \
2665     echo "done." || echo "failure."
2666     unset MAGE_INFO_REBUILD
2667     fi
2668    
2669     # rebuilds the enviroment with the content of /etc/env.d
2670     if [[ ${MAGE_ENV_REBUILD} = true ]]
2671     then
2672     echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2673     echo -n "rebuilding environment ... "
2674     ${MLIBDIR}/env-rebuild.sh > /dev/null && \
2675     echo "done." || echo "failure."
2676     unset MAGE_ENV_REBUILD
2677     fi
2678    
2679     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2680     echo -n "package "
2681     # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2682     # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2683     echo "successfully removed."
2684 niro 248
2685 niro 258 # unset these functions
2686     unset -f preinstall
2687     unset -f postinstall
2688     unset -f preremove
2689     unset -f postremove
2690 niro 226 }
2691    
2692     show_etc_update_mesg() {
2693     [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2694    
2695     echo
2696     echo -ne "${COLRED}"
2697     echo "Important:"
2698     echo -ne ${COLDEFAULT}
2699     echo "${MAGE_PROTECT_COUNTER} protected file(s) were installed."
2700     echo
2701     echo "Please run 'etc-update' to update your configuration files."
2702     echo
2703     }
2704 niro 237
2705     pkgsearch()
2706     {
2707     local string="$1"
2708     local result
2709     local pkg
2710     local pcat
2711     local pname
2712     local magefile
2713     local pver
2714     local pbuild
2715     local state
2716     local descriptiom
2717     local homepage
2718     local i
2719     local all_installed
2720     local ipver
2721     local ipbuild
2722 niro 445 local latest_available
2723 niro 458 local depsfull
2724     local sdepsfull
2725     local deps
2726     local sdeps
2727     local dep
2728     local sign
2729 niro 237
2730     # only names no versions
2731 niro 391 result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2732 niro 328 #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2733 niro 237
2734     # nothing found
2735     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2736    
2737     for pkg in ${result}
2738     do
2739     # dirty, but does the job
2740     pcat="$(magename2pcat ${pkg}/foo)"
2741     pname="$(magename2pname ${pkg}-foo-foo)"
2742    
2743     # get highest version available
2744     magefile=$(get_highest_magefile ${pcat} ${pname})
2745    
2746 niro 445 if [[ ! -z ${magefile} ]]
2747     then
2748     # now get all needed infos to print a nice output
2749     pver="$(magename2pver ${magefile})"
2750     pbuild="$(magename2pbuild ${magefile})"
2751     state="$(get_value_from_magefile STATE ${magefile})"
2752     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2753     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2754    
2755     # all installed
2756     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2757     do
2758     ipver="$(magename2pver ${i})"
2759     ipbuild="$(magename2pbuild ${i})"
2760    
2761     if [[ -z ${all_installed} ]]
2762     then
2763     all_installed="${ipver}-${ipbuild}"
2764     else
2765     all_installed="${all_installed} ${ipver}-${ipbuild}"
2766     fi
2767     done
2768     [[ -z ${all_installed} ]] && all_installed="none"
2769    
2770     case ${state} in
2771     stable) state=${COLGREEN}"[s] ";;
2772     testing) state=${COLYELLOW}"[t] ";;
2773     unstable) state=${COLRED}"[u] ";;
2774     old) state=${COLGRAY}"[o] ";;
2775     esac
2776 niro 237
2777 niro 445 latest_available="${pver}-${pbuild}"
2778     else
2779     # package is masked
2780     state="${COLRED}[m] "
2781     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2782     fi
2783 niro 237
2784 niro 458 depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2785     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
2786    
2787     while read sign dep
2788     do
2789     case ${dep} in
2790     "") continue;;
2791     esac
2792    
2793     deps="${deps} $(basename ${dep%-*})"
2794     done << EOF
2795     ${depsfull}
2796     EOF
2797    
2798     while read sign dep
2799     do
2800     case ${dep} in
2801     "") continue;;
2802     esac
2803    
2804     sdeps="${sdeps} $(basename ${dep%-*})"
2805     done << EOF
2806     ${sdepsfull}
2807     EOF
2808    
2809 niro 237 echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2810 niro 445 echo -e " Latest available: ${latest_available}"
2811 niro 237 echo " Installed versions: ${all_installed}"
2812     echo " Description: ${description}"
2813     echo " Homepage: ${homepage}"
2814 niro 458 echo " Depends: ${deps}"
2815     echo " SDepends: ${sdeps}"
2816 niro 237 echo
2817    
2818     unset pcat
2819     unset pname
2820     unset magefile
2821     unset pver
2822     unset pbuild
2823     unset state
2824     unset descriptiom
2825     unset homepage
2826     unset all_installed
2827     unset ipver
2828     unset ipbuild
2829 niro 458 unset depsfull
2830     unset sdepsfull
2831     unset deps
2832     unset sdeps
2833     unset dep
2834     unset sign
2835 niro 237 done
2836     }
2837 niro 249
2838     export_inherits()
2839     {
2840     local include="$1"
2841     shift
2842    
2843     while [ "$1" ]
2844     do
2845     local functions="$1"
2846    
2847     # sanity checks
2848     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2849     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2850    
2851     eval "${functions}() { ${include}_${functions} ; }"
2852    
2853     # debug
2854     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2855    
2856     shift
2857     done
2858     }
2859 niro 350
2860     mlibdir()
2861     {
2862     local libdir=lib
2863     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2864    
2865     echo "${libdir}"
2866     }
2867 niro 370
2868     ## blacklisted ${magefile}
2869     blacklisted()
2870     {
2871     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2872    
2873     # compat
2874     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2875     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2876    
2877 niro 892 # support both types for the moment
2878     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
2879     then
2880     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2881     else
2882     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
2883     fi
2884 niro 370
2885     # return 0 if the list not exist; nothin is masked
2886     [[ ! -f ${EXCLUDED} ]] && return 0
2887    
2888     local MAGEFILE="$1"
2889    
2890     local PCAT="$(magename2pcat ${MAGEFILE})"
2891     local PNAME="$(magename2pname ${MAGEFILE})"
2892     local PVER="$(magename2pver ${MAGEFILE})"
2893     local PBUILD="$(magename2pbuild ${MAGEFILE})"
2894    
2895     local EXPCAT EXPNAME EXPVER EXPBUILD
2896     while read EXPCAT EXPNAME EXPVER EXPBUILD
2897     do
2898     # ignore spaces and comments
2899     case "${EXPCAT}" in
2900     \#*|"") continue ;;
2901     esac
2902    
2903     # exclude full pver
2904     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2905     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2906     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
2907     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
2908     then
2909     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
2910     fi
2911    
2912     # exclude pcat/pname only
2913     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2914     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2915     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
2916     then
2917     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
2918     fi
2919     done << EOF
2920     $( cat ${EXCLUDED}; echo)
2921     EOF
2922    
2923     return 0
2924     }
2925