Magellan Linux

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

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

revision 237 by niro, Sat Sep 10 13:35:55 2005 UTC revision 1648 by niro, Fri Jan 13 20:51:18 2012 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.2 2005-09-10 13:35:55 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 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49    
50     # very basic getops
51     for i in $*
52     do
53     case $1 in
54     --rundir|-r) shift; rundir="$1" ;;
55     --file|-f) shift; file="$1" ;;
56     --method|-m) shift; method="$1" ;;
57     esac
58     shift
59     done
60    
61     # sanity checks
62     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
63     [[ -z ${file} ]] && die "mchecksum(): file missing"
64     [[ -z ${method} ]] && die "mchecksum(): method missing"
65    
66     case ${method} in
67     md5) cmd="md5sum" ;;
68     sha256) cmd="sha256sum" ;;
69     *) die "mchecksum(): unknown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     ${cmd} -c ${file} &> /dev/null
76     retval="$?"
77     popd &> /dev/null
78     else
79     retval=1
80     fi
81    
82     return "${retval}"
83    }
84    
85  unpack_packages()  unpack_packages()
86  {  {
87   local list="$@"   local list="$@"
# Line 23  unpack_packages() Line 90  unpack_packages()
90   local pkgtype   local pkgtype
91   local count_current   local count_current
92   local count_total   local count_total
93     local tar_opts
94    
95   # get count of total packages   # get count of total packages
96   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 122  unpack_packages()
122   continue   continue
123   fi   fi
124    
125     # busybox?
126     if need_busybox_support tar
127     then
128     tar_opts="xjf"
129     else
130     tar_opts="xjmf"
131     fi
132    
133   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
134   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
135   done   done
136    
137   # add a crlf for a better view   # add a crlf for a better view
# Line 130  install_directories() Line 206  install_directories()
206   while read pathto posix user group   while read pathto posix user group
207   do   do
208   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
209   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
210    
211   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
212   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 273  install_files()
273   is_config_protected "${pathto}"   is_config_protected "${pathto}"
274   retval="$?"   retval="$?"
275    
276   # 0 - not protected        #   # 0 - not protected         #
277   # 1 - error                #   # 1 - error                 #
278   # 2 - protected            #   # 2 - protected             #
279   # 3 - protected but masked #   # 3 - protected but masked  #
280     # 4 - protected but ignored #
281    
282   case ${retval} in   case ${retval} in
283   # file is not protected - (over)write it   # file is not protected - (over)write it
284   0|3)   0|3)
285   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
286   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
287   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
288   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 294  install_files()
294   "${user}" \   "${user}" \
295   "${group}" \   "${group}" \
296   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
297   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
298   "${md5sum}"   "${md5sum}"
299   ;;   ;;
300    
301   # file is protected, write backup file   # file is protected, write backup file
302   2)   2)
303   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
304   then   then
305   echo -en "${COLRED}"   echo -en "${COLRED}"
306   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 321  install_files()
321   "${user}" \   "${user}" \
322   "${group}" \   "${group}" \
323   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
324   "${dest_protected}")" \   "${dest_protected}")" \
325   "${md5sum}"   "${md5sum}"
326    
327   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
328   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
329   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
330   ;;   ;;
331    
332     # file is protected but ignored, delete the update/do nothing
333     4)
334     if mqueryfeature "verbose"
335     then
336     echo -en "${COLRED}"
337     echo -n "! ignr "
338     echo -en "${COLDEFAULT}"
339     echo " === FILE: ${MROOT}${pathto}"
340     fi
341     # simply do nothing here - only fix mtime
342     fix_descriptor ${pkgname}/.files \
343     "${pathto}" \
344     "${posix}" \
345     "${user}" \
346     "${group}" \
347     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348     "${MROOT}${pathto}")" \
349     "${md5sum}"
350     ;;
351   esac   esac
352   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
353    
# Line 294  install_symlinks() Line 390  install_symlinks()
390   while read pathto posix link mtime   while read pathto posix link mtime
391   do   do
392   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
393   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
394    
395   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
396    
397   # fix mtime and db  # # fix mtime and db
398   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
399   "${pathto}" \  # "${pathto}" \
400   "${posix}" \  # "${posix}" \
401   "${link}" \  # "${link}" \
402   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
403   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
404    
405   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
406    
407   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
408   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
409   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
410    
411   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
412   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 422  install_blockdevices()
422   local pkgname="$1"   local pkgname="$1"
423   local pathto   local pathto
424   local posix   local posix
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 339  install_blockdevices() Line 437  install_blockdevices()
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>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
444    
445   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
446     # make it optional atm !!
447     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
448     then
449     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
450     fi
451   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
452    
453   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 464  install_characterdevices()
464   local pkgname="$1"   local pkgname="$1"
465   local pathto   local pathto
466   local posix   local posix
467     local major
468     local minor
469     local user
470     local group
471   local IFS   local IFS
472    
473   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 481  install_characterdevices()
481   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
482   IFS=§   IFS=§
483    
484   while read pathto posix   while read pathto posix major minor user group
485   do   do
486   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
487   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
488    
489   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
490    
491     # make it optional atm !!
492     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
493     then
494     chown "${user}:${group}" "${MROOT}${pathto}"
495     fi
496   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
497    
498   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
499   IFS=$'\n'   IFS=$'\n'
500  }  }
501    
502    ###################################################
503    # function install_fifos                          #
504    # install_fifos $PKGNAME                    #
505    ###################################################
506    install_fifos()
507    {
508     local pkgname="$1"
509     local pathto
510     local posix
511     local user
512     local group
513     local IFS
514    
515     # sanity checks; abort if not given
516     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
517    
518     # check needed global vars
519     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
520    
521     # make it optional atm !!
522     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
523     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
524    
525     # sets fieldseperator to "§" instead of " "
526     IFS=§
527    
528     while read pathto posix user group
529     do
530     [ -z "${pathto}" ] && continue
531     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
532    
533     mkfifo -m "${posix}" "${MROOT}${pathto}"
534     chown "${user}:${group}" "${MROOT}${pathto}"
535     done < ${BUILDDIR}/${pkgname}/.fifo
536    
537     # very important: unsetting the '§' fieldseperator
538     IFS=$'\n'
539    }
540    
541    
542  ###################################################  ###################################################
543  # function build_doinstall                        #  # function build_doinstall                        #
544  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
545  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
546  ###################################################  ###################################################
547  build_doinstall()  build_doinstall()
548  {  {
# Line 398  build_doinstall() Line 550  build_doinstall()
550    
551   # sanity checks; abort if not given   # sanity checks; abort if not given
552   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
553    
554   # this is only a wrapper   # this is only a wrapper
555    
556   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 565  build_doinstall()
565   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
566   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
567   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
568     install_fifos ${pkgname} || die "install fifos ${pkgname}"
569  }  }
570    
571    
# Line 432  install_database_entry() Line 585  install_database_entry()
585   local magefile   local magefile
586   local dbrecorddir   local dbrecorddir
587   local provide   local provide
588     local i
589    
590   # very basic getops   # very basic getops
591   for i in $*   for i in $*
# Line 473  install_database_entry() Line 627  install_database_entry()
627    
628   # create fake file descriptors   # create fake file descriptors
629   # used by virtual and source packages   # used by virtual and source packages
630   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
631   do   do
632   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
633   done   done
# Line 492  install_database_entry() Line 645  install_database_entry()
645    
646   # normal packages needs these files   # normal packages needs these files
647   local i   local i
648   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
649   do   do
650   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
651   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
652     then
653     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
654     fi
655   done   done
656   ;;   ;;
657   esac   esac
# Line 504  install_database_entry() Line 660  install_database_entry()
660   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
661   if [ -n "${provide}" ]   if [ -n "${provide}" ]
662   then   then
663   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
664     do
665     virtuals_add "${i}" "${pcat}/${pname}"
666     done
667   fi   fi
668  }  }
669    
# Line 523  remove_database_entry() Line 682  remove_database_entry()
682   local magefile   local magefile
683   local dbrecorddir   local dbrecorddir
684   local provide   local provide
685     local i
686    
687   # very basic getops   # very basic getops
688   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 712  remove_database_entry()
712   # abort if mage file not exists   # abort if mage file not exists
713   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
714    
715   # first unregister virtuals   # remove virtuals only if no other exist
716   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
717   then   then
718   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
719     provide="$(get_value_from_magefile PROVIDE ${magefile})"
720     if [ -n "${provide}" ]
721     then
722     for i in ${provide}
723     do
724     virtuals_del "${i}" "${pcat}/${pname}"
725     done
726     fi
727   fi   fi
728    
729   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 733  remove_database_entry()
733   fi   fi
734  }  }
735    
736    # get the number of installed packages
737    count_installed_pkgs()
738    {
739     local pcat
740     local pname
741     local pkg
742     local i
743    
744     # very basic getops
745     for i in $*
746     do
747     case $1 in
748     --pcat|-c) shift; pcat="$1" ;;
749     --pname|-n) shift; pname="$1" ;;
750     esac
751     shift
752     done
753    
754     # sanity checks; abort if not given
755     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
756     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
757    
758     declare -i i=0
759     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
760     do
761     (( i++ ))
762     #echo "$i ${pkg}"
763     done
764    
765     # return the value
766     echo "${i}"
767    }
768    
769    
770  ###################################################  ###################################################
771  # function compare_mtime                          #  # function compare_mtime                          #
# Line 662  remove_symlinks() Line 862  remove_symlinks()
862   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
863   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
864   then   then
865   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
866   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
867   continue   continue
868   fi   fi
# Line 674  remove_symlinks() Line 874  remove_symlinks()
874   # 1=keep me   #   # 1=keep me   #
875   case ${retval} in   case ${retval} in
876   0)   0)
877   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
878   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
879   ;;   ;;
880    
881   1)   1)
882   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
883   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
884   ;;   ;;
885   esac   esac
# Line 726  remove_files() Line 926  remove_files()
926   done   done
927    
928   # sanity checks; abort if not given   # sanity checks; abort if not given
929   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
930   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
931   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
932   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
933   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
934    
935   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 944  remove_files()
944   do   do
945   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
946    
947   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
948   then   then
949   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
950   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
951   continue   continue
952   fi   fi
# Line 758  remove_files() Line 958  remove_files()
958   # 1=keep me   #   # 1=keep me   #
959   case ${retval} in   case ${retval} in
960   0)   0)
961   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
962   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
963   ;;   is_config_protected "${pathto}"
964     retval="$?"
965    
966     # 0 - not protected         #
967     # 1 - error                 #
968     # 2 - protected             #
969     # 3 - protected but masked  #
970     # 4 - protected but ignored #
971    
972     case ${retval} in
973     # file is not protected - delete it
974     0|3)
975     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
976     rm "${MROOT}${pathto}"
977     ;;
978    
979     # file is protected, do not delete
980     2)
981     if mqueryfeature "verbose"
982     then
983     echo -en "${COLRED}"
984     echo -n "! prot "
985     echo -en "${COLDEFAULT}"
986     echo " === FILE: ${MROOT}${pathto}"
987     fi
988     ;;
989    
990     # file is protected but ignored, delete the update/do nothing
991     4)
992     if mqueryfeature "verbose"
993     then
994     echo -en "${COLRED}"
995     echo -n "! ignr "
996     echo -en "${COLDEFAULT}"
997     echo " === FILE: ${MROOT}${pathto}"
998     fi
999     # simply do nothing here
1000     ;;
1001     esac
1002     ;;
1003   1)   1)
1004   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1005   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1006   ;;   ;;
1007   esac   esac
# Line 782  remove_blockdevices() Line 1020  remove_blockdevices()
1020  {  {
1021   local pathto   local pathto
1022   local posix   local posix
1023     local user
1024     local group
1025   local IFS   local IFS
1026   local pcat   local pcat
1027   local pname   local pname
# Line 805  remove_blockdevices() Line 1045  remove_blockdevices()
1045   done   done
1046    
1047   # sanity checks; abort if not given   # sanity checks; abort if not given
1048   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1049   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1050   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1051   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1052   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1053    
1054   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1059  remove_blockdevices()
1059   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1060   IFS=§   IFS=§
1061    
1062   while read pathto posix   while read pathto posix user group
1063   do   do
1064   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1065    
1066   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1067   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1068   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1069    
# Line 840  remove_characterdevices() Line 1080  remove_characterdevices()
1080  {  {
1081   local pathto   local pathto
1082   local posix   local posix
1083     local user
1084     local group
1085   local IFS   local IFS
1086   local pcat   local pcat
1087   local pname   local pname
# Line 863  remove_characterdevices() Line 1105  remove_characterdevices()
1105   done   done
1106    
1107   # sanity checks; abort if not given   # sanity checks; abort if not given
1108   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1109   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1110   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1111   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1112   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1113    
1114   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1119  remove_characterdevices()
1119   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1120   IFS=§   IFS=§
1121    
1122   while read pathto posix   while read pathto posix user group
1123   do   do
1124   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1125    
1126   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1127   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1128   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1129    
# Line 891  remove_characterdevices() Line 1133  remove_characterdevices()
1133    
1134    
1135  ###################################################  ###################################################
1136    # function remove_fifos                           #
1137    # remove_fifos $PKGNAME                     #
1138    ###################################################
1139    remove_fifos()
1140    {
1141     local pathto
1142     local posix
1143     local user
1144     local group
1145     local IFS
1146     local pcat
1147     local pname
1148     local pver
1149     local pbuild
1150     local i
1151     local pfull
1152    
1153     IFS=$'\n'
1154    
1155     # very basic getops
1156     for i in $*
1157     do
1158     case $1 in
1159     --pcat|-c) shift; pcat="$1" ;;
1160     --pname|-n) shift; pname="$1" ;;
1161     --pver|-v) shift; pver="$1" ;;
1162     --pbuild|-b) shift; pbuild="$1" ;;
1163     esac
1164     shift
1165     done
1166    
1167     # sanity checks; abort if not given
1168     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1169     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1170     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1171     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1172     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1173    
1174     # check needed global vars
1175     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1176    
1177     # make it optional atm !!
1178     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1179     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1180    
1181     # sets fieldseperator to "§" instead of " "
1182     IFS=§
1183    
1184     while read pathto posix user group
1185     do
1186     [ -z "${pathto}" ] && continue
1187    
1188     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1189     rm "${MROOT}${pathto}"
1190     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1191    
1192     # very important: unsetting the '§' fieldseperator
1193     IFS=$'\n'
1194    }
1195    
1196    
1197    ###################################################
1198  # function remove_direcories                      #  # function remove_direcories                      #
1199  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1200  ###################################################  ###################################################
# Line 921  remove_directories() Line 1225  remove_directories()
1225   done   done
1226    
1227   # sanity checks; abort if not given   # sanity checks; abort if not given
1228   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1229   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1230   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1231   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1232   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1233    
1234   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1236  remove_directories()
1236    
1237   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1238    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1239   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1240   IFS=§   IFS=§
1241    
1242   while read pathto posix   # reversed order is mandatory !
1243     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1244   do   do
1245   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1246    
1247   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1248   then   then
1249   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1250   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1251   continue   continue
1252   fi   fi
# Line 953  remove_directories() Line 1254  remove_directories()
1254   # exclude .keep directories   # exclude .keep directories
1255   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1256   then   then
1257   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1258   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1259   continue   continue
1260   fi   fi
1261    
# Line 966  remove_directories() Line 1267  remove_directories()
1267    
1268   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1269   then   then
1270   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1271   else   else
1272   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1273   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1274   fi   fi
1275   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1276    
1277   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1278   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1282  remove_directories()
1282  ###################################################  ###################################################
1283  # function build_douninstall                      #  # function build_douninstall                      #
1284  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1285  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1286  ###################################################  ###################################################
1287  build_douninstall()  build_douninstall()
1288  {  {
# Line 1015  build_douninstall() Line 1316  build_douninstall()
1316   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1317   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1318    
1319   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1320   do   do
1321   remove_${i} \   remove_${i} \
1322   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1026  build_douninstall() Line 1327  build_douninstall()
1327   done   done
1328  }  }
1329    
1330    # convertmirrors [uri]
1331    convertmirrors()
1332    {
1333     local uri="$1"
1334     local scheme
1335     local mirror
1336     local mirrors
1337     local addon
1338     local real_uri
1339     local output
1340    
1341     # needs
1342     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1343     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1344     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1345     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1346     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1347    
1348     # check known uri schemes
1349     case ${uri} in
1350     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1351     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1352     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1353     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1354     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1355     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1356     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1357     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1358     esac
1359    
1360     if [[ ! -z ${mirrors} ]]
1361     then
1362     for mirror in ${mirrors}
1363     do
1364     # add a whitespace to the output
1365     [[ -z ${output} ]] || output+=" "
1366     output+="${mirror}${addon}/${uri/${scheme}/}"
1367     done
1368     else
1369     output="${uri}"
1370     fi
1371    
1372     echo "${output}"
1373    }
1374    
1375    mdownload()
1376    {
1377     local i
1378     local uri
1379     local real_uris
1380     local mirror
1381     local outputfile
1382     local outputdir
1383     local retval
1384     local wget_opts
1385    
1386     # very basic getops
1387     for i in $*
1388     do
1389     case $1 in
1390     --uri|-u) shift; uri="$1" ;;
1391     --dir|-d) shift; outputdir="$1" ;;
1392     esac
1393     shift
1394     done
1395    
1396     # sanity checks; abort if not given
1397     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1398     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1399    
1400     # convert mirrored uris to the real ones
1401     real_uris="$(convertmirrors ${uri})"
1402    
1403     # verbose or not
1404     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1405    
1406     # filter wget options if busybox was found
1407     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1408    
1409     # create outputdir
1410     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1411    
1412     for mirror in ${real_uris}
1413     do
1414     # get the name of the output file
1415     outputfile="${mirror##*/}"
1416    
1417     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1418     retval="$?"
1419     if [[ ${retval} = 0 ]]
1420     then
1421     break
1422     else
1423     continue
1424     fi
1425     done
1426    
1427     # return wget retval
1428     return "${retval}"
1429    }
1430    
1431  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1432  fetch_packages()  fetch_packages()
1433  {  {
1434     local i
1435   local list="$@"   local list="$@"
1436   local pkg   local pkg
1437   local mirr   local mirr
# Line 1037  fetch_packages() Line 1440  fetch_packages()
1440   local opt   local opt
1441   local count_current   local count_current
1442   local count_total   local count_total
1443     local wget_opts
1444    
1445   [ -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}."
1446    
1447     # filter wget command if busybox was found
1448     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1449    
1450   # get count of total packages   # get count of total packages
1451   declare -i count_current=0   declare -i count_current=0
# Line 1078  fetch_packages() Line 1485  fetch_packages()
1485   continue   continue
1486   fi   fi
1487    
1488   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1489   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1490   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  --passive-ftp \  
  --tries 3 \  
  --continue \  
  --progress bar \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/packages/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
1491   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1492   then   then
1493   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1494   fi   fi
1495   done   done
1496    
# Line 1113  syncmage() Line 1502  syncmage()
1502  {  {
1503   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1504   then   then
1505   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1506   fi   fi
1507    
1508   local i   local i
1509   for i in ${RSYNC}   for i in ${RSYNC}
1510   do   do
1511   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
1512   --recursive \   if [[ $? = 0 ]]
1513   --links \   then
1514   --perms \   break
1515   --times \   else
1516   --devices \   continue
1517   --timeout=600 \   fi
1518   --verbose \   done
1519   --compress \  
1520   --progress \   # clean up backup files (foo~)
1521   --stats \   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1522   --delete \  
1523   --delete-after \   # check if a newer mage version is available
1524   ${i} ${MAGEDIR}   is_newer_mage_version_available
1525    }
1526    
1527    syncmage_tarball()
1528    {
1529     local latest_tarball
1530     local latest_md5
1531     local temp="$(mktemp -d)"
1532     local mirr mymirr
1533     local opt
1534     local tar_opts
1535     local wget_opts
1536    
1537     # try to get the md5 marked as latest on the server
1538     latest_md5="mage-latest.md5"
1539    
1540     # try to get the tarball marked as latest on the server
1541     latest_tarball="mage-latest.tar.bz2"
1542    
1543     # filter wget command if busybox was found
1544     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1545    
1546     for mirr in ${MIRRORS}
1547     do
1548     # path without distribution
1549     mymirr="${mirr%/*}"
1550    
1551     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1552     echo "fetching latest md5 from ${mymirr} ..."
1553     mqueryfeature "!verbose" && opt="--quiet"
1554     wget \
1555     ${wget_opts} \
1556     --directory-prefix=${temp} \
1557     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1558    
1559     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1560     echo "fetching latest tarball from ${mymirr} ..."
1561     wget \
1562     ${wget_opts} \
1563     --directory-prefix=${temp} \
1564     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1565   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1566   then   then
1567   break   break
# Line 1141  syncmage() Line 1570  syncmage()
1570   fi   fi
1571   done   done
1572    
1573   # clean up backup files (foo~)   if [[ -f ${temp}/${latest_tarball} ]]
1574   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   then
1575     # check md5
1576     if [[ ! -f ${temp}/${latest_md5} ]]
1577     then
1578     die "md5 is missing ... aborting"
1579     else
1580     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1581     echo -n "checking md5sum... "
1582     ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1583     fi
1584    
1585   # check if an newer mage version is available   if [[ -d ${MAGEDIR} ]]
1586   is_newer_mage_version_available   then
1587     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1588     echo "cleaning old mage-tree ${MAGEDIR}..."
1589     rm -rf ${MAGEDIR}
1590     fi
1591    
1592     if need_busybox_support tar
1593     then
1594     tar_opts="xjf"
1595     else
1596     tar_opts="xjmf"
1597     fi
1598    
1599     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1600     echo "updating mage-tree from tarball ..."
1601     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1602     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1603    
1604     if [[ -d ${temp} ]]
1605     then
1606     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1607     echo "cleaning temp-files ..."
1608     rm -rf ${temp}
1609     fi
1610    
1611     # check if a newer mage version is available
1612     is_newer_mage_version_available
1613     else
1614     die "Could not fetch the latest tarball ... aborting"
1615     fi
1616  }  }
1617    
1618  cleanpkg()  cleanpkg()
# Line 1178  xtitleclean() Line 1645  xtitleclean()
1645  }  }
1646    
1647    
1648  # cuts full pathnames or versioniezed names down to basename  # cuts full pathnames or versionized names down to basename
1649  choppkgname()  choppkgname()
1650  {  {
1651   #we want this only if full name was used   #we want this only if full name was used
1652   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1653   then   then
1654   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1655   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1656   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1657    
1658   #cuts version number   #cuts version number
# Line 1218  pname2pcat() Line 1685  pname2pcat()
1685  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1686  check_stable_package()  check_stable_package()
1687  {  {
1688     # first check if this magefile is not blacklisted
1689     blacklisted "$1" || return 1
1690    
1691   local STATE   local STATE
1692   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1693    
1694   # state testing   # state testing
1695   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1696   then   then
1697   case ${STATE} in   case ${STATE} in
1698   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1701  check_stable_package()
1701   fi   fi
1702    
1703   # state unstable   # state unstable
1704   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1705   then   then
1706   case ${STATE} in   case ${STATE} in
1707   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1727  get_highest_magefile()
1727   local PNAME="$2"   local PNAME="$2"
1728   local magefile   local magefile
1729    
1730   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1731     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1732   do   do
1733     [[ -z ${magefile} ]] && continue
1734   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1735   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1736   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1737   then   then
1738   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1739   #for debug only   #for debug only
1740   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1741   fi   fi
1742   done   done
1743    
  # 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  
   
1744   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1745   return 0   return 0
1746  }  }
# Line 1304  get_highest_magefile() Line 1755  get_highest_magefile()
1755  #        1 - error                                #  #        1 - error                                #
1756  #        2 - protected                            #  #        2 - protected                            #
1757  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1758    #        4 - protected but ignored                #
1759  #                                                 #  #                                                 #
1760  ###################################################  ###################################################
1761  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1764  is_config_protected()
1764   local TEST   local TEST
1765   local PROTECTED   local PROTECTED
1766   local IFS   local IFS
1767     local i
1768     local x
1769    
1770   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1771    
1772   # file does not exist; it can be written   # file does not exist; it can be written
1773   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1774    
1775   # to be safe; it may be '§'   # to be safe; it may be '§'
1776   IFS=' '   IFS=' '
1777    
1778   # check ob in config protect   # check if config protected
1779   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1780   do   do
1781   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1782   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1783   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1784   then   then
1785   # setzen das es protected ist   # file is config proteced
1786   PROTECTED=TRUE   PROTECTED=TRUE
1787    
1788   # check ob nicht doch maskiert   # check if not masked
1789   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1790   do   do
1791   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1792   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1793   then   then
1794   PROTECTED=MASKED   PROTECTED=MASKED
1795   fi   fi
1796   done   done
1797    
1798     # check if not ignored
1799     for x in ${CONFIG_PROTECT_IGNORE}
1800     do
1801     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1802     if [[ ${TEST} != ${EXPFILE} ]]
1803     then
1804     PROTECTED=IGNORED
1805     fi
1806     done
1807   fi   fi
1808   done   done
1809    
# Line 1354  is_config_protected() Line 1818  is_config_protected()
1818   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1819   return 3   return 3
1820   ;;   ;;
1821     IGNORED)
1822     #echo "I'm protected, but ignored - keep me, del update"
1823     return 4
1824     ;;
1825   *)   *)
1826   #echo "delete me"   #echo "delete me"
1827   return 0   return 0
# Line 1371  is_config_protected() Line 1839  is_config_protected()
1839  ###################################################  ###################################################
1840  count_protected_files()  count_protected_files()
1841  {  {
1842   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1843     local dirname="${file%/*}"
1844     local filename="${file##*/}"
1845     local count
1846     local output
1847     local i
1848    
1849     declare -i count=0
1850    
1851     # check if there are already protected files
1852     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1853     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1854     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1855     do
1856     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1857     done
1858     (( count ++ ))
1859    
1860     # fill output up with zeros
1861     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1862     output="${output}${count}"
1863    
1864     echo "${output}"
1865  }  }
1866    
1867  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1878  get_uninstall_candidates()
1878   local list   local list
1879   local pcatdir   local pcatdir
1880   local protected   local protected
1881     local i
1882    
1883   # very basic getops   # very basic getops
1884   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1891  get_uninstall_candidates()
1891   shift   shift
1892   done   done
1893    
1894   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1895   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1896    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1897    
1898    
1899   # check needed global vars   # check needed global vars
1900   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1901    
1902   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1903   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1904    
1905   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1906   do   do
# Line 1493  virtuals_add() Line 1985  virtuals_add()
1985   local oldline   local oldline
1986   local line i   local line i
1987   local installed_file   local installed_file
1988     local OLDIFS
1989    
1990   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1991   then   then
1992   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1993   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1994   do   do
1995   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2008  virtuals_add()
2008   # make a backup   # make a backup
2009   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2010    
2011     OLDIFS="${IFS}"
2012   IFS=$'\n'   IFS=$'\n'
2013   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2014   do   do
# Line 1526  virtuals_add() Line 2020  virtuals_add()
2020   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2021   fi   fi
2022   done   done
2023     # unset IFS
2024   #unset IFS   IFS="${OLDIFS}"
2025   else   else
2026   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2027   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2028   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2029   fi   fi
# Line 1539  virtuals_add() Line 2033  virtuals_add()
2033    
2034  #deletes pakages from virtual database  #deletes pakages from virtual database
2035  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2036  virtuals_del() {  virtuals_del()
2037    {
2038    
2039   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2040     local pkgname="$2"
2041   VIRTUAL_NAME=$1   local oldline
2042   PKG_NAME=$2   local method
2043     local line i x
2044   #first check if exists   local pkg_installed
2045   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2046    
2047     # first check if exists
2048     if virtuals_read ${virtualname}
2049   then   then
2050   #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}
2051   declare -i x=0   declare -i x=0
2052   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2053   do   do
2054   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2055   then   then
2056   PKG_INSTALLED=true   pkg_installed=true
2057   fi   fi
2058   ((x++))   ((x++))
2059   done   done
2060    
2061   #abort if not installed   # abort if not installed
2062   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2063   then   then
2064   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2065     echo "${pkgname} does not exists in ${virtualname}."
2066   return 0   return 0
2067   fi   fi
2068    
2069   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2070   then   then
2071   METHOD=update   method=update
2072   else   else
2073   METHOD=delall   method=delall
2074   fi   fi
2075    
2076   #get the complete line   # get the complete line
2077   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2078    
2079   #make a backup   # make a backup of the db
2080   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2081    
2082   #parse virtualdb   # parse virtualdb
2083     OLDIFS="${IFS}"
2084   IFS=$'\n'   IFS=$'\n'
2085   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2086   do   do
2087   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2088   then   then
2089   #delall or update?   #delall or update?
2090   case ${METHOD} in   case ${method} in
2091   update)   update)
2092   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2093   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2094   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2095     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2096   ;;   ;;
2097   delall)   delall)
2098   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2099   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2100     # continue; do not write anything
2101   continue   continue
2102   ;;   ;;
2103   esac   esac
# Line 1603  virtuals_del() { Line 2105  virtuals_del() {
2105   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2106   fi   fi
2107   done   done
2108   unset IFS   # unset IFS
2109     IFS="${OLDIFS}"
2110   else   else
2111   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2112     echo "${virtualname} does not exists in virtual database."
2113   fi   fi
2114  }  }
2115    
# Line 1637  minclude() Line 2141  minclude()
2141  {  {
2142   local i   local i
2143    
2144   if [ -n "$@" ]   if [[ -n $* ]]
2145   then   then
2146   for i in $@   for i in $*
2147   do   do
2148   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2149   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2150   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2151   done   done
2152   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2153   fi   fi
2154  }  }
2155    
# Line 1653  sminclude() Line 2157  sminclude()
2157  {  {
2158   local i   local i
2159    
2160   if [ -n "$@" ]   if [[ -n $* ]]
2161   then   then
2162   for i in $@   for i in $*
2163   do   do
2164   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2165   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2174  is_newer_mage_version_available()
2174   local newest_mage   local newest_mage
2175   local installed_mage   local installed_mage
2176    
2177   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2178   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2179    
2180   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2183  is_newer_mage_version_available()
2183   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2184   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2185   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2186   echo "or your current system installation may brake."   echo "or your current system installation may break."
2187   echo   echo
2188   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2189   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2455  get_value_from_magefile()
2455   local magefile="$2"   local magefile="$2"
2456   local value   local value
2457    
2458     [[ -z ${var} ]] && return 1
2459     [[ -z ${magefile} ]] && return 1
2460    
2461   # local all possible vars of a mage file   # local all possible vars of a mage file
2462   # to prevent bad issues   # to prevent bad issues
2463   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2468  get_value_from_magefile()
2468   local SDEPEND   local SDEPEND
2469   local PROVIDE   local PROVIDE
2470   local PKGTYPE   local PKGTYPE
2471     local MAGE_TARGETS
2472     local SPLIT_PACKAGE_BASE
2473   local preinstall   local preinstall
2474   local postinstall   local postinstall
2475     local preremove
2476     local postremove
2477    
2478   # sanity checks   # sanity checks
2479   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2483  get_value_from_magefile()
2483   source ${magefile}   source ${magefile}
2484   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2485   echo "${value}"   echo "${value}"
2486    
2487     # unset these functions
2488     unset -f preinstall
2489     unset -f postinstall
2490     unset -f preremove
2491     unset -f postremove
2492  }  }
2493    
2494  mage_install()  mage_install()
# Line 1988  mage_install() Line 2505  mage_install()
2505   local PKGTYPE   local PKGTYPE
2506   local preinstall   local preinstall
2507   local postinstall   local postinstall
2508     local preremove
2509     local postremove
2510    
2511   local pcat   local pcat
2512   local pname   local pname
# Line 1997  mage_install() Line 2516  mage_install()
2516   local count_current   local count_current
2517   local magefile   local magefile
2518   local src_install   local src_install
2519     local i
2520    
2521   # very basic getops   # very basic getops
2522   for i in $*   for i in $*
# Line 2070  mage_install() Line 2590  mage_install()
2590   echo B:${pbuild}   echo B:${pbuild}
2591   fi   fi
2592    
2593   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2594     then
2595     # basic svn compat
2596     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2597     then
2598     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2599     do
2600     smage2file="${i}"
2601     done
2602     else
2603     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2604     fi
2605    
2606     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2607     then
2608     # basic svn compat
2609     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2610     then
2611     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2612     do
2613     smage2file="${i}"
2614     done
2615     else
2616     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2617     fi
2618    
2619     else
2620     # basic svn compat
2621     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2622     then
2623     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2624     do
2625     smage2file="${i}"
2626     done
2627     else
2628     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2629     fi
2630     fi
2631    
2632   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2633   then   then
2634     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2635   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2636   else   else
2637   echo   echo
# Line 2086  mage_install() Line 2645  mage_install()
2645   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2646   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2647   then   then
2648   # 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  
2649   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2650   fi   fi
2651    
# Line 2149  mage_install() Line 2701  mage_install()
2701  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2702  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2703   echo "successfully installed."   echo "successfully installed."
2704    
2705     # unset these functions
2706     unset -f preinstall
2707     unset -f postinstall
2708     unset -f preremove
2709     unset -f postremove
2710  }  }
2711    
2712  md5sum_packages()  md5sum_packages()
# Line 2201  md5sum_packages() Line 2759  md5sum_packages()
2759   then   then
2760   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2761   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2762   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2763   else   else
2764   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2765   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2253  uninstall_packages() Line 2811  uninstall_packages()
2811   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2812   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2813   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2814   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2815   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2816   echo   echo
2817   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2818   echo "( Press [CTRL+C] to abort )"   then
2819   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2820   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2821   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2822   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2823   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2824   sleep 1   do
2825   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2826   echo   sleep 1
2827   echo   done
2828     echo
2829     echo
2830     fi
2831    
2832   for pkg in ${list}   for pkg in ${list}
2833   do   do
# Line 2304  mage_uninstall() Line 2865  mage_uninstall()
2865   local PKGTYPE   local PKGTYPE
2866   local preinstall   local preinstall
2867   local postinstall   local postinstall
2868     local preremove
2869     local postremove
2870    
2871   local pcat   local pcat
2872   local pname   local pname
# Line 2339  mage_uninstall() Line 2902  mage_uninstall()
2902   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2903   echo -n "removing: "   echo -n "removing: "
2904   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2905   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2906    
2907   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2908   source ${magefile}   source ${magefile}
2909    
2910   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2964  mage_uninstall()
2964  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2965  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2966   echo "successfully removed."   echo "successfully removed."
2967    
2968     # unset these functions
2969     unset -f preinstall
2970     unset -f postinstall
2971     unset -f preremove
2972     unset -f postremove
2973  }  }
2974    
2975  show_etc_update_mesg() {  show_etc_update_mesg()
2976    {
2977   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2978    
2979   echo   echo
# Line 2429  pkgsearch() Line 2999  pkgsearch()
2999   local state   local state
3000   local descriptiom   local descriptiom
3001   local homepage   local homepage
3002     local license
3003   local i   local i
3004   local all_installed   local all_installed
3005   local ipver   local ipver
3006   local ipbuild   local ipbuild
3007     local latest_available
3008     local depsfull
3009     local sdepsfull
3010     local deps
3011     local sdeps
3012     local dep
3013     local sign
3014    
3015   # only names no versions   # only names no versions
3016   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3017   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3018    
3019   # nothing found   # nothing found
3020   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2450  pkgsearch() Line 3028  pkgsearch()
3028   # get highest version available   # get highest version available
3029   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3030    
3031   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3032   pver="$(magename2pver ${magefile})"   then
3033   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3034   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3035   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3036   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3037     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3038     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3039     license="$(get_value_from_magefile LICENSE ${magefile})"
3040    
3041   # all installed   # all installed
3042   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3043   do   do
3044   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3045   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3046    
3047   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3048   then   then
3049   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
3050   else   else
3051   all_installed="${all_installed} ${ipver}-${ipbuild}"   all_installed="${all_installed} ${ipver}-${ipbuild}"
3052   fi   fi
3053   done   done
3054   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3055    
3056   case ${state} in   case ${state} in
3057   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3058   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
3059   unstable) state=${COLRED}"[u] ";;   unstable) state=${COLRED}"[u] ";;
3060   old) state=${COLGRAY}"[o] ";;   old) state=${COLGRAY}"[o] ";;
3061   esac   esac
3062    
3063     latest_available="${pver}-${pbuild}"
3064     else
3065     # package is masked
3066     state="${COLRED}[m] "
3067     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3068     fi
3069    
3070     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3071     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3072    
3073     while read sign dep
3074     do
3075     case ${dep} in
3076     "") continue;;
3077     esac
3078    
3079     deps="${deps} $(basename ${dep%-*})"
3080     done << EOF
3081    ${depsfull}
3082    EOF
3083    
3084     while read sign dep
3085     do
3086     case ${dep} in
3087     "") continue;;
3088     esac
3089    
3090     sdeps="${sdeps} $(basename ${dep%-*})"
3091     done << EOF
3092    ${sdepsfull}
3093    EOF
3094    
3095   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3096   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3097   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3098   echo "      Description: ${description}"   echo "      Description: ${description}"
3099   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3100     if [[ ! -z ${license} ]]
3101     then
3102     echo "      License:  ${license}"
3103     fi
3104     echo "      Depends: ${deps}"
3105     echo "      SDepends: ${sdeps}"
3106   echo   echo
3107    
3108   unset pcat   unset pcat
# Line 2497  pkgsearch() Line 3116  pkgsearch()
3116   unset all_installed   unset all_installed
3117   unset ipver   unset ipver
3118   unset ipbuild   unset ipbuild
3119     unset depsfull
3120     unset sdepsfull
3121     unset deps
3122     unset sdeps
3123     unset dep
3124     unset sign
3125     done
3126    }
3127    
3128    export_inherits()
3129    {
3130     local include="$1"
3131     shift
3132    
3133     while [ "$1" ]
3134     do
3135     local functions="$1"
3136    
3137     # sanity checks
3138     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3139     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3140    
3141     eval "${functions}() { ${include}_${functions} ; }"
3142    
3143     # debug
3144     mqueryfeature "debug" && typeset -f "${functions}"
3145    
3146     shift
3147     done
3148    }
3149    
3150    mlibdir()
3151    {
3152     local libdir=lib
3153     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3154    
3155     echo "${libdir}"
3156    }
3157    
3158    ## blacklisted ${magefile}
3159    blacklisted()
3160    {
3161     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3162    
3163     # compat
3164     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3165     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3166    
3167     # support both types for the moment
3168     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3169     then
3170     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3171     else
3172     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3173     fi
3174    
3175     # return 0 if the list not exist; nothin is masked
3176     [[ ! -f ${EXCLUDED} ]] && return 0
3177    
3178     local MAGEFILE="$1"
3179    
3180     local PCAT="$(magename2pcat ${MAGEFILE})"
3181     local PNAME="$(magename2pname ${MAGEFILE})"
3182     local PVER="$(magename2pver ${MAGEFILE})"
3183     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3184    
3185     local EXPCAT EXPNAME EXPVER EXPBUILD
3186     while read EXPCAT EXPNAME EXPVER EXPBUILD
3187     do
3188     # ignore spaces and comments
3189             case "${EXPCAT}" in
3190                     \#*|"") continue ;;
3191             esac
3192    
3193     # exclude full pver
3194     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3195     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3196     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3197     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3198     then
3199     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3200     fi
3201    
3202     # exclude pcat/pname only
3203     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3204     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3205     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3206     then
3207     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3208     fi
3209     done << EOF
3210    $( cat ${EXCLUDED}; echo)
3211    EOF
3212    
3213     return 0
3214    }
3215    
3216    # need_busybox_support ${cmd}
3217    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3218    need_busybox_support()
3219    {
3220     local cmd
3221     cmd="$1"
3222    
3223     if [[ -x /bin/busybox ]]
3224     then
3225     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3226     then
3227     # needs busybox support
3228     return 0
3229     fi
3230     fi
3231    
3232     # no busybox
3233     return 1
3234    }
3235    
3236    # busybox_filter_wget_options ${wget_opts}
3237    busybox_filter_wget_options()
3238    {
3239     local opts="$@"
3240     local i
3241     local fixed_opts
3242    
3243     if need_busybox_support wget
3244     then
3245     for i in ${opts}
3246     do
3247     # show only the allowed ones
3248     case ${i} in
3249     -c|--continue) fixed_opts+=" -c" ;;
3250     -s|--spider) fixed_opts+=" -s" ;;
3251     -q|--quiet) fixed_opts+=" -q" ;;
3252     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3253     --header) shift; fixed_opts+=" --header $1" ;;
3254     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3255     -P) shift; fixed_opts+=" -P $1" ;;
3256     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3257     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3258     # simply drop all other opts
3259     *) continue ;;
3260     esac
3261     done
3262    
3263     echo "${fixed_opts}"
3264     else
3265     echo "${opts}"
3266     fi
3267    }
3268    
3269    have_root_privileges()
3270    {
3271     local retval
3272    
3273     if [[ $(id -u) = 0 ]]
3274     then
3275     retval=0
3276     else
3277     retval=1
3278     fi
3279    
3280     return ${retval}
3281    }
3282    
3283    known_mage_feature()
3284    {
3285     local feature="$1"
3286     local retval
3287    
3288     case "${feature}" in
3289     autosvc|!autosvc) retval=0 ;;
3290     buildlog|!buildlog) retval=0 ;;
3291     ccache|!ccache) retval=0 ;;
3292     check|!check) retval=0 ;;
3293     compressdoc|!compressdoc) retval=0 ;;
3294     debug|!debug) retval=0 ;;
3295     distcc|!distcc) retval=0 ;;
3296     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3297     libtool|!libtool) retval=0 ;;
3298     linuxsymlink|!linuxsymlink) retval=0 ;;
3299     pkgbuild|!pkgbuild) retval=0 ;;
3300     purge|!purge) retval=0 ;;
3301     qalint|!qalint) retval=0 ;;
3302     regentree|!regentree) retval=0 ;;
3303     resume|!resume) retval=0 ;;
3304     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3305     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3306     static|!static) retval=0 ;;
3307     stepbystep|!stepbystep) retval=0 ;;
3308     strip|!strip) retval=0 ;;
3309     verbose|!verbose) retval=0 ;;
3310     *) retval=1 ;;
3311     esac
3312    
3313     return "${retval}"
3314    }
3315    
3316    load_mage_features()
3317    {
3318     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3319     do
3320     FVERBOSE=off msetfeature ${i}
3321     done
3322    }
3323    
3324    msetfeature()
3325    {
3326     local feature
3327     local count
3328     local i
3329     local found
3330    
3331     for feature in $@
3332     do
3333     found=0
3334     count="${#MAGE_FEATURES_CURRENT[*]}"
3335    
3336     if ! known_mage_feature "${feature}"
3337     then
3338     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3339     return 3
3340     fi
3341    
3342     for ((i=0; i<count; i++))
3343     do
3344     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3345     then
3346     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3347     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3348     found=1
3349     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3350     then
3351     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3352     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3353     found=1
3354     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3355     then
3356     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3357     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3358     found=1
3359     fi
3360     done
3361    
3362     # if the feature was not found after proccessing the whole array
3363     # it was not declared. in this case enable it
3364     if [[ ${found} = 0 ]]
3365     then
3366     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3367     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3368     fi
3369    
3370     export MAGE_FEATURE_CURRENT
3371   done   done
3372  }  }
3373    
3374    mqueryfeature()
3375    {
3376     local feature="$1"
3377     local retval=1
3378     local i
3379    
3380     if known_mage_feature "${feature}"
3381     then
3382     for i in ${MAGE_FEATURES_CURRENT[*]}
3383     do
3384     if [[ ${i} = ${feature} ]]
3385     then
3386     retval=0
3387     break # found break here
3388     fi
3389     done
3390     else
3391     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3392     retval=3
3393     fi
3394    
3395     return ${retval}
3396    }
3397    
3398    mprintfeatures()
3399    {
3400     echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"
3401     echo "Local features:   ${MAGE_FEATURES[*]}"
3402     echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"
3403    }

Legend:
Removed from v.237  
changed lines
  Added in v.1648