Magellan Linux

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

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

revision 449 by niro, Tue Mar 27 16:35:57 2007 UTC revision 2271 by niro, Fri Oct 25 07:28:23 2013 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.29 2007-03-27 16:35:57 niro Exp $  # $Id$
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49     local sum
50     local dest
51    
52     # very basic getops
53     for i in $*
54     do
55     case $1 in
56     --rundir|-r) shift; rundir="$1" ;;
57     --file|-f) shift; file="$1" ;;
58     --method|-m) shift; method="$1" ;;
59     esac
60     shift
61     done
62    
63     # sanity checks
64     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
65     [[ -z ${file} ]] && die "mchecksum(): file missing"
66     [[ -z ${method} ]] && die "mchecksum(): method missing"
67    
68     case ${method} in
69     md5) cmd="md5sum" ;;
70     sha256) cmd="sha256sum" ;;
71     *) die "mchecksum(): unknown method '${method}'" ;;
72     esac
73    
74     if [[ -d ${rundir} ]]
75     then
76     pushd ${rundir} &> /dev/null
77    
78     # all file must be non-zero
79     retval=0
80     while read sum dest
81     do
82     if [ ! -s ${dest} ]
83     then
84     echo "${dest}: file is empty ;("
85     retval=127
86     fi
87     done < ${file}
88     if [[ ${retval} != 127 ]]
89     then
90     # be verbose here
91     ${cmd} -c ${file} #&> /dev/null
92     retval="$?"
93     fi
94    
95     popd &> /dev/null
96     else
97     retval=1
98     fi
99    
100     return "${retval}"
101    }
102    
103    mcheckemptydir()
104    {
105     local dir="$1"
106     local retval=1
107    
108     if [[ ! -d ${dir} ]]
109     then
110     echo "mcheckemptydir(): '${dir}' is not a directory!"
111     retval=3
112     else
113     shopt -s nullglob dotglob
114     files=( ${dir}/* )
115     (( ${#files[*]} )) || retval=0
116     shopt -u nullglob dotglob
117     fi
118    
119     return ${retval}
120    }
121    
122    unpack_package()
123    {
124     local magefile="$1"
125     local pkgname
126     local pkgfile
127     local pkgtype
128     local tar_opts
129    
130     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
131     pkgfile="${pkgname}.${PKGSUFFIX}"
132     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
133    
134     xtitle "[ Unpacking ${pkg} ]"
135    
136     # abort on virtual pkg
137     if [[ ${pkgtype} = virtual ]]
138     then
139     echo -ne " ${COLBLUE}---${COLDEFAULT}"
140     echo " !unpack virtual ${pkgname} ... "
141     continue
142     fi
143    
144     # abort on sources pkg
145     if [[ ${pkgtype} = sources ]]
146     then
147     echo -ne " ${COLBLUE}---${COLDEFAULT}"
148     echo " !unpack sources ${pkgname} ... "
149     continue
150     fi
151    
152     # busybox?
153     if need_busybox_support tar
154     then
155     tar_opts="xjf"
156     else
157     tar_opts="xjmf"
158     fi
159    
160     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
161     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
162    }
163    
164  unpack_packages()  unpack_packages()
165  {  {
166   local list="$@"   local list="$@"
167   local magefile   local magefile
  local pkg  
  local pkgtype  
168   local count_current   local count_current
169   local count_total   local count_total
170     local tar_opts
171    
172   # get count of total packages   # get count of total packages
173   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 177  unpack_packages()
177    
178   for magefile in ${list}   for magefile in ${list}
179   do   do
180   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
181   (( 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}"  
182   done   done
183    
184   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 198  fix_mtime()
198   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
199   touch \   touch \
200   --no-create \   --no-create \
201     --no-dereference \
202   --time=mtime \   --time=mtime \
203   --reference "${reference}" \   --reference="${reference}" \
204   "${pathto}"   "${pathto}"
205    
206   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 254  install_directories()
254   while read pathto posix user group   while read pathto posix user group
255   do   do
256   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
257   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
258    
259   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
260   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 321  install_files()
321   is_config_protected "${pathto}"   is_config_protected "${pathto}"
322   retval="$?"   retval="$?"
323    
324   # 0 - not protected        #   # 0 - not protected         #
325   # 1 - error                #   # 1 - error                 #
326   # 2 - protected            #   # 2 - protected             #
327   # 3 - protected but masked #   # 3 - protected but masked  #
328     # 4 - protected but ignored #
329    
330   case ${retval} in   case ${retval} in
331   # file is not protected - (over)write it   # file is not protected - (over)write it
332   0|3)   0|3)
333   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
334   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
335   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
336   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 342  install_files()
342   "${user}" \   "${user}" \
343   "${group}" \   "${group}" \
344   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
345   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
346   "${md5sum}"   "${md5sum}"
347   ;;   ;;
348    
349   # file is protected, write backup file   # file is protected, write backup file
350   2)   2)
351   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
352   then   then
353   echo -en "${COLRED}"   echo -en "${COLRED}"
354   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 369  install_files()
369   "${user}" \   "${user}" \
370   "${group}" \   "${group}" \
371   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
372   "${dest_protected}")" \   "${dest_protected}")" \
373   "${md5sum}"   "${md5sum}"
374    
375   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
376   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
377   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
378   ;;   ;;
379    
380     # file is protected but ignored, delete the update/do nothing
381     4)
382     if mqueryfeature "verbose"
383     then
384     echo -en "${COLRED}"
385     echo -n "! ignr "
386     echo -en "${COLDEFAULT}"
387     echo " === FILE: ${MROOT}${pathto}"
388     fi
389     # simply do nothing here - only fix mtime
390     fix_descriptor ${pkgname}/.files \
391     "${pathto}" \
392     "${posix}" \
393     "${user}" \
394     "${group}" \
395     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
396     "${MROOT}${pathto}")" \
397     "${md5sum}"
398     ;;
399   esac   esac
400   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
401    
# Line 294  install_symlinks() Line 438  install_symlinks()
438   while read pathto posix link mtime   while read pathto posix link mtime
439   do   do
440   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
441   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
442    
443   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
444    
445   # fix mtime and db   # fix mtime and db
446   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
447   "${pathto}" \   "${pathto}" \
448   "${posix}" \   "${posix}" \
449   "${link}" \   "${link}" \
450   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
451   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
452    
453   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
454    
455   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
456   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
457   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
458    
459   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
460   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 470  install_blockdevices()
470   local pkgname="$1"   local pkgname="$1"
471   local pathto   local pathto
472   local posix   local posix
473     local user
474     local group
475   local IFS   local IFS
476    
477   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 485  install_blockdevices()
485   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
486   IFS=§   IFS=§
487    
488   while read pathto posix   while read pathto posix major minor user group
489   do   do
490   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
491   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
492    
493   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
494     # make it optional atm !!
495     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
496     then
497     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
498     fi
499   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
500    
501   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 363  install_characterdevices() Line 514  install_characterdevices()
514   local posix   local posix
515   local major   local major
516   local minor   local minor
517     local user
518     local group
519   local IFS   local IFS
520    
521   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 376  install_characterdevices() Line 529  install_characterdevices()
529   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
530   IFS=§   IFS=§
531    
532   while read pathto posix major minor   while read pathto posix major minor user group
533   do   do
534   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
535   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
536    
537   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
538    
539     # make it optional atm !!
540     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
541     then
542     chown "${user}:${group}" "${MROOT}${pathto}"
543     fi
544   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
545    
546   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
547   IFS=$'\n'   IFS=$'\n'
548  }  }
549    
550    ###################################################
551    # function install_fifos                          #
552    # install_fifos $PKGNAME                    #
553    ###################################################
554    install_fifos()
555    {
556     local pkgname="$1"
557     local pathto
558     local posix
559     local user
560     local group
561     local IFS
562    
563     # sanity checks; abort if not given
564     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
565    
566     # check needed global vars
567     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
568    
569     # make it optional atm !!
570     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
571     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
572    
573     # sets fieldseperator to "§" instead of " "
574     IFS=§
575    
576     while read pathto posix user group
577     do
578     [ -z "${pathto}" ] && continue
579     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
580    
581     mkfifo -m "${posix}" "${MROOT}${pathto}"
582     chown "${user}:${group}" "${MROOT}${pathto}"
583     done < ${BUILDDIR}/${pkgname}/.fifo
584    
585     # very important: unsetting the '§' fieldseperator
586     IFS=$'\n'
587    }
588    
589    
590  ###################################################  ###################################################
591  # function build_doinstall                        #  # function build_doinstall                        #
592  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
593  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
594  ###################################################  ###################################################
595  build_doinstall()  build_doinstall()
596  {  {
# Line 400  build_doinstall() Line 598  build_doinstall()
598    
599   # sanity checks; abort if not given   # sanity checks; abort if not given
600   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
601    
602   # this is only a wrapper   # this is only a wrapper
603    
604   # NOTE:   # NOTE:
# Line 415  build_doinstall() Line 613  build_doinstall()
613   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
614   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
615   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
616     install_fifos ${pkgname} || die "install fifos ${pkgname}"
617  }  }
618    
619    
# Line 476  install_database_entry() Line 675  install_database_entry()
675    
676   # create fake file descriptors   # create fake file descriptors
677   # used by virtual and source packages   # used by virtual and source packages
678   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
679   do   do
680   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
681   done   done
# Line 494  install_database_entry() Line 693  install_database_entry()
693    
694   # normal packages needs these files   # normal packages needs these files
695   local i   local i
696   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
697   do   do
698   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
699   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
700     then
701     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
702     fi
703   done   done
704   ;;   ;;
705   esac   esac
# Line 633  compare_mtime() Line 835  compare_mtime()
835    
836   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
837    
838   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
839   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
840   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  
841    
842   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
843    
# Line 708  remove_symlinks() Line 899  remove_symlinks()
899   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
900   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
901   then   then
902   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
903   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
904   continue   continue
905   fi   fi
# Line 720  remove_symlinks() Line 911  remove_symlinks()
911   # 1=keep me   #   # 1=keep me   #
912   case ${retval} in   case ${retval} in
913   0)   0)
914   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
915   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
916   ;;   ;;
917    
918   1)   1)
919   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
920   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
921   ;;   ;;
922   esac   esac
# Line 772  remove_files() Line 963  remove_files()
963   done   done
964    
965   # sanity checks; abort if not given   # sanity checks; abort if not given
966   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
967   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
968   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
969   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
970   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
971    
972   # check needed global vars   # check needed global vars
# Line 792  remove_files() Line 983  remove_files()
983    
984   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
985   then   then
986   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
987   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
988   continue   continue
989   fi   fi
# Line 809  remove_files() Line 1000  remove_files()
1000   is_config_protected "${pathto}"   is_config_protected "${pathto}"
1001   retval="$?"   retval="$?"
1002    
1003   # 0 - not protected        #   # 0 - not protected         #
1004   # 1 - error                #   # 1 - error                 #
1005   # 2 - protected            #   # 2 - protected             #
1006   # 3 - protected but masked #   # 3 - protected but masked  #
1007     # 4 - protected but ignored #
1008    
1009   case ${retval} in   case ${retval} in
1010   # file is not protected - delete it   # file is not protected - delete it
1011   0|3)   0|3)
1012   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1013   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1014   ;;   ;;
1015    
1016   # file is protected, do not delete   # file is protected, do not delete
1017   2)   2)
1018   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1019   then   then
1020   echo -en "${COLRED}"   echo -en "${COLRED}"
1021   echo -n "! prot "   echo -n "! prot "
# Line 831  remove_files() Line 1023  remove_files()
1023   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
1024   fi   fi
1025   ;;   ;;
1026    
1027     # file is protected but ignored, delete the update/do nothing
1028     4)
1029     if mqueryfeature "verbose"
1030     then
1031     echo -en "${COLRED}"
1032     echo -n "! ignr "
1033     echo -en "${COLDEFAULT}"
1034     echo " === FILE: ${MROOT}${pathto}"
1035     fi
1036     # simply do nothing here
1037     ;;
1038   esac   esac
1039   ;;   ;;
1040   1)   1)
1041   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1042   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1043   ;;   ;;
1044   esac   esac
# Line 853  remove_blockdevices() Line 1057  remove_blockdevices()
1057  {  {
1058   local pathto   local pathto
1059   local posix   local posix
1060     local user
1061     local group
1062   local IFS   local IFS
1063   local pcat   local pcat
1064   local pname   local pname
# Line 876  remove_blockdevices() Line 1082  remove_blockdevices()
1082   done   done
1083    
1084   # sanity checks; abort if not given   # sanity checks; abort if not given
1085   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1086   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1087   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1088   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1089   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1090    
1091   # check needed global vars   # check needed global vars
# Line 890  remove_blockdevices() Line 1096  remove_blockdevices()
1096   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1097   IFS=§   IFS=§
1098    
1099   while read pathto posix   while read pathto posix user group
1100   do   do
1101   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1102    
1103   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1104   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1105   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1106    
# Line 911  remove_characterdevices() Line 1117  remove_characterdevices()
1117  {  {
1118   local pathto   local pathto
1119   local posix   local posix
1120     local user
1121     local group
1122   local IFS   local IFS
1123   local pcat   local pcat
1124   local pname   local pname
# Line 934  remove_characterdevices() Line 1142  remove_characterdevices()
1142   done   done
1143    
1144   # sanity checks; abort if not given   # sanity checks; abort if not given
1145   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1146   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1147   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1148   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1149   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1150    
1151   # check needed global vars   # check needed global vars
# Line 948  remove_characterdevices() Line 1156  remove_characterdevices()
1156   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1157   IFS=§   IFS=§
1158    
1159   while read pathto posix   while read pathto posix user group
1160   do   do
1161   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1162    
1163   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1164   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1165   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1166    
# Line 962  remove_characterdevices() Line 1170  remove_characterdevices()
1170    
1171    
1172  ###################################################  ###################################################
1173    # function remove_fifos                           #
1174    # remove_fifos $PKGNAME                     #
1175    ###################################################
1176    remove_fifos()
1177    {
1178     local pathto
1179     local posix
1180     local user
1181     local group
1182     local IFS
1183     local pcat
1184     local pname
1185     local pver
1186     local pbuild
1187     local i
1188     local pfull
1189    
1190     IFS=$'\n'
1191    
1192     # very basic getops
1193     for i in $*
1194     do
1195     case $1 in
1196     --pcat|-c) shift; pcat="$1" ;;
1197     --pname|-n) shift; pname="$1" ;;
1198     --pver|-v) shift; pver="$1" ;;
1199     --pbuild|-b) shift; pbuild="$1" ;;
1200     esac
1201     shift
1202     done
1203    
1204     # sanity checks; abort if not given
1205     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1206     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1207     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1208     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1209     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1210    
1211     # check needed global vars
1212     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1213    
1214     # make it optional atm !!
1215     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1216     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1217    
1218     # sets fieldseperator to "§" instead of " "
1219     IFS=§
1220    
1221     while read pathto posix user group
1222     do
1223     [ -z "${pathto}" ] && continue
1224    
1225     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1226     rm "${MROOT}${pathto}"
1227     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1228    
1229     # very important: unsetting the '§' fieldseperator
1230     IFS=$'\n'
1231    }
1232    
1233    
1234    ###################################################
1235  # function remove_direcories                      #  # function remove_direcories                      #
1236  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1237  ###################################################  ###################################################
# Line 992  remove_directories() Line 1262  remove_directories()
1262   done   done
1263    
1264   # sanity checks; abort if not given   # sanity checks; abort if not given
1265   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1266   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1267   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1268   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1269   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1270    
1271   # check needed global vars   # check needed global vars
# Line 1013  remove_directories() Line 1283  remove_directories()
1283    
1284   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1285   then   then
1286   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1287   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1288   continue   continue
1289   fi   fi
# Line 1021  remove_directories() Line 1291  remove_directories()
1291   # exclude .keep directories   # exclude .keep directories
1292   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1293   then   then
1294   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1295   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1296   continue   continue
1297   fi   fi
# Line 1034  remove_directories() Line 1304  remove_directories()
1304    
1305   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1306   then   then
1307   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1308   else   else
1309   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1310   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1311   fi   fi
1312   done   done
# Line 1049  remove_directories() Line 1319  remove_directories()
1319  ###################################################  ###################################################
1320  # function build_douninstall                      #  # function build_douninstall                      #
1321  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1322  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1323  ###################################################  ###################################################
1324  build_douninstall()  build_douninstall()
1325  {  {
# Line 1083  build_douninstall() Line 1353  build_douninstall()
1353   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1354   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1355    
1356   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1357   do   do
1358   remove_${i} \   remove_${i} \
1359   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1094  build_douninstall() Line 1364  build_douninstall()
1364   done   done
1365  }  }
1366    
1367    # convertmirrors [uri]
1368    convertmirrors()
1369    {
1370     local uri="$1"
1371     local scheme
1372     local mirror
1373     local mirrors
1374     local addon
1375     local real_uri
1376     local output
1377    
1378     # needs
1379     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1380     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1381     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1382     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1383     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1384    
1385     # check known uri schemes
1386     case ${uri} in
1387     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1388     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1389     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1390     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1391     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1392     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1393     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1394     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1395     esac
1396    
1397     if [[ ! -z ${mirrors} ]]
1398     then
1399     for mirror in ${mirrors}
1400     do
1401     # add a whitespace to the output
1402     [[ -z ${output} ]] || output+=" "
1403     output+="${mirror}${addon}/${uri/${scheme}/}"
1404     done
1405     else
1406     output="${uri}"
1407     fi
1408    
1409     echo "${output}"
1410    }
1411    
1412    mdownload()
1413    {
1414     local i
1415     local uri
1416     local real_uris
1417     local mirror
1418     local outputfile
1419     local outputdir
1420     local retval
1421     local wget_opts
1422    
1423     # very basic getops
1424     for i in $*
1425     do
1426     case $1 in
1427     --uri|-u) shift; uri="$1" ;;
1428     --dir|-d) shift; outputdir="$1" ;;
1429     esac
1430     shift
1431     done
1432    
1433     # sanity checks; abort if not given
1434     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1435     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1436    
1437     # convert mirrored uris to the real ones
1438     real_uris="$(convertmirrors ${uri})"
1439    
1440     # verbose or not
1441     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1442    
1443     # filter wget options if busybox was found
1444     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1445    
1446     # create outputdir
1447     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1448    
1449     for mirror in ${real_uris}
1450     do
1451     # get the name of the output file
1452     outputfile="${mirror##*/}"
1453    
1454     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1455     retval="$?"
1456     if [[ ${retval} = 0 ]]
1457     then
1458     break
1459     else
1460     continue
1461     fi
1462     done
1463    
1464     # return wget retval
1465     return "${retval}"
1466    }
1467    
1468  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1469  fetch_packages()  fetch_packages()
1470  {  {
1471     local i
1472   local list="$@"   local list="$@"
1473   local pkg   local pkgname
1474     local pkgfile
1475   local mirr   local mirr
1476   local magefile   local magefile
1477   local md5file   local md5file
1478   local opt   local opt
1479   local count_current   local count_current
1480   local count_total   local count_total
1481     local wget_opts
1482    
1483   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1484    
1485     # filter wget command if busybox was found
1486     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1487    
1488   # get count of total packages   # get count of total packages
1489   declare -i count_current=0   declare -i count_current=0
1490   declare -i count_total=0   declare -i count_total=0
# Line 1116  fetch_packages() Line 1493  fetch_packages()
1493    
1494   for magefile in ${list}   for magefile in ${list}
1495   do   do
1496   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1497     pkgfile="${pkgname}.${PKGSUFFIX}"
1498   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1499    
1500   (( count_current++ ))   (( count_current++ ))
1501   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1502    
1503   # abort on virtual pkg   # abort on virtual pkg
1504   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1505   then   then
1506   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1507   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1508   continue   continue
1509   fi   fi
1510    
# Line 1134  fetch_packages() Line 1512  fetch_packages()
1512   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1513   then   then
1514   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1515   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1516   continue   continue
1517   fi   fi
1518    
1519   # abort if already exist   # abort if already exist
1520   if [ -f ${PKGDIR}/${pkg} ]   if [ -f ${PKGDIR}/${pkgfile} ]
1521   then   then
1522   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1523   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1524   continue   continue
1525   fi   fi
1526    
1527   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1528   do   echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1529   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1530   #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "   if [ ! -f ${PKGDIR}/${pkgfile} ]
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  --passive-ftp \  
  --tries 3 \  
  --continue \  
  --progress bar \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
  if [ ! -f ${PKGDIR}/${pkg} ]  
1531   then   then
1532   die "Could not download ${pkg}"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1533   fi   fi
1534   done   done
1535    
# Line 1197  syncmage() Line 1557  syncmage()
1557   done   done
1558    
1559   # clean up backup files (foo~)   # clean up backup files (foo~)
1560   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1561    
1562   # check if an newer mage version is available   # check if a newer mage version is available
1563   is_newer_mage_version_available   is_newer_mage_version_available
1564  }  }
1565    
1566    syncmage_tarball()
1567    {
1568     local latest_tarball
1569     local latest_md5
1570     local temp="$(mktemp -d)"
1571     local mirr mymirr
1572     local opt
1573     local tar_opts
1574     local wget_opts
1575    
1576     # try to get the md5 marked as latest on the server
1577     latest_md5="mage-latest.md5"
1578    
1579     # try to get the tarball marked as latest on the server
1580     latest_tarball="mage-latest.tar.bz2"
1581    
1582     # filter wget command if busybox was found
1583     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1584    
1585     for mirr in ${MIRRORS}
1586     do
1587     # path without distribution
1588     # (only for stable|testing|unstable and not DISTROTAG)
1589     case ${mirr##*/} in
1590     stable|testing|unstable) mymirr="${mirr%/*}";;
1591     *) mymirr="${mirr}";;
1592     esac
1593    
1594     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1595     echo "fetching latest md5 from ${mymirr} ..."
1596     mqueryfeature "!verbose" && opt="--quiet"
1597     wget \
1598     ${wget_opts} \
1599     --directory-prefix=${temp} \
1600     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1601    
1602     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1603     echo "fetching latest tarball from ${mymirr} ..."
1604     wget \
1605     ${wget_opts} \
1606     --directory-prefix=${temp} \
1607     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1608     if [[ $? = 0 ]]
1609     then
1610     break
1611     else
1612     continue
1613     fi
1614     done
1615    
1616     if [[ -f ${temp}/${latest_tarball} ]]
1617     then
1618     # check md5
1619     if [[ ! -f ${temp}/${latest_md5} ]]
1620     then
1621     die "md5 is missing ... aborting"
1622     else
1623     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1624     echo -n "checking md5sum... "
1625     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1626     fi
1627    
1628     if [[ -d ${MAGEDIR} ]]
1629     then
1630     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1631     echo "cleaning old mage-tree ${MAGEDIR}..."
1632     # honor mountpoints and empty dirs
1633     if mountpoint -q ${MAGEDIR}
1634     then
1635     if ! mcheckemptydir ${MAGEDIR}
1636     then
1637     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1638     fi
1639     else
1640     rm -rf ${MAGEDIR}
1641     fi
1642     fi
1643    
1644     if need_busybox_support tar
1645     then
1646     tar_opts="xjf"
1647     else
1648     tar_opts="xjmf"
1649     fi
1650    
1651     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1652     echo "updating mage-tree from tarball ..."
1653     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1654     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1655    
1656     if [[ -d ${temp} ]]
1657     then
1658     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1659     echo "cleaning temp-files ..."
1660     rm -rf ${temp}
1661     fi
1662    
1663     # check if a newer mage version is available
1664     is_newer_mage_version_available
1665     else
1666     die "Could not fetch the latest tarball ... aborting"
1667     fi
1668    }
1669    
1670  cleanpkg()  cleanpkg()
1671  {  {
1672   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1233  xtitleclean() Line 1697  xtitleclean()
1697  }  }
1698    
1699    
1700  # cuts full pathnames or versioniezed names down to basename  # unused?
1701  choppkgname()  #
1702  {  # # cuts full pathnames or versionized names down to basename
1703   #we want this only if full name was used  # choppkgname()
1704   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1705   then  # #we want this only if full name was used
1706   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1707   #ARCH comes from ${MAGERC}  # then
1708   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1709    # #ARCH comes from ${MAGERC}
1710    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1711    #
1712    # #cuts version number
1713    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1714    # fi
1715    # }
1716    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1717    
1718  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1719  # $1=pname  # $1=pname
# Line 1315  get_highest_magefile() Line 1782  get_highest_magefile()
1782   local PNAME="$2"   local PNAME="$2"
1783   local magefile   local magefile
1784    
1785   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1786     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1787   do   do
1788     [[ -z ${magefile} ]] && continue
1789   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1790   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1791   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1792   then   then
1793   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1794   #for debug only   #for debug only
1795   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1796   fi   fi
1797   done   done
1798    
 # 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  
   
1799   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1800   return 0   return 0
1801  }  }
# Line 1363  get_highest_magefile() Line 1810  get_highest_magefile()
1810  #        1 - error                                #  #        1 - error                                #
1811  #        2 - protected                            #  #        2 - protected                            #
1812  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1813    #        4 - protected but ignored                #
1814  #                                                 #  #                                                 #
1815  ###################################################  ###################################################
1816  is_config_protected()  is_config_protected()
# Line 1371  is_config_protected() Line 1819  is_config_protected()
1819   local TEST   local TEST
1820   local PROTECTED   local PROTECTED
1821   local IFS   local IFS
1822     local i
1823     local x
1824    
1825   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1826    
1827   # file does not exist; it can be written   # file does not exist; it can be written
1828   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1829    
1830   # to be safe; it may be '§'   # to be safe; it may be '§'
1831   IFS=' '   IFS=' '
1832    
1833   # check ob in config protect   # check if config protected
1834   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1835   do   do
1836   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1837   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1838   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1839   then   then
1840   # setzen das es protected ist   # file is config proteced
1841   PROTECTED=TRUE   PROTECTED=TRUE
1842    
1843   # check ob nicht doch maskiert   # check if not masked
1844   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1845   do   do
1846   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1847   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1848   then   then
1849   PROTECTED=MASKED   PROTECTED=MASKED
1850   fi   fi
1851   done   done
1852    
1853     # check if not ignored
1854     for x in ${CONFIG_PROTECT_IGNORE}
1855     do
1856     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1857     if [[ ${TEST} != ${EXPFILE} ]]
1858     then
1859     PROTECTED=IGNORED
1860     fi
1861     done
1862   fi   fi
1863   done   done
1864    
# Line 1413  is_config_protected() Line 1873  is_config_protected()
1873   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1874   return 3   return 3
1875   ;;   ;;
1876     IGNORED)
1877     #echo "I'm protected, but ignored - keep me, del update"
1878     return 4
1879     ;;
1880   *)   *)
1881   #echo "delete me"   #echo "delete me"
1882   return 0   return 0
# Line 1430  is_config_protected() Line 1894  is_config_protected()
1894  ###################################################  ###################################################
1895  count_protected_files()  count_protected_files()
1896  {  {
1897   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1898     local dirname="${file%/*}"
1899     local filename="${file##*/}"
1900     local count
1901     local output
1902     local oldprotected
1903     local i
1904     local x
1905    
1906     # hack; do not honor a global set IFS like '§'
1907     local IFS
1908    
1909     count=0
1910    
1911     # check if there are already protected files
1912     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1913     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1914     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1915     do
1916     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1917     done
1918    
1919     # convert 0001 -> 1; 0120 -> 120 etc
1920     # use bash internal base functions to this task
1921     x="$((10#${count}))"
1922     for (( i=0; i<x; i++ ))
1923     do
1924     if [[ ${count:${i}:1} != 0 ]]
1925     then
1926     count="${count:${i}}"
1927     break
1928     fi
1929     done
1930    
1931     count="$(( ${count}+1 ))"
1932    
1933     # fill output up with zeros
1934     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1935     output="${output}${count}"
1936    
1937     echo "${output}"
1938  }  }
1939    
1940  # call with  # call with
# Line 1602  virtuals_add() Line 2106  virtuals_add()
2106    
2107  #deletes pakages from virtual database  #deletes pakages from virtual database
2108  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2109  virtuals_del() {  virtuals_del()
2110    {
2111    
2112   local virtualname="$1"   local virtualname="$1"
2113   local pkgname="$2"   local pkgname="$2"
# Line 1713  minclude() Line 2218  minclude()
2218   then   then
2219   for i in $*   for i in $*
2220   do   do
2221   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2222   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2223   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2224   done   done
2225   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2226   fi   fi
2227  }  }
2228    
# Line 2036  get_value_from_magefile() Line 2541  get_value_from_magefile()
2541   local SDEPEND   local SDEPEND
2542   local PROVIDE   local PROVIDE
2543   local PKGTYPE   local PKGTYPE
2544     local MAGE_TARGETS
2545     local SPLIT_PACKAGE_BASE
2546   local preinstall   local preinstall
2547   local postinstall   local postinstall
2548   local preremove   local preremove
# Line 2082  mage_install() Line 2589  mage_install()
2589   local count_current   local count_current
2590   local magefile   local magefile
2591   local src_install   local src_install
2592     local i
2593    
2594   # very basic getops   # very basic getops
2595   for i in $*   for i in $*
# Line 2155  mage_install() Line 2663  mage_install()
2663   echo B:${pbuild}   echo B:${pbuild}
2664   fi   fi
2665    
2666   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2667     then
2668     # basic svn compat
2669     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2670     then
2671     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2672     do
2673     smage2file="${i}"
2674     done
2675     else
2676     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2677     fi
2678    
2679     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2680     then
2681     # basic svn compat
2682     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2683     then
2684     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2685     do
2686     smage2file="${i}"
2687     done
2688     else
2689     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2690     fi
2691    
2692     else
2693     # basic svn compat
2694     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2695     then
2696     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2697     do
2698     smage2file="${i}"
2699     done
2700     else
2701     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2702     fi
2703     fi
2704    
2705   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2706   then   then
2707   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
# Line 2172  mage_install() Line 2718  mage_install()
2718   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2719   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2720   then   then
2721     unpack_package "${magefile}"
2722   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2723   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2724   fi   fi
# Line 2260  md5sum_packages() Line 2807  md5sum_packages()
2807   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2808   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2809   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2810   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2811   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2812    
2813   (( count_current++ ))   (( count_current++ ))
# Line 2270  md5sum_packages() Line 2817  md5sum_packages()
2817   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2818   then   then
2819   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2820   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2821   continue   continue
2822   fi   fi
2823    
# Line 2278  md5sum_packages() Line 2825  md5sum_packages()
2825   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2826   then   then
2827   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2828   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2829   continue   continue
2830   fi   fi
2831    
# Line 2286  md5sum_packages() Line 2833  md5sum_packages()
2833   then   then
2834   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2835   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2836   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2837   else   else
2838   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2839   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2326  uninstall_packages() Line 2873  uninstall_packages()
2873   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2874   can_pcat="${pcat}"   can_pcat="${pcat}"
2875   can_pname="${pname}"   can_pname="${pname}"
2876    
2877   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2878   then   then
2879   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2431  mage_uninstall() Line 2978  mage_uninstall()
2978   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2979   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2980    
2981   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2982   source ${magefile}   source ${magefile}
2983    
2984   ## preremove scripts   ## preremove scripts
# Line 2499  mage_uninstall() Line 3046  mage_uninstall()
3046   unset -f postremove   unset -f postremove
3047  }  }
3048    
3049  show_etc_update_mesg() {  show_etc_update_mesg()
3050    {
3051   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3052    
3053   echo   echo
# Line 2525  pkgsearch() Line 3073  pkgsearch()
3073   local state   local state
3074   local descriptiom   local descriptiom
3075   local homepage   local homepage
3076     local license
3077   local i   local i
3078   local all_installed   local all_installed
3079   local ipver   local ipver
3080   local ipbuild   local ipbuild
3081   local latest_available   local latest_available
3082     local depsfull
3083     local sdepsfull
3084     local deps
3085     local sdeps
3086     local dep
3087     local sign
3088    
3089   # only names no versions   # only names no versions
3090   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
# Line 2555  pkgsearch() Line 3110  pkgsearch()
3110   state="$(get_value_from_magefile STATE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3111   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3112   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3113     license="$(get_value_from_magefile LICENSE ${magefile})"
3114    
3115   # all installed   # all installed
3116   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3117   do   do
3118   ipver="$(magename2pver ${i})"   ipver="$(magename2pver ${i})"
3119   ipbuild="$(magename2pbuild ${i})"   ipbuild="$(magename2pbuild ${i})"
3120    
3121   if [[ -z ${all_installed} ]]   if [[ -z ${all_installed} ]]
3122   then   then
3123   all_installed="${ipver}-${ipbuild}"   all_installed="${ipver}-${ipbuild}"
# Line 2570  pkgsearch() Line 3126  pkgsearch()
3126   fi   fi
3127   done   done
3128   [[ -z ${all_installed} ]] && all_installed="none"   [[ -z ${all_installed} ]] && all_installed="none"
3129    
3130   case ${state} in   case ${state} in
3131   stable) state=${COLGREEN}"[s] ";;   stable) state=${COLGREEN}"[s] ";;
3132   testing) state=${COLYELLOW}"[t] ";;   testing) state=${COLYELLOW}"[t] ";;
# Line 2585  pkgsearch() Line 3141  pkgsearch()
3141   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3142   fi   fi
3143    
3144     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3145     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3146    
3147     while read sign dep
3148     do
3149     case ${dep} in
3150     "") continue;;
3151     esac
3152    
3153     if [[ -z ${deps} ]]
3154     then
3155     deps="$(basename ${dep%-*})"
3156     else
3157     deps="${deps} $(basename ${dep%-*})"
3158     fi
3159     done << EOF
3160    ${depsfull}
3161    EOF
3162    
3163     while read sign dep
3164     do
3165     case ${dep} in
3166     "") continue;;
3167     esac
3168    
3169     if [[ -z ${sdeps} ]]
3170     then
3171     sdeps="$(basename ${dep%-*})"
3172     else
3173     sdeps="${sdeps} $(basename ${dep%-*})"
3174     fi
3175     done << EOF
3176    ${sdepsfull}
3177    EOF
3178    
3179   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3180   echo -e "      Latest available:   ${latest_available}"   echo -e "      Latest available:   ${latest_available}"
3181   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3182   echo "      Description: ${description}"   echo "      Description: ${description}"
3183   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3184     if [[ ! -z ${license} ]]
3185     then
3186     echo "      License:  ${license}"
3187     fi
3188     echo "      Depends:  ${deps}"
3189     echo "      SDepends: ${sdeps}"
3190   echo   echo
3191    
3192   unset pcat   unset pcat
# Line 2603  pkgsearch() Line 3200  pkgsearch()
3200   unset all_installed   unset all_installed
3201   unset ipver   unset ipver
3202   unset ipbuild   unset ipbuild
3203     unset depsfull
3204     unset sdepsfull
3205     unset deps
3206     unset sdeps
3207     unset dep
3208     unset sign
3209   done   done
3210  }  }
3211    
# Line 2622  export_inherits() Line 3225  export_inherits()
3225   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3226    
3227   # debug   # debug
3228   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3229    
3230   shift   shift
3231   done   done
# Line 2645  blacklisted() Line 3248  blacklisted()
3248   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3249   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3250    
3251   local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"   # support both types for the moment
3252     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3253     then
3254     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3255     else
3256     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3257     fi
3258    
3259   # return 0 if the list not exist; nothin is masked   # return 0 if the list not exist; nothin is masked
3260   [[ ! -f ${EXCLUDED} ]] && return 0   [[ ! -f ${EXCLUDED} ]] && return 0
# Line 2688  EOF Line 3297  EOF
3297   return 0   return 0
3298  }  }
3299    
3300    # need_busybox_support ${cmd}
3301    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3302    need_busybox_support()
3303    {
3304     local cmd
3305     local busybox
3306     cmd="$1"
3307    
3308     for busybox in {,/usr}/bin/busybox
3309     do
3310     if [[ -x ${busybox} ]]
3311     then
3312     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3313     then
3314     # needs busybox support
3315     return 0
3316     fi
3317     fi
3318     done
3319    
3320     # no busybox
3321     return 1
3322    }
3323    
3324    # busybox_filter_wget_options ${wget_opts}
3325    busybox_filter_wget_options()
3326    {
3327     local opts="$@"
3328     local i
3329     local fixed_opts
3330    
3331     if need_busybox_support wget
3332     then
3333     for i in ${opts}
3334     do
3335     # show only the allowed ones
3336     case ${i} in
3337     -c|--continue) fixed_opts+=" -c" ;;
3338     -s|--spider) fixed_opts+=" -s" ;;
3339     -q|--quiet) fixed_opts+=" -q" ;;
3340     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3341     --header) shift; fixed_opts+=" --header $1" ;;
3342     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3343     -P) shift; fixed_opts+=" -P $1" ;;
3344     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3345     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3346     # simply drop all other opts
3347     *) continue ;;
3348     esac
3349     done
3350    
3351     echo "${fixed_opts}"
3352     else
3353     echo "${opts}"
3354     fi
3355    }
3356    
3357    have_root_privileges()
3358    {
3359     local retval
3360    
3361     if [[ $(id -u) = 0 ]]
3362     then
3363     retval=0
3364     else
3365     retval=1
3366     fi
3367    
3368     return ${retval}
3369    }
3370    
3371    known_mage_feature()
3372    {
3373     local feature="$1"
3374     local retval
3375    
3376     case "${feature}" in
3377     autosvc|!autosvc) retval=0 ;;
3378     buildlog|!buildlog) retval=0 ;;
3379     ccache|!ccache) retval=0 ;;
3380     check|!check) retval=0 ;;
3381     compressdoc|!compressdoc) retval=0 ;;
3382     debug|!debug) retval=0 ;;
3383     distcc|!distcc) retval=0 ;;
3384     icecc|!icecc) retval=0 ;;
3385     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3386     libtool|!libtool) retval=0 ;;
3387     linuxsymlink|!linuxsymlink) retval=0 ;;
3388     pkgbuild|!pkgbuild) retval=0 ;;
3389     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3390     purge|!purge) retval=0 ;;
3391     qalint|!qalint) retval=0 ;;
3392     regentree|!regentree) retval=0 ;;
3393     resume|!resume) retval=0 ;;
3394     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3395     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3396     static|!static) retval=0 ;;
3397     stepbystep|!stepbystep) retval=0 ;;
3398     strip|!strip) retval=0 ;;
3399     verbose|!verbose) retval=0 ;;
3400     *) retval=1 ;;
3401     esac
3402    
3403     return "${retval}"
3404    }
3405    
3406    load_mage_features()
3407    {
3408     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3409     do
3410     FVERBOSE=off msetfeature ${i}
3411     done
3412    }
3413    
3414    msetfeature()
3415    {
3416     local feature
3417     local count
3418     local i
3419     local found
3420    
3421     for feature in $@
3422     do
3423     found=0
3424     count="${#MAGE_FEATURES_CURRENT[*]}"
3425    
3426     if ! known_mage_feature "${feature}"
3427     then
3428     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3429     return 3
3430     fi
3431    
3432     for ((i=0; i<count; i++))
3433     do
3434     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3435     then
3436     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3437     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3438     found=1
3439     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3440     then
3441     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3442     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3443     found=1
3444     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3445     then
3446     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3447     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3448     found=1
3449     fi
3450     done
3451    
3452     # if the feature was not found after proccessing the whole array
3453     # it was not declared. in this case enable it
3454     if [[ ${found} = 0 ]]
3455     then
3456     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3457     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3458     fi
3459    
3460     export MAGE_FEATURE_CURRENT
3461     done
3462    }
3463    
3464    mqueryfeature()
3465    {
3466     local feature="$1"
3467     local retval=1
3468     local i
3469    
3470     if known_mage_feature "${feature}"
3471     then
3472     for i in ${MAGE_FEATURES_CURRENT[*]}
3473     do
3474     if [[ ${i} = ${feature} ]]
3475     then
3476     retval=0
3477     break # found break here
3478     fi
3479     done
3480     else
3481     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3482     retval=3
3483     fi
3484    
3485     return ${retval}
3486    }
3487    
3488    mprintfeatures()
3489    {
3490     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3491     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3492     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3493    }

Legend:
Removed from v.449  
changed lines
  Added in v.2271