Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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