Magellan Linux

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

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

revision 445 by niro, Mon Mar 19 20:00:35 2007 UTC revision 2224 by niro, Wed Oct 16 07:46:58 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.28 2007-03-19 20:00:35 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49    
50     # very basic getops
51     for i in $*
52     do
53     case $1 in
54     --rundir|-r) shift; rundir="$1" ;;
55     --file|-f) shift; file="$1" ;;
56     --method|-m) shift; method="$1" ;;
57     esac
58     shift
59     done
60    
61     # sanity checks
62     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
63     [[ -z ${file} ]] && die "mchecksum(): file missing"
64     [[ -z ${method} ]] && die "mchecksum(): method missing"
65    
66     case ${method} in
67     md5) cmd="md5sum" ;;
68     sha256) cmd="sha256sum" ;;
69     *) die "mchecksum(): unknown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     # be verbose here
76     ${cmd} -c ${file} #&> /dev/null
77     retval="$?"
78     popd &> /dev/null
79     else
80     retval=1
81     fi
82    
83     return "${retval}"
84    }
85    
86    mcheckemptydir()
87    {
88     local dir="$1"
89     local retval=1
90    
91     if [[ ! -d ${dir} ]]
92     then
93     echo "mcheckemptydir(): '${dir}' is not a directory!"
94     retval=3
95     else
96     shopt -s nullglob dotglob
97     files=( ${dir}/* )
98     (( ${#files[*]} )) || retval=0
99     shopt -u nullglob dotglob
100     fi
101    
102     return ${retval}
103    }
104    
105    unpack_package()
106    {
107     local magefile="$1"
108     local pkg
109     local pkgtype
110     local tar_opts
111    
112     pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"
113     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
114    
115     xtitle "[ Unpacking ${pkg} ]"
116    
117     # abort on virtual pkg
118     if [[ ${pkgtype} = virtual ]]
119     then
120     echo -ne " ${COLBLUE}---${COLDEFAULT}"
121     echo " !unpack virtual ${pkg/.${PKGSUFFIX}/} ... "
122     continue
123     fi
124    
125     # abort on sources pkg
126     if [[ ${pkgtype} = sources ]]
127     then
128     echo -ne " ${COLBLUE}---${COLDEFAULT}"
129     echo " !unpack sources ${pkg/.${PKGSUFFIX}/} ... "
130     continue
131     fi
132    
133     # busybox?
134     if need_busybox_support tar
135     then
136     tar_opts="xjf"
137     else
138     tar_opts="xjmf"
139     fi
140    
141     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkg} ... "
142     tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
143    }
144    
145  unpack_packages()  unpack_packages()
146  {  {
147   local list="$@"   local list="$@"
148   local magefile   local magefile
  local pkg  
  local pkgtype  
149   local count_current   local count_current
150   local count_total   local count_total
151     local tar_opts
152    
153   # get count of total packages   # get count of total packages
154   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 158  unpack_packages()
158    
159   for magefile in ${list}   for magefile in ${list}
160   do   do
161   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
162   (( 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}"  
163   done   done
164    
165   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 179  fix_mtime()
179   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
180   touch \   touch \
181   --no-create \   --no-create \
182     --no-dereference \
183   --time=mtime \   --time=mtime \
184   --reference "${reference}" \   --reference="${reference}" \
185   "${pathto}"   "${pathto}"
186    
187   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 235  install_directories()
235   while read pathto posix user group   while read pathto posix user group
236   do   do
237   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
238   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
239    
240   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
241   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 302  install_files()
302   is_config_protected "${pathto}"   is_config_protected "${pathto}"
303   retval="$?"   retval="$?"
304    
305   # 0 - not protected        #   # 0 - not protected         #
306   # 1 - error                #   # 1 - error                 #
307   # 2 - protected            #   # 2 - protected             #
308   # 3 - protected but masked #   # 3 - protected but masked  #
309     # 4 - protected but ignored #
310    
311   case ${retval} in   case ${retval} in
312   # file is not protected - (over)write it   # file is not protected - (over)write it
313   0|3)   0|3)
314   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
315   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
316   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
317   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 323  install_files()
323   "${user}" \   "${user}" \
324   "${group}" \   "${group}" \
325   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
326   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
327   "${md5sum}"   "${md5sum}"
328   ;;   ;;
329    
330   # file is protected, write backup file   # file is protected, write backup file
331   2)   2)
332   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
333   then   then
334   echo -en "${COLRED}"   echo -en "${COLRED}"
335   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 350  install_files()
350   "${user}" \   "${user}" \
351   "${group}" \   "${group}" \
352   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
353   "${dest_protected}")" \   "${dest_protected}")" \
354   "${md5sum}"   "${md5sum}"
355    
356   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
357   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
358   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
359   ;;   ;;
360    
361     # file is protected but ignored, delete the update/do nothing
362     4)
363     if mqueryfeature "verbose"
364     then
365     echo -en "${COLRED}"
366     echo -n "! ignr "
367     echo -en "${COLDEFAULT}"
368     echo " === FILE: ${MROOT}${pathto}"
369     fi
370     # simply do nothing here - only fix mtime
371     fix_descriptor ${pkgname}/.files \
372     "${pathto}" \
373     "${posix}" \
374     "${user}" \
375     "${group}" \
376     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
377     "${MROOT}${pathto}")" \
378     "${md5sum}"
379     ;;
380   esac   esac
381   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
382    
# Line 294  install_symlinks() Line 419  install_symlinks()
419   while read pathto posix link mtime   while read pathto posix link mtime
420   do   do
421   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
422   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
423    
424   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
425    
426   # fix mtime and db   # fix mtime and db
427   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
428   "${pathto}" \   "${pathto}" \
429   "${posix}" \   "${posix}" \
430   "${link}" \   "${link}" \
431   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
432   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
433    
434   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
435    
436   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
437   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
438   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
439    
440   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
441   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 451  install_blockdevices()
451   local pkgname="$1"   local pkgname="$1"
452   local pathto   local pathto
453   local posix   local posix
454     local user
455     local group
456   local IFS   local IFS
457    
458   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 466  install_blockdevices()
466   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
467   IFS=§   IFS=§
468    
469   while read pathto posix   while read pathto posix major minor user group
470   do   do
471   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
472   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
473    
474   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
475     # make it optional atm !!
476     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
477     then
478     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
479     fi
480   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
481    
482   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 363  install_characterdevices() Line 495  install_characterdevices()
495   local posix   local posix
496   local major   local major
497   local minor   local minor
498     local user
499     local group
500   local IFS   local IFS
501    
502   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 376  install_characterdevices() Line 510  install_characterdevices()
510   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
511   IFS=§   IFS=§
512    
513   while read pathto posix major minor   while read pathto posix major minor user group
514   do   do
515   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
516   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
517    
518   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
519    
520     # make it optional atm !!
521     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
522     then
523     chown "${user}:${group}" "${MROOT}${pathto}"
524     fi
525   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
526    
527   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
528   IFS=$'\n'   IFS=$'\n'
529  }  }
530    
531    ###################################################
532    # function install_fifos                          #
533    # install_fifos $PKGNAME                    #
534    ###################################################
535    install_fifos()
536    {
537     local pkgname="$1"
538     local pathto
539     local posix
540     local user
541     local group
542     local IFS
543    
544     # sanity checks; abort if not given
545     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
546    
547     # check needed global vars
548     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
549    
550     # make it optional atm !!
551     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
552     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
553    
554     # sets fieldseperator to "§" instead of " "
555     IFS=§
556    
557     while read pathto posix user group
558     do
559     [ -z "${pathto}" ] && continue
560     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
561    
562     mkfifo -m "${posix}" "${MROOT}${pathto}"
563     chown "${user}:${group}" "${MROOT}${pathto}"
564     done < ${BUILDDIR}/${pkgname}/.fifo
565    
566     # very important: unsetting the '§' fieldseperator
567     IFS=$'\n'
568    }
569    
570    
571  ###################################################  ###################################################
572  # function build_doinstall                        #  # function build_doinstall                        #
573  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
574  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
575  ###################################################  ###################################################
576  build_doinstall()  build_doinstall()
577  {  {
# Line 400  build_doinstall() Line 579  build_doinstall()
579    
580   # sanity checks; abort if not given   # sanity checks; abort if not given
581   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
582    
583   # this is only a wrapper   # this is only a wrapper
584    
585   # NOTE:   # NOTE:
# Line 415  build_doinstall() Line 594  build_doinstall()
594   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
595   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
596   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
597     install_fifos ${pkgname} || die "install fifos ${pkgname}"
598  }  }
599    
600    
# Line 476  install_database_entry() Line 656  install_database_entry()
656    
657   # create fake file descriptors   # create fake file descriptors
658   # used by virtual and source packages   # used by virtual and source packages
659   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
660   do   do
661   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
662   done   done
# Line 494  install_database_entry() Line 674  install_database_entry()
674    
675   # normal packages needs these files   # normal packages needs these files
676   local i   local i
677   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
678   do   do
679   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
680   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
681     then
682     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
683     fi
684   done   done
685   ;;   ;;
686   esac   esac
# Line 633  compare_mtime() Line 816  compare_mtime()
816    
817   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
818    
819   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
820   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
821   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  
822    
823   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
824    
# Line 708  remove_symlinks() Line 880  remove_symlinks()
880   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
881   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
882   then   then
883   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
884   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
885   continue   continue
886   fi   fi
# Line 720  remove_symlinks() Line 892  remove_symlinks()
892   # 1=keep me   #   # 1=keep me   #
893   case ${retval} in   case ${retval} in
894   0)   0)
895   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
896   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
897   ;;   ;;
898    
899   1)   1)
900   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
901   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
902   ;;   ;;
903   esac   esac
# Line 772  remove_files() Line 944  remove_files()
944   done   done
945    
946   # sanity checks; abort if not given   # sanity checks; abort if not given
947   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
948   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
949   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
950   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
951   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
952    
953   # check needed global vars   # check needed global vars
# Line 792  remove_files() Line 964  remove_files()
964    
965   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
966   then   then
967   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
968   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
969   continue   continue
970   fi   fi
# Line 809  remove_files() Line 981  remove_files()
981   is_config_protected "${pathto}"   is_config_protected "${pathto}"
982   retval="$?"   retval="$?"
983    
984   # 0 - not protected        #   # 0 - not protected         #
985   # 1 - error                #   # 1 - error                 #
986   # 2 - protected            #   # 2 - protected             #
987   # 3 - protected but masked #   # 3 - protected but masked  #
988     # 4 - protected but ignored #
989    
990   case ${retval} in   case ${retval} in
991   # file is not protected - delete it   # file is not protected - delete it
992   0|3)   0|3)
993   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
994   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
995   ;;   ;;
996    
997   # file is protected, do not delete   # file is protected, do not delete
998   2)   2)
999   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1000   then   then
1001   echo -en "${COLRED}"   echo -en "${COLRED}"
1002   echo -n "! prot "   echo -n "! prot "
# Line 831  remove_files() Line 1004  remove_files()
1004   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
1005   fi   fi
1006   ;;   ;;
1007    
1008     # file is protected but ignored, delete the update/do nothing
1009     4)
1010     if mqueryfeature "verbose"
1011     then
1012     echo -en "${COLRED}"
1013     echo -n "! ignr "
1014     echo -en "${COLDEFAULT}"
1015     echo " === FILE: ${MROOT}${pathto}"
1016     fi
1017     # simply do nothing here
1018     ;;
1019   esac   esac
1020   ;;   ;;
1021   1)   1)
1022   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1023   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1024   ;;   ;;
1025   esac   esac
# Line 853  remove_blockdevices() Line 1038  remove_blockdevices()
1038  {  {
1039   local pathto   local pathto
1040   local posix   local posix
1041     local user
1042     local group
1043   local IFS   local IFS
1044   local pcat   local pcat
1045   local pname   local pname
# Line 876  remove_blockdevices() Line 1063  remove_blockdevices()
1063   done   done
1064    
1065   # sanity checks; abort if not given   # sanity checks; abort if not given
1066   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1067   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1068   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1069   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1070   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1071    
1072   # check needed global vars   # check needed global vars
# Line 890  remove_blockdevices() Line 1077  remove_blockdevices()
1077   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1078   IFS=§   IFS=§
1079    
1080   while read pathto posix   while read pathto posix user group
1081   do   do
1082   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1083    
1084   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1085   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1086   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1087    
# Line 911  remove_characterdevices() Line 1098  remove_characterdevices()
1098  {  {
1099   local pathto   local pathto
1100   local posix   local posix
1101     local user
1102     local group
1103   local IFS   local IFS
1104   local pcat   local pcat
1105   local pname   local pname
# Line 934  remove_characterdevices() Line 1123  remove_characterdevices()
1123   done   done
1124    
1125   # sanity checks; abort if not given   # sanity checks; abort if not given
1126   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1127   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1128   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1129   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1130   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1131    
1132   # check needed global vars   # check needed global vars
# Line 948  remove_characterdevices() Line 1137  remove_characterdevices()
1137   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1138   IFS=§   IFS=§
1139    
1140   while read pathto posix   while read pathto posix user group
1141   do   do
1142   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1143    
1144   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1145   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1146   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1147    
# Line 962  remove_characterdevices() Line 1151  remove_characterdevices()
1151    
1152    
1153  ###################################################  ###################################################
1154    # function remove_fifos                           #
1155    # remove_fifos $PKGNAME                     #
1156    ###################################################
1157    remove_fifos()
1158    {
1159     local pathto
1160     local posix
1161     local user
1162     local group
1163     local IFS
1164     local pcat
1165     local pname
1166     local pver
1167     local pbuild
1168     local i
1169     local pfull
1170    
1171     IFS=$'\n'
1172    
1173     # very basic getops
1174     for i in $*
1175     do
1176     case $1 in
1177     --pcat|-c) shift; pcat="$1" ;;
1178     --pname|-n) shift; pname="$1" ;;
1179     --pver|-v) shift; pver="$1" ;;
1180     --pbuild|-b) shift; pbuild="$1" ;;
1181     esac
1182     shift
1183     done
1184    
1185     # sanity checks; abort if not given
1186     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1187     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1188     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1189     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1190     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1191    
1192     # check needed global vars
1193     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1194    
1195     # make it optional atm !!
1196     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1197     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1198    
1199     # sets fieldseperator to "§" instead of " "
1200     IFS=§
1201    
1202     while read pathto posix user group
1203     do
1204     [ -z "${pathto}" ] && continue
1205    
1206     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1207     rm "${MROOT}${pathto}"
1208     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1209    
1210     # very important: unsetting the '§' fieldseperator
1211     IFS=$'\n'
1212    }
1213    
1214    
1215    ###################################################
1216  # function remove_direcories                      #  # function remove_direcories                      #
1217  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1218  ###################################################  ###################################################
# Line 992  remove_directories() Line 1243  remove_directories()
1243   done   done
1244    
1245   # sanity checks; abort if not given   # sanity checks; abort if not given
1246   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1247   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1248   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1249   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1250   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1251    
1252   # check needed global vars   # check needed global vars
# Line 1013  remove_directories() Line 1264  remove_directories()
1264    
1265   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1266   then   then
1267   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1268   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1269   continue   continue
1270   fi   fi
# Line 1021  remove_directories() Line 1272  remove_directories()
1272   # exclude .keep directories   # exclude .keep directories
1273   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1274   then   then
1275   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1276   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1277   continue   continue
1278   fi   fi
# Line 1034  remove_directories() Line 1285  remove_directories()
1285    
1286   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1287   then   then
1288   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1289   else   else
1290   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1291   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1292   fi   fi
1293   done   done
# Line 1049  remove_directories() Line 1300  remove_directories()
1300  ###################################################  ###################################################
1301  # function build_douninstall                      #  # function build_douninstall                      #
1302  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1303  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1304  ###################################################  ###################################################
1305  build_douninstall()  build_douninstall()
1306  {  {
# Line 1083  build_douninstall() Line 1334  build_douninstall()
1334   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1335   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1336    
1337   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1338   do   do
1339   remove_${i} \   remove_${i} \
1340   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1094  build_douninstall() Line 1345  build_douninstall()
1345   done   done
1346  }  }
1347    
1348    # convertmirrors [uri]
1349    convertmirrors()
1350    {
1351     local uri="$1"
1352     local scheme
1353     local mirror
1354     local mirrors
1355     local addon
1356     local real_uri
1357     local output
1358    
1359     # needs
1360     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1361     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1362     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1363     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1364     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1365    
1366     # check known uri schemes
1367     case ${uri} in
1368     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1369     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1370     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1371     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1372     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1373     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1374     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1375     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1376     esac
1377    
1378     if [[ ! -z ${mirrors} ]]
1379     then
1380     for mirror in ${mirrors}
1381     do
1382     # add a whitespace to the output
1383     [[ -z ${output} ]] || output+=" "
1384     output+="${mirror}${addon}/${uri/${scheme}/}"
1385     done
1386     else
1387     output="${uri}"
1388     fi
1389    
1390     echo "${output}"
1391    }
1392    
1393    mdownload()
1394    {
1395     local i
1396     local uri
1397     local real_uris
1398     local mirror
1399     local outputfile
1400     local outputdir
1401     local retval
1402     local wget_opts
1403    
1404     # very basic getops
1405     for i in $*
1406     do
1407     case $1 in
1408     --uri|-u) shift; uri="$1" ;;
1409     --dir|-d) shift; outputdir="$1" ;;
1410     esac
1411     shift
1412     done
1413    
1414     # sanity checks; abort if not given
1415     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1416     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1417    
1418     # convert mirrored uris to the real ones
1419     real_uris="$(convertmirrors ${uri})"
1420    
1421     # verbose or not
1422     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1423    
1424     # filter wget options if busybox was found
1425     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1426    
1427     # create outputdir
1428     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1429    
1430     for mirror in ${real_uris}
1431     do
1432     # get the name of the output file
1433     outputfile="${mirror##*/}"
1434    
1435     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1436     retval="$?"
1437     if [[ ${retval} = 0 ]]
1438     then
1439     break
1440     else
1441     continue
1442     fi
1443     done
1444    
1445     # return wget retval
1446     return "${retval}"
1447    }
1448    
1449  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1450  fetch_packages()  fetch_packages()
1451  {  {
1452     local i
1453   local list="$@"   local list="$@"
1454   local pkg   local pkg
1455   local mirr   local mirr
# Line 1105  fetch_packages() Line 1458  fetch_packages()
1458   local opt   local opt
1459   local count_current   local count_current
1460   local count_total   local count_total
1461     local wget_opts
1462    
1463   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1464    
1465     # filter wget command if busybox was found
1466     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1467    
1468   # get count of total packages   # get count of total packages
1469   declare -i count_current=0   declare -i count_current=0
1470   declare -i count_total=0   declare -i count_total=0
# Line 1146  fetch_packages() Line 1503  fetch_packages()
1503   continue   continue
1504   fi   fi
1505    
1506   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1507   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1508   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_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
1509   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1510   then   then
1511   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1512   fi   fi
1513   done   done
1514    
# Line 1197  syncmage() Line 1536  syncmage()
1536   done   done
1537    
1538   # clean up backup files (foo~)   # clean up backup files (foo~)
1539   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1540    
1541   # check if an newer mage version is available   # check if a newer mage version is available
1542   is_newer_mage_version_available   is_newer_mage_version_available
1543  }  }
1544    
1545    syncmage_tarball()
1546    {
1547     local latest_tarball
1548     local latest_md5
1549     local temp="$(mktemp -d)"
1550     local mirr mymirr
1551     local opt
1552     local tar_opts
1553     local wget_opts
1554    
1555     # try to get the md5 marked as latest on the server
1556     latest_md5="mage-latest.md5"
1557    
1558     # try to get the tarball marked as latest on the server
1559     latest_tarball="mage-latest.tar.bz2"
1560    
1561     # filter wget command if busybox was found
1562     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1563    
1564     for mirr in ${MIRRORS}
1565     do
1566     # path without distribution
1567     # (only for stable|testing|unstable and not DISTROTAG)
1568     case ${mirr##*/} in
1569     stable|testing|unstable) mymirr="${mirr%/*}";;
1570     *) mymirr="${mirr}";;
1571     esac
1572    
1573     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1574     echo "fetching latest md5 from ${mymirr} ..."
1575     mqueryfeature "!verbose" && opt="--quiet"
1576     wget \
1577     ${wget_opts} \
1578     --directory-prefix=${temp} \
1579     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1580    
1581     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1582     echo "fetching latest tarball from ${mymirr} ..."
1583     wget \
1584     ${wget_opts} \
1585     --directory-prefix=${temp} \
1586     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1587     if [[ $? = 0 ]]
1588     then
1589     break
1590     else
1591     continue
1592     fi
1593     done
1594    
1595     if [[ -f ${temp}/${latest_tarball} ]]
1596     then
1597     # check md5
1598     if [[ ! -f ${temp}/${latest_md5} ]]
1599     then
1600     die "md5 is missing ... aborting"
1601     else
1602     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1603     echo -n "checking md5sum... "
1604     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1605     fi
1606    
1607     if [[ -d ${MAGEDIR} ]]
1608     then
1609     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1610     echo "cleaning old mage-tree ${MAGEDIR}..."
1611     # honor mountpoints and empty dirs
1612     if mountpoint -q ${MAGEDIR}
1613     then
1614     if ! mcheckemptydir ${MAGEDIR}
1615     then
1616     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1617     fi
1618     else
1619     rm -rf ${MAGEDIR}
1620     fi
1621     fi
1622    
1623     if need_busybox_support tar
1624     then
1625     tar_opts="xjf"
1626     else
1627     tar_opts="xjmf"
1628     fi
1629    
1630     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1631     echo "updating mage-tree from tarball ..."
1632     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1633     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1634    
1635     if [[ -d ${temp} ]]
1636     then
1637     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1638     echo "cleaning temp-files ..."
1639     rm -rf ${temp}
1640     fi
1641    
1642     # check if a newer mage version is available
1643     is_newer_mage_version_available
1644     else
1645     die "Could not fetch the latest tarball ... aborting"
1646     fi
1647    }
1648    
1649  cleanpkg()  cleanpkg()
1650  {  {
1651   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1233  xtitleclean() Line 1676  xtitleclean()
1676  }  }
1677    
1678    
1679  # cuts full pathnames or versioniezed names down to basename  # unused?
1680  choppkgname()  #
1681  {  # # cuts full pathnames or versionized names down to basename
1682   #we want this only if full name was used  # choppkgname()
1683   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1684   then  # #we want this only if full name was used
1685   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1686   #ARCH comes from ${MAGERC}  # then
1687   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1688    # #ARCH comes from ${MAGERC}
1689    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1690    #
1691    # #cuts version number
1692    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1693    # fi
1694    # }
1695    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1696    
1697  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1698  # $1=pname  # $1=pname
# Line 1315  get_highest_magefile() Line 1761  get_highest_magefile()
1761   local PNAME="$2"   local PNAME="$2"
1762   local magefile   local magefile
1763    
1764   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1765     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1766   do   do
1767     [[ -z ${magefile} ]] && continue
1768   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1769   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1770   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1771   then   then
1772   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1773   #for debug only   #for debug only
1774   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1775   fi   fi
1776   done   done
1777    
 # do not so anything  
 # # 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  
   
1778   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1779   return 0   return 0
1780  }  }
# Line 1363  get_highest_magefile() Line 1789  get_highest_magefile()
1789  #        1 - error                                #  #        1 - error                                #
1790  #        2 - protected                            #  #        2 - protected                            #
1791  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1792    #        4 - protected but ignored                #
1793  #                                                 #  #                                                 #
1794  ###################################################  ###################################################
1795  is_config_protected()  is_config_protected()
# Line 1371  is_config_protected() Line 1798  is_config_protected()
1798   local TEST   local TEST
1799   local PROTECTED   local PROTECTED
1800   local IFS   local IFS
1801     local i
1802     local x
1803    
1804   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1805    
1806   # file does not exist; it can be written   # file does not exist; it can be written
1807   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1808    
1809   # to be safe; it may be '§'   # to be safe; it may be '§'
1810   IFS=' '   IFS=' '
1811    
1812   # check ob in config protect   # check if config protected
1813   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1814   do   do
1815   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1816   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1817   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1818   then   then
1819   # setzen das es protected ist   # file is config proteced
1820   PROTECTED=TRUE   PROTECTED=TRUE
1821    
1822   # check ob nicht doch maskiert   # check if not masked
1823   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1824   do   do
1825   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1826   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1827   then   then
1828   PROTECTED=MASKED   PROTECTED=MASKED
1829   fi   fi
1830   done   done
1831    
1832     # check if not ignored
1833     for x in ${CONFIG_PROTECT_IGNORE}
1834     do
1835     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1836     if [[ ${TEST} != ${EXPFILE} ]]
1837     then
1838     PROTECTED=IGNORED
1839     fi
1840     done
1841   fi   fi
1842   done   done
1843    
# Line 1413  is_config_protected() Line 1852  is_config_protected()
1852   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1853   return 3   return 3
1854   ;;   ;;
1855     IGNORED)
1856     #echo "I'm protected, but ignored - keep me, del update"
1857     return 4
1858     ;;
1859   *)   *)
1860   #echo "delete me"   #echo "delete me"
1861   return 0   return 0
# Line 1430  is_config_protected() Line 1873  is_config_protected()
1873  ###################################################  ###################################################
1874  count_protected_files()  count_protected_files()
1875  {  {
1876   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1877     local dirname="${file%/*}"
1878     local filename="${file##*/}"
1879     local count
1880     local output
1881     local oldprotected
1882     local i
1883     local x
1884    
1885     # hack; do not honor a global set IFS like '§'
1886     local IFS
1887    
1888     count=0
1889    
1890     # check if there are already protected files
1891     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1892     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1893     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1894     do
1895     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1896     done
1897    
1898     # convert 0001 -> 1; 0120 -> 120 etc
1899     # use bash internal base functions to this task
1900     x="$((10#${count}))"
1901     for (( i=0; i<x; i++ ))
1902     do
1903     if [[ ${count:${i}:1} != 0 ]]
1904     then
1905     count="${count:${i}}"
1906     break
1907     fi
1908     done
1909    
1910     count="$(( ${count}+1 ))"
1911    
1912     # fill output up with zeros
1913     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1914     output="${output}${count}"
1915    
1916     echo "${output}"
1917  }  }
1918    
1919  # call with  # call with
# Line 1447  get_uninstall_candidates() Line 1930  get_uninstall_candidates()
1930   local list   local list
1931   local pcatdir   local pcatdir
1932   local protected   local protected
1933     local i
1934    
1935   # very basic getops   # very basic getops
1936   for i in $*   for i in $*
# Line 1601  virtuals_add() Line 2085  virtuals_add()
2085    
2086  #deletes pakages from virtual database  #deletes pakages from virtual database
2087  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2088  virtuals_del() {  virtuals_del()
2089    {
2090    
2091   local virtualname="$1"   local virtualname="$1"
2092   local pkgname="$2"   local pkgname="$2"
# Line 1712  minclude() Line 2197  minclude()
2197   then   then
2198   for i in $*   for i in $*
2199   do   do
2200   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2201   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2202   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2203   done   done
2204   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2205   fi   fi
2206  }  }
2207    
# Line 2035  get_value_from_magefile() Line 2520  get_value_from_magefile()
2520   local SDEPEND   local SDEPEND
2521   local PROVIDE   local PROVIDE
2522   local PKGTYPE   local PKGTYPE
2523     local MAGE_TARGETS
2524     local SPLIT_PACKAGE_BASE
2525   local preinstall   local preinstall
2526   local postinstall   local postinstall
2527   local preremove   local preremove
# Line 2081  mage_install() Line 2568  mage_install()
2568   local count_current   local count_current
2569   local magefile   local magefile
2570   local src_install   local src_install
2571     local i
2572    
2573   # very basic getops   # very basic getops
2574   for i in $*   for i in $*
# Line 2154  mage_install() Line 2642  mage_install()
2642   echo B:${pbuild}   echo B:${pbuild}
2643   fi   fi
2644    
2645   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2646     then
2647     # basic svn compat
2648     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2649     then
2650     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2651     do
2652     smage2file="${i}"
2653     done
2654     else
2655     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2656     fi
2657    
2658     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2659     then
2660     # basic svn compat
2661     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2662     then
2663     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2664     do
2665     smage2file="${i}"
2666     done
2667     else
2668     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2669     fi
2670    
2671     else
2672     # basic svn compat
2673     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2674     then
2675     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2676     do
2677     smage2file="${i}"
2678     done
2679     else
2680     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2681     fi
2682     fi
2683    
2684   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2685   then   then
2686   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
# Line 2171  mage_install() Line 2697  mage_install()
2697   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2698   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2699   then   then
2700     unpack_package "${magefile}"
2701   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2702   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2703   fi   fi
# Line 2285  md5sum_packages() Line 2812  md5sum_packages()
2812   then   then
2813   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2814   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2815   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2816   else   else
2817   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2818   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2430  mage_uninstall() Line 2957  mage_uninstall()
2957   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2958   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2959    
2960   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2961   source ${magefile}   source ${magefile}
2962    
2963   ## preremove scripts   ## preremove scripts
# Line 2498  mage_uninstall() Line 3025  mage_uninstall()
3025   unset -f postremove   unset -f postremove
3026  }  }
3027    
3028  show_etc_update_mesg() {  show_etc_update_mesg()
3029    {
3030   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3031    
3032   echo   echo
# Line 2524  pkgsearch() Line 3052  pkgsearch()
3052   local state   local state
3053   local descriptiom   local descriptiom
3054   local homepage   local homepage
3055     local license
3056   local i   local i
3057   local all_installed   local all_installed
3058   local ipver   local ipver
3059   local ipbuild   local ipbuild
3060   local latest_available   local latest_available
3061     local depsfull
3062     local sdepsfull
3063     local deps
3064     local sdeps
3065     local dep
3066     local sign
3067    
3068   # only names no versions   # only names no versions
3069   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
# Line 2554  pkgsearch() Line 3089  pkgsearch()
3089   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3090   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3091   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3092     license="$(get_value_from_magefile LICENSE ${magefile})"
3093    
3094   # all installed   # all installed
3095   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3096   do   do
3097   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3098   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3099    
3100   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3101   then   then
3102   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2569  pkgsearch() Line 3105  pkgsearch()
3105   fi   fi
3106   done   done
3107   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3108    
3109   case ${state} in   case ${state} in
3110   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3111   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2584  pkgsearch() Line 3120  pkgsearch()
3120   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3121   fi   fi
3122    
3123     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3124     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3125    
3126     while read sign dep
3127     do
3128     case ${dep} in
3129     "") continue;;
3130     esac
3131    
3132     if [[ -z ${deps} ]]
3133     then
3134     deps="$(basename ${dep%-*})"
3135     else
3136     deps="${deps} $(basename ${dep%-*})"
3137     fi
3138     done << EOF
3139    ${depsfull}
3140    EOF
3141    
3142     while read sign dep
3143     do
3144     case ${dep} in
3145     "") continue;;
3146     esac
3147    
3148     if [[ -z ${sdeps} ]]
3149     then
3150     sdeps="$(basename ${dep%-*})"
3151     else
3152     sdeps="${sdeps} $(basename ${dep%-*})"
3153     fi
3154     done << EOF
3155    ${sdepsfull}
3156    EOF
3157    
3158   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3159   echo -e "      Latest available:   ${latest_available}"   echo -e "      Latest available:   ${latest_available}"
3160   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3161   echo "      Description: ${description}"   echo "      Description: ${description}"
3162   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3163     if [[ ! -z ${license} ]]
3164     then
3165     echo "      License:  ${license}"
3166     fi
3167     echo "      Depends:  ${deps}"
3168     echo "      SDepends: ${sdeps}"
3169   echo   echo
3170    
3171   unset pcat   unset pcat
# Line 2602  pkgsearch() Line 3179  pkgsearch()
3179   unset all_installed   unset all_installed
3180   unset ipver   unset ipver
3181   unset ipbuild   unset ipbuild
3182     unset depsfull
3183     unset sdepsfull
3184     unset deps
3185     unset sdeps
3186     unset dep
3187     unset sign
3188   done   done
3189  }  }
3190    
# Line 2621  export_inherits() Line 3204  export_inherits()
3204   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3205    
3206   # debug   # debug
3207   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3208    
3209   shift   shift
3210   done   done
# Line 2644  blacklisted() Line 3227  blacklisted()
3227   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3228   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3229    
3230   local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"   # support both types for the moment
3231     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3232     then
3233     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3234     else
3235     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3236     fi
3237    
3238   # return 0 if the list not exist; nothin is masked   # return 0 if the list not exist; nothin is masked
3239   [[ ! -f ${EXCLUDED} ]] && return 0   [[ ! -f ${EXCLUDED} ]] && return 0
# Line 2687  EOF Line 3276  EOF
3276   return 0   return 0
3277  }  }
3278    
3279    # need_busybox_support ${cmd}
3280    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3281    need_busybox_support()
3282    {
3283     local cmd
3284     local busybox
3285     cmd="$1"
3286    
3287     for busybox in {,/usr}/bin/busybox
3288     do
3289     if [[ -x ${busybox} ]]
3290     then
3291     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3292     then
3293     # needs busybox support
3294     return 0
3295     fi
3296     fi
3297     done
3298    
3299     # no busybox
3300     return 1
3301    }
3302    
3303    # busybox_filter_wget_options ${wget_opts}
3304    busybox_filter_wget_options()
3305    {
3306     local opts="$@"
3307     local i
3308     local fixed_opts
3309    
3310     if need_busybox_support wget
3311     then
3312     for i in ${opts}
3313     do
3314     # show only the allowed ones
3315     case ${i} in
3316     -c|--continue) fixed_opts+=" -c" ;;
3317     -s|--spider) fixed_opts+=" -s" ;;
3318     -q|--quiet) fixed_opts+=" -q" ;;
3319     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3320     --header) shift; fixed_opts+=" --header $1" ;;
3321     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3322     -P) shift; fixed_opts+=" -P $1" ;;
3323     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3324     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3325     # simply drop all other opts
3326     *) continue ;;
3327     esac
3328     done
3329    
3330     echo "${fixed_opts}"
3331     else
3332     echo "${opts}"
3333     fi
3334    }
3335    
3336    have_root_privileges()
3337    {
3338     local retval
3339    
3340     if [[ $(id -u) = 0 ]]
3341     then
3342     retval=0
3343     else
3344     retval=1
3345     fi
3346    
3347     return ${retval}
3348    }
3349    
3350    known_mage_feature()
3351    {
3352     local feature="$1"
3353     local retval
3354    
3355     case "${feature}" in
3356     autosvc|!autosvc) retval=0 ;;
3357     buildlog|!buildlog) retval=0 ;;
3358     ccache|!ccache) retval=0 ;;
3359     check|!check) retval=0 ;;
3360     compressdoc|!compressdoc) retval=0 ;;
3361     debug|!debug) retval=0 ;;
3362     distcc|!distcc) retval=0 ;;
3363     icecc|!icecc) retval=0 ;;
3364     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3365     libtool|!libtool) retval=0 ;;
3366     linuxsymlink|!linuxsymlink) retval=0 ;;
3367     pkgbuild|!pkgbuild) retval=0 ;;
3368     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3369     purge|!purge) retval=0 ;;
3370     qalint|!qalint) retval=0 ;;
3371     regentree|!regentree) retval=0 ;;
3372     resume|!resume) retval=0 ;;
3373     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3374     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3375     static|!static) retval=0 ;;
3376     stepbystep|!stepbystep) retval=0 ;;
3377     strip|!strip) retval=0 ;;
3378     verbose|!verbose) retval=0 ;;
3379     *) retval=1 ;;
3380     esac
3381    
3382     return "${retval}"
3383    }
3384    
3385    load_mage_features()
3386    {
3387     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3388     do
3389     FVERBOSE=off msetfeature ${i}
3390     done
3391    }
3392    
3393    msetfeature()
3394    {
3395     local feature
3396     local count
3397     local i
3398     local found
3399    
3400     for feature in $@
3401     do
3402     found=0
3403     count="${#MAGE_FEATURES_CURRENT[*]}"
3404    
3405     if ! known_mage_feature "${feature}"
3406     then
3407     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3408     return 3
3409     fi
3410    
3411     for ((i=0; i<count; i++))
3412     do
3413     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3414     then
3415     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3416     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3417     found=1
3418     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3419     then
3420     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3421     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3422     found=1
3423     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3424     then
3425     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3426     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3427     found=1
3428     fi
3429     done
3430    
3431     # if the feature was not found after proccessing the whole array
3432     # it was not declared. in this case enable it
3433     if [[ ${found} = 0 ]]
3434     then
3435     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3436     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3437     fi
3438    
3439     export MAGE_FEATURE_CURRENT
3440     done
3441    }
3442    
3443    mqueryfeature()
3444    {
3445     local feature="$1"
3446     local retval=1
3447     local i
3448    
3449     if known_mage_feature "${feature}"
3450     then
3451     for i in ${MAGE_FEATURES_CURRENT[*]}
3452     do
3453     if [[ ${i} = ${feature} ]]
3454     then
3455     retval=0
3456     break # found break here
3457     fi
3458     done
3459     else
3460     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3461     retval=3
3462     fi
3463    
3464     return ${retval}
3465    }
3466    
3467    mprintfeatures()
3468    {
3469     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3470     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3471     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3472    }

Legend:
Removed from v.445  
changed lines
  Added in v.2224