Magellan Linux

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

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

trunk/mage/usr/lib/mage/mage4.functions.sh revision 1085 by niro, Mon Jun 28 18:15:44 2010 UTC branches/mage-next/src/mage4.functions.sh.in revision 2613 by niro, Tue Mar 4 15:26:05 2014 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.38 2008-10-05 10:32:24 niro Exp $  # $Id$
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 15  mage_setup() Line 15  mage_setup()
15   return 0   return 0
16  }  }
17    
18    mchecksum()
19    {
20     local i
21     local rundir
22     local file
23     local method
24     local cmd
25     local retval
26     local sum
27     local dest
28    
29     # very basic getops
30     for i in $*
31     do
32     case $1 in
33     --rundir|-r) shift; rundir="$1" ;;
34     --file|-f) shift; file="$1" ;;
35     --method|-m) shift; method="$1" ;;
36     esac
37     shift
38     done
39    
40     # sanity checks
41     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
42     [[ -z ${file} ]] && die "mchecksum(): file missing"
43     [[ -z ${method} ]] && die "mchecksum(): method missing"
44    
45     case ${method} in
46     md5) cmd="md5sum" ;;
47     sha256) cmd="sha256sum" ;;
48     *) die "mchecksum(): unknown method '${method}'" ;;
49     esac
50    
51     if [[ -d ${rundir} ]]
52     then
53     pushd ${rundir} &> /dev/null
54    
55     # all file must be non-zero
56     retval=0
57     while read sum dest
58     do
59     if [ ! -s ${dest} ]
60     then
61     echo "${dest}: file is empty ;("
62     retval=127
63     fi
64     done < ${file}
65     if [[ ${retval} != 127 ]]
66     then
67     # be verbose here
68     ${cmd} -c ${file} #&> /dev/null
69     retval="$?"
70     fi
71    
72     popd &> /dev/null
73     else
74     retval=1
75     fi
76    
77     return "${retval}"
78    }
79    
80    mcheckemptydir()
81    {
82     local dir="$1"
83     local retval=1
84    
85     if [[ ! -d ${dir} ]]
86     then
87     echo "mcheckemptydir(): '${dir}' is not a directory!"
88     retval=3
89     else
90     shopt -s nullglob dotglob
91     files=( ${dir}/* )
92     (( ${#files[*]} )) || retval=0
93     shopt -u nullglob dotglob
94     fi
95    
96     return ${retval}
97    }
98    
99    unpack_package()
100    {
101     local magefile="$1"
102     local pkgname
103     local pkgfile
104     local pkgtype
105     local tar_opts
106    
107     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
108     pkgfile="${pkgname}.${PKGSUFFIX}"
109     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
110    
111     xtitle "[ Unpacking ${pkg} ]"
112    
113     # abort on virtual pkg
114     if [[ ${pkgtype} = virtual ]]
115     then
116     echo -ne " ${COLBLUE}---${COLDEFAULT}"
117     echo " !unpack virtual ${pkgname} ... "
118     continue
119     fi
120    
121     # abort on sources pkg
122     if [[ ${pkgtype} = sources ]]
123     then
124     echo -ne " ${COLBLUE}---${COLDEFAULT}"
125     echo " !unpack sources ${pkgname} ... "
126     continue
127     fi
128    
129     # busybox?
130     if need_busybox_support tar
131     then
132     tar_opts="xjf"
133     else
134     tar_opts="xjmf"
135     fi
136    
137     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
138     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
139    }
140    
141  unpack_packages()  unpack_packages()
142  {  {
143   local list="$@"   local list="$@"
144   local magefile   local magefile
  local pkg  
  local pkgtype  
145   local count_current   local count_current
146   local count_total   local count_total
147     local tar_opts
148    
149   # get count of total packages   # get count of total packages
150   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 154  unpack_packages()
154    
155   for magefile in ${list}   for magefile in ${list}
156   do   do
157   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
158   (( 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}"  
159   done   done
160    
161   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 175  fix_mtime()
175   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
176   touch \   touch \
177   --no-create \   --no-create \
178     --no-dereference \
179   --time=mtime \   --time=mtime \
180   --reference "${reference}" \   --reference="${reference}" \
181   "${pathto}"   "${pathto}"
182    
183   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 231  install_directories()
231   while read pathto posix user group   while read pathto posix user group
232   do   do
233   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
234   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
235    
236   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
237   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 207  install_files() Line 307  install_files()
307   case ${retval} in   case ${retval} in
308   # file is not protected - (over)write it   # file is not protected - (over)write it
309   0|3)   0|3)
310   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
311   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
312   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
313   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 219  install_files() Line 319  install_files()
319   "${user}" \   "${user}" \
320   "${group}" \   "${group}" \
321   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
322   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
323   "${md5sum}"   "${md5sum}"
324   ;;   ;;
325    
326   # file is protected, write backup file   # file is protected, write backup file
327   2)   2)
328   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
329   then   then
330   echo -en "${COLRED}"   echo -en "${COLRED}"
331   echo -n "! prot "   echo -n "! prot "
# Line 246  install_files() Line 346  install_files()
346   "${user}" \   "${user}" \
347   "${group}" \   "${group}" \
348   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
349   "${dest_protected}")" \   "${dest_protected}")" \
350   "${md5sum}"   "${md5sum}"
351    
352   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
# Line 256  install_files() Line 356  install_files()
356    
357   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
358   4)   4)
359   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
360   then   then
361   echo -en "${COLRED}"   echo -en "${COLRED}"
362   echo -n "! ignr "   echo -n "! ignr "
363   echo -en "${COLDEFAULT}"   echo -en "${COLDEFAULT}"
364   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
365   fi   fi
366   # simply do nothing here   # simply do nothing here - only fix mtime
367     fix_descriptor ${pkgname}/.files \
368     "${pathto}" \
369     "${posix}" \
370     "${user}" \
371     "${group}" \
372     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
373     "${MROOT}${pathto}")" \
374     "${md5sum}"
375   ;;   ;;
376   esac   esac
377   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
# Line 307  install_symlinks() Line 415  install_symlinks()
415   while read pathto posix link mtime   while read pathto posix link mtime
416   do   do
417   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
418   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
419    
420   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
421    
422  # # fix mtime and db   # fix mtime and db
423  # fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
424  # "${pathto}" \   "${pathto}" \
425  # "${posix}" \   "${posix}" \
426  # "${link}" \   "${link}" \
427  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
428  # "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
429    
430   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
431    
# Line 339  install_blockdevices() Line 447  install_blockdevices()
447   local pkgname="$1"   local pkgname="$1"
448   local pathto   local pathto
449   local posix   local posix
450     local user
451     local group
452   local IFS   local IFS
453    
454   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 352  install_blockdevices() Line 462  install_blockdevices()
462   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
463   IFS=§   IFS=§
464    
465   while read pathto posix   while read pathto posix major minor user group
466   do   do
467   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
468   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
469    
470   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
471     # make it optional atm !!
472     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
473     then
474     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
475     fi
476   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
477    
478   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 376  install_characterdevices() Line 491  install_characterdevices()
491   local posix   local posix
492   local major   local major
493   local minor   local minor
494     local user
495     local group
496   local IFS   local IFS
497    
498   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 389  install_characterdevices() Line 506  install_characterdevices()
506   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
507   IFS=§   IFS=§
508    
509   while read pathto posix major minor   while read pathto posix major minor user group
510   do   do
511   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
512   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
513    
514   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
515    
516     # make it optional atm !!
517     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
518     then
519     chown "${user}:${group}" "${MROOT}${pathto}"
520     fi
521   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
522    
523   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
524   IFS=$'\n'   IFS=$'\n'
525  }  }
526    
527    ###################################################
528    # function install_fifos                          #
529    # install_fifos $PKGNAME                    #
530    ###################################################
531    install_fifos()
532    {
533     local pkgname="$1"
534     local pathto
535     local posix
536     local user
537     local group
538     local IFS
539    
540     # sanity checks; abort if not given
541     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
542    
543     # check needed global vars
544     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
545    
546     # make it optional atm !!
547     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
548     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
549    
550     # sets fieldseperator to "§" instead of " "
551     IFS=§
552    
553     while read pathto posix user group
554     do
555     [ -z "${pathto}" ] && continue
556     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
557    
558     mkfifo -m "${posix}" "${MROOT}${pathto}"
559     chown "${user}:${group}" "${MROOT}${pathto}"
560     done < ${BUILDDIR}/${pkgname}/.fifo
561    
562     # very important: unsetting the '§' fieldseperator
563     IFS=$'\n'
564    }
565    
566    
567  ###################################################  ###################################################
568  # function build_doinstall                        #  # function build_doinstall                        #
569  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
570  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
571  ###################################################  ###################################################
572  build_doinstall()  build_doinstall()
573  {  {
# Line 413  build_doinstall() Line 575  build_doinstall()
575    
576   # sanity checks; abort if not given   # sanity checks; abort if not given
577   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
578    
579   # this is only a wrapper   # this is only a wrapper
580    
581   # NOTE:   # NOTE:
# Line 428  build_doinstall() Line 590  build_doinstall()
590   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
591   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
592   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
593     install_fifos ${pkgname} || die "install fifos ${pkgname}"
594  }  }
595    
596    
# Line 489  install_database_entry() Line 652  install_database_entry()
652    
653   # create fake file descriptors   # create fake file descriptors
654   # used by virtual and source packages   # used by virtual and source packages
655   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
656   do   do
657   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
658   done   done
# Line 507  install_database_entry() Line 670  install_database_entry()
670    
671   # normal packages needs these files   # normal packages needs these files
672   local i   local i
673   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
674   do   do
675   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
676   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
677     then
678     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
679     fi
680   done   done
681   ;;   ;;
682   esac   esac
# Line 646  compare_mtime() Line 812  compare_mtime()
812    
813   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
814    
815   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
816   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
817   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  
818    
819   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
820    
# Line 721  remove_symlinks() Line 876  remove_symlinks()
876   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
877   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
878   then   then
879   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
880   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
881   continue   continue
882   fi   fi
# Line 733  remove_symlinks() Line 888  remove_symlinks()
888   # 1=keep me   #   # 1=keep me   #
889   case ${retval} in   case ${retval} in
890   0)   0)
891   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
892   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
893   ;;   ;;
894    
895   1)   1)
896   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
897   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
898   ;;   ;;
899   esac   esac
# Line 785  remove_files() Line 940  remove_files()
940   done   done
941    
942   # sanity checks; abort if not given   # sanity checks; abort if not given
943   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
944   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
945   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
946   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
947   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
948    
949   # check needed global vars   # check needed global vars
# Line 805  remove_files() Line 960  remove_files()
960    
961   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
962   then   then
963   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
964   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
965   continue   continue
966   fi   fi
# Line 831  remove_files() Line 986  remove_files()
986   case ${retval} in   case ${retval} in
987   # file is not protected - delete it   # file is not protected - delete it
988   0|3)   0|3)
989   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
990   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
991   ;;   ;;
992    
993   # file is protected, do not delete   # file is protected, do not delete
994   2)   2)
995   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
996   then   then
997   echo -en "${COLRED}"   echo -en "${COLRED}"
998   echo -n "! prot "   echo -n "! prot "
# Line 848  remove_files() Line 1003  remove_files()
1003    
1004   # file is protected but ignored, delete the update/do nothing   # file is protected but ignored, delete the update/do nothing
1005   4)   4)
1006   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1007   then   then
1008   echo -en "${COLRED}"   echo -en "${COLRED}"
1009   echo -n "! ignr "   echo -n "! ignr "
# Line 860  remove_files() Line 1015  remove_files()
1015   esac   esac
1016   ;;   ;;
1017   1)   1)
1018   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1019   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1020   ;;   ;;
1021   esac   esac
# Line 879  remove_blockdevices() Line 1034  remove_blockdevices()
1034  {  {
1035   local pathto   local pathto
1036   local posix   local posix
1037     local user
1038     local group
1039   local IFS   local IFS
1040   local pcat   local pcat
1041   local pname   local pname
# Line 902  remove_blockdevices() Line 1059  remove_blockdevices()
1059   done   done
1060    
1061   # sanity checks; abort if not given   # sanity checks; abort if not given
1062   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1063   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1064   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1065   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1066   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1067    
1068   # check needed global vars   # check needed global vars
# Line 916  remove_blockdevices() Line 1073  remove_blockdevices()
1073   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1074   IFS=§   IFS=§
1075    
1076   while read pathto posix   while read pathto posix user group
1077   do   do
1078   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1079    
1080   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1081   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1082   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1083    
# Line 937  remove_characterdevices() Line 1094  remove_characterdevices()
1094  {  {
1095   local pathto   local pathto
1096   local posix   local posix
1097     local user
1098     local group
1099   local IFS   local IFS
1100   local pcat   local pcat
1101   local pname   local pname
# Line 960  remove_characterdevices() Line 1119  remove_characterdevices()
1119   done   done
1120    
1121   # sanity checks; abort if not given   # sanity checks; abort if not given
1122   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1123   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1124   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1125   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1126   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1127    
1128   # check needed global vars   # check needed global vars
# Line 974  remove_characterdevices() Line 1133  remove_characterdevices()
1133   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1134   IFS=§   IFS=§
1135    
1136   while read pathto posix   while read pathto posix user group
1137   do   do
1138   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1139    
1140   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1141   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1142   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1143    
# Line 988  remove_characterdevices() Line 1147  remove_characterdevices()
1147    
1148    
1149  ###################################################  ###################################################
1150    # function remove_fifos                           #
1151    # remove_fifos $PKGNAME                     #
1152    ###################################################
1153    remove_fifos()
1154    {
1155     local pathto
1156     local posix
1157     local user
1158     local group
1159     local IFS
1160     local pcat
1161     local pname
1162     local pver
1163     local pbuild
1164     local i
1165     local pfull
1166    
1167     IFS=$'\n'
1168    
1169     # very basic getops
1170     for i in $*
1171     do
1172     case $1 in
1173     --pcat|-c) shift; pcat="$1" ;;
1174     --pname|-n) shift; pname="$1" ;;
1175     --pver|-v) shift; pver="$1" ;;
1176     --pbuild|-b) shift; pbuild="$1" ;;
1177     esac
1178     shift
1179     done
1180    
1181     # sanity checks; abort if not given
1182     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1183     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1184     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1185     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1186     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1187    
1188     # check needed global vars
1189     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1190    
1191     # make it optional atm !!
1192     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1193     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1194    
1195     # sets fieldseperator to "§" instead of " "
1196     IFS=§
1197    
1198     while read pathto posix user group
1199     do
1200     [ -z "${pathto}" ] && continue
1201    
1202     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1203     rm "${MROOT}${pathto}"
1204     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1205    
1206     # very important: unsetting the '§' fieldseperator
1207     IFS=$'\n'
1208    }
1209    
1210    
1211    ###################################################
1212  # function remove_direcories                      #  # function remove_direcories                      #
1213  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1214  ###################################################  ###################################################
# Line 1018  remove_directories() Line 1239  remove_directories()
1239   done   done
1240    
1241   # sanity checks; abort if not given   # sanity checks; abort if not given
1242   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1243   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1244   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1245   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1246   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1247    
1248   # check needed global vars   # check needed global vars
# Line 1039  remove_directories() Line 1260  remove_directories()
1260    
1261   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1262   then   then
1263   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1264   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1265   continue   continue
1266   fi   fi
# Line 1047  remove_directories() Line 1268  remove_directories()
1268   # exclude .keep directories   # exclude .keep directories
1269   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1270   then   then
1271   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1272   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1273   continue   continue
1274   fi   fi
# Line 1060  remove_directories() Line 1281  remove_directories()
1281    
1282   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1283   then   then
1284   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1285   else   else
1286   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1287   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1288   fi   fi
1289   done   done
# Line 1075  remove_directories() Line 1296  remove_directories()
1296  ###################################################  ###################################################
1297  # function build_douninstall                      #  # function build_douninstall                      #
1298  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1299  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1300  ###################################################  ###################################################
1301  build_douninstall()  build_douninstall()
1302  {  {
# Line 1109  build_douninstall() Line 1330  build_douninstall()
1330   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1331   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1332    
1333   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1334   do   do
1335   remove_${i} \   remove_${i} \
1336   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1120  build_douninstall() Line 1341  build_douninstall()
1341   done   done
1342  }  }
1343    
1344    # convertmirrors [uri]
1345    convertmirrors()
1346    {
1347     local uri="$1"
1348     local scheme
1349     local mirror
1350     local mirrors
1351     local addon
1352     local real_uri
1353     local output
1354    
1355     # needs
1356     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1357     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1358     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1359     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1360     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1361    
1362     # check known uri schemes
1363     case ${uri} in
1364     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1365     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1366     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1367     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1368     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1369     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1370     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1371     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1372     esac
1373    
1374     if [[ ! -z ${mirrors} ]]
1375     then
1376     for mirror in ${mirrors}
1377     do
1378     # add a whitespace to the output
1379     [[ -z ${output} ]] || output+=" "
1380     output+="${mirror}${addon}/${uri/${scheme}/}"
1381     done
1382     else
1383     output="${uri}"
1384     fi
1385    
1386     echo "${output}"
1387    }
1388    
1389    mdownload()
1390    {
1391     local i
1392     local uri
1393     local real_uris
1394     local mirror
1395     local outputfile
1396     local outputdir
1397     local retval
1398     local wget_opts
1399    
1400     # very basic getops
1401     for i in $*
1402     do
1403     case $1 in
1404     --uri|-u) shift; uri="$1" ;;
1405     --dir|-d) shift; outputdir="$1" ;;
1406     esac
1407     shift
1408     done
1409    
1410     # sanity checks; abort if not given
1411     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1412     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1413    
1414     # convert mirrored uris to the real ones
1415     real_uris="$(convertmirrors ${uri})"
1416    
1417     # verbose or not
1418     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1419    
1420     # filter wget options if busybox was found
1421     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1422    
1423     # create outputdir
1424     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1425    
1426     for mirror in ${real_uris}
1427     do
1428     # get the name of the output file
1429     outputfile="${mirror##*/}"
1430    
1431     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1432     retval="$?"
1433     if [[ ${retval} = 0 ]]
1434     then
1435     break
1436     else
1437     continue
1438     fi
1439     done
1440    
1441     # return wget retval
1442     return "${retval}"
1443    }
1444    
1445  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1446  fetch_packages()  fetch_packages()
1447  {  {
1448     local i
1449   local list="$@"   local list="$@"
1450   local pkg   local pkgname
1451     local pkgfile
1452     local pcat
1453     local pname
1454   local mirr   local mirr
1455   local magefile   local magefile
1456   local md5file   local md5file
1457   local opt   local opt
1458   local count_current   local count_current
1459   local count_total   local count_total
1460     local wget_opts
1461     local fetching
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 1142  fetch_packages() Line 1473  fetch_packages()
1473    
1474   for magefile in ${list}   for magefile in ${list}
1475   do   do
1476   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1477     pkgfile="${pkgname}.${PKGSUFFIX}"
1478   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1479    
1480     pcat=$(magename2pcat ${magefile})
1481     pname=$(magename2pname ${magefile})
1482     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1483    
1484   (( count_current++ ))   (( count_current++ ))
1485   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1486    
1487   # abort on virtual pkg   # abort on virtual pkg
1488   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1489   then   then
1490   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1491   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1492   continue   continue
1493   fi   fi
1494    
# Line 1160  fetch_packages() Line 1496  fetch_packages()
1496   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1497   then   then
1498   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1499   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1500   continue   continue
1501   fi   fi
1502    
1503   # abort if already exist   # check if FETCHING is required
1504   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1505   then   then
1506   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1507   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1508   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
  fi  
   
  for mirr in ${MIRRORS}  
  do  
  echo -ne " ${COLBLUE}***${COLDEFAULT}"  
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  ${WGET_FETCH_OPTIONS} \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
1509   then   then
1510   break   # md5's ok, no fetching required
1511     fetching=false
1512   else   else
1513   continue   fetching=true
1514   fi   fi
1515   done   fi
1516    
1517   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1518   then   then
1519   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1520     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1521     continue
1522     else
1523     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1524     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1525     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1526     fi
1527    
1528     # sanity check, not really needed but to be sure
1529     if [ ! -f ${PKGDIR}/${pkgfile} ]
1530     then
1531     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1532   fi   fi
1533   done   done
1534    
# Line 1220  syncmage() Line 1556  syncmage()
1556   done   done
1557    
1558   # clean up backup files (foo~)   # clean up backup files (foo~)
1559   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1560    
1561   # check if a newer mage version is available   # check if a newer mage version is available
1562   is_newer_mage_version_available   is_newer_mage_version_available
# Line 1232  syncmage_tarball() Line 1568  syncmage_tarball()
1568   local latest_md5   local latest_md5
1569   local temp="$(mktemp -d)"   local temp="$(mktemp -d)"
1570   local mirr mymirr   local mirr mymirr
1571     local opt
1572     local tar_opts
1573     local wget_opts
1574    
1575   # try to get the md5 marked as latest on the server   # try to get the md5 marked as latest on the server
1576   latest_md5="mage-latest.md5"   latest_md5="mage-latest.md5"
# Line 1239  syncmage_tarball() Line 1578  syncmage_tarball()
1578   # try to get the tarball marked as latest on the server   # try to get the tarball marked as latest on the server
1579   latest_tarball="mage-latest.tar.bz2"   latest_tarball="mage-latest.tar.bz2"
1580    
1581     # filter wget command if busybox was found
1582     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1583    
1584   for mirr in ${MIRRORS}   for mirr in ${MIRRORS}
1585   do   do
1586   # path without distribution   # path without distribution
1587   mymirr="${mirr%/*}"   # (only for stable|testing|unstable and not DISTROTAG)
1588     case ${mirr##*/} in
1589     stable|testing|unstable) mymirr="${mirr%/*}";;
1590     *) mymirr="${mirr}";;
1591     esac
1592    
1593   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1594   echo "fetching latest md5 from ${mymirr} ..."   echo "fetching latest md5 from ${mymirr} ..."
1595     mqueryfeature "!verbose" && opt="--quiet"
1596   wget \   wget \
1597   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1598   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1599   ${mymirr}/rsync/tarballs/${latest_md5}   ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1600    
1601   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1602   echo "fetching latest tarball from ${mymirr} ..."   echo "fetching latest tarball from ${mymirr} ..."
1603   wget \   wget \
1604   ${WGET_FETCH_OPTIONS} \   ${wget_opts} \
1605   --directory-prefix=${temp} \   --directory-prefix=${temp} \
1606   ${mymirr}/rsync/tarballs/${latest_tarball}   ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1607   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1608   then   then
1609   break   break
# Line 1272  syncmage_tarball() Line 1619  syncmage_tarball()
1619   then   then
1620   die "md5 is missing ... aborting"   die "md5 is missing ... aborting"
1621   else   else
1622   ( cd ${temp}; md5sum --check ${lastest_md5} ) || die "md5 for ${lastest_tarball} failed"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1623     echo -n "checking md5sum... "
1624     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1625   fi   fi
1626    
1627   if [[ -d ${MAGEDIR} ]]   if [[ -d ${MAGEDIR} ]]
1628   then   then
1629   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1630   echo "cleaning old mage-tree ${MAGEDIR}..."   echo "cleaning old mage-tree ${MAGEDIR}..."
1631   rm -rf ${MAGEDIR}   # honor mountpoints and empty dirs
1632     if mountpoint -q ${MAGEDIR}
1633     then
1634     if ! mcheckemptydir ${MAGEDIR}
1635     then
1636     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1637     fi
1638     else
1639     rm -rf ${MAGEDIR}
1640     fi
1641     fi
1642    
1643     if need_busybox_support tar
1644     then
1645     tar_opts="xjf"
1646     else
1647     tar_opts="xjmf"
1648   fi   fi
1649    
1650   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1651   echo "updating mage-tree from tarball ..."   echo "updating mage-tree from tarball ..."
1652   # unpack in dirname of MAGEDIR, as the tarball has already the mage   # unpack in dirname of MAGEDIR, as the tarball has already the mage
1653   tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"   tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1654    
1655   if [[ -d ${temp} ]]   if [[ -d ${temp} ]]
1656   then   then
# Line 1311  cleanpkg() Line 1676  cleanpkg()
1676   fi   fi
1677  }  }
1678    
1679  xtitle()  # unused?
1680  {  #
1681   if [[ ${TERM} = xterm ]]  # # cuts full pathnames or versionized names down to basename
1682   then  # choppkgname()
1683   echo -ne "\033]0;Mage: $1\007"  # {
1684   fi  # #we want this only if full name was used
1685   return 0  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1686  }  # then
1687    # #cuts ARCH and PBUILD
1688    # #ARCH comes from ${MAGERC}
1689  xtitleclean()  # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1690  {  #
1691   if [[ ${TERM} = xterm ]]  # #cuts version number
1692   then  # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1693   echo -ne "\033]0;\007"  # fi
1694   fi  # }
  return 0  
 }  
   
1695    
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
 {  
  #we want this only if full name was used  
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
  then  
  #cuts ARCH and PBUILD  
  #ARCH comes from ${MAGERC}  
  MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  
   
  #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 1414  get_highest_magefile() Line 1762  get_highest_magefile()
1762   local magefile   local magefile
1763    
1764   # do not list the content of a directory, only the name (-d)   # 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}/*)   for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1766   do   do
1767   [[ -z ${magefile} ]] && continue   [[ -z ${magefile} ]] && continue
1768   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
# Line 1423  get_highest_magefile() Line 1771  get_highest_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 1552  count_protected_files() Line 1878  count_protected_files()
1878   local filename="${file##*/}"   local filename="${file##*/}"
1879   local count   local count
1880   local output   local output
1881     local oldprotected
1882   local i   local i
1883     local x
1884    
1885     # hack; do not honor a global set IFS like '§'
1886     local IFS
1887    
1888   declare -i count=0   count=0
1889    
1890   # check if there are already protected files   # check if there are already protected files
1891   for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |   for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1892   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |   sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1893   sort -t'%' -k3 -k2 | cut -f1 -d'%')   sort -t'%' -k3 -k2 | cut -f1 -d'%')
1894   do   do
1895   count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")   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   done
1909   (( count ++ ))  
1910     count="$(( ${count}+1 ))"
1911    
1912   # fill output up with zeros   # fill output up with zeros
1913   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done   for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
# Line 1741  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 1852  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 1868  sminclude() Line 2213  sminclude()
2213   then   then
2214   for i in $*   for i in $*
2215   do   do
2216   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2217   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2218   done   done
2219   echo   [[ ${SILENT} = 1 ]] || echo
2220   fi   fi
2221  }  }
2222    
# Line 1898  is_newer_mage_version_available() Line 2243  is_newer_mage_version_available()
2243   fi   fi
2244  }  }
2245    
   
2246  # returns pname from pkgname  # returns pname from pkgname
2247  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2248  pkgname2pname()  pkgname2pname()
# Line 2175  get_value_from_magefile() Line 2519  get_value_from_magefile()
2519   local SDEPEND   local SDEPEND
2520   local PROVIDE   local PROVIDE
2521   local PKGTYPE   local PKGTYPE
  local MAGE_TARGETS  
2522   local SPLIT_PACKAGE_BASE   local SPLIT_PACKAGE_BASE
2523   local preinstall   local preinstall
2524   local postinstall   local postinstall
# Line 2297  mage_install() Line 2640  mage_install()
2640   echo B:${pbuild}   echo B:${pbuild}
2641   fi   fi
2642    
2643   if [[ -n ${MAGE_TARGETS} ]]   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2644   then   then
2645   # basic svn compat   # basic svn compat
2646   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2647   then   then
2648   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
  do  
  smage2file="${i}"  
  done  
  else  
  smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2  
  fi  
   
  elif [[ -n ${SPLIT_PACKAGE_BASE} ]]  
  then  
  # basic svn compat  
  if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]  
  then  
  for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2  
2649   do   do
2650   smage2file="${i}"   smage2file="${i}"
2651   done   done
# Line 2325  mage_install() Line 2655  mage_install()
2655    
2656   else   else
2657   # basic svn compat   # basic svn compat
2658   if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]   if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2659   then   then
2660   for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2   for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2661   do   do
2662   smage2file="${i}"   smage2file="${i}"
2663   done   done
# Line 2352  mage_install() Line 2682  mage_install()
2682   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2683   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2684   then   then
2685     unpack_package "${magefile}"
2686   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2687   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2688   fi   fi
# Line 2396  mage_install() Line 2727  mage_install()
2727   then   then
2728   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2729   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2730   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2731   echo "done." || echo "failure."   echo "done." || echo "failure."
2732   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2733   fi   fi
# Line 2440  md5sum_packages() Line 2771  md5sum_packages()
2771   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2772   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2773   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2774   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2775   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2776    
2777   (( count_current++ ))   (( count_current++ ))
# Line 2450  md5sum_packages() Line 2781  md5sum_packages()
2781   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2782   then   then
2783   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2784   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2785   continue   continue
2786   fi   fi
2787    
# Line 2458  md5sum_packages() Line 2789  md5sum_packages()
2789   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2790   then   then
2791   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2792   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2793   continue   continue
2794   fi   fi
2795    
# Line 2466  md5sum_packages() Line 2797  md5sum_packages()
2797   then   then
2798   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2799   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2800   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2801   else   else
2802   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2803   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2506  uninstall_packages() Line 2837  uninstall_packages()
2837   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2838   can_pcat="${pcat}"   can_pcat="${pcat}"
2839   can_pname="${pname}"   can_pname="${pname}"
2840    
2841   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2842   then   then
2843   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2661  mage_uninstall() Line 2992  mage_uninstall()
2992   then   then
2993   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2994   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2995   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2996   echo "done." || echo "failure."   echo "done." || echo "failure."
2997   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2998   fi   fi
# Line 2679  mage_uninstall() Line 3010  mage_uninstall()
3010   unset -f postremove   unset -f postremove
3011  }  }
3012    
3013  show_etc_update_mesg() {  # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3014    rerun_pkgfunctions()
3015    {
3016     local method
3017     local list
3018     local pcat
3019     local pname
3020     local pver
3021     local pbuild
3022     local magefile
3023     local i
3024    
3025     # very basic getops
3026     case $1 in
3027     --method) shift; method="$1" ;;
3028     esac
3029     shift
3030     local list="$@"
3031    
3032     # sanity check
3033     case ${method} in
3034     preinstall|postinstall) ;;
3035     preremove|postremove) ;;
3036     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3037     esac
3038    
3039     if [[ -n ${MROOT} ]]
3040     then
3041     echo -ne ${COLRED}
3042     echo "!! running in MROOT=${MROOT}"
3043     echo -ne ${COLDEFAULT}
3044     echo
3045     fi
3046    
3047     for pkg in ${list}
3048     do
3049     pcat=$(dep2pcat ${pkg})
3050     pname=$(magename2pname ${pkg})
3051     pver=$(magename2pver ${pkg})
3052     pbuild=$(magename2pbuild ${pkg})
3053     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3054    
3055     if [ -e ${magefile} ]
3056     then
3057     source ${magefile}
3058     if [ -n "$(typeset -f ${method})" ]
3059     then
3060     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3061     ${method}
3062     else
3063     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3064     fi
3065     unset -f preinstall postinstall preremove postremove
3066     else
3067     die "Magefile '${magefile}' does not exist."
3068     fi
3069     done
3070    }
3071    
3072    show_etc_update_mesg()
3073    {
3074   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3075    
3076   echo   echo
# Line 2705  pkgsearch() Line 3096  pkgsearch()
3096   local state   local state
3097   local descriptiom   local descriptiom
3098   local homepage   local homepage
3099     local license
3100   local i   local i
3101   local all_installed   local all_installed
3102   local ipver   local ipver
# Line 2741  pkgsearch() Line 3133  pkgsearch()
3133   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3134   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3135   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3136     license="$(get_value_from_magefile LICENSE ${magefile})"
3137    
3138   # all installed   # all installed
3139   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3140   do   do
3141   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3142   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3143    
3144   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3145   then   then
3146   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2756  pkgsearch() Line 3149  pkgsearch()
3149   fi   fi
3150   done   done
3151   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3152    
3153   case ${state} in   case ${state} in
3154   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3155   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2780  pkgsearch() Line 3173  pkgsearch()
3173   "") continue;;   "") continue;;
3174   esac   esac
3175    
3176   deps="${deps} $(basename ${dep%-*})"   if [[ -z ${deps} ]]
3177     then
3178     deps="$(basename ${dep%-*})"
3179     else
3180     deps="${deps} $(basename ${dep%-*})"
3181     fi
3182   done << EOF   done << EOF
3183  ${depsfull}  ${depsfull}
3184  EOF  EOF
# Line 2791  EOF Line 3189  EOF
3189   "") continue;;   "") continue;;
3190   esac   esac
3191    
3192   sdeps="${sdeps} $(basename ${dep%-*})"   if [[ -z ${sdeps} ]]
3193     then
3194     sdeps="$(basename ${dep%-*})"
3195     else
3196     sdeps="${sdeps} $(basename ${dep%-*})"
3197     fi
3198   done << EOF   done << EOF
3199  ${sdepsfull}  ${sdepsfull}
3200  EOF  EOF
# Line 2801  EOF Line 3204  EOF
3204   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3205   echo "      Description: ${description}"   echo "      Description: ${description}"
3206   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3207   echo "      Depends: ${deps}"   if [[ ! -z ${license} ]]
3208     then
3209     echo "      License:  ${license}"
3210     fi
3211     echo "      Depends:  ${deps}"
3212   echo "      SDepends: ${sdeps}"   echo "      SDepends: ${sdeps}"
3213   echo   echo
3214    
# Line 2841  export_inherits() Line 3248  export_inherits()
3248   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3249    
3250   # debug   # debug
3251   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3252    
3253   shift   shift
3254   done   done
# Line 2913  EOF Line 3320  EOF
3320   return 0   return 0
3321  }  }
3322    
3323    # need_busybox_support ${cmd}
3324    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3325    need_busybox_support()
3326    {
3327     local cmd
3328     local busybox
3329     cmd="$1"
3330    
3331     for busybox in {,/usr}/bin/busybox
3332     do
3333     if [[ -x ${busybox} ]]
3334     then
3335     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3336     then
3337     # needs busybox support
3338     return 0
3339     fi
3340     fi
3341     done
3342    
3343     # no busybox
3344     return 1
3345    }
3346    
3347    # busybox_filter_wget_options ${wget_opts}
3348    busybox_filter_wget_options()
3349    {
3350     local opts="$@"
3351     local i
3352     local fixed_opts
3353    
3354     if need_busybox_support wget
3355     then
3356     for i in ${opts}
3357     do
3358     # show only the allowed ones
3359     case ${i} in
3360     -c|--continue) fixed_opts+=" -c" ;;
3361     -s|--spider) fixed_opts+=" -s" ;;
3362     -q|--quiet) fixed_opts+=" -q" ;;
3363     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3364     --header) shift; fixed_opts+=" --header $1" ;;
3365     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3366     -P) shift; fixed_opts+=" -P $1" ;;
3367     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3368     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3369     # simply drop all other opts
3370     *) continue ;;
3371     esac
3372     done
3373    
3374     echo "${fixed_opts}"
3375     else
3376     echo "${opts}"
3377     fi
3378    }
3379    
3380    have_root_privileges()
3381    {
3382     local retval
3383    
3384     if [[ $(id -u) = 0 ]]
3385     then
3386     retval=0
3387     else
3388     retval=1
3389     fi
3390    
3391     return ${retval}
3392    }
3393    
3394    known_mage_feature()
3395    {
3396     local feature="$1"
3397     local retval
3398    
3399     case "${feature}" in
3400     autosvc|!autosvc) retval=0 ;;
3401     buildlog|!buildlog) retval=0 ;;
3402     ccache|!ccache) retval=0 ;;
3403     check|!check) retval=0 ;;
3404     compressdoc|!compressdoc) retval=0 ;;
3405     debug|!debug) retval=0 ;;
3406     distcc|!distcc) retval=0 ;;
3407     icecc|!icecc) retval=0 ;;
3408     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3409     libtool|!libtool) retval=0 ;;
3410     linuxsymlink|!linuxsymlink) retval=0 ;;
3411     multilib|!multilib) reval=0 ;;
3412     pkgbuild|!pkgbuild) retval=0 ;;
3413     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3414     pkgmetadata|!pkgmetadata) retval=0 ;;
3415     purge|!purge) retval=0 ;;
3416     qalint|!qalint) retval=0 ;;
3417     regentree|!regentree) retval=0 ;;
3418     resume|!resume) retval=0 ;;
3419     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3420     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3421     static|!static) retval=0 ;;
3422     stepbystep|!stepbystep) retval=0 ;;
3423     strip|!strip) retval=0 ;;
3424     verbose|!verbose) retval=0 ;;
3425     *) retval=1 ;;
3426     esac
3427    
3428     return "${retval}"
3429    }
3430    
3431    load_mage_features()
3432    {
3433     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3434     do
3435     FVERBOSE=off msetfeature ${i}
3436     done
3437    }
3438    
3439    msetfeature()
3440    {
3441     local feature
3442     local count
3443     local i
3444     local found
3445    
3446     for feature in $@
3447     do
3448     found=0
3449     count="${#MAGE_FEATURES_CURRENT[*]}"
3450    
3451     if ! known_mage_feature "${feature}"
3452     then
3453     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3454     return 3
3455     fi
3456    
3457     for ((i=0; i<count; i++))
3458     do
3459     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3460     then
3461     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3462     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3463     found=1
3464     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3465     then
3466     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3467     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3468     found=1
3469     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3470     then
3471     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3472     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3473     found=1
3474     fi
3475     done
3476    
3477     # if the feature was not found after proccessing the whole array
3478     # it was not declared. in this case enable it
3479     if [[ ${found} = 0 ]]
3480     then
3481     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3482     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3483     fi
3484    
3485     export MAGE_FEATURE_CURRENT
3486     done
3487    }
3488    
3489    mqueryfeature()
3490    {
3491     local feature="$1"
3492     local retval=1
3493     local i
3494    
3495     if known_mage_feature "${feature}"
3496     then
3497     for i in ${MAGE_FEATURES_CURRENT[*]}
3498     do
3499     if [[ ${i} = ${feature} ]]
3500     then
3501     retval=0
3502     break # found break here
3503     fi
3504     done
3505     else
3506     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3507     retval=3
3508     fi
3509    
3510     return ${retval}
3511    }
3512    
3513    mprintfeatures()
3514    {
3515     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3516     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3517     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3518    }

Legend:
Removed from v.1085  
changed lines
  Added in v.2613