Magellan Linux

Diff of /branches/mage-next/src/mage4.functions.sh.in

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 2232 by niro, Wed Oct 16 09:28:00 2013 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 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     local sum
50     local dest
51    
52     # very basic getops
53     for i in $*
54     do
55     case $1 in
56     --rundir|-r) shift; rundir="$1" ;;
57     --file|-f) shift; file="$1" ;;
58     --method|-m) shift; method="$1" ;;
59     esac
60     shift
61     done
62    
63     # sanity checks
64     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
65     [[ -z ${file} ]] && die "mchecksum(): file missing"
66     [[ -z ${method} ]] && die "mchecksum(): method missing"
67    
68     case ${method} in
69     md5) cmd="md5sum" ;;
70     sha256) cmd="sha256sum" ;;
71     *) die "mchecksum(): unknown method '${method}'" ;;
72     esac
73    
74     if [[ -d ${rundir} ]]
75     then
76     pushd ${rundir} &> /dev/null
77    
78     # all file must be non-zero
79     retval=0
80     while read sum dest
81     do
82     if [ ! -s ${dest} ]
83     then
84     echo "${dest}: file is empty ;("
85     retval=127
86     fi
87     done < ${file}
88     if [[ ${retval} != 127 ]]
89     then
90     # be verbose here
91     ${cmd} -c ${file} #&> /dev/null
92     retval="$?"
93     fi
94    
95     popd &> /dev/null
96     else
97     retval=1
98     fi
99    
100     return "${retval}"
101    }
102    
103    mcheckemptydir()
104    {
105     local dir="$1"
106     local retval=1
107    
108     if [[ ! -d ${dir} ]]
109     then
110     echo "mcheckemptydir(): '${dir}' is not a directory!"
111     retval=3
112     else
113     shopt -s nullglob dotglob
114     files=( ${dir}/* )
115     (( ${#files[*]} )) || retval=0
116     shopt -u nullglob dotglob
117     fi
118    
119     return ${retval}
120    }
121    
122    unpack_package()
123    {
124     local magefile="$1"
125     local pkg
126     local pkgtype
127     local tar_opts
128    
129     pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
130     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
131    
132     xtitle "[ Unpacking ${pkg} ]"
133    
134     # abort on virtual pkg
135     if [[ ${pkgtype} = virtual ]]
136     then
137     echo -ne " ${COLBLUE}---${COLDEFAULT}"
138     echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "
139     continue
140     fi
141    
142     # abort on sources pkg
143     if [[ ${pkgtype} = sources ]]
144     then
145     echo -ne " ${COLBLUE}---${COLDEFAULT}"
146     echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "
147     continue
148     fi
149    
150     # busybox?
151     if need_busybox_support tar
152     then
153     tar_opts="xjf"
154     else
155     tar_opts="xjmf"
156     fi
157    
158     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "
159     tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
160    }
161    
162  unpack_packages()  unpack_packages()
163  {  {
164   local list="$@"   local list="$@"
165   local magefile   local magefile
  local pkg  
  local pkgtype  
166   local count_current   local count_current
167   local count_total   local count_total
168     local tar_opts
169    
170   # get count of total packages   # get count of total packages
171   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 175  unpack_packages()
175    
176   for magefile in ${list}   for magefile in ${list}
177   do   do
178   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
179   (( count_current++ ))   (( count_current++ ))
  xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"  
   
  # abort on virtual pkg  
  if [[ ${pkgtype} = virtual ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # abort on sources pkg  
  if [[ ${pkgtype} = sources ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "  
  tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"  
180   done   done
181    
182   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 196  fix_mtime()
196   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
197   touch \   touch \
198   --no-create \   --no-create \
199     --no-dereference \
200   --time=mtime \   --time=mtime \
201   --reference "${reference}" \   --reference="${reference}" \
202   "${pathto}"   "${pathto}"
203    
204   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 252  install_directories()
252   while read pathto posix user group   while read pathto posix user group
253   do   do
254   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
255   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
256    
257   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
258   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 319  install_files()
319   is_config_protected "${pathto}"   is_config_protected "${pathto}"
320   retval="$?"   retval="$?"
321    
322   # 0 - not protected        #   # 0 - not protected         #
323   # 1 - error                #   # 1 - error                 #
324   # 2 - protected            #   # 2 - protected             #
325   # 3 - protected but masked #   # 3 - protected but masked  #
326     # 4 - protected but ignored #
327    
328   case ${retval} in   case ${retval} in
329   # file is not protected - (over)write it   # file is not protected - (over)write it
330   0|3)   0|3)
331   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
332   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
333   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
334   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 340  install_files()
340   "${user}" \   "${user}" \
341   "${group}" \   "${group}" \
342   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
343   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
344   "${md5sum}"   "${md5sum}"
345   ;;   ;;
346    
347   # file is protected, write backup file   # file is protected, write backup file
348   2)   2)
349   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
350   then   then
351   echo -en "${COLRED}"   echo -en "${COLRED}"
352   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 367  install_files()
367   "${user}" \   "${user}" \
368   "${group}" \   "${group}" \
369   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
370   "${dest_protected}")" \   "${dest_protected}")" \
371   "${md5sum}"   "${md5sum}"
372    
373   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
374   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
375   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
376   ;;   ;;
377    
378     # file is protected but ignored, delete the update/do nothing
379     4)
380     if mqueryfeature "verbose"
381     then
382     echo -en "${COLRED}"
383     echo -n "! ignr "
384     echo -en "${COLDEFAULT}"
385     echo " === FILE: ${MROOT}${pathto}"
386     fi
387     # simply do nothing here - only fix mtime
388     fix_descriptor ${pkgname}/.files \
389     "${pathto}" \
390     "${posix}" \
391     "${user}" \
392     "${group}" \
393     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
394     "${MROOT}${pathto}")" \
395     "${md5sum}"
396     ;;
397   esac   esac
398   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
399    
# Line 294  install_symlinks() Line 436  install_symlinks()
436   while read pathto posix link mtime   while read pathto posix link mtime
437   do   do
438   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
439   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
440    
441   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
442    
443   # fix mtime and db   # fix mtime and db
444   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
445   "${pathto}" \   "${pathto}" \
446   "${posix}" \   "${posix}" \
447   "${link}" \   "${link}" \
448   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
449   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
450    
451   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
452    
453   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
454   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
455   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
456    
457   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
458   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 468  install_blockdevices()
468   local pkgname="$1"   local pkgname="$1"
469   local pathto   local pathto
470   local posix   local posix
471     local user
472     local group
473   local IFS   local IFS
474    
475   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 483  install_blockdevices()
483   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
484   IFS=§   IFS=§
485    
486   while read pathto posix   while read pathto posix major minor user group
487   do   do
488   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
489   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
490    
491   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
492     # make it optional atm !!
493     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
494     then
495     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
496     fi
497   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
498    
499   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 510  install_characterdevices()
510   local pkgname="$1"   local pkgname="$1"
511   local pathto   local pathto
512   local posix   local posix
513     local major
514     local minor
515     local user
516     local group
517   local IFS   local IFS
518    
519   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 527  install_characterdevices()
527   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
528   IFS=§   IFS=§
529    
530   while read pathto posix   while read pathto posix major minor user group
531   do   do
532   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
533   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
534    
535   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
536    
537     # make it optional atm !!
538     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
539     then
540     chown "${user}:${group}" "${MROOT}${pathto}"
541     fi
542   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
543    
544   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
545   IFS=$'\n'   IFS=$'\n'
546  }  }
547    
548    ###################################################
549    # function install_fifos                          #
550    # install_fifos $PKGNAME                    #
551    ###################################################
552    install_fifos()
553    {
554     local pkgname="$1"
555     local pathto
556     local posix
557     local user
558     local group
559     local IFS
560    
561     # sanity checks; abort if not given
562     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
563    
564     # check needed global vars
565     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
566    
567     # make it optional atm !!
568     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
569     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
570    
571     # sets fieldseperator to "§" instead of " "
572     IFS=§
573    
574     while read pathto posix user group
575     do
576     [ -z "${pathto}" ] && continue
577     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
578    
579     mkfifo -m "${posix}" "${MROOT}${pathto}"
580     chown "${user}:${group}" "${MROOT}${pathto}"
581     done < ${BUILDDIR}/${pkgname}/.fifo
582    
583     # very important: unsetting the '§' fieldseperator
584     IFS=$'\n'
585    }
586    
587    
588  ###################################################  ###################################################
589  # function build_doinstall                        #  # function build_doinstall                        #
590  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
591  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
592  ###################################################  ###################################################
593  build_doinstall()  build_doinstall()
594  {  {
# Line 398  build_doinstall() Line 596  build_doinstall()
596    
597   # sanity checks; abort if not given   # sanity checks; abort if not given
598   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
599    
600   # this is only a wrapper   # this is only a wrapper
601    
602   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 611  build_doinstall()
611   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
612   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
613   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
614     install_fifos ${pkgname} || die "install fifos ${pkgname}"
615  }  }
616    
617    
# Line 432  install_database_entry() Line 631  install_database_entry()
631   local magefile   local magefile
632   local dbrecorddir   local dbrecorddir
633   local provide   local provide
634     local i
635    
636   # very basic getops   # very basic getops
637   for i in $*   for i in $*
# Line 473  install_database_entry() Line 673  install_database_entry()
673    
674   # create fake file descriptors   # create fake file descriptors
675   # used by virtual and source packages   # used by virtual and source packages
676   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
677   do   do
678   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
679   done   done
# Line 492  install_database_entry() Line 691  install_database_entry()
691    
692   # normal packages needs these files   # normal packages needs these files
693   local i   local i
694   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
695   do   do
696   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
697   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
698     then
699     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
700     fi
701   done   done
702   ;;   ;;
703   esac   esac
# Line 504  install_database_entry() Line 706  install_database_entry()
706   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
707   if [ -n "${provide}" ]   if [ -n "${provide}" ]
708   then   then
709   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
710     do
711     virtuals_add "${i}" "${pcat}/${pname}"
712     done
713   fi   fi
714  }  }
715    
# Line 523  remove_database_entry() Line 728  remove_database_entry()
728   local magefile   local magefile
729   local dbrecorddir   local dbrecorddir
730   local provide   local provide
731     local i
732    
733   # very basic getops   # very basic getops
734   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 758  remove_database_entry()
758   # abort if mage file not exists   # abort if mage file not exists
759   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
760    
761   # first unregister virtuals   # remove virtuals only if no other exist
762   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
763   then   then
764   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
765     provide="$(get_value_from_magefile PROVIDE ${magefile})"
766     if [ -n "${provide}" ]
767     then
768     for i in ${provide}
769     do
770     virtuals_del "${i}" "${pcat}/${pname}"
771     done
772     fi
773   fi   fi
774    
775   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 779  remove_database_entry()
779   fi   fi
780  }  }
781    
782    # get the number of installed packages
783    count_installed_pkgs()
784    {
785     local pcat
786     local pname
787     local pkg
788     local i
789    
790     # very basic getops
791     for i in $*
792     do
793     case $1 in
794     --pcat|-c) shift; pcat="$1" ;;
795     --pname|-n) shift; pname="$1" ;;
796     esac
797     shift
798     done
799    
800     # sanity checks; abort if not given
801     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
802     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
803    
804     declare -i i=0
805     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
806     do
807     (( i++ ))
808     #echo "$i ${pkg}"
809     done
810    
811     # return the value
812     echo "${i}"
813    }
814    
815    
816  ###################################################  ###################################################
817  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  compare_mtime() Line 833  compare_mtime()
833    
834   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
835    
836   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
837   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
838   then   x=$(stat -c %Y "${MROOT}${pathto}")
  # readlink -f resolves full path of linked file  
  x="$(readlink -f "${MROOT}${pathto}")"  
   
  # abort if target does not exists  
  # we keep safe here, theoretically the link can removed  
  [ ! -e "${x}" ] && return 1  
   
  x=$(stat -c %Y "${x}")  
  else  
  x=$(stat -c %Y "${MROOT}${pathto}")  
  fi  
839    
840   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
841    
# Line 662  remove_symlinks() Line 897  remove_symlinks()
897   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
898   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
899   then   then
900   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
901   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
902   continue   continue
903   fi   fi
# Line 674  remove_symlinks() Line 909  remove_symlinks()
909   # 1=keep me   #   # 1=keep me   #
910   case ${retval} in   case ${retval} in
911   0)   0)
912   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
913   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
914   ;;   ;;
915    
916   1)   1)
917   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
918   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
919   ;;   ;;
920   esac   esac
# Line 726  remove_files() Line 961  remove_files()
961   done   done
962    
963   # sanity checks; abort if not given   # sanity checks; abort if not given
964   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
965   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
966   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
967   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
968   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
969    
970   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 979  remove_files()
979   do   do
980   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
981    
982   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
983   then   then
984   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
985   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
986   continue   continue
987   fi   fi
# Line 758  remove_files() Line 993  remove_files()
993   # 1=keep me   #   # 1=keep me   #
994   case ${retval} in   case ${retval} in
995   0)   0)
996   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
997   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
998   ;;   is_config_protected "${pathto}"
999     retval="$?"
1000    
1001     # 0 - not protected         #
1002     # 1 - error                 #
1003     # 2 - protected             #
1004     # 3 - protected but masked  #
1005     # 4 - protected but ignored #
1006    
1007     case ${retval} in
1008     # file is not protected - delete it
1009     0|3)
1010     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1011     rm "${MROOT}${pathto}"
1012     ;;
1013    
1014     # file is protected, do not delete
1015     2)
1016     if mqueryfeature "verbose"
1017     then
1018     echo -en "${COLRED}"
1019     echo -n "! prot "
1020     echo -en "${COLDEFAULT}"
1021     echo " === FILE: ${MROOT}${pathto}"
1022     fi
1023     ;;
1024    
1025     # file is protected but ignored, delete the update/do nothing
1026     4)
1027     if mqueryfeature "verbose"
1028     then
1029     echo -en "${COLRED}"
1030     echo -n "! ignr "
1031     echo -en "${COLDEFAULT}"
1032     echo " === FILE: ${MROOT}${pathto}"
1033     fi
1034     # simply do nothing here
1035     ;;
1036     esac
1037     ;;
1038   1)   1)
1039   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1040   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1041   ;;   ;;
1042   esac   esac
# Line 782  remove_blockdevices() Line 1055  remove_blockdevices()
1055  {  {
1056   local pathto   local pathto
1057   local posix   local posix
1058     local user
1059     local group
1060   local IFS   local IFS
1061   local pcat   local pcat
1062   local pname   local pname
# Line 805  remove_blockdevices() Line 1080  remove_blockdevices()
1080   done   done
1081    
1082   # sanity checks; abort if not given   # sanity checks; abort if not given
1083   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1084   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1085   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1086   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1087   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1088    
1089   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1094  remove_blockdevices()
1094   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1095   IFS=§   IFS=§
1096    
1097   while read pathto posix   while read pathto posix user group
1098   do   do
1099   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1100    
1101   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1102   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1103   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1104    
# Line 840  remove_characterdevices() Line 1115  remove_characterdevices()
1115  {  {
1116   local pathto   local pathto
1117   local posix   local posix
1118     local user
1119     local group
1120   local IFS   local IFS
1121   local pcat   local pcat
1122   local pname   local pname
# Line 863  remove_characterdevices() Line 1140  remove_characterdevices()
1140   done   done
1141    
1142   # sanity checks; abort if not given   # sanity checks; abort if not given
1143   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1144   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1145   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1146   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1147   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1148    
1149   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1154  remove_characterdevices()
1154   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1155   IFS=§   IFS=§
1156    
1157   while read pathto posix   while read pathto posix user group
1158   do   do
1159   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1160    
1161   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1162   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1163   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1164    
# Line 891  remove_characterdevices() Line 1168  remove_characterdevices()
1168    
1169    
1170  ###################################################  ###################################################
1171    # function remove_fifos                           #
1172    # remove_fifos $PKGNAME                     #
1173    ###################################################
1174    remove_fifos()
1175    {
1176     local pathto
1177     local posix
1178     local user
1179     local group
1180     local IFS
1181     local pcat
1182     local pname
1183     local pver
1184     local pbuild
1185     local i
1186     local pfull
1187    
1188     IFS=$'\n'
1189    
1190     # very basic getops
1191     for i in $*
1192     do
1193     case $1 in
1194     --pcat|-c) shift; pcat="$1" ;;
1195     --pname|-n) shift; pname="$1" ;;
1196     --pver|-v) shift; pver="$1" ;;
1197     --pbuild|-b) shift; pbuild="$1" ;;
1198     esac
1199     shift
1200     done
1201    
1202     # sanity checks; abort if not given
1203     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1204     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1205     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1206     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1207     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1208    
1209     # check needed global vars
1210     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1211    
1212     # make it optional atm !!
1213     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1214     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1215    
1216     # sets fieldseperator to "§" instead of " "
1217     IFS=§
1218    
1219     while read pathto posix user group
1220     do
1221     [ -z "${pathto}" ] && continue
1222    
1223     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1224     rm "${MROOT}${pathto}"
1225     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1226    
1227     # very important: unsetting the '§' fieldseperator
1228     IFS=$'\n'
1229    }
1230    
1231    
1232    ###################################################
1233  # function remove_direcories                      #  # function remove_direcories                      #
1234  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1235  ###################################################  ###################################################
# Line 921  remove_directories() Line 1260  remove_directories()
1260   done   done
1261    
1262   # sanity checks; abort if not given   # sanity checks; abort if not given
1263   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1264   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1265   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1266   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1267   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1268    
1269   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1271  remove_directories()
1271    
1272   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1273    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1274   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1275   IFS=§   IFS=§
1276    
1277   while read pathto posix   # reversed order is mandatory !
1278     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1279   do   do
1280   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1281    
1282   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1283   then   then
1284   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1285   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1286   continue   continue
1287   fi   fi
# Line 953  remove_directories() Line 1289  remove_directories()
1289   # exclude .keep directories   # exclude .keep directories
1290   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1291   then   then
1292   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1293   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1294   continue   continue
1295   fi   fi
1296    
# Line 966  remove_directories() Line 1302  remove_directories()
1302    
1303   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1304   then   then
1305   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1306   else   else
1307   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1308   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1309   fi   fi
1310   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1311    
1312   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1313   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1317  remove_directories()
1317  ###################################################  ###################################################
1318  # function build_douninstall                      #  # function build_douninstall                      #
1319  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1320  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1321  ###################################################  ###################################################
1322  build_douninstall()  build_douninstall()
1323  {  {
# Line 1015  build_douninstall() Line 1351  build_douninstall()
1351   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1352   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1353    
1354   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1355   do   do
1356   remove_${i} \   remove_${i} \
1357   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1026  build_douninstall() Line 1362  build_douninstall()
1362   done   done
1363  }  }
1364    
1365    # convertmirrors [uri]
1366    convertmirrors()
1367    {
1368     local uri="$1"
1369     local scheme
1370     local mirror
1371     local mirrors
1372     local addon
1373     local real_uri
1374     local output
1375    
1376     # needs
1377     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1378     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1379     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1380     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1381     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1382    
1383     # check known uri schemes
1384     case ${uri} in
1385     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1386     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1387     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1388     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1389     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1390     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1391     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1392     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1393     esac
1394    
1395     if [[ ! -z ${mirrors} ]]
1396     then
1397     for mirror in ${mirrors}
1398     do
1399     # add a whitespace to the output
1400     [[ -z ${output} ]] || output+=" "
1401     output+="${mirror}${addon}/${uri/${scheme}/}"
1402     done
1403     else
1404     output="${uri}"
1405     fi
1406    
1407     echo "${output}"
1408    }
1409    
1410    mdownload()
1411    {
1412     local i
1413     local uri
1414     local real_uris
1415     local mirror
1416     local outputfile
1417     local outputdir
1418     local retval
1419     local wget_opts
1420    
1421     # very basic getops
1422     for i in $*
1423     do
1424     case $1 in
1425     --uri|-u) shift; uri="$1" ;;
1426     --dir|-d) shift; outputdir="$1" ;;
1427     esac
1428     shift
1429     done
1430    
1431     # sanity checks; abort if not given
1432     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1433     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1434    
1435     # convert mirrored uris to the real ones
1436     real_uris="$(convertmirrors ${uri})"
1437    
1438     # verbose or not
1439     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1440    
1441     # filter wget options if busybox was found
1442     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1443    
1444     # create outputdir
1445     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1446    
1447     for mirror in ${real_uris}
1448     do
1449     # get the name of the output file
1450     outputfile="${mirror##*/}"
1451    
1452     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1453     retval="$?"
1454     if [[ ${retval} = 0 ]]
1455     then
1456     break
1457     else
1458     continue
1459     fi
1460     done
1461    
1462     # return wget retval
1463     return "${retval}"
1464    }
1465    
1466  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1467  fetch_packages()  fetch_packages()
1468  {  {
1469     local i
1470   local list="$@"   local list="$@"
1471   local pkg   local pkg
1472   local mirr   local mirr
# Line 1037  fetch_packages() Line 1475  fetch_packages()
1475   local opt   local opt
1476   local count_current   local count_current
1477   local count_total   local count_total
1478     local wget_opts
1479    
1480     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1481    
1482   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1483     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1484    
1485   # get count of total packages   # get count of total packages
1486   declare -i count_current=0   declare -i count_current=0
# Line 1078  fetch_packages() Line 1520  fetch_packages()
1520   continue   continue
1521   fi   fi
1522    
1523   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1524   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1525   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  
   
1526   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1527   then   then
1528   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1529   fi   fi
1530   done   done
1531    
# Line 1113  syncmage() Line 1537  syncmage()
1537  {  {
1538   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1539   then   then
1540   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1541   fi   fi
1542    
1543   local i   local i
1544   for i in ${RSYNC}   for i in ${RSYNC}
1545   do   do
1546   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1547   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1548   then   then
1549   break   break
# Line 1142  syncmage() Line 1553  syncmage()
1553   done   done
1554    
1555   # clean up backup files (foo~)   # clean up backup files (foo~)
1556   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1557    
1558   # check if an newer mage version is available   # check if a newer mage version is available
1559   is_newer_mage_version_available   is_newer_mage_version_available
1560  }  }
1561    
1562    syncmage_tarball()
1563    {
1564     local latest_tarball
1565     local latest_md5
1566     local temp="$(mktemp -d)"
1567     local mirr mymirr
1568     local opt
1569     local tar_opts
1570     local wget_opts
1571    
1572     # try to get the md5 marked as latest on the server
1573     latest_md5="mage-latest.md5"
1574    
1575     # try to get the tarball marked as latest on the server
1576     latest_tarball="mage-latest.tar.bz2"
1577    
1578     # filter wget command if busybox was found
1579     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1580    
1581     for mirr in ${MIRRORS}
1582     do
1583     # path without distribution
1584     # (only for stable|testing|unstable and not DISTROTAG)
1585     case ${mirr##*/} in
1586     stable|testing|unstable) mymirr="${mirr%/*}";;
1587     *) mymirr="${mirr}";;
1588     esac
1589    
1590     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1591     echo "fetching latest md5 from ${mymirr} ..."
1592     mqueryfeature "!verbose" && opt="--quiet"
1593     wget \
1594     ${wget_opts} \
1595     --directory-prefix=${temp} \
1596     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1597    
1598     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1599     echo "fetching latest tarball from ${mymirr} ..."
1600     wget \
1601     ${wget_opts} \
1602     --directory-prefix=${temp} \
1603     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1604     if [[ $? = 0 ]]
1605     then
1606     break
1607     else
1608     continue
1609     fi
1610     done
1611    
1612     if [[ -f ${temp}/${latest_tarball} ]]
1613     then
1614     # check md5
1615     if [[ ! -f ${temp}/${latest_md5} ]]
1616     then
1617     die "md5 is missing ... aborting"
1618     else
1619     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1620     echo -n "checking md5sum... "
1621     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1622     fi
1623    
1624     if [[ -d ${MAGEDIR} ]]
1625     then
1626     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1627     echo "cleaning old mage-tree ${MAGEDIR}..."
1628     # honor mountpoints and empty dirs
1629     if mountpoint -q ${MAGEDIR}
1630     then
1631     if ! mcheckemptydir ${MAGEDIR}
1632     then
1633     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1634     fi
1635     else
1636     rm -rf ${MAGEDIR}
1637     fi
1638     fi
1639    
1640     if need_busybox_support tar
1641     then
1642     tar_opts="xjf"
1643     else
1644     tar_opts="xjmf"
1645     fi
1646    
1647     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1648     echo "updating mage-tree from tarball ..."
1649     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1650     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1651    
1652     if [[ -d ${temp} ]]
1653     then
1654     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1655     echo "cleaning temp-files ..."
1656     rm -rf ${temp}
1657     fi
1658    
1659     # check if a newer mage version is available
1660     is_newer_mage_version_available
1661     else
1662     die "Could not fetch the latest tarball ... aborting"
1663     fi
1664    }
1665    
1666  cleanpkg()  cleanpkg()
1667  {  {
1668   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1178  xtitleclean() Line 1693  xtitleclean()
1693  }  }
1694    
1695    
1696  # cuts full pathnames or versioniezed names down to basename  # unused?
1697  choppkgname()  #
1698  {  # # cuts full pathnames or versionized names down to basename
1699   #we want this only if full name was used  # choppkgname()
1700   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1701   then  # #we want this only if full name was used
1702   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1703   #ARCH comes from /etc/mage.rc  # then
1704   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1705    # #ARCH comes from ${MAGERC}
1706    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1707    #
1708    # #cuts version number
1709    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1710    # fi
1711    # }
1712    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1713    
1714  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1715  # $1=pname  # $1=pname
# Line 1218  pname2pcat() Line 1736  pname2pcat()
1736  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1737  check_stable_package()  check_stable_package()
1738  {  {
1739     # first check if this magefile is not blacklisted
1740     blacklisted "$1" || return 1
1741    
1742   local STATE   local STATE
1743   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1744    
1745   # state testing   # state testing
1746   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1747   then   then
1748   case ${STATE} in   case ${STATE} in
1749   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1752  check_stable_package()
1752   fi   fi
1753    
1754   # state unstable   # state unstable
1755   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1756   then   then
1757   case ${STATE} in   case ${STATE} in
1758   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1778  get_highest_magefile()
1778   local PNAME="$2"   local PNAME="$2"
1779   local magefile   local magefile
1780    
1781   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1782     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1783   do   do
1784     [[ -z ${magefile} ]] && continue
1785   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1786   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1787   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1788   then   then
1789   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1790   #for debug only   #for debug only
1791   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1792   fi   fi
1793   done   done
1794    
  # 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  
   
1795   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1796   return 0   return 0
1797  }  }
# Line 1304  get_highest_magefile() Line 1806  get_highest_magefile()
1806  #        1 - error                                #  #        1 - error                                #
1807  #        2 - protected                            #  #        2 - protected                            #
1808  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1809    #        4 - protected but ignored                #
1810  #                                                 #  #                                                 #
1811  ###################################################  ###################################################
1812  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1815  is_config_protected()
1815   local TEST   local TEST
1816   local PROTECTED   local PROTECTED
1817   local IFS   local IFS
1818     local i
1819     local x
1820    
1821   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1822    
1823   # file does not exist; it can be written   # file does not exist; it can be written
1824   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1825    
1826   # to be safe; it may be '§'   # to be safe; it may be '§'
1827   IFS=' '   IFS=' '
1828    
1829   # check ob in config protect   # check if config protected
1830   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1831   do   do
1832   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1833   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1834   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1835   then   then
1836   # setzen das es protected ist   # file is config proteced
1837   PROTECTED=TRUE   PROTECTED=TRUE
1838    
1839   # check ob nicht doch maskiert   # check if not masked
1840   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1841   do   do
1842   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1843   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1844   then   then
1845   PROTECTED=MASKED   PROTECTED=MASKED
1846   fi   fi
1847   done   done
1848    
1849     # check if not ignored
1850     for x in ${CONFIG_PROTECT_IGNORE}
1851     do
1852     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1853     if [[ ${TEST} != ${EXPFILE} ]]
1854     then
1855     PROTECTED=IGNORED
1856     fi
1857     done
1858   fi   fi
1859   done   done
1860    
# Line 1354  is_config_protected() Line 1869  is_config_protected()
1869   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1870   return 3   return 3
1871   ;;   ;;
1872     IGNORED)
1873     #echo "I'm protected, but ignored - keep me, del update"
1874     return 4
1875     ;;
1876   *)   *)
1877   #echo "delete me"   #echo "delete me"
1878   return 0   return 0
# Line 1371  is_config_protected() Line 1890  is_config_protected()
1890  ###################################################  ###################################################
1891  count_protected_files()  count_protected_files()
1892  {  {
1893   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1894     local dirname="${file%/*}"
1895     local filename="${file##*/}"
1896     local count
1897     local output
1898     local oldprotected
1899     local i
1900     local x
1901    
1902     # hack; do not honor a global set IFS like '§'
1903     local IFS
1904    
1905     count=0
1906    
1907     # check if there are already protected files
1908     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1909     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1910     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1911     do
1912     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1913     done
1914    
1915     # convert 0001 -> 1; 0120 -> 120 etc
1916     # use bash internal base functions to this task
1917     x="$((10#${count}))"
1918     for (( i=0; i<x; i++ ))
1919     do
1920     if [[ ${count:${i}:1} != 0 ]]
1921     then
1922     count="${count:${i}}"
1923     break
1924     fi
1925     done
1926    
1927     count="$(( ${count}+1 ))"
1928    
1929     # fill output up with zeros
1930     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1931     output="${output}${count}"
1932    
1933     echo "${output}"
1934  }  }
1935    
1936  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1947  get_uninstall_candidates()
1947   local list   local list
1948   local pcatdir   local pcatdir
1949   local protected   local protected
1950     local i
1951    
1952   # very basic getops   # very basic getops
1953   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1960  get_uninstall_candidates()
1960   shift   shift
1961   done   done
1962    
1963   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1964   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1965    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1966    
1967    
1968   # check needed global vars   # check needed global vars
1969   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1970    
1971   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1972   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1973    
1974   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1975   do   do
# Line 1493  virtuals_add() Line 2054  virtuals_add()
2054   local oldline   local oldline
2055   local line i   local line i
2056   local installed_file   local installed_file
2057     local OLDIFS
2058    
2059   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2060   then   then
2061   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2062   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2063   do   do
2064   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2077  virtuals_add()
2077   # make a backup   # make a backup
2078   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2079    
2080     OLDIFS="${IFS}"
2081   IFS=$'\n'   IFS=$'\n'
2082   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2083   do   do
# Line 1526  virtuals_add() Line 2089  virtuals_add()
2089   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2090   fi   fi
2091   done   done
2092     # unset IFS
2093   #unset IFS   IFS="${OLDIFS}"
2094   else   else
2095   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2096   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2097   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2098   fi   fi
# Line 1539  virtuals_add() Line 2102  virtuals_add()
2102    
2103  #deletes pakages from virtual database  #deletes pakages from virtual database
2104  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2105  virtuals_del() {  virtuals_del()
2106    {
2107    
2108   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2109     local pkgname="$2"
2110   VIRTUAL_NAME=$1   local oldline
2111   PKG_NAME=$2   local method
2112     local line i x
2113   #first check if exists   local pkg_installed
2114   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2115    
2116     # first check if exists
2117     if virtuals_read ${virtualname}
2118   then   then
2119   #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}
2120   declare -i x=0   declare -i x=0
2121   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2122   do   do
2123   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2124   then   then
2125   PKG_INSTALLED=true   pkg_installed=true
2126   fi   fi
2127   ((x++))   ((x++))
2128   done   done
2129    
2130   #abort if not installed   # abort if not installed
2131   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2132   then   then
2133   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2134     echo "${pkgname} does not exists in ${virtualname}."
2135   return 0   return 0
2136   fi   fi
2137    
2138   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2139   then   then
2140   METHOD=update   method=update
2141   else   else
2142   METHOD=delall   method=delall
2143   fi   fi
2144    
2145   #get the complete line   # get the complete line
2146   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2147    
2148   #make a backup   # make a backup of the db
2149   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2150    
2151   #parse virtualdb   # parse virtualdb
2152     OLDIFS="${IFS}"
2153   IFS=$'\n'   IFS=$'\n'
2154   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2155   do   do
2156   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2157   then   then
2158   #delall or update?   #delall or update?
2159   case ${METHOD} in   case ${method} in
2160   update)   update)
2161   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2162   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2163   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2164     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2165   ;;   ;;
2166   delall)   delall)
2167   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2168   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2169     # continue; do not write anything
2170   continue   continue
2171   ;;   ;;
2172   esac   esac
# Line 1603  virtuals_del() { Line 2174  virtuals_del() {
2174   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2175   fi   fi
2176   done   done
2177   unset IFS   # unset IFS
2178     IFS="${OLDIFS}"
2179   else   else
2180   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2181     echo "${virtualname} does not exists in virtual database."
2182   fi   fi
2183  }  }
2184    
# Line 1637  minclude() Line 2210  minclude()
2210  {  {
2211   local i   local i
2212    
2213   if [ -n "$@" ]   if [[ -n $* ]]
2214   then   then
2215   for i in $@   for i in $*
2216   do   do
2217   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2218   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2219   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2220   done   done
2221   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2222   fi   fi
2223  }  }
2224    
# Line 1653  sminclude() Line 2226  sminclude()
2226  {  {
2227   local i   local i
2228    
2229   if [ -n "$@" ]   if [[ -n $* ]]
2230   then   then
2231   for i in $@   for i in $*
2232   do   do
2233   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2234   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2243  is_newer_mage_version_available()
2243   local newest_mage   local newest_mage
2244   local installed_mage   local installed_mage
2245    
2246   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2247   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2248    
2249   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2252  is_newer_mage_version_available()
2252   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2253   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2254   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2255   echo "or your current system installation may brake."   echo "or your current system installation may break."
2256   echo   echo
2257   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2258   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2524  get_value_from_magefile()
2524   local magefile="$2"   local magefile="$2"
2525   local value   local value
2526    
2527     [[ -z ${var} ]] && return 1
2528     [[ -z ${magefile} ]] && return 1
2529    
2530   # local all possible vars of a mage file   # local all possible vars of a mage file
2531   # to prevent bad issues   # to prevent bad issues
2532   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2537  get_value_from_magefile()
2537   local SDEPEND   local SDEPEND
2538   local PROVIDE   local PROVIDE
2539   local PKGTYPE   local PKGTYPE
2540     local MAGE_TARGETS
2541     local SPLIT_PACKAGE_BASE
2542   local preinstall   local preinstall
2543   local postinstall   local postinstall
2544     local preremove
2545     local postremove
2546    
2547   # sanity checks   # sanity checks
2548   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2552  get_value_from_magefile()
2552   source ${magefile}   source ${magefile}
2553   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2554   echo "${value}"   echo "${value}"
2555    
2556     # unset these functions
2557     unset -f preinstall
2558     unset -f postinstall
2559     unset -f preremove
2560     unset -f postremove
2561  }  }
2562    
2563  mage_install()  mage_install()
# Line 1988  mage_install() Line 2574  mage_install()
2574   local PKGTYPE   local PKGTYPE
2575   local preinstall   local preinstall
2576   local postinstall   local postinstall
2577     local preremove
2578     local postremove
2579    
2580   local pcat   local pcat
2581   local pname   local pname
# Line 1997  mage_install() Line 2585  mage_install()
2585   local count_current   local count_current
2586   local magefile   local magefile
2587   local src_install   local src_install
2588     local i
2589    
2590   # very basic getops   # very basic getops
2591   for i in $*   for i in $*
# Line 2070  mage_install() Line 2659  mage_install()
2659   echo B:${pbuild}   echo B:${pbuild}
2660   fi   fi
2661    
2662   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2663     then
2664     # basic svn compat
2665     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2666     then
2667     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2668     do
2669     smage2file="${i}"
2670     done
2671     else
2672     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2673     fi
2674    
2675     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2676     then
2677     # basic svn compat
2678     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2679     then
2680     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2681     do
2682     smage2file="${i}"
2683     done
2684     else
2685     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2686     fi
2687    
2688     else
2689     # basic svn compat
2690     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2691     then
2692     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2693     do
2694     smage2file="${i}"
2695     done
2696     else
2697     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2698     fi
2699     fi
2700    
2701   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2702   then   then
2703     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2704   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2705   else   else
2706   echo   echo
# Line 2086  mage_install() Line 2714  mage_install()
2714   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2715   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2716   then   then
2717   # show a verbose message on src-install   unpack_package "${magefile}"
2718   if [[ ${src_install} = true ]]   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
  then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "merging files: "  
  echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  
  echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"  
  fi  
2719   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2720   fi   fi
2721    
# Line 2149  mage_install() Line 2771  mage_install()
2771  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2772  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2773   echo "successfully installed."   echo "successfully installed."
2774    
2775     # unset these functions
2776     unset -f preinstall
2777     unset -f postinstall
2778     unset -f preremove
2779     unset -f postremove
2780  }  }
2781    
2782  md5sum_packages()  md5sum_packages()
# Line 2201  md5sum_packages() Line 2829  md5sum_packages()
2829   then   then
2830   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2831   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2832   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2833   else   else
2834   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2835   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2253  uninstall_packages() Line 2881  uninstall_packages()
2881   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2882   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2883   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2884   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2885   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2886   echo   echo
2887   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2888   echo "( Press [CTRL+C] to abort )"   then
2889   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2890   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2891   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2892   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2893   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2894   sleep 1   do
2895   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2896   echo   sleep 1
2897   echo   done
2898     echo
2899     echo
2900     fi
2901    
2902   for pkg in ${list}   for pkg in ${list}
2903   do   do
# Line 2304  mage_uninstall() Line 2935  mage_uninstall()
2935   local PKGTYPE   local PKGTYPE
2936   local preinstall   local preinstall
2937   local postinstall   local postinstall
2938     local preremove
2939     local postremove
2940    
2941   local pcat   local pcat
2942   local pname   local pname
# Line 2339  mage_uninstall() Line 2972  mage_uninstall()
2972   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2973   echo -n "removing: "   echo -n "removing: "
2974   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2975   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2976    
2977   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2978   source ${magefile}   source ${magefile}
2979    
2980   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 3034  mage_uninstall()
3034  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
3035  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3036   echo "successfully removed."   echo "successfully removed."
3037    
3038     # unset these functions
3039     unset -f preinstall
3040     unset -f postinstall
3041     unset -f preremove
3042     unset -f postremove
3043  }  }
3044    
3045  show_etc_update_mesg() {  show_etc_update_mesg()
3046    {
3047   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3048    
3049   echo   echo
# Line 2415  show_etc_update_mesg() { Line 3055  show_etc_update_mesg() {
3055   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
3056   echo   echo
3057  }  }
3058    
3059    pkgsearch()
3060    {
3061     local string="$1"
3062     local result
3063     local pkg
3064     local pcat
3065     local pname
3066     local magefile
3067     local pver
3068     local pbuild
3069     local state
3070     local descriptiom
3071     local homepage
3072     local license
3073     local i
3074     local all_installed
3075     local ipver
3076     local ipbuild
3077     local latest_available
3078     local depsfull
3079     local sdepsfull
3080     local deps
3081     local sdeps
3082     local dep
3083     local sign
3084    
3085     # only names no versions
3086     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3087     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3088    
3089     # nothing found
3090     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
3091    
3092     for pkg in ${result}
3093     do
3094     # dirty, but does the job
3095     pcat="$(magename2pcat ${pkg}/foo)"
3096     pname="$(magename2pname ${pkg}-foo-foo)"
3097    
3098     # get highest version available
3099     magefile=$(get_highest_magefile ${pcat} ${pname})
3100    
3101     if [[ ! -z ${magefile} ]]
3102     then
3103     # now get all needed infos to print a nice output
3104     pver="$(magename2pver ${magefile})"
3105     pbuild="$(magename2pbuild ${magefile})"
3106     state="$(get_value_from_magefile STATE ${magefile})"
3107     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3108     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3109     license="$(get_value_from_magefile LICENSE ${magefile})"
3110    
3111     # all installed
3112     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3113     do
3114     ipver="$(magename2pver ${i})"
3115     ipbuild="$(magename2pbuild ${i})"
3116    
3117     if [[ -z ${all_installed} ]]
3118     then
3119     all_installed="${ipver}-${ipbuild}"
3120     else
3121     all_installed="${all_installed} ${ipver}-${ipbuild}"
3122     fi
3123     done
3124     [[ -z ${all_installed} ]] && all_installed="none"
3125    
3126     case ${state} in
3127     stable) state=${COLGREEN}"[s] ";;
3128     testing) state=${COLYELLOW}"[t] ";;
3129     unstable) state=${COLRED}"[u] ";;
3130     old) state=${COLGRAY}"[o] ";;
3131     esac
3132    
3133     latest_available="${pver}-${pbuild}"
3134     else
3135     # package is masked
3136     state="${COLRED}[m] "
3137     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3138     fi
3139    
3140     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3141     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3142    
3143     while read sign dep
3144     do
3145     case ${dep} in
3146     "") continue;;
3147     esac
3148    
3149     if [[ -z ${deps} ]]
3150     then
3151     deps="$(basename ${dep%-*})"
3152     else
3153     deps="${deps} $(basename ${dep%-*})"
3154     fi
3155     done << EOF
3156    ${depsfull}
3157    EOF
3158    
3159     while read sign dep
3160     do
3161     case ${dep} in
3162     "") continue;;
3163     esac
3164    
3165     if [[ -z ${sdeps} ]]
3166     then
3167     sdeps="$(basename ${dep%-*})"
3168     else
3169     sdeps="${sdeps} $(basename ${dep%-*})"
3170     fi
3171     done << EOF
3172    ${sdepsfull}
3173    EOF
3174    
3175     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3176     echo -e "      Latest available:   ${latest_available}"
3177     echo "      Installed versions: ${all_installed}"
3178     echo "      Description: ${description}"
3179     echo "      Homepage: ${homepage}"
3180     if [[ ! -z ${license} ]]
3181     then
3182     echo "      License:  ${license}"
3183     fi
3184     echo "      Depends:  ${deps}"
3185     echo "      SDepends: ${sdeps}"
3186     echo
3187    
3188     unset pcat
3189     unset pname
3190     unset magefile
3191     unset pver
3192     unset pbuild
3193     unset state
3194     unset descriptiom
3195     unset homepage
3196     unset all_installed
3197     unset ipver
3198     unset ipbuild
3199     unset depsfull
3200     unset sdepsfull
3201     unset deps
3202     unset sdeps
3203     unset dep
3204     unset sign
3205     done
3206    }
3207    
3208    export_inherits()
3209    {
3210     local include="$1"
3211     shift
3212    
3213     while [ "$1" ]
3214     do
3215     local functions="$1"
3216    
3217     # sanity checks
3218     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3219     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3220    
3221     eval "${functions}() { ${include}_${functions} ; }"
3222    
3223     # debug
3224     mqueryfeature "debug" && typeset -f "${functions}"
3225    
3226     shift
3227     done
3228    }
3229    
3230    mlibdir()
3231    {
3232     local libdir=lib
3233     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3234    
3235     echo "${libdir}"
3236    }
3237    
3238    ## blacklisted ${magefile}
3239    blacklisted()
3240    {
3241     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3242    
3243     # compat
3244     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3245     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3246    
3247     # support both types for the moment
3248     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3249     then
3250     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3251     else
3252     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3253     fi
3254    
3255     # return 0 if the list not exist; nothin is masked
3256     [[ ! -f ${EXCLUDED} ]] && return 0
3257    
3258     local MAGEFILE="$1"
3259    
3260     local PCAT="$(magename2pcat ${MAGEFILE})"
3261     local PNAME="$(magename2pname ${MAGEFILE})"
3262     local PVER="$(magename2pver ${MAGEFILE})"
3263     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3264    
3265     local EXPCAT EXPNAME EXPVER EXPBUILD
3266     while read EXPCAT EXPNAME EXPVER EXPBUILD
3267     do
3268     # ignore spaces and comments
3269             case "${EXPCAT}" in
3270                     \#*|"") continue ;;
3271             esac
3272    
3273     # exclude full pver
3274     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3275     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3276     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3277     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3278     then
3279     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3280     fi
3281    
3282     # exclude pcat/pname only
3283     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3284     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3285     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3286     then
3287     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3288     fi
3289     done << EOF
3290    $( cat ${EXCLUDED}; echo)
3291    EOF
3292    
3293     return 0
3294    }
3295    
3296    # need_busybox_support ${cmd}
3297    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3298    need_busybox_support()
3299    {
3300     local cmd
3301     local busybox
3302     cmd="$1"
3303    
3304     for busybox in {,/usr}/bin/busybox
3305     do
3306     if [[ -x ${busybox} ]]
3307     then
3308     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3309     then
3310     # needs busybox support
3311     return 0
3312     fi
3313     fi
3314     done
3315    
3316     # no busybox
3317     return 1
3318    }
3319    
3320    # busybox_filter_wget_options ${wget_opts}
3321    busybox_filter_wget_options()
3322    {
3323     local opts="$@"
3324     local i
3325     local fixed_opts
3326    
3327     if need_busybox_support wget
3328     then
3329     for i in ${opts}
3330     do
3331     # show only the allowed ones
3332     case ${i} in
3333     -c|--continue) fixed_opts+=" -c" ;;
3334     -s|--spider) fixed_opts+=" -s" ;;
3335     -q|--quiet) fixed_opts+=" -q" ;;
3336     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3337     --header) shift; fixed_opts+=" --header $1" ;;
3338     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3339     -P) shift; fixed_opts+=" -P $1" ;;
3340     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3341     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3342     # simply drop all other opts
3343     *) continue ;;
3344     esac
3345     done
3346    
3347     echo "${fixed_opts}"
3348     else
3349     echo "${opts}"
3350     fi
3351    }
3352    
3353    have_root_privileges()
3354    {
3355     local retval
3356    
3357     if [[ $(id -u) = 0 ]]
3358     then
3359     retval=0
3360     else
3361     retval=1
3362     fi
3363    
3364     return ${retval}
3365    }
3366    
3367    known_mage_feature()
3368    {
3369     local feature="$1"
3370     local retval
3371    
3372     case "${feature}" in
3373     autosvc|!autosvc) retval=0 ;;
3374     buildlog|!buildlog) retval=0 ;;
3375     ccache|!ccache) retval=0 ;;
3376     check|!check) retval=0 ;;
3377     compressdoc|!compressdoc) retval=0 ;;
3378     debug|!debug) retval=0 ;;
3379     distcc|!distcc) retval=0 ;;
3380     icecc|!icecc) retval=0 ;;
3381     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3382     libtool|!libtool) retval=0 ;;
3383     linuxsymlink|!linuxsymlink) retval=0 ;;
3384     pkgbuild|!pkgbuild) retval=0 ;;
3385     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3386     purge|!purge) retval=0 ;;
3387     qalint|!qalint) retval=0 ;;
3388     regentree|!regentree) retval=0 ;;
3389     resume|!resume) retval=0 ;;
3390     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3391     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3392     static|!static) retval=0 ;;
3393     stepbystep|!stepbystep) retval=0 ;;
3394     strip|!strip) retval=0 ;;
3395     verbose|!verbose) retval=0 ;;
3396     *) retval=1 ;;
3397     esac
3398    
3399     return "${retval}"
3400    }
3401    
3402    load_mage_features()
3403    {
3404     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3405     do
3406     FVERBOSE=off msetfeature ${i}
3407     done
3408    }
3409    
3410    msetfeature()
3411    {
3412     local feature
3413     local count
3414     local i
3415     local found
3416    
3417     for feature in $@
3418     do
3419     found=0
3420     count="${#MAGE_FEATURES_CURRENT[*]}"
3421    
3422     if ! known_mage_feature "${feature}"
3423     then
3424     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3425     return 3
3426     fi
3427    
3428     for ((i=0; i<count; i++))
3429     do
3430     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3431     then
3432     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3433     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3434     found=1
3435     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3436     then
3437     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3438     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3439     found=1
3440     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3441     then
3442     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3443     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3444     found=1
3445     fi
3446     done
3447    
3448     # if the feature was not found after proccessing the whole array
3449     # it was not declared. in this case enable it
3450     if [[ ${found} = 0 ]]
3451     then
3452     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3453     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3454     fi
3455    
3456     export MAGE_FEATURE_CURRENT
3457     done
3458    }
3459    
3460    mqueryfeature()
3461    {
3462     local feature="$1"
3463     local retval=1
3464     local i
3465    
3466     if known_mage_feature "${feature}"
3467     then
3468     for i in ${MAGE_FEATURES_CURRENT[*]}
3469     do
3470     if [[ ${i} = ${feature} ]]
3471     then
3472     retval=0
3473     break # found break here
3474     fi
3475     done
3476     else
3477     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3478     retval=3
3479     fi
3480    
3481     return ${retval}
3482    }
3483    
3484    mprintfeatures()
3485    {
3486     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3487     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3488     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3489    }

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