Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1548 by niro, Tue Dec 27 10:00:34 2011 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.1 2005-09-09 16:35:38 niro Exp $  # $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    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
# Line 23  unpack_packages() Line 46  unpack_packages()
46   local pkgtype   local pkgtype
47   local count_current   local count_current
48   local count_total   local count_total
49     local tar_opts
50    
51   # get count of total packages   # get count of total packages
52   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 78  unpack_packages()
78   continue   continue
79   fi   fi
80    
81     # busybox?
82     if need_busybox_support tar
83     then
84     tar_opts="xjf"
85     else
86     tar_opts="xjmf"
87     fi
88    
89   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
90   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
91   done   done
92    
93   # add a crlf for a better view   # add a crlf for a better view
# Line 132  install_directories() Line 164  install_directories()
164   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
165   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
166    
   
167   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
168   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
169    
# Line 198  install_files() Line 229  install_files()
229   is_config_protected "${pathto}"   is_config_protected "${pathto}"
230   retval="$?"   retval="$?"
231    
232   # 0 - not protected        #   # 0 - not protected         #
233   # 1 - error                #   # 1 - error                 #
234   # 2 - protected            #   # 2 - protected             #
235   # 3 - protected but masked #   # 3 - protected but masked  #
236     # 4 - protected but ignored #
237    
238   case ${retval} in   case ${retval} in
239   # file is not protected - (over)write it   # file is not protected - (over)write it
# Line 218  install_files() Line 250  install_files()
250   "${user}" \   "${user}" \
251   "${group}" \   "${group}" \
252   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
253   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
254   "${md5sum}"   "${md5sum}"
255   ;;   ;;
256    
# Line 245  install_files() Line 277  install_files()
277   "${user}" \   "${user}" \
278   "${group}" \   "${group}" \
279   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
280   "${dest_protected}")" \   "${dest_protected}")" \
281   "${md5sum}"   "${md5sum}"
282    
283   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
284   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
285   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
286   ;;   ;;
287    
288     # file is protected but ignored, delete the update/do nothing
289     4)
290     if [[ ${VERBOSE} = on ]]
291     then
292     echo -en "${COLRED}"
293     echo -n "! ignr "
294     echo -en "${COLDEFAULT}"
295     echo " === FILE: ${MROOT}${pathto}"
296     fi
297     # simply do nothing here - only fix mtime
298     fix_descriptor ${pkgname}/.files \
299     "${pathto}" \
300     "${posix}" \
301     "${user}" \
302     "${group}" \
303     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
304     "${MROOT}${pathto}")" \
305     "${md5sum}"
306     ;;
307   esac   esac
308   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
309    
# Line 298  install_symlinks() Line 350  install_symlinks()
350    
351   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
352    
353   # fix mtime and db  # # fix mtime and db
354   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
355   "${pathto}" \  # "${pathto}" \
356   "${posix}" \  # "${posix}" \
357   "${link}" \  # "${link}" \
358   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
359   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
360    
361   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
362    
363   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
364   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
365   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
366    
367   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
368   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 378  install_blockdevices()
378   local pkgname="$1"   local pkgname="$1"
379   local pathto   local pathto
380   local posix   local posix
381     local user
382     local group
383   local IFS   local IFS
384    
385   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 393  install_blockdevices()
393   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
394   IFS=§   IFS=§
395    
396   while read pathto posix   while read pathto posix major minor user group
397   do   do
398   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
399   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
400    
401   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
402     # make it optional atm !!
403     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
404     then
405     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
406     fi
407   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
408    
409   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 420  install_characterdevices()
420   local pkgname="$1"   local pkgname="$1"
421   local pathto   local pathto
422   local posix   local posix
423     local major
424     local minor
425     local user
426     local group
427   local IFS   local IFS
428    
429   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 437  install_characterdevices()
437   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
438   IFS=§   IFS=§
439    
440   while read pathto posix   while read pathto posix major minor user group
441   do   do
442   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
443   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
444    
445   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
446    
447     # make it optional atm !!
448     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
449     then
450     chown "${user}:${group}" "${MROOT}${pathto}"
451     fi
452   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
453    
454   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
455   IFS=$'\n'   IFS=$'\n'
456  }  }
457    
458    ###################################################
459    # function install_fifos                          #
460    # install_fifos $PKGNAME                    #
461    ###################################################
462    install_fifos()
463    {
464     local pkgname="$1"
465     local pathto
466     local posix
467     local user
468     local group
469     local IFS
470    
471     # sanity checks; abort if not given
472     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
473    
474     # check needed global vars
475     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
476    
477     # make it optional atm !!
478     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
479     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
480    
481     # sets fieldseperator to "§" instead of " "
482     IFS=§
483    
484     while read pathto posix user group
485     do
486     [ -z "${pathto}" ] && continue
487     [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
488    
489     mkfifo -m "${posix}" "${MROOT}${pathto}"
490     chown "${user}:${group}" "${MROOT}${pathto}"
491     done < ${BUILDDIR}/${pkgname}/.fifo
492    
493     # very important: unsetting the '§' fieldseperator
494     IFS=$'\n'
495    }
496    
497    
498  ###################################################  ###################################################
499  # function build_doinstall                        #  # function build_doinstall                        #
500  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
501  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
502  ###################################################  ###################################################
503  build_doinstall()  build_doinstall()
504  {  {
# Line 398  build_doinstall() Line 506  build_doinstall()
506    
507   # sanity checks; abort if not given   # sanity checks; abort if not given
508   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
509    
510   # this is only a wrapper   # this is only a wrapper
511    
512   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 521  build_doinstall()
521   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
522   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
523   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
524     install_fifos ${pkgname} || die "install fifos ${pkgname}"
525  }  }
526    
527    
# Line 432  install_database_entry() Line 541  install_database_entry()
541   local magefile   local magefile
542   local dbrecorddir   local dbrecorddir
543   local provide   local provide
544     local i
545    
546   # very basic getops   # very basic getops
547   for i in $*   for i in $*
# Line 473  install_database_entry() Line 583  install_database_entry()
583    
584   # create fake file descriptors   # create fake file descriptors
585   # used by virtual and source packages   # used by virtual and source packages
586   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
587   do   do
588   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
589   done   done
# Line 492  install_database_entry() Line 601  install_database_entry()
601    
602   # normal packages needs these files   # normal packages needs these files
603   local i   local i
604   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
605   do   do
606   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
607   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
608     then
609     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
610     fi
611   done   done
612   ;;   ;;
613   esac   esac
# Line 504  install_database_entry() Line 616  install_database_entry()
616   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
617   if [ -n "${provide}" ]   if [ -n "${provide}" ]
618   then   then
619   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
620     do
621     virtuals_add "${i}" "${pcat}/${pname}"
622     done
623   fi   fi
624  }  }
625    
# Line 523  remove_database_entry() Line 638  remove_database_entry()
638   local magefile   local magefile
639   local dbrecorddir   local dbrecorddir
640   local provide   local provide
641     local i
642    
643   # very basic getops   # very basic getops
644   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 668  remove_database_entry()
668   # abort if mage file not exists   # abort if mage file not exists
669   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
670    
671   # first unregister virtuals   # remove virtuals only if no other exist
672   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
673   then   then
674   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
675     provide="$(get_value_from_magefile PROVIDE ${magefile})"
676     if [ -n "${provide}" ]
677     then
678     for i in ${provide}
679     do
680     virtuals_del "${i}" "${pcat}/${pname}"
681     done
682     fi
683   fi   fi
684    
685   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 689  remove_database_entry()
689   fi   fi
690  }  }
691    
692    # get the number of installed packages
693    count_installed_pkgs()
694    {
695     local pcat
696     local pname
697     local pkg
698     local i
699    
700     # very basic getops
701     for i in $*
702     do
703     case $1 in
704     --pcat|-c) shift; pcat="$1" ;;
705     --pname|-n) shift; pname="$1" ;;
706     esac
707     shift
708     done
709    
710     # sanity checks; abort if not given
711     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
712     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
713    
714     declare -i i=0
715     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
716     do
717     (( i++ ))
718     #echo "$i ${pkg}"
719     done
720    
721     # return the value
722     echo "${i}"
723    }
724    
725    
726  ###################################################  ###################################################
727  # function compare_mtime                          #  # function compare_mtime                          #
# Line 726  remove_files() Line 882  remove_files()
882   done   done
883    
884   # sanity checks; abort if not given   # sanity checks; abort if not given
885   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
886   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
887   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
888   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
889   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
890    
891   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 900  remove_files()
900   do   do
901   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
902    
903   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
904   then   then
905   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
906   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 758  remove_files() Line 914  remove_files()
914   # 1=keep me   #   # 1=keep me   #
915   case ${retval} in   case ${retval} in
916   0)   0)
917   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
918   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
919   ;;   is_config_protected "${pathto}"
920     retval="$?"
921    
922     # 0 - not protected         #
923     # 1 - error                 #
924     # 2 - protected             #
925     # 3 - protected but masked  #
926     # 4 - protected but ignored #
927    
928     case ${retval} in
929     # file is not protected - delete it
930     0|3)
931     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
932     rm "${MROOT}${pathto}"
933     ;;
934    
935     # file is protected, do not delete
936     2)
937     if [[ ${VERBOSE} = on ]]
938     then
939     echo -en "${COLRED}"
940     echo -n "! prot "
941     echo -en "${COLDEFAULT}"
942     echo " === FILE: ${MROOT}${pathto}"
943     fi
944     ;;
945    
946     # file is protected but ignored, delete the update/do nothing
947     4)
948     if [[ ${VERBOSE} = on ]]
949     then
950     echo -en "${COLRED}"
951     echo -n "! ignr "
952     echo -en "${COLDEFAULT}"
953     echo " === FILE: ${MROOT}${pathto}"
954     fi
955     # simply do nothing here
956     ;;
957     esac
958     ;;
959   1)   1)
960   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
961   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 782  remove_blockdevices() Line 976  remove_blockdevices()
976  {  {
977   local pathto   local pathto
978   local posix   local posix
979     local user
980     local group
981   local IFS   local IFS
982   local pcat   local pcat
983   local pname   local pname
# Line 805  remove_blockdevices() Line 1001  remove_blockdevices()
1001   done   done
1002    
1003   # sanity checks; abort if not given   # sanity checks; abort if not given
1004   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1005   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1006   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1007   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1008   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1009    
1010   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1015  remove_blockdevices()
1015   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1016   IFS=§   IFS=§
1017    
1018   while read pathto posix   while read pathto posix user group
1019   do   do
1020   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1021    
# Line 840  remove_characterdevices() Line 1036  remove_characterdevices()
1036  {  {
1037   local pathto   local pathto
1038   local posix   local posix
1039     local user
1040     local group
1041   local IFS   local IFS
1042   local pcat   local pcat
1043   local pname   local pname
# Line 863  remove_characterdevices() Line 1061  remove_characterdevices()
1061   done   done
1062    
1063   # sanity checks; abort if not given   # sanity checks; abort if not given
1064   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1065   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1066   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1067   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1068   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1069    
1070   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1075  remove_characterdevices()
1075   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1076   IFS=§   IFS=§
1077    
1078   while read pathto posix   while read pathto posix user group
1079   do   do
1080   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1081    
# Line 891  remove_characterdevices() Line 1089  remove_characterdevices()
1089    
1090    
1091  ###################################################  ###################################################
1092    # function remove_fifos                           #
1093    # remove_fifos $PKGNAME                     #
1094    ###################################################
1095    remove_fifos()
1096    {
1097     local pathto
1098     local posix
1099     local user
1100     local group
1101     local IFS
1102     local pcat
1103     local pname
1104     local pver
1105     local pbuild
1106     local i
1107     local pfull
1108    
1109     IFS=$'\n'
1110    
1111     # very basic getops
1112     for i in $*
1113     do
1114     case $1 in
1115     --pcat|-c) shift; pcat="$1" ;;
1116     --pname|-n) shift; pname="$1" ;;
1117     --pver|-v) shift; pver="$1" ;;
1118     --pbuild|-b) shift; pbuild="$1" ;;
1119     esac
1120     shift
1121     done
1122    
1123     # sanity checks; abort if not given
1124     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1125     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1126     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1127     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1128     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1129    
1130     # check needed global vars
1131     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1132    
1133     # make it optional atm !!
1134     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1135     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1136    
1137     # sets fieldseperator to "§" instead of " "
1138     IFS=§
1139    
1140     while read pathto posix user group
1141     do
1142     [ -z "${pathto}" ] && continue
1143    
1144     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1145     rm "${MROOT}${pathto}"
1146     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1147    
1148     # very important: unsetting the '§' fieldseperator
1149     IFS=$'\n'
1150    }
1151    
1152    
1153    ###################################################
1154  # function remove_direcories                      #  # function remove_direcories                      #
1155  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1156  ###################################################  ###################################################
# Line 921  remove_directories() Line 1181  remove_directories()
1181   done   done
1182    
1183   # sanity checks; abort if not given   # sanity checks; abort if not given
1184   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1185   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1186   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1187   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1188   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1189    
1190   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1192  remove_directories()
1192    
1193   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1194    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1195   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1196   IFS=§   IFS=§
1197    
1198   while read pathto posix   # reversed order is mandatory !
1199     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1200   do   do
1201   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1202    
# Line 954  remove_directories() Line 1211  remove_directories()
1211   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1212   then   then
1213   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1214   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1215   continue   continue
1216   fi   fi
1217    
# Line 971  remove_directories() Line 1228  remove_directories()
1228   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1229   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1230   fi   fi
1231   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1232    
1233   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1234   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1238  remove_directories()
1238  ###################################################  ###################################################
1239  # function build_douninstall                      #  # function build_douninstall                      #
1240  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1241  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1242  ###################################################  ###################################################
1243  build_douninstall()  build_douninstall()
1244  {  {
# Line 1015  build_douninstall() Line 1272  build_douninstall()
1272   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1273   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1274    
1275   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1276   do   do
1277   remove_${i} \   remove_${i} \
1278   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1037  fetch_packages() Line 1294  fetch_packages()
1294   local opt   local opt
1295   local count_current   local count_current
1296   local count_total   local count_total
1297     local wget_opts
1298    
1299   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1300    
1301     # filter wget command if busybox was found
1302     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1303    
1304   # get count of total packages   # get count of total packages
1305   declare -i count_current=0   declare -i count_current=0
# Line 1085  fetch_packages() Line 1346  fetch_packages()
1346   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1347   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1348   wget \   wget \
1349   --passive-ftp \   ${wget_opts} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1350   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1351   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1352   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1353   then   then
1354   break   break
# Line 1113  syncmage() Line 1371  syncmage()
1371  {  {
1372   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1373   then   then
1374   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1375   fi   fi
1376    
1377   local i   local i
1378   for i in ${RSYNC}   for i in ${RSYNC}
1379   do   do
1380   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1381   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1382   then   then
1383   break   break
# Line 1142  syncmage() Line 1387  syncmage()
1387   done   done
1388    
1389   # clean up backup files (foo~)   # clean up backup files (foo~)
1390   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1391    
1392   # check if an newer mage version is available   # check if a newer mage version is available
1393   is_newer_mage_version_available   is_newer_mage_version_available
1394  }  }
1395    
1396    syncmage_tarball()
1397    {
1398     local latest_tarball
1399     local latest_md5
1400     local temp="$(mktemp -d)"
1401     local mirr mymirr
1402     local opt
1403     local tar_opts
1404     local wget_opts
1405    
1406     # try to get the md5 marked as latest on the server
1407     latest_md5="mage-latest.md5"
1408    
1409     # try to get the tarball marked as latest on the server
1410     latest_tarball="mage-latest.tar.bz2"
1411    
1412     # filter wget command if busybox was found
1413     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1414    
1415     for mirr in ${MIRRORS}
1416     do
1417     # path without distribution
1418     mymirr="${mirr%/*}"
1419    
1420     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1421     echo "fetching latest md5 from ${mymirr} ..."
1422     [[ ${VERBOSE} = off ]] && opt="--quiet"
1423     wget \
1424     ${wget_opts} \
1425     --directory-prefix=${temp} \
1426     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1427    
1428     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1429     echo "fetching latest tarball from ${mymirr} ..."
1430     wget \
1431     ${wget_opts} \
1432     --directory-prefix=${temp} \
1433     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1434     if [[ $? = 0 ]]
1435     then
1436     break
1437     else
1438     continue
1439     fi
1440     done
1441    
1442     if [[ -f ${temp}/${latest_tarball} ]]
1443     then
1444     # check md5
1445     if [[ ! -f ${temp}/${latest_md5} ]]
1446     then
1447     die "md5 is missing ... aborting"
1448     else
1449     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1450     echo -n "checking md5sum... "
1451     ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1452     fi
1453    
1454     if [[ -d ${MAGEDIR} ]]
1455     then
1456     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1457     echo "cleaning old mage-tree ${MAGEDIR}..."
1458     rm -rf ${MAGEDIR}
1459     fi
1460    
1461     if need_busybox_support tar
1462     then
1463     tar_opts="xjf"
1464     else
1465     tar_opts="xjmf"
1466     fi
1467    
1468     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1469     echo "updating mage-tree from tarball ..."
1470     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1471     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1472    
1473     if [[ -d ${temp} ]]
1474     then
1475     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1476     echo "cleaning temp-files ..."
1477     rm -rf ${temp}
1478     fi
1479    
1480     # check if a newer mage version is available
1481     is_newer_mage_version_available
1482     else
1483     die "Could not fetch the latest tarball ... aborting"
1484     fi
1485    }
1486    
1487  cleanpkg()  cleanpkg()
1488  {  {
1489   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1178  xtitleclean() Line 1514  xtitleclean()
1514  }  }
1515    
1516    
1517  # cuts full pathnames or versioniezed names down to basename  # cuts full pathnames or versionized names down to basename
1518  choppkgname()  choppkgname()
1519  {  {
1520   #we want this only if full name was used   #we want this only if full name was used
1521   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1522   then   then
1523   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1524   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1525   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1526    
1527   #cuts version number   #cuts version number
# Line 1218  pname2pcat() Line 1554  pname2pcat()
1554  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1555  check_stable_package()  check_stable_package()
1556  {  {
1557     # first check if this magefile is not blacklisted
1558     blacklisted "$1" || return 1
1559    
1560   local STATE   local STATE
1561   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1562    
1563   # state testing   # state testing
1564   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1565   then   then
1566   case ${STATE} in   case ${STATE} in
1567   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1570  check_stable_package()
1570   fi   fi
1571    
1572   # state unstable   # state unstable
1573   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1574   then   then
1575   case ${STATE} in   case ${STATE} in
1576   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1596  get_highest_magefile()
1596   local PNAME="$2"   local PNAME="$2"
1597   local magefile   local magefile
1598    
1599   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1600     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1601   do   do
1602     [[ -z ${magefile} ]] && continue
1603   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1604   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1605   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1606   then   then
1607   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1269  get_highest_magefile() Line 1610  get_highest_magefile()
1610   fi   fi
1611   done   done
1612    
  # stop here if HIGHEST_MAGEFILE is zero  
  # this package must be unstable or old  
  if [ -z "${HIGHEST_MAGEFILE}" ]  
  then  
  echo  
  echo -n "All packages named "  
  echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  
  echo -n " are marked "  
  echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  
  echo "."  
  echo "You need to declare USE_UNSTABLE=true to install this."  
  echo  
  echo "Example:"  
  echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  
  echo  
  echo "Be warned that these packages are not stable and may cause serious problems."  
  echo "You should know what you are doing, so don't complain about any damage."  
  echo  
  return 1  
  fi  
   
1613   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1614   return 0   return 0
1615  }  }
# Line 1304  get_highest_magefile() Line 1624  get_highest_magefile()
1624  #        1 - error                                #  #        1 - error                                #
1625  #        2 - protected                            #  #        2 - protected                            #
1626  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1627    #        4 - protected but ignored                #
1628  #                                                 #  #                                                 #
1629  ###################################################  ###################################################
1630  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1633  is_config_protected()
1633   local TEST   local TEST
1634   local PROTECTED   local PROTECTED
1635   local IFS   local IFS
1636     local i
1637     local x
1638    
1639   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1640    
1641   # file does not exist; it can be written   # file does not exist; it can be written
1642   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1643    
1644   # to be safe; it may be '§'   # to be safe; it may be '§'
1645   IFS=' '   IFS=' '
1646    
1647   # check ob in config protect   # check if config protected
1648   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1649   do   do
1650   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1651   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1652   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1653   then   then
1654   # setzen das es protected ist   # file is config proteced
1655   PROTECTED=TRUE   PROTECTED=TRUE
1656    
1657   # check ob nicht doch maskiert   # check if not masked
1658   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1659   do   do
1660   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1661   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1662   then   then
1663   PROTECTED=MASKED   PROTECTED=MASKED
1664   fi   fi
1665   done   done
1666    
1667     # check if not ignored
1668     for x in ${CONFIG_PROTECT_IGNORE}
1669     do
1670     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1671     if [[ ${TEST} != ${EXPFILE} ]]
1672     then
1673     PROTECTED=IGNORED
1674     fi
1675     done
1676   fi   fi
1677   done   done
1678    
# Line 1354  is_config_protected() Line 1687  is_config_protected()
1687   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1688   return 3   return 3
1689   ;;   ;;
1690     IGNORED)
1691     #echo "I'm protected, but ignored - keep me, del update"
1692     return 4
1693     ;;
1694   *)   *)
1695   #echo "delete me"   #echo "delete me"
1696   return 0   return 0
# Line 1371  is_config_protected() Line 1708  is_config_protected()
1708  ###################################################  ###################################################
1709  count_protected_files()  count_protected_files()
1710  {  {
1711   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1712     local dirname="${file%/*}"
1713     local filename="${file##*/}"
1714     local count
1715     local output
1716     local i
1717    
1718     declare -i count=0
1719    
1720     # check if there are already protected files
1721     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1722     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1723     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1724     do
1725     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1726     done
1727     (( count ++ ))
1728    
1729     # fill output up with zeros
1730     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1731     output="${output}${count}"
1732    
1733     echo "${output}"
1734  }  }
1735    
1736  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1747  get_uninstall_candidates()
1747   local list   local list
1748   local pcatdir   local pcatdir
1749   local protected   local protected
1750     local i
1751    
1752   # very basic getops   # very basic getops
1753   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1760  get_uninstall_candidates()
1760   shift   shift
1761   done   done
1762    
1763   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1764   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1765    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1766    
1767    
1768   # check needed global vars   # check needed global vars
1769   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1770    
1771   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1772   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1773    
1774   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1775   do   do
# Line 1493  virtuals_add() Line 1854  virtuals_add()
1854   local oldline   local oldline
1855   local line i   local line i
1856   local installed_file   local installed_file
1857     local OLDIFS
1858    
1859   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1860   then   then
1861   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1862   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1863   do   do
1864   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 1877  virtuals_add()
1877   # make a backup   # make a backup
1878   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1879    
1880     OLDIFS="${IFS}"
1881   IFS=$'\n'   IFS=$'\n'
1882   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1883   do   do
# Line 1526  virtuals_add() Line 1889  virtuals_add()
1889   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1890   fi   fi
1891   done   done
1892     # unset IFS
1893   #unset IFS   IFS="${OLDIFS}"
1894   else   else
1895   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1896   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1897   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1898   fi   fi
# Line 1539  virtuals_add() Line 1902  virtuals_add()
1902    
1903  #deletes pakages from virtual database  #deletes pakages from virtual database
1904  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1905  virtuals_del() {  virtuals_del()
1906    {
1907    
1908   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1909     local pkgname="$2"
1910   VIRTUAL_NAME=$1   local oldline
1911   PKG_NAME=$2   local method
1912     local line i x
1913   #first check if exists   local pkg_installed
1914   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1915    
1916     # first check if exists
1917     if virtuals_read ${virtualname}
1918   then   then
1919   #get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}   # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
1920   declare -i x=0   declare -i x=0
1921   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1922   do   do
1923   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1924   then   then
1925   PKG_INSTALLED=true   pkg_installed=true
1926   fi   fi
1927   ((x++))   ((x++))
1928   done   done
1929    
1930   #abort if not installed   # abort if not installed
1931   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1932   then   then
1933   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1934     echo "${pkgname} does not exists in ${virtualname}."
1935   return 0   return 0
1936   fi   fi
1937    
1938   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1939   then   then
1940   METHOD=update   method=update
1941   else   else
1942   METHOD=delall   method=delall
1943   fi   fi
1944    
1945   #get the complete line   # get the complete line
1946   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1947    
1948   #make a backup   # make a backup of the db
1949   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1950    
1951   #parse virtualdb   # parse virtualdb
1952     OLDIFS="${IFS}"
1953   IFS=$'\n'   IFS=$'\n'
1954   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1955   do   do
1956   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1957   then   then
1958   #delall or update?   #delall or update?
1959   case ${METHOD} in   case ${method} in
1960   update)   update)
1961   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1962   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1963   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1964     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1965   ;;   ;;
1966   delall)   delall)
1967   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1968   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1969     # continue; do not write anything
1970   continue   continue
1971   ;;   ;;
1972   esac   esac
# Line 1603  virtuals_del() { Line 1974  virtuals_del() {
1974   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1975   fi   fi
1976   done   done
1977   unset IFS   # unset IFS
1978     IFS="${OLDIFS}"
1979   else   else
1980   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1981     echo "${virtualname} does not exists in virtual database."
1982   fi   fi
1983  }  }
1984    
# Line 1637  minclude() Line 2010  minclude()
2010  {  {
2011   local i   local i
2012    
2013   if [ -n "$@" ]   if [[ -n $* ]]
2014   then   then
2015   for i in $@   for i in $*
2016   do   do
2017   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
2018   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1653  sminclude() Line 2026  sminclude()
2026  {  {
2027   local i   local i
2028    
2029   if [ -n "$@" ]   if [[ -n $* ]]
2030   then   then
2031   for i in $@   for i in $*
2032   do   do
2033   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2034   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2043  is_newer_mage_version_available()
2043   local newest_mage   local newest_mage
2044   local installed_mage   local installed_mage
2045    
2046   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2047   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2048    
2049   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2052  is_newer_mage_version_available()
2052   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2053   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2054   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2055   echo "or your current system installation may brake."   echo "or your current system installation may break."
2056   echo   echo
2057   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2058   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2324  get_value_from_magefile()
2324   local magefile="$2"   local magefile="$2"
2325   local value   local value
2326    
2327     [[ -z ${var} ]] && return 1
2328     [[ -z ${magefile} ]] && return 1
2329    
2330   # local all possible vars of a mage file   # local all possible vars of a mage file
2331   # to prevent bad issues   # to prevent bad issues
2332   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2337  get_value_from_magefile()
2337   local SDEPEND   local SDEPEND
2338   local PROVIDE   local PROVIDE
2339   local PKGTYPE   local PKGTYPE
2340     local MAGE_TARGETS
2341     local SPLIT_PACKAGE_BASE
2342   local preinstall   local preinstall
2343   local postinstall   local postinstall
2344     local preremove
2345     local postremove
2346    
2347   # sanity checks   # sanity checks
2348   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2352  get_value_from_magefile()
2352   source ${magefile}   source ${magefile}
2353   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2354   echo "${value}"   echo "${value}"
2355    
2356     # unset these functions
2357     unset -f preinstall
2358     unset -f postinstall
2359     unset -f preremove
2360     unset -f postremove
2361  }  }
2362    
2363  mage_install()  mage_install()
# Line 1988  mage_install() Line 2374  mage_install()
2374   local PKGTYPE   local PKGTYPE
2375   local preinstall   local preinstall
2376   local postinstall   local postinstall
2377     local preremove
2378     local postremove
2379    
2380   local pcat   local pcat
2381   local pname   local pname
# Line 1997  mage_install() Line 2385  mage_install()
2385   local count_current   local count_current
2386   local magefile   local magefile
2387   local src_install   local src_install
2388     local i
2389    
2390   # very basic getops   # very basic getops
2391   for i in $*   for i in $*
# Line 2070  mage_install() Line 2459  mage_install()
2459   echo B:${pbuild}   echo B:${pbuild}
2460   fi   fi
2461    
2462   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2463     then
2464     # basic svn compat
2465     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2466     then
2467     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2468     do
2469     smage2file="${i}"
2470     done
2471     else
2472     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2473     fi
2474    
2475     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2476     then
2477     # basic svn compat
2478     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2479     then
2480     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2481     do
2482     smage2file="${i}"
2483     done
2484     else
2485     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2486     fi
2487    
2488     else
2489     # basic svn compat
2490     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2491     then
2492     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2493     do
2494     smage2file="${i}"
2495     done
2496     else
2497     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2498     fi
2499     fi
2500    
2501   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2502   then   then
2503     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2504   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2505   else   else
2506   echo   echo
# Line 2086  mage_install() Line 2514  mage_install()
2514   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2515   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2516   then   then
2517   # show a verbose message on src-install   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
  if [[ ${src_install} = true ]]  
  then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "merging files: "  
  echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  
  echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"  
  fi  
2518   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2519   fi   fi
2520    
# Line 2149  mage_install() Line 2570  mage_install()
2570  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2571  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2572   echo "successfully installed."   echo "successfully installed."
2573    
2574     # unset these functions
2575     unset -f preinstall
2576     unset -f postinstall
2577     unset -f preremove
2578     unset -f postremove
2579  }  }
2580    
2581  md5sum_packages()  md5sum_packages()
# Line 2201  md5sum_packages() Line 2628  md5sum_packages()
2628   then   then
2629   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2630   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2631   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2632   else   else
2633   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2634   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2253  uninstall_packages() Line 2680  uninstall_packages()
2680   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2681   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2682   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2683   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2684   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2685   echo   echo
2686   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2687   echo "( Press [CTRL+C] to abort )"   then
2688   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2689   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2690   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2691   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2692   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2693   sleep 1   do
2694   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2695   echo   sleep 1
2696   echo   done
2697     echo
2698     echo
2699     fi
2700    
2701   for pkg in ${list}   for pkg in ${list}
2702   do   do
# Line 2304  mage_uninstall() Line 2734  mage_uninstall()
2734   local PKGTYPE   local PKGTYPE
2735   local preinstall   local preinstall
2736   local postinstall   local postinstall
2737     local preremove
2738     local postremove
2739    
2740   local pcat   local pcat
2741   local pname   local pname
# Line 2339  mage_uninstall() Line 2771  mage_uninstall()
2771   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2772   echo -n "removing: "   echo -n "removing: "
2773   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2774   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2775    
2776   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2777   source ${magefile}   source ${magefile}
2778    
2779   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2833  mage_uninstall()
2833  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2834  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2835   echo "successfully removed."   echo "successfully removed."
2836    
2837     # unset these functions
2838     unset -f preinstall
2839     unset -f postinstall
2840     unset -f preremove
2841     unset -f postremove
2842  }  }
2843    
2844  show_etc_update_mesg() {  show_etc_update_mesg()
2845    {
2846   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2847    
2848   echo   echo
# Line 2415  show_etc_update_mesg() { Line 2854  show_etc_update_mesg() {
2854   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
2855   echo   echo
2856  }  }
2857    
2858    pkgsearch()
2859    {
2860     local string="$1"
2861     local result
2862     local pkg
2863     local pcat
2864     local pname
2865     local magefile
2866     local pver
2867     local pbuild
2868     local state
2869     local descriptiom
2870     local homepage
2871     local i
2872     local all_installed
2873     local ipver
2874     local ipbuild
2875     local latest_available
2876     local depsfull
2877     local sdepsfull
2878     local deps
2879     local sdeps
2880     local dep
2881     local sign
2882    
2883     # only names no versions
2884     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2885     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2886    
2887     # nothing found
2888     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2889    
2890     for pkg in ${result}
2891     do
2892     # dirty, but does the job
2893     pcat="$(magename2pcat ${pkg}/foo)"
2894     pname="$(magename2pname ${pkg}-foo-foo)"
2895    
2896     # get highest version available
2897     magefile=$(get_highest_magefile ${pcat} ${pname})
2898    
2899     if [[ ! -z ${magefile} ]]
2900     then
2901     # now get all needed infos to print a nice output
2902     pver="$(magename2pver ${magefile})"
2903     pbuild="$(magename2pbuild ${magefile})"
2904     state="$(get_value_from_magefile STATE ${magefile})"
2905     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2906     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2907    
2908     # all installed
2909     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2910     do
2911     ipver="$(magename2pver ${i})"
2912     ipbuild="$(magename2pbuild ${i})"
2913    
2914     if [[ -z ${all_installed} ]]
2915     then
2916     all_installed="${ipver}-${ipbuild}"
2917     else
2918     all_installed="${all_installed} ${ipver}-${ipbuild}"
2919     fi
2920     done
2921     [[ -z ${all_installed} ]] && all_installed="none"
2922    
2923     case ${state} in
2924     stable) state=${COLGREEN}"[s] ";;
2925     testing) state=${COLYELLOW}"[t] ";;
2926     unstable) state=${COLRED}"[u] ";;
2927     old) state=${COLGRAY}"[o] ";;
2928     esac
2929    
2930     latest_available="${pver}-${pbuild}"
2931     else
2932     # package is masked
2933     state="${COLRED}[m] "
2934     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2935     fi
2936    
2937     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2938     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
2939    
2940     while read sign dep
2941     do
2942     case ${dep} in
2943     "") continue;;
2944     esac
2945    
2946     deps="${deps} $(basename ${dep%-*})"
2947     done << EOF
2948    ${depsfull}
2949    EOF
2950    
2951     while read sign dep
2952     do
2953     case ${dep} in
2954     "") continue;;
2955     esac
2956    
2957     sdeps="${sdeps} $(basename ${dep%-*})"
2958     done << EOF
2959    ${sdepsfull}
2960    EOF
2961    
2962     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2963     echo -e "      Latest available:   ${latest_available}"
2964     echo "      Installed versions: ${all_installed}"
2965     echo "      Description: ${description}"
2966     echo "      Homepage: ${homepage}"
2967     echo "      Depends: ${deps}"
2968     echo "      SDepends: ${sdeps}"
2969     echo
2970    
2971     unset pcat
2972     unset pname
2973     unset magefile
2974     unset pver
2975     unset pbuild
2976     unset state
2977     unset descriptiom
2978     unset homepage
2979     unset all_installed
2980     unset ipver
2981     unset ipbuild
2982     unset depsfull
2983     unset sdepsfull
2984     unset deps
2985     unset sdeps
2986     unset dep
2987     unset sign
2988     done
2989    }
2990    
2991    export_inherits()
2992    {
2993     local include="$1"
2994     shift
2995    
2996     while [ "$1" ]
2997     do
2998     local functions="$1"
2999    
3000     # sanity checks
3001     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3002     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3003    
3004     eval "${functions}() { ${include}_${functions} ; }"
3005    
3006     # debug
3007     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
3008    
3009     shift
3010     done
3011    }
3012    
3013    mlibdir()
3014    {
3015     local libdir=lib
3016     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3017    
3018     echo "${libdir}"
3019    }
3020    
3021    ## blacklisted ${magefile}
3022    blacklisted()
3023    {
3024     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3025    
3026     # compat
3027     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3028     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3029    
3030     # support both types for the moment
3031     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3032     then
3033     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3034     else
3035     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3036     fi
3037    
3038     # return 0 if the list not exist; nothin is masked
3039     [[ ! -f ${EXCLUDED} ]] && return 0
3040    
3041     local MAGEFILE="$1"
3042    
3043     local PCAT="$(magename2pcat ${MAGEFILE})"
3044     local PNAME="$(magename2pname ${MAGEFILE})"
3045     local PVER="$(magename2pver ${MAGEFILE})"
3046     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3047    
3048     local EXPCAT EXPNAME EXPVER EXPBUILD
3049     while read EXPCAT EXPNAME EXPVER EXPBUILD
3050     do
3051     # ignore spaces and comments
3052             case "${EXPCAT}" in
3053                     \#*|"") continue ;;
3054             esac
3055    
3056     # exclude full pver
3057     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3058     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3059     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3060     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3061     then
3062     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3063     fi
3064    
3065     # exclude pcat/pname only
3066     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3067     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3068     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3069     then
3070     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3071     fi
3072     done << EOF
3073    $( cat ${EXCLUDED}; echo)
3074    EOF
3075    
3076     return 0
3077    }
3078    
3079    # need_busybox_support ${cmd}
3080    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3081    need_busybox_support()
3082    {
3083     local cmd
3084     cmd="$1"
3085    
3086     if [[ -x /bin/busybox ]]
3087     then
3088     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3089     then
3090     # needs busybox support
3091     return 0
3092     fi
3093     fi
3094    
3095     # no busybox
3096     return 1
3097    }
3098    
3099    # busybox_filter_wget_options ${wget_opts}
3100    busybox_filter_wget_options()
3101    {
3102     local opts="$@"
3103     local i
3104     local fixed_opts
3105    
3106     if need_busybox_support wget
3107     then
3108     for i in ${opts}
3109     do
3110     # show only the allowed ones
3111     case ${i} in
3112     -c|--continue) fixed_opts+=" -c" ;;
3113     -s|--spider) fixed_opts+=" -s" ;;
3114     -q|--quiet) fixed_opts+=" -q" ;;
3115     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3116     --header) shift; fixed_opts+=" --header $1" ;;
3117     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3118     -P) shift; fixed_opts+=" -P $1" ;;
3119     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3120     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3121     # simply drop all other opts
3122     *) continue ;;
3123     esac
3124     done
3125    
3126     echo "${fixed_opts}"
3127     else
3128     echo "${opts}"
3129     fi
3130    }
3131    
3132    have_root_privileges()
3133    {
3134     local retval
3135    
3136     if [[ $(id -u) = 0 ]]
3137     then
3138     retval=0
3139     else
3140     retval=1
3141     fi
3142    
3143     return ${retval}
3144    }

Legend:
Removed from v.226  
changed lines
  Added in v.1548