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

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