Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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