Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 2225 by niro, Wed Oct 16 07:49:19 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-size OK"
85     else
86     echo "${dest}: file is empty ;("
87     retval=127
88     fi
89     done < ${file}
90     if [[ ${retval} != 127 ]]
91     then
92     # insert an empty line for cosmetic
93     echo
94    
95     # be verbose here
96     ${cmd} -c ${file} #&> /dev/null
97     retval="$?"
98     fi
99    
100     popd &> /dev/null
101     else
102     retval=1
103     fi
104    
105     return "${retval}"
106    }
107    
108    mcheckemptydir()
109    {
110     local dir="$1"
111     local retval=1
112    
113     if [[ ! -d ${dir} ]]
114     then
115     echo "mcheckemptydir(): '${dir}' is not a directory!"
116     retval=3
117     else
118     shopt -s nullglob dotglob
119     files=( ${dir}/* )
120     (( ${#files[*]} )) || retval=0
121     shopt -u nullglob dotglob
122     fi
123    
124     return ${retval}
125    }
126    
127    unpack_package()
128    {
129     local magefile="$1"
130     local pkg
131     local pkgtype
132     local tar_opts
133    
134     pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
135     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
136    
137     xtitle "[ Unpacking ${pkg} ]"
138    
139     # abort on virtual pkg
140     if [[ ${pkgtype} = virtual ]]
141     then
142     echo -ne " ${COLBLUE}---${COLDEFAULT}"
143     echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "
144     continue
145     fi
146    
147     # abort on sources pkg
148     if [[ ${pkgtype} = sources ]]
149     then
150     echo -ne " ${COLBLUE}---${COLDEFAULT}"
151     echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "
152     continue
153     fi
154    
155     # busybox?
156     if need_busybox_support tar
157     then
158     tar_opts="xjf"
159     else
160     tar_opts="xjmf"
161     fi
162    
163     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "
164     tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
165    }
166    
167  unpack_packages()  unpack_packages()
168  {  {
169   local list="$@"   local list="$@"
170   local magefile   local magefile
  local pkg  
  local pkgtype  
171   local count_current   local count_current
172   local count_total   local count_total
173     local tar_opts
174    
175   # get count of total packages   # get count of total packages
176   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 180  unpack_packages()
180    
181   for magefile in ${list}   for magefile in ${list}
182   do   do
183   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
184   (( 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}"  
185   done   done
186    
187   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 201  fix_mtime()
201   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
202   touch \   touch \
203   --no-create \   --no-create \
204     --no-dereference \
205   --time=mtime \   --time=mtime \
206   --reference "${reference}" \   --reference="${reference}" \
207   "${pathto}"   "${pathto}"
208    
209   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 257  install_directories()
257   while read pathto posix user group   while read pathto posix user group
258   do   do
259   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
260   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
261    
262   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
263   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 324  install_files()
324   is_config_protected "${pathto}"   is_config_protected "${pathto}"
325   retval="$?"   retval="$?"
326    
327   # 0 - not protected        #   # 0 - not protected         #
328   # 1 - error                #   # 1 - error                 #
329   # 2 - protected            #   # 2 - protected             #
330   # 3 - protected but masked #   # 3 - protected but masked  #
331     # 4 - protected but ignored #
332    
333   case ${retval} in   case ${retval} in
334   # file is not protected - (over)write it   # file is not protected - (over)write it
335   0|3)   0|3)
336   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
337   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
338   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
339   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 345  install_files()
345   "${user}" \   "${user}" \
346   "${group}" \   "${group}" \
347   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
349   "${md5sum}"   "${md5sum}"
350   ;;   ;;
351    
352   # file is protected, write backup file   # file is protected, write backup file
353   2)   2)
354   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
355   then   then
356   echo -en "${COLRED}"   echo -en "${COLRED}"
357   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 372  install_files()
372   "${user}" \   "${user}" \
373   "${group}" \   "${group}" \
374   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
375   "${dest_protected}")" \   "${dest_protected}")" \
376   "${md5sum}"   "${md5sum}"
377    
378   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
379   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
380   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
381   ;;   ;;
382    
383     # file is protected but ignored, delete the update/do nothing
384     4)
385     if mqueryfeature "verbose"
386     then
387     echo -en "${COLRED}"
388     echo -n "! ignr "
389     echo -en "${COLDEFAULT}"
390     echo " === FILE: ${MROOT}${pathto}"
391     fi
392     # simply do nothing here - only fix mtime
393     fix_descriptor ${pkgname}/.files \
394     "${pathto}" \
395     "${posix}" \
396     "${user}" \
397     "${group}" \
398     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
399     "${MROOT}${pathto}")" \
400     "${md5sum}"
401     ;;
402   esac   esac
403   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
404    
# Line 294  install_symlinks() Line 441  install_symlinks()
441   while read pathto posix link mtime   while read pathto posix link mtime
442   do   do
443   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
444   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
445    
446   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
447    
448   # fix mtime and db   # fix mtime and db
449   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
450   "${pathto}" \   "${pathto}" \
451   "${posix}" \   "${posix}" \
452   "${link}" \   "${link}" \
453   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
454   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
455    
456   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
457    
458   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
459   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
460   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
461    
462   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
463   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 473  install_blockdevices()
473   local pkgname="$1"   local pkgname="$1"
474   local pathto   local pathto
475   local posix   local posix
476     local user
477     local group
478   local IFS   local IFS
479    
480   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 488  install_blockdevices()
488   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
489   IFS=§   IFS=§
490    
491   while read pathto posix   while read pathto posix major minor user group
492   do   do
493   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
494   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
495    
496   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
497     # make it optional atm !!
498     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
499     then
500     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
501     fi
502   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
503    
504   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 515  install_characterdevices()
515   local pkgname="$1"   local pkgname="$1"
516   local pathto   local pathto
517   local posix   local posix
518     local major
519     local minor
520     local user
521     local group
522   local IFS   local IFS
523    
524   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 532  install_characterdevices()
532   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
533   IFS=§   IFS=§
534    
535   while read pathto posix   while read pathto posix major minor user group
536   do   do
537   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
538   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
539    
540     mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
541    
542   mknode -m ${posix} -c "${MROOT}${pathto}"   # make it optional atm !!
543     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
544     then
545     chown "${user}:${group}" "${MROOT}${pathto}"
546     fi
547   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
548    
549   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
550   IFS=$'\n'   IFS=$'\n'
551  }  }
552    
553    ###################################################
554    # function install_fifos                          #
555    # install_fifos $PKGNAME                    #
556    ###################################################
557    install_fifos()
558    {
559     local pkgname="$1"
560     local pathto
561     local posix
562     local user
563     local group
564     local IFS
565    
566     # sanity checks; abort if not given
567     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
568    
569     # check needed global vars
570     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
571    
572     # make it optional atm !!
573     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
574     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
575    
576     # sets fieldseperator to "§" instead of " "
577     IFS=§
578    
579     while read pathto posix user group
580     do
581     [ -z "${pathto}" ] && continue
582     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
583    
584     mkfifo -m "${posix}" "${MROOT}${pathto}"
585     chown "${user}:${group}" "${MROOT}${pathto}"
586     done < ${BUILDDIR}/${pkgname}/.fifo
587    
588     # very important: unsetting the '§' fieldseperator
589     IFS=$'\n'
590    }
591    
592    
593  ###################################################  ###################################################
594  # function build_doinstall                        #  # function build_doinstall                        #
595  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
596  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
597  ###################################################  ###################################################
598  build_doinstall()  build_doinstall()
599  {  {
# Line 398  build_doinstall() Line 601  build_doinstall()
601    
602   # sanity checks; abort if not given   # sanity checks; abort if not given
603   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
604    
605   # this is only a wrapper   # this is only a wrapper
606    
607   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 616  build_doinstall()
616   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
617   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
618   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
619     install_fifos ${pkgname} || die "install fifos ${pkgname}"
620  }  }
621    
622    
# Line 432  install_database_entry() Line 636  install_database_entry()
636   local magefile   local magefile
637   local dbrecorddir   local dbrecorddir
638   local provide   local provide
639     local i
640    
641   # very basic getops   # very basic getops
642   for i in $*   for i in $*
# Line 473  install_database_entry() Line 678  install_database_entry()
678    
679   # create fake file descriptors   # create fake file descriptors
680   # used by virtual and source packages   # used by virtual and source packages
681   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
682   do   do
683   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
684   done   done
# Line 492  install_database_entry() Line 696  install_database_entry()
696    
697   # normal packages needs these files   # normal packages needs these files
698   local i   local i
699   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
700   do   do
701   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
702   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
703     then
704     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
705     fi
706   done   done
707   ;;   ;;
708   esac   esac
# Line 504  install_database_entry() Line 711  install_database_entry()
711   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
712   if [ -n "${provide}" ]   if [ -n "${provide}" ]
713   then   then
714   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
715     do
716     virtuals_add "${i}" "${pcat}/${pname}"
717     done
718   fi   fi
719  }  }
720    
# Line 523  remove_database_entry() Line 733  remove_database_entry()
733   local magefile   local magefile
734   local dbrecorddir   local dbrecorddir
735   local provide   local provide
736     local i
737    
738   # very basic getops   # very basic getops
739   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 763  remove_database_entry()
763   # abort if mage file not exists   # abort if mage file not exists
764   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
765    
766   # first unregister virtuals   # remove virtuals only if no other exist
767   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
768   then   then
769   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
770     provide="$(get_value_from_magefile PROVIDE ${magefile})"
771     if [ -n "${provide}" ]
772     then
773     for i in ${provide}
774     do
775     virtuals_del "${i}" "${pcat}/${pname}"
776     done
777     fi
778   fi   fi
779    
780   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 784  remove_database_entry()
784   fi   fi
785  }  }
786    
787    # get the number of installed packages
788    count_installed_pkgs()
789    {
790     local pcat
791     local pname
792     local pkg
793     local i
794    
795     # very basic getops
796     for i in $*
797     do
798     case $1 in
799     --pcat|-c) shift; pcat="$1" ;;
800     --pname|-n) shift; pname="$1" ;;
801     esac
802     shift
803     done
804    
805     # sanity checks; abort if not given
806     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
807     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
808    
809     declare -i i=0
810     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
811     do
812     (( i++ ))
813     #echo "$i ${pkg}"
814     done
815    
816     # return the value
817     echo "${i}"
818    }
819    
820    
821  ###################################################  ###################################################
822  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  compare_mtime() Line 838  compare_mtime()
838    
839   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
840    
841   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
842   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
843   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  
844    
845   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
846    
# Line 662  remove_symlinks() Line 902  remove_symlinks()
902   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
903   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
904   then   then
905   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
906   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
907   continue   continue
908   fi   fi
# Line 674  remove_symlinks() Line 914  remove_symlinks()
914   # 1=keep me   #   # 1=keep me   #
915   case ${retval} in   case ${retval} in
916   0)   0)
917   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
918   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
919   ;;   ;;
920    
921   1)   1)
922   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
923   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
924   ;;   ;;
925   esac   esac
# Line 726  remove_files() Line 966  remove_files()
966   done   done
967    
968   # sanity checks; abort if not given   # sanity checks; abort if not given
969   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
970   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
971   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
972   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
973   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
974    
975   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 984  remove_files()
984   do   do
985   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
986    
987   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
988   then   then
989   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
990   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
991   continue   continue
992   fi   fi
# Line 758  remove_files() Line 998  remove_files()
998   # 1=keep me   #   # 1=keep me   #
999   case ${retval} in   case ${retval} in
1000   0)   0)
1001   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
1002   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
1003   ;;   is_config_protected "${pathto}"
1004     retval="$?"
1005    
1006     # 0 - not protected         #
1007     # 1 - error                 #
1008     # 2 - protected             #
1009     # 3 - protected but masked  #
1010     # 4 - protected but ignored #
1011    
1012     case ${retval} in
1013     # file is not protected - delete it
1014     0|3)
1015     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1016     rm "${MROOT}${pathto}"
1017     ;;
1018    
1019     # file is protected, do not delete
1020     2)
1021     if mqueryfeature "verbose"
1022     then
1023     echo -en "${COLRED}"
1024     echo -n "! prot "
1025     echo -en "${COLDEFAULT}"
1026     echo " === FILE: ${MROOT}${pathto}"
1027     fi
1028     ;;
1029    
1030     # file is protected but ignored, delete the update/do nothing
1031     4)
1032     if mqueryfeature "verbose"
1033     then
1034     echo -en "${COLRED}"
1035     echo -n "! ignr "
1036     echo -en "${COLDEFAULT}"
1037     echo " === FILE: ${MROOT}${pathto}"
1038     fi
1039     # simply do nothing here
1040     ;;
1041     esac
1042     ;;
1043   1)   1)
1044   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1045   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1046   ;;   ;;
1047   esac   esac
# Line 782  remove_blockdevices() Line 1060  remove_blockdevices()
1060  {  {
1061   local pathto   local pathto
1062   local posix   local posix
1063     local user
1064     local group
1065   local IFS   local IFS
1066   local pcat   local pcat
1067   local pname   local pname
# Line 805  remove_blockdevices() Line 1085  remove_blockdevices()
1085   done   done
1086    
1087   # sanity checks; abort if not given   # sanity checks; abort if not given
1088   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1089   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1090   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1091   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1092   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1093    
1094   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1099  remove_blockdevices()
1099   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1100   IFS=§   IFS=§
1101    
1102   while read pathto posix   while read pathto posix user group
1103   do   do
1104   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1105    
1106   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1107   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1108   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1109    
# Line 840  remove_characterdevices() Line 1120  remove_characterdevices()
1120  {  {
1121   local pathto   local pathto
1122   local posix   local posix
1123     local user
1124     local group
1125   local IFS   local IFS
1126   local pcat   local pcat
1127   local pname   local pname
# Line 863  remove_characterdevices() Line 1145  remove_characterdevices()
1145   done   done
1146    
1147   # sanity checks; abort if not given   # sanity checks; abort if not given
1148   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1149   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1150   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1151   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1152   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1153    
1154   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1159  remove_characterdevices()
1159   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1160   IFS=§   IFS=§
1161    
1162   while read pathto posix   while read pathto posix user group
1163   do   do
1164   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1165    
1166   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1167   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1168   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1169    
# Line 891  remove_characterdevices() Line 1173  remove_characterdevices()
1173    
1174    
1175  ###################################################  ###################################################
1176    # function remove_fifos                           #
1177    # remove_fifos $PKGNAME                     #
1178    ###################################################
1179    remove_fifos()
1180    {
1181     local pathto
1182     local posix
1183     local user
1184     local group
1185     local IFS
1186     local pcat
1187     local pname
1188     local pver
1189     local pbuild
1190     local i
1191     local pfull
1192    
1193     IFS=$'\n'
1194    
1195     # very basic getops
1196     for i in $*
1197     do
1198     case $1 in
1199     --pcat|-c) shift; pcat="$1" ;;
1200     --pname|-n) shift; pname="$1" ;;
1201     --pver|-v) shift; pver="$1" ;;
1202     --pbuild|-b) shift; pbuild="$1" ;;
1203     esac
1204     shift
1205     done
1206    
1207     # sanity checks; abort if not given
1208     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1209     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1210     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1211     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1212     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1213    
1214     # check needed global vars
1215     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1216    
1217     # make it optional atm !!
1218     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1219     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1220    
1221     # sets fieldseperator to "§" instead of " "
1222     IFS=§
1223    
1224     while read pathto posix user group
1225     do
1226     [ -z "${pathto}" ] && continue
1227    
1228     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1229     rm "${MROOT}${pathto}"
1230     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1231    
1232     # very important: unsetting the '§' fieldseperator
1233     IFS=$'\n'
1234    }
1235    
1236    
1237    ###################################################
1238  # function remove_direcories                      #  # function remove_direcories                      #
1239  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1240  ###################################################  ###################################################
# Line 921  remove_directories() Line 1265  remove_directories()
1265   done   done
1266    
1267   # sanity checks; abort if not given   # sanity checks; abort if not given
1268   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1269   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1270   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1271   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1272   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1273    
1274   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1276  remove_directories()
1276    
1277   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1278    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1279   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1280   IFS=§   IFS=§
1281    
1282   while read pathto posix   # reversed order is mandatory !
1283     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1284   do   do
1285   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1286    
1287   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1288   then   then
1289   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1290   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1291   continue   continue
1292   fi   fi
# Line 953  remove_directories() Line 1294  remove_directories()
1294   # exclude .keep directories   # exclude .keep directories
1295   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1296   then   then
1297   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1298   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1299   continue   continue
1300   fi   fi
1301    
# Line 966  remove_directories() Line 1307  remove_directories()
1307    
1308   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1309   then   then
1310   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1311   else   else
1312   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1313   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1314   fi   fi
1315   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1316    
1317   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1318   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1322  remove_directories()
1322  ###################################################  ###################################################
1323  # function build_douninstall                      #  # function build_douninstall                      #
1324  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1325  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1326  ###################################################  ###################################################
1327  build_douninstall()  build_douninstall()
1328  {  {
# Line 1015  build_douninstall() Line 1356  build_douninstall()
1356   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1357   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1358    
1359   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1360   do   do
1361   remove_${i} \   remove_${i} \
1362   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1026  build_douninstall() Line 1367  build_douninstall()
1367   done   done
1368  }  }
1369    
1370    # convertmirrors [uri]
1371    convertmirrors()
1372    {
1373     local uri="$1"
1374     local scheme
1375     local mirror
1376     local mirrors
1377     local addon
1378     local real_uri
1379     local output
1380    
1381     # needs
1382     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1383     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1384     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1385     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1386     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1387    
1388     # check known uri schemes
1389     case ${uri} in
1390     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1391     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1392     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1393     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1394     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1395     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1396     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1397     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1398     esac
1399    
1400     if [[ ! -z ${mirrors} ]]
1401     then
1402     for mirror in ${mirrors}
1403     do
1404     # add a whitespace to the output
1405     [[ -z ${output} ]] || output+=" "
1406     output+="${mirror}${addon}/${uri/${scheme}/}"
1407     done
1408     else
1409     output="${uri}"
1410     fi
1411    
1412     echo "${output}"
1413    }
1414    
1415    mdownload()
1416    {
1417     local i
1418     local uri
1419     local real_uris
1420     local mirror
1421     local outputfile
1422     local outputdir
1423     local retval
1424     local wget_opts
1425    
1426     # very basic getops
1427     for i in $*
1428     do
1429     case $1 in
1430     --uri|-u) shift; uri="$1" ;;
1431     --dir|-d) shift; outputdir="$1" ;;
1432     esac
1433     shift
1434     done
1435    
1436     # sanity checks; abort if not given
1437     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1438     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1439    
1440     # convert mirrored uris to the real ones
1441     real_uris="$(convertmirrors ${uri})"
1442    
1443     # verbose or not
1444     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1445    
1446     # filter wget options if busybox was found
1447     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1448    
1449     # create outputdir
1450     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1451    
1452     for mirror in ${real_uris}
1453     do
1454     # get the name of the output file
1455     outputfile="${mirror##*/}"
1456    
1457     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1458     retval="$?"
1459     if [[ ${retval} = 0 ]]
1460     then
1461     break
1462     else
1463     continue
1464     fi
1465     done
1466    
1467     # return wget retval
1468     return "${retval}"
1469    }
1470    
1471  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1472  fetch_packages()  fetch_packages()
1473  {  {
1474     local i
1475   local list="$@"   local list="$@"
1476   local pkg   local pkg
1477   local mirr   local mirr
# Line 1037  fetch_packages() Line 1480  fetch_packages()
1480   local opt   local opt
1481   local count_current   local count_current
1482   local count_total   local count_total
1483     local wget_opts
1484    
1485   [ -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}."
1486    
1487     # filter wget command if busybox was found
1488     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1489    
1490   # get count of total packages   # get count of total packages
1491   declare -i count_current=0   declare -i count_current=0
# Line 1078  fetch_packages() Line 1525  fetch_packages()
1525   continue   continue
1526   fi   fi
1527    
1528   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1529   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1530   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  
   
1531   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1532   then   then
1533   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1534   fi   fi
1535   done   done
1536    
# Line 1113  syncmage() Line 1542  syncmage()
1542  {  {
1543   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1544   then   then
1545   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1546   fi   fi
1547    
1548   local i   local i
1549   for i in ${RSYNC}   for i in ${RSYNC}
1550   do   do
1551   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1552   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1553   then   then
1554   break   break
# Line 1142  syncmage() Line 1558  syncmage()
1558   done   done
1559    
1560   # clean up backup files (foo~)   # clean up backup files (foo~)
1561   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1562    
1563   # check if an newer mage version is available   # check if a newer mage version is available
1564   is_newer_mage_version_available   is_newer_mage_version_available
1565  }  }
1566    
1567    syncmage_tarball()
1568    {
1569     local latest_tarball
1570     local latest_md5
1571     local temp="$(mktemp -d)"
1572     local mirr mymirr
1573     local opt
1574     local tar_opts
1575     local wget_opts
1576    
1577     # try to get the md5 marked as latest on the server
1578     latest_md5="mage-latest.md5"
1579    
1580     # try to get the tarball marked as latest on the server
1581     latest_tarball="mage-latest.tar.bz2"
1582    
1583     # filter wget command if busybox was found
1584     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1585    
1586     for mirr in ${MIRRORS}
1587     do
1588     # path without distribution
1589     # (only for stable|testing|unstable and not DISTROTAG)
1590     case ${mirr##*/} in
1591     stable|testing|unstable) mymirr="${mirr%/*}";;
1592     *) mymirr="${mirr}";;
1593     esac
1594    
1595     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1596     echo "fetching latest md5 from ${mymirr} ..."
1597     mqueryfeature "!verbose" && opt="--quiet"
1598     wget \
1599     ${wget_opts} \
1600     --directory-prefix=${temp} \
1601     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1602    
1603     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1604     echo "fetching latest tarball from ${mymirr} ..."
1605     wget \
1606     ${wget_opts} \
1607     --directory-prefix=${temp} \
1608     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1609     if [[ $? = 0 ]]
1610     then
1611     break
1612     else
1613     continue
1614     fi
1615     done
1616    
1617     if [[ -f ${temp}/${latest_tarball} ]]
1618     then
1619     # check md5
1620     if [[ ! -f ${temp}/${latest_md5} ]]
1621     then
1622     die "md5 is missing ... aborting"
1623     else
1624     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1625     echo -n "checking md5sum... "
1626     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1627     fi
1628    
1629     if [[ -d ${MAGEDIR} ]]
1630     then
1631     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1632     echo "cleaning old mage-tree ${MAGEDIR}..."
1633     # honor mountpoints and empty dirs
1634     if mountpoint -q ${MAGEDIR}
1635     then
1636     if ! mcheckemptydir ${MAGEDIR}
1637     then
1638     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1639     fi
1640     else
1641     rm -rf ${MAGEDIR}
1642     fi
1643     fi
1644    
1645     if need_busybox_support tar
1646     then
1647     tar_opts="xjf"
1648     else
1649     tar_opts="xjmf"
1650     fi
1651    
1652     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1653     echo "updating mage-tree from tarball ..."
1654     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1655     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1656    
1657     if [[ -d ${temp} ]]
1658     then
1659     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1660     echo "cleaning temp-files ..."
1661     rm -rf ${temp}
1662     fi
1663    
1664     # check if a newer mage version is available
1665     is_newer_mage_version_available
1666     else
1667     die "Could not fetch the latest tarball ... aborting"
1668     fi
1669    }
1670    
1671  cleanpkg()  cleanpkg()
1672  {  {
1673   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1178  xtitleclean() Line 1698  xtitleclean()
1698  }  }
1699    
1700    
1701  # cuts full pathnames or versioniezed names down to basename  # unused?
1702  choppkgname()  #
1703  {  # # cuts full pathnames or versionized names down to basename
1704   #we want this only if full name was used  # choppkgname()
1705   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1706   then  # #we want this only if full name was used
1707   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1708   #ARCH comes from /etc/mage.rc  # then
1709   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1710    # #ARCH comes from ${MAGERC}
1711    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1712    #
1713    # #cuts version number
1714    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1715    # fi
1716    # }
1717    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1718    
1719  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1720  # $1=pname  # $1=pname
# Line 1218  pname2pcat() Line 1741  pname2pcat()
1741  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1742  check_stable_package()  check_stable_package()
1743  {  {
1744     # first check if this magefile is not blacklisted
1745     blacklisted "$1" || return 1
1746    
1747   local STATE   local STATE
1748   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1749    
1750   # state testing   # state testing
1751   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1752   then   then
1753   case ${STATE} in   case ${STATE} in
1754   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1757  check_stable_package()
1757   fi   fi
1758    
1759   # state unstable   # state unstable
1760   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1761   then   then
1762   case ${STATE} in   case ${STATE} in
1763   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1783  get_highest_magefile()
1783   local PNAME="$2"   local PNAME="$2"
1784   local magefile   local magefile
1785    
1786   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1787     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1788   do   do
1789     [[ -z ${magefile} ]] && continue
1790   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1791   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1792   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1793   then   then
1794   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1795   #for debug only   #for debug only
1796   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1797   fi   fi
1798   done   done
1799    
  # 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  
   
1800   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1801   return 0   return 0
1802  }  }
# Line 1304  get_highest_magefile() Line 1811  get_highest_magefile()
1811  #        1 - error                                #  #        1 - error                                #
1812  #        2 - protected                            #  #        2 - protected                            #
1813  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1814    #        4 - protected but ignored                #
1815  #                                                 #  #                                                 #
1816  ###################################################  ###################################################
1817  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1820  is_config_protected()
1820   local TEST   local TEST
1821   local PROTECTED   local PROTECTED
1822   local IFS   local IFS
1823     local i
1824     local x
1825    
1826   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1827    
1828   # file does not exist; it can be written   # file does not exist; it can be written
1829   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1830    
1831   # to be safe; it may be '§'   # to be safe; it may be '§'
1832   IFS=' '   IFS=' '
1833    
1834   # check ob in config protect   # check if config protected
1835   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1836   do   do
1837   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1838   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1839   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1840   then   then
1841   # setzen das es protected ist   # file is config proteced
1842   PROTECTED=TRUE   PROTECTED=TRUE
1843    
1844   # check ob nicht doch maskiert   # check if not masked
1845   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1846   do   do
1847   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1848   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1849   then   then
1850   PROTECTED=MASKED   PROTECTED=MASKED
1851   fi   fi
1852   done   done
1853    
1854     # check if not ignored
1855     for x in ${CONFIG_PROTECT_IGNORE}
1856     do
1857     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1858     if [[ ${TEST} != ${EXPFILE} ]]
1859     then
1860     PROTECTED=IGNORED
1861     fi
1862     done
1863   fi   fi
1864   done   done
1865    
# Line 1354  is_config_protected() Line 1874  is_config_protected()
1874   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1875   return 3   return 3
1876   ;;   ;;
1877     IGNORED)
1878     #echo "I'm protected, but ignored - keep me, del update"
1879     return 4
1880     ;;
1881   *)   *)
1882   #echo "delete me"   #echo "delete me"
1883   return 0   return 0
# Line 1371  is_config_protected() Line 1895  is_config_protected()
1895  ###################################################  ###################################################
1896  count_protected_files()  count_protected_files()
1897  {  {
1898   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1899     local dirname="${file%/*}"
1900     local filename="${file##*/}"
1901     local count
1902     local output
1903     local oldprotected
1904     local i
1905     local x
1906    
1907     # hack; do not honor a global set IFS like '§'
1908     local IFS
1909    
1910     count=0
1911    
1912     # check if there are already protected files
1913     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1914     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1915     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1916     do
1917     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1918     done
1919    
1920     # convert 0001 -> 1; 0120 -> 120 etc
1921     # use bash internal base functions to this task
1922     x="$((10#${count}))"
1923     for (( i=0; i<x; i++ ))
1924     do
1925     if [[ ${count:${i}:1} != 0 ]]
1926     then
1927     count="${count:${i}}"
1928     break
1929     fi
1930     done
1931    
1932     count="$(( ${count}+1 ))"
1933    
1934     # fill output up with zeros
1935     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1936     output="${output}${count}"
1937    
1938     echo "${output}"
1939  }  }
1940    
1941  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1952  get_uninstall_candidates()
1952   local list   local list
1953   local pcatdir   local pcatdir
1954   local protected   local protected
1955     local i
1956    
1957   # very basic getops   # very basic getops
1958   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1965  get_uninstall_candidates()
1965   shift   shift
1966   done   done
1967    
1968   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1969   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1970    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1971    
1972    
1973   # check needed global vars   # check needed global vars
1974   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1975    
1976   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1977   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1978    
1979   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1980   do   do
# Line 1493  virtuals_add() Line 2059  virtuals_add()
2059   local oldline   local oldline
2060   local line i   local line i
2061   local installed_file   local installed_file
2062     local OLDIFS
2063    
2064   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2065   then   then
2066   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2067   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2068   do   do
2069   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2082  virtuals_add()
2082   # make a backup   # make a backup
2083   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2084    
2085     OLDIFS="${IFS}"
2086   IFS=$'\n'   IFS=$'\n'
2087   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2088   do   do
# Line 1526  virtuals_add() Line 2094  virtuals_add()
2094   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2095   fi   fi
2096   done   done
2097     # unset IFS
2098   #unset IFS   IFS="${OLDIFS}"
2099   else   else
2100   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2101   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2102   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2103   fi   fi
# Line 1539  virtuals_add() Line 2107  virtuals_add()
2107    
2108  #deletes pakages from virtual database  #deletes pakages from virtual database
2109  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2110  virtuals_del() {  virtuals_del()
2111    {
2112    
2113   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2114     local pkgname="$2"
2115   VIRTUAL_NAME=$1   local oldline
2116   PKG_NAME=$2   local method
2117     local line i x
2118   #first check if exists   local pkg_installed
2119   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2120    
2121     # first check if exists
2122     if virtuals_read ${virtualname}
2123   then   then
2124   #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}
2125   declare -i x=0   declare -i x=0
2126   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2127   do   do
2128   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2129   then   then
2130   PKG_INSTALLED=true   pkg_installed=true
2131   fi   fi
2132   ((x++))   ((x++))
2133   done   done
2134    
2135   #abort if not installed   # abort if not installed
2136   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2137   then   then
2138   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2139     echo "${pkgname} does not exists in ${virtualname}."
2140   return 0   return 0
2141   fi   fi
2142    
2143   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2144   then   then
2145   METHOD=update   method=update
2146   else   else
2147   METHOD=delall   method=delall
2148   fi   fi
2149    
2150   #get the complete line   # get the complete line
2151   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2152    
2153   #make a backup   # make a backup of the db
2154   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2155    
2156   #parse virtualdb   # parse virtualdb
2157     OLDIFS="${IFS}"
2158   IFS=$'\n'   IFS=$'\n'
2159   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2160   do   do
2161   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2162   then   then
2163   #delall or update?   #delall or update?
2164   case ${METHOD} in   case ${method} in
2165   update)   update)
2166   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2167   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2168   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2169     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2170   ;;   ;;
2171   delall)   delall)
2172   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2173   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2174     # continue; do not write anything
2175   continue   continue
2176   ;;   ;;
2177   esac   esac
# Line 1603  virtuals_del() { Line 2179  virtuals_del() {
2179   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2180   fi   fi
2181   done   done
2182   unset IFS   # unset IFS
2183     IFS="${OLDIFS}"
2184   else   else
2185   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2186     echo "${virtualname} does not exists in virtual database."
2187   fi   fi
2188  }  }
2189    
# Line 1637  minclude() Line 2215  minclude()
2215  {  {
2216   local i   local i
2217    
2218   if [ -n "$@" ]   if [[ -n $* ]]
2219   then   then
2220   for i in $@   for i in $*
2221   do   do
2222   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2223   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2224   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2225   done   done
2226   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2227   fi   fi
2228  }  }
2229    
# Line 1653  sminclude() Line 2231  sminclude()
2231  {  {
2232   local i   local i
2233    
2234   if [ -n "$@" ]   if [[ -n $* ]]
2235   then   then
2236   for i in $@   for i in $*
2237   do   do
2238   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2239   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2248  is_newer_mage_version_available()
2248   local newest_mage   local newest_mage
2249   local installed_mage   local installed_mage
2250    
2251   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2252   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2253    
2254   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2257  is_newer_mage_version_available()
2257   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2258   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2259   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2260   echo "or your current system installation may brake."   echo "or your current system installation may break."
2261   echo   echo
2262   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2263   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2529  get_value_from_magefile()
2529   local magefile="$2"   local magefile="$2"
2530   local value   local value
2531    
2532     [[ -z ${var} ]] && return 1
2533     [[ -z ${magefile} ]] && return 1
2534    
2535   # local all possible vars of a mage file   # local all possible vars of a mage file
2536   # to prevent bad issues   # to prevent bad issues
2537   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2542  get_value_from_magefile()
2542   local SDEPEND   local SDEPEND
2543   local PROVIDE   local PROVIDE
2544   local PKGTYPE   local PKGTYPE
2545     local MAGE_TARGETS
2546     local SPLIT_PACKAGE_BASE
2547   local preinstall   local preinstall
2548   local postinstall   local postinstall
2549     local preremove
2550     local postremove
2551    
2552   # sanity checks   # sanity checks
2553   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2557  get_value_from_magefile()
2557   source ${magefile}   source ${magefile}
2558   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2559   echo "${value}"   echo "${value}"
2560    
2561     # unset these functions
2562     unset -f preinstall
2563     unset -f postinstall
2564     unset -f preremove
2565     unset -f postremove
2566  }  }
2567    
2568  mage_install()  mage_install()
# Line 1988  mage_install() Line 2579  mage_install()
2579   local PKGTYPE   local PKGTYPE
2580   local preinstall   local preinstall
2581   local postinstall   local postinstall
2582     local preremove
2583     local postremove
2584    
2585   local pcat   local pcat
2586   local pname   local pname
# Line 1997  mage_install() Line 2590  mage_install()
2590   local count_current   local count_current
2591   local magefile   local magefile
2592   local src_install   local src_install
2593     local i
2594    
2595   # very basic getops   # very basic getops
2596   for i in $*   for i in $*
# Line 2070  mage_install() Line 2664  mage_install()
2664   echo B:${pbuild}   echo B:${pbuild}
2665   fi   fi
2666    
2667   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2668     then
2669     # basic svn compat
2670     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2671     then
2672     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2673     do
2674     smage2file="${i}"
2675     done
2676     else
2677     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2678     fi
2679    
2680     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2681     then
2682     # basic svn compat
2683     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2684     then
2685     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2686     do
2687     smage2file="${i}"
2688     done
2689     else
2690     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2691     fi
2692    
2693     else
2694     # basic svn compat
2695     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2696     then
2697     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2698     do
2699     smage2file="${i}"
2700     done
2701     else
2702     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2703     fi
2704     fi
2705    
2706   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2707   then   then
2708     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2709   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2710   else   else
2711   echo   echo
# Line 2086  mage_install() Line 2719  mage_install()
2719   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2720   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2721   then   then
2722   # show a verbose message on src-install   unpack_package "${magefile}"
2723   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  
2724   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2725   fi   fi
2726    
# Line 2149  mage_install() Line 2776  mage_install()
2776  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2777  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2778   echo "successfully installed."   echo "successfully installed."
2779    
2780     # unset these functions
2781     unset -f preinstall
2782     unset -f postinstall
2783     unset -f preremove
2784     unset -f postremove
2785  }  }
2786    
2787  md5sum_packages()  md5sum_packages()
# Line 2201  md5sum_packages() Line 2834  md5sum_packages()
2834   then   then
2835   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2836   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2837   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2838   else   else
2839   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2840   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2253  uninstall_packages() Line 2886  uninstall_packages()
2886   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2887   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2888   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2889   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2890   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2891   echo   echo
2892   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2893   echo "( Press [CTRL+C] to abort )"   then
2894   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2895   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2896   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2897   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2898   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2899   sleep 1   do
2900   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2901   echo   sleep 1
2902   echo   done
2903     echo
2904     echo
2905     fi
2906    
2907   for pkg in ${list}   for pkg in ${list}
2908   do   do
# Line 2304  mage_uninstall() Line 2940  mage_uninstall()
2940   local PKGTYPE   local PKGTYPE
2941   local preinstall   local preinstall
2942   local postinstall   local postinstall
2943     local preremove
2944     local postremove
2945    
2946   local pcat   local pcat
2947   local pname   local pname
# Line 2339  mage_uninstall() Line 2977  mage_uninstall()
2977   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2978   echo -n "removing: "   echo -n "removing: "
2979   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2980   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2981    
2982   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2983   source ${magefile}   source ${magefile}
2984    
2985   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 3039  mage_uninstall()
3039  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
3040  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3041   echo "successfully removed."   echo "successfully removed."
3042    
3043     # unset these functions
3044     unset -f preinstall
3045     unset -f postinstall
3046     unset -f preremove
3047     unset -f postremove
3048  }  }
3049    
3050  show_etc_update_mesg() {  show_etc_update_mesg()
3051    {
3052   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3053    
3054   echo   echo
# Line 2415  show_etc_update_mesg() { Line 3060  show_etc_update_mesg() {
3060   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
3061   echo   echo
3062  }  }
3063    
3064    pkgsearch()
3065    {
3066     local string="$1"
3067     local result
3068     local pkg
3069     local pcat
3070     local pname
3071     local magefile
3072     local pver
3073     local pbuild
3074     local state
3075     local descriptiom
3076     local homepage
3077     local license
3078     local i
3079     local all_installed
3080     local ipver
3081     local ipbuild
3082     local latest_available
3083     local depsfull
3084     local sdepsfull
3085     local deps
3086     local sdeps
3087     local dep
3088     local sign
3089    
3090     # only names no versions
3091     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3092     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3093    
3094     # nothing found
3095     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
3096    
3097     for pkg in ${result}
3098     do
3099     # dirty, but does the job
3100     pcat="$(magename2pcat ${pkg}/foo)"
3101     pname="$(magename2pname ${pkg}-foo-foo)"
3102    
3103     # get highest version available
3104     magefile=$(get_highest_magefile ${pcat} ${pname})
3105    
3106     if [[ ! -z ${magefile} ]]
3107     then
3108     # now get all needed infos to print a nice output
3109     pver="$(magename2pver ${magefile})"
3110     pbuild="$(magename2pbuild ${magefile})"
3111     state="$(get_value_from_magefile STATE ${magefile})"
3112     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3113     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3114     license="$(get_value_from_magefile LICENSE ${magefile})"
3115    
3116     # all installed
3117     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3118     do
3119     ipver="$(magename2pver ${i})"
3120     ipbuild="$(magename2pbuild ${i})"
3121    
3122     if [[ -z ${all_installed} ]]
3123     then
3124     all_installed="${ipver}-${ipbuild}"
3125     else
3126     all_installed="${all_installed} ${ipver}-${ipbuild}"
3127     fi
3128     done
3129     [[ -z ${all_installed} ]] && all_installed="none"
3130    
3131     case ${state} in
3132     stable) state=${COLGREEN}"[s] ";;
3133     testing) state=${COLYELLOW}"[t] ";;
3134     unstable) state=${COLRED}"[u] ";;
3135     old) state=${COLGRAY}"[o] ";;
3136     esac
3137    
3138     latest_available="${pver}-${pbuild}"
3139     else
3140     # package is masked
3141     state="${COLRED}[m] "
3142     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3143     fi
3144    
3145     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3146     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3147    
3148     while read sign dep
3149     do
3150     case ${dep} in
3151     "") continue;;
3152     esac
3153    
3154     if [[ -z ${deps} ]]
3155     then
3156     deps="$(basename ${dep%-*})"
3157     else
3158     deps="${deps} $(basename ${dep%-*})"
3159     fi
3160     done << EOF
3161    ${depsfull}
3162    EOF
3163    
3164     while read sign dep
3165     do
3166     case ${dep} in
3167     "") continue;;
3168     esac
3169    
3170     if [[ -z ${sdeps} ]]
3171     then
3172     sdeps="$(basename ${dep%-*})"
3173     else
3174     sdeps="${sdeps} $(basename ${dep%-*})"
3175     fi
3176     done << EOF
3177    ${sdepsfull}
3178    EOF
3179    
3180     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3181     echo -e "      Latest available:   ${latest_available}"
3182     echo "      Installed versions: ${all_installed}"
3183     echo "      Description: ${description}"
3184     echo "      Homepage: ${homepage}"
3185     if [[ ! -z ${license} ]]
3186     then
3187     echo "      License:  ${license}"
3188     fi
3189     echo "      Depends:  ${deps}"
3190     echo "      SDepends: ${sdeps}"
3191     echo
3192    
3193     unset pcat
3194     unset pname
3195     unset magefile
3196     unset pver
3197     unset pbuild
3198     unset state
3199     unset descriptiom
3200     unset homepage
3201     unset all_installed
3202     unset ipver
3203     unset ipbuild
3204     unset depsfull
3205     unset sdepsfull
3206     unset deps
3207     unset sdeps
3208     unset dep
3209     unset sign
3210     done
3211    }
3212    
3213    export_inherits()
3214    {
3215     local include="$1"
3216     shift
3217    
3218     while [ "$1" ]
3219     do
3220     local functions="$1"
3221    
3222     # sanity checks
3223     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3224     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3225    
3226     eval "${functions}() { ${include}_${functions} ; }"
3227    
3228     # debug
3229     mqueryfeature "debug" && typeset -f "${functions}"
3230    
3231     shift
3232     done
3233    }
3234    
3235    mlibdir()
3236    {
3237     local libdir=lib
3238     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3239    
3240     echo "${libdir}"
3241    }
3242    
3243    ## blacklisted ${magefile}
3244    blacklisted()
3245    {
3246     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3247    
3248     # compat
3249     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3250     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3251    
3252     # support both types for the moment
3253     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3254     then
3255     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3256     else
3257     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3258     fi
3259    
3260     # return 0 if the list not exist; nothin is masked
3261     [[ ! -f ${EXCLUDED} ]] && return 0
3262    
3263     local MAGEFILE="$1"
3264    
3265     local PCAT="$(magename2pcat ${MAGEFILE})"
3266     local PNAME="$(magename2pname ${MAGEFILE})"
3267     local PVER="$(magename2pver ${MAGEFILE})"
3268     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3269    
3270     local EXPCAT EXPNAME EXPVER EXPBUILD
3271     while read EXPCAT EXPNAME EXPVER EXPBUILD
3272     do
3273     # ignore spaces and comments
3274             case "${EXPCAT}" in
3275                     \#*|"") continue ;;
3276             esac
3277    
3278     # exclude full pver
3279     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3280     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3281     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3282     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3283     then
3284     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3285     fi
3286    
3287     # exclude pcat/pname only
3288     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3289     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3290     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3291     then
3292     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3293     fi
3294     done << EOF
3295    $( cat ${EXCLUDED}; echo)
3296    EOF
3297    
3298     return 0
3299    }
3300    
3301    # need_busybox_support ${cmd}
3302    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3303    need_busybox_support()
3304    {
3305     local cmd
3306     local busybox
3307     cmd="$1"
3308    
3309     for busybox in {,/usr}/bin/busybox
3310     do
3311     if [[ -x ${busybox} ]]
3312     then
3313     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3314     then
3315     # needs busybox support
3316     return 0
3317     fi
3318     fi
3319     done
3320    
3321     # no busybox
3322     return 1
3323    }
3324    
3325    # busybox_filter_wget_options ${wget_opts}
3326    busybox_filter_wget_options()
3327    {
3328     local opts="$@"
3329     local i
3330     local fixed_opts
3331    
3332     if need_busybox_support wget
3333     then
3334     for i in ${opts}
3335     do
3336     # show only the allowed ones
3337     case ${i} in
3338     -c|--continue) fixed_opts+=" -c" ;;
3339     -s|--spider) fixed_opts+=" -s" ;;
3340     -q|--quiet) fixed_opts+=" -q" ;;
3341     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3342     --header) shift; fixed_opts+=" --header $1" ;;
3343     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3344     -P) shift; fixed_opts+=" -P $1" ;;
3345     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3346     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3347     # simply drop all other opts
3348     *) continue ;;
3349     esac
3350     done
3351    
3352     echo "${fixed_opts}"
3353     else
3354     echo "${opts}"
3355     fi
3356    }
3357    
3358    have_root_privileges()
3359    {
3360     local retval
3361    
3362     if [[ $(id -u) = 0 ]]
3363     then
3364     retval=0
3365     else
3366     retval=1
3367     fi
3368    
3369     return ${retval}
3370    }
3371    
3372    known_mage_feature()
3373    {
3374     local feature="$1"
3375     local retval
3376    
3377     case "${feature}" in
3378     autosvc|!autosvc) retval=0 ;;
3379     buildlog|!buildlog) retval=0 ;;
3380     ccache|!ccache) retval=0 ;;
3381     check|!check) retval=0 ;;
3382     compressdoc|!compressdoc) retval=0 ;;
3383     debug|!debug) retval=0 ;;
3384     distcc|!distcc) retval=0 ;;
3385     icecc|!icecc) retval=0 ;;
3386     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3387     libtool|!libtool) retval=0 ;;
3388     linuxsymlink|!linuxsymlink) retval=0 ;;
3389     pkgbuild|!pkgbuild) retval=0 ;;
3390     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3391     purge|!purge) retval=0 ;;
3392     qalint|!qalint) retval=0 ;;
3393     regentree|!regentree) retval=0 ;;
3394     resume|!resume) retval=0 ;;
3395     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3396     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3397     static|!static) retval=0 ;;
3398     stepbystep|!stepbystep) retval=0 ;;
3399     strip|!strip) retval=0 ;;
3400     verbose|!verbose) retval=0 ;;
3401     *) retval=1 ;;
3402     esac
3403    
3404     return "${retval}"
3405    }
3406    
3407    load_mage_features()
3408    {
3409     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3410     do
3411     FVERBOSE=off msetfeature ${i}
3412     done
3413    }
3414    
3415    msetfeature()
3416    {
3417     local feature
3418     local count
3419     local i
3420     local found
3421    
3422     for feature in $@
3423     do
3424     found=0
3425     count="${#MAGE_FEATURES_CURRENT[*]}"
3426    
3427     if ! known_mage_feature "${feature}"
3428     then
3429     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3430     return 3
3431     fi
3432    
3433     for ((i=0; i<count; i++))
3434     do
3435     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3436     then
3437     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${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 disabled, enabling it!${COLDEFAULT}"
3443     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3444     found=1
3445     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3446     then
3447     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3448     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3449     found=1
3450     fi
3451     done
3452    
3453     # if the feature was not found after proccessing the whole array
3454     # it was not declared. in this case enable it
3455     if [[ ${found} = 0 ]]
3456     then
3457     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3458     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3459     fi
3460    
3461     export MAGE_FEATURE_CURRENT
3462     done
3463    }
3464    
3465    mqueryfeature()
3466    {
3467     local feature="$1"
3468     local retval=1
3469     local i
3470    
3471     if known_mage_feature "${feature}"
3472     then
3473     for i in ${MAGE_FEATURES_CURRENT[*]}
3474     do
3475     if [[ ${i} = ${feature} ]]
3476     then
3477     retval=0
3478     break # found break here
3479     fi
3480     done
3481     else
3482     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3483     retval=3
3484     fi
3485    
3486     return ${retval}
3487    }
3488    
3489    mprintfeatures()
3490    {
3491     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3492     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3493     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3494    }

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