Magellan Linux

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

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

revision 419 by niro, Mon Jan 22 00:24:14 2007 UTC revision 2752 by niro, Thu Aug 14 14:26:07 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.26 2007-01-22 00:24:14 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}" b "${major}" "${minor}"
538    
539   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}   # 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 559  remove_database_entry() Line 761  remove_database_entry()
761   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
762    
763   # remove virtuals only if no other exist   # remove virtuals only if no other exist
764   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
765   then   then
766   # first unregister virtuals   # first unregister virtuals
767   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 588  count_installed_pkgs() Line 790  count_installed_pkgs()
790   local i   local i
791    
792   # very basic getops   # very basic getops
793   for i in $*   for i in $@
794   do   do
795   case $1 in   case ${i} in
796   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
797   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
798   esac   esac
  shift  
799   done   done
800    
801   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 633  compare_mtime() Line 834  compare_mtime()
834    
835   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
836    
837   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
838   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
839   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  
840    
841   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
842    
# Line 708  remove_symlinks() Line 898  remove_symlinks()
898   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
899   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
900   then   then
901   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
902   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
903   continue   continue
904   fi   fi
# Line 720  remove_symlinks() Line 910  remove_symlinks()
910   # 1=keep me   #   # 1=keep me   #
911   case ${retval} in   case ${retval} in
912   0)   0)
913   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
914   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
915   ;;   ;;
916    
917   1)   1)
918   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
919   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
920   ;;   ;;
921   esac   esac
# Line 772  remove_files() Line 962  remove_files()
962   done   done
963    
964   # sanity checks; abort if not given   # sanity checks; abort if not given
965   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
966   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
967   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
968   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
969   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
970    
971   # check needed global vars   # check needed global vars
# Line 792  remove_files() Line 982  remove_files()
982    
983   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
984   then   then
985   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
986   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
987   continue   continue
988   fi   fi
# Line 809  remove_files() Line 999  remove_files()
999   is_config_protected "${pathto}"   is_config_protected "${pathto}"
1000   retval="$?"   retval="$?"
1001    
1002   # 0 - not protected        #   # 0 - not protected         #
1003   # 1 - error                #   # 1 - error                 #
1004   # 2 - protected            #   # 2 - protected             #
1005   # 3 - protected but masked #   # 3 - protected but masked  #
1006     # 4 - protected but ignored #
1007    
1008   case ${retval} in   case ${retval} in
1009   # file is not protected - delete it   # file is not protected - delete it
1010   0|3)   0|3)
1011   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1012   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1013   ;;   ;;
1014    
1015   # file is protected, do not delete   # file is protected, do not delete
1016   2)   2)
1017   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
1018   then   then
1019   echo -en "${COLRED}"   echo -en "${COLRED}"
1020   echo -n "! prot "   echo -n "! prot "
# Line 831  remove_files() Line 1022  remove_files()
1022   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
1023   fi   fi
1024   ;;   ;;
1025    
1026     # file is protected but ignored, delete the update/do nothing
1027     4)
1028     if mqueryfeature "verbose"
1029     then
1030     echo -en "${COLRED}"
1031     echo -n "! ignr "
1032     echo -en "${COLDEFAULT}"
1033     echo " === FILE: ${MROOT}${pathto}"
1034     fi
1035     # simply do nothing here
1036     ;;
1037   esac   esac
1038   ;;   ;;
1039   1)   1)
1040   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1041   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1042   ;;   ;;
1043   esac   esac
# Line 853  remove_blockdevices() Line 1056  remove_blockdevices()
1056  {  {
1057   local pathto   local pathto
1058   local posix   local posix
1059     local user
1060     local group
1061   local IFS   local IFS
1062   local pcat   local pcat
1063   local pname   local pname
# Line 876  remove_blockdevices() Line 1081  remove_blockdevices()
1081   done   done
1082    
1083   # sanity checks; abort if not given   # sanity checks; abort if not given
1084   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1085   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1086   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1087   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1088   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1089    
1090   # check needed global vars   # check needed global vars
# Line 890  remove_blockdevices() Line 1095  remove_blockdevices()
1095   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1096   IFS=§   IFS=§
1097    
1098   while read pathto posix   while read pathto posix user group
1099   do   do
1100   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1101    
1102   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1103   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1104   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1105    
# Line 911  remove_characterdevices() Line 1116  remove_characterdevices()
1116  {  {
1117   local pathto   local pathto
1118   local posix   local posix
1119     local user
1120     local group
1121   local IFS   local IFS
1122   local pcat   local pcat
1123   local pname   local pname
# Line 934  remove_characterdevices() Line 1141  remove_characterdevices()
1141   done   done
1142    
1143   # sanity checks; abort if not given   # sanity checks; abort if not given
1144   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1145   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1146   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1147   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1148   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1149    
1150   # check needed global vars   # check needed global vars
# Line 948  remove_characterdevices() Line 1155  remove_characterdevices()
1155   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1156   IFS=§   IFS=§
1157    
1158   while read pathto posix   while read pathto posix user group
1159   do   do
1160   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1161    
1162   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1163   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1164   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1165    
# Line 962  remove_characterdevices() Line 1169  remove_characterdevices()
1169    
1170    
1171  ###################################################  ###################################################
1172    # function remove_fifos                           #
1173    # remove_fifos $PKGNAME                     #
1174    ###################################################
1175    remove_fifos()
1176    {
1177     local pathto
1178     local posix
1179     local user
1180     local group
1181     local IFS
1182     local pcat
1183     local pname
1184     local pver
1185     local pbuild
1186     local i
1187     local pfull
1188    
1189     IFS=$'\n'
1190    
1191     # very basic getops
1192     for i in $*
1193     do
1194     case $1 in
1195     --pcat|-c) shift; pcat="$1" ;;
1196     --pname|-n) shift; pname="$1" ;;
1197     --pver|-v) shift; pver="$1" ;;
1198     --pbuild|-b) shift; pbuild="$1" ;;
1199     esac
1200     shift
1201     done
1202    
1203     # sanity checks; abort if not given
1204     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1205     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1206     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1207     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1208     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1209    
1210     # check needed global vars
1211     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1212    
1213     # make it optional atm !!
1214     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1215     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1216    
1217     # sets fieldseperator to "§" instead of " "
1218     IFS=§
1219    
1220     while read pathto posix user group
1221     do
1222     [ -z "${pathto}" ] && continue
1223    
1224     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1225     rm "${MROOT}${pathto}"
1226     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1227    
1228     # very important: unsetting the '§' fieldseperator
1229     IFS=$'\n'
1230    }
1231    
1232    
1233    ###################################################
1234  # function remove_direcories                      #  # function remove_direcories                      #
1235  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1236  ###################################################  ###################################################
# Line 992  remove_directories() Line 1261  remove_directories()
1261   done   done
1262    
1263   # sanity checks; abort if not given   # sanity checks; abort if not given
1264   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1265   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1266   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1267   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1268   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1269    
1270   # check needed global vars   # check needed global vars
# Line 1013  remove_directories() Line 1282  remove_directories()
1282    
1283   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1284   then   then
1285   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1286   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1287   continue   continue
1288   fi   fi
# Line 1021  remove_directories() Line 1290  remove_directories()
1290   # exclude .keep directories   # exclude .keep directories
1291   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1292   then   then
1293   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1294   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1295   continue   continue
1296   fi   fi
# Line 1034  remove_directories() Line 1303  remove_directories()
1303    
1304   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1305   then   then
1306   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1307   else   else
1308   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1309   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1310   fi   fi
1311   done   done
# Line 1049  remove_directories() Line 1318  remove_directories()
1318  ###################################################  ###################################################
1319  # function build_douninstall                      #  # function build_douninstall                      #
1320  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1321  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1322  ###################################################  ###################################################
1323  build_douninstall()  build_douninstall()
1324  {  {
# Line 1083  build_douninstall() Line 1352  build_douninstall()
1352   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1353   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1354    
1355   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1356   do   do
1357   remove_${i} \   remove_${i} \
1358   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1094  build_douninstall() Line 1363  build_douninstall()
1363   done   done
1364  }  }
1365    
1366    # convertmirrors [uri]
1367    convertmirrors()
1368    {
1369     local uri="$1"
1370     local scheme
1371     local mirror
1372     local mirrors
1373     local addon
1374     local real_uri
1375     local output
1376    
1377     # needs
1378     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1379     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1380     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1381     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1382     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1383    
1384     # check known uri schemes
1385     case ${uri} in
1386     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1387     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1388     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1389     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1390     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1391     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1392     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1393     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1394     esac
1395    
1396     if [[ ! -z ${mirrors} ]]
1397     then
1398     for mirror in ${mirrors}
1399     do
1400     # add a whitespace to the output
1401     [[ -z ${output} ]] || output+=" "
1402     output+="${mirror}${addon}/${uri/${scheme}/}"
1403     done
1404     else
1405     output="${uri}"
1406     fi
1407    
1408     echo "${output}"
1409    }
1410    
1411    mdownload()
1412    {
1413     local i
1414     local uri
1415     local real_uris
1416     local mirror
1417     local outputfile
1418     local outputdir
1419     local retval
1420     local wget_opts
1421    
1422     # very basic getops
1423     for i in $*
1424     do
1425     case $1 in
1426     --uri|-u) shift; uri="$1" ;;
1427     --dir|-d) shift; outputdir="$1" ;;
1428     esac
1429     shift
1430     done
1431    
1432     # sanity checks; abort if not given
1433     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1434     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1435    
1436     # convert mirrored uris to the real ones
1437     real_uris="$(convertmirrors ${uri})"
1438    
1439     # verbose or not
1440     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1441    
1442     # filter wget options if busybox was found
1443     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1444    
1445     # create outputdir
1446     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1447    
1448     for mirror in ${real_uris}
1449     do
1450     # get the name of the output file
1451     outputfile="${mirror##*/}"
1452    
1453     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1454     retval="$?"
1455     if [[ ${retval} = 0 ]]
1456     then
1457     break
1458     else
1459     continue
1460     fi
1461     done
1462    
1463     # return wget retval
1464     return "${retval}"
1465    }
1466    
1467  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1468  fetch_packages()  fetch_packages()
1469  {  {
1470     local i
1471   local list="$@"   local list="$@"
1472   local pkg   local pkgname
1473     local pkgfile
1474     local pcat
1475     local pname
1476   local mirr   local mirr
1477   local magefile   local magefile
1478   local md5file   local md5file
1479   local opt   local opt
1480   local count_current   local count_current
1481   local count_total   local count_total
1482     local wget_opts
1483     local fetching
1484    
1485   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1486    
1487     # filter wget command if busybox was found
1488     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1489    
1490   # get count of total packages   # get count of total packages
1491   declare -i count_current=0   declare -i count_current=0
1492   declare -i count_total=0   declare -i count_total=0
# Line 1116  fetch_packages() Line 1495  fetch_packages()
1495    
1496   for magefile in ${list}   for magefile in ${list}
1497   do   do
1498   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1499     pkgfile="${pkgname}.${PKGSUFFIX}"
1500   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1501    
1502     pcat=$(magename2pcat ${magefile})
1503     pname=$(magename2pname ${magefile})
1504     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1505    
1506   (( count_current++ ))   (( count_current++ ))
1507   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1508    
1509   # abort on virtual pkg   # abort on virtual pkg
1510   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1511   then   then
1512   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1513   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1514   continue   continue
1515   fi   fi
1516    
# Line 1134  fetch_packages() Line 1518  fetch_packages()
1518   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1519   then   then
1520   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1521   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1522   continue   continue
1523   fi   fi
1524    
1525   # abort if already exist   # check if FETCHING is required
1526   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1527   then   then
1528   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1529   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1530   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
1531     then
1532     # md5's ok, no fetching required
1533     fetching=false
1534     else
1535     fetching=true
1536     fi
1537   fi   fi
1538    
1539   for mirr in ${MIRRORS}   if [[ ${fetching} = false ]]
1540   do   then
1541     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1542     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1543     continue
1544     else
1545   echo -ne " ${COLBLUE}***${COLDEFAULT}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1546   #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1547   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1548   [[ ${VERBOSE} = off ]] && opt="--quiet"   fi
  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  
1549    
1550   if [ ! -f ${PKGDIR}/${pkg} ]   # sanity check, not really needed but to be sure
1551     if [ ! -f ${PKGDIR}/${pkgfile} ]
1552   then   then
1553   die "Could not download ${pkg}"   die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1554   fi   fi
1555   done   done
1556    
# Line 1197  syncmage() Line 1578  syncmage()
1578   done   done
1579    
1580   # clean up backup files (foo~)   # clean up backup files (foo~)
1581   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1582    
1583   # check if an newer mage version is available   # check if a newer mage version is available
1584   is_newer_mage_version_available   is_newer_mage_version_available
1585  }  }
1586    
1587    syncmage_tarball()
1588    {
1589     local latest_tarball
1590     local latest_md5
1591     local temp="$(mktemp -d)"
1592     local mirr mymirr
1593     local opt
1594     local tar_opts
1595     local wget_opts
1596    
1597     # try to get the md5 marked as latest on the server
1598     latest_md5="mage-latest.md5"
1599    
1600     # try to get the tarball marked as latest on the server
1601     latest_tarball="mage-latest.tar.bz2"
1602    
1603     # filter wget command if busybox was found
1604     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1605    
1606     for mirr in ${MIRRORS}
1607     do
1608     # path without distribution
1609     # (only for stable|testing|unstable and not DISTROTAG)
1610     case ${mirr##*/} in
1611     stable|testing|unstable) mymirr="${mirr%/*}";;
1612     *) mymirr="${mirr}";;
1613     esac
1614    
1615     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1616     echo "fetching latest md5 from ${mymirr} ..."
1617     mqueryfeature "!verbose" && opt="--quiet"
1618     wget \
1619     ${wget_opts} \
1620     --directory-prefix=${temp} \
1621     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1622    
1623     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1624     echo "fetching latest tarball from ${mymirr} ..."
1625     wget \
1626     ${wget_opts} \
1627     --directory-prefix=${temp} \
1628     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1629     if [[ $? = 0 ]]
1630     then
1631     break
1632     else
1633     continue
1634     fi
1635     done
1636    
1637     if [[ -f ${temp}/${latest_tarball} ]]
1638     then
1639     # check md5
1640     if [[ ! -f ${temp}/${latest_md5} ]]
1641     then
1642     die "md5 is missing ... aborting"
1643     else
1644     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1645     echo -n "checking md5sum... "
1646     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1647     fi
1648    
1649     if [[ -d ${MAGEDIR} ]]
1650     then
1651     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1652     echo "cleaning old mage-tree ${MAGEDIR}..."
1653     # honor mountpoints and empty dirs
1654     if mountpoint -q ${MAGEDIR}
1655     then
1656     if ! mcheckemptydir ${MAGEDIR}
1657     then
1658     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1659     fi
1660     else
1661     rm -rf ${MAGEDIR}
1662     fi
1663     fi
1664    
1665     if need_busybox_support tar
1666     then
1667     tar_opts="xjf"
1668     else
1669     tar_opts="xjmf"
1670     fi
1671    
1672     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1673     echo "updating mage-tree from tarball ..."
1674     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1675     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1676    
1677     if [[ -d ${temp} ]]
1678     then
1679     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1680     echo "cleaning temp-files ..."
1681     rm -rf ${temp}
1682     fi
1683    
1684     # check if a newer mage version is available
1685     is_newer_mage_version_available
1686     else
1687     die "Could not fetch the latest tarball ... aborting"
1688     fi
1689    }
1690    
1691  cleanpkg()  cleanpkg()
1692  {  {
1693   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1233  xtitleclean() Line 1718  xtitleclean()
1718  }  }
1719    
1720    
1721  # cuts full pathnames or versioniezed names down to basename  # unused?
1722  choppkgname()  #
1723  {  # # cuts full pathnames or versionized names down to basename
1724   #we want this only if full name was used  # choppkgname()
1725   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1726   then  # #we want this only if full name was used
1727   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1728   #ARCH comes from ${MAGERC}  # then
1729   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1730    # #ARCH comes from ${MAGERC}
1731    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1732    #
1733    # #cuts version number
1734    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1735    # fi
1736    # }
1737    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1738    
1739  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1740  # $1=pname  # $1=pname
# Line 1315  get_highest_magefile() Line 1803  get_highest_magefile()
1803   local PNAME="$2"   local PNAME="$2"
1804   local magefile   local magefile
1805    
1806   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1807     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1808   do   do
1809     [[ -z ${magefile} ]] && continue
1810   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1811   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1812   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1813   then   then
1814   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1815   #for debug only   #for debug only
1816   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1817   fi   fi
1818   done   done
1819    
 # 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  
   
1820   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1821   return 0   return 0
1822  }  }
# Line 1363  get_highest_magefile() Line 1831  get_highest_magefile()
1831  #        1 - error                                #  #        1 - error                                #
1832  #        2 - protected                            #  #        2 - protected                            #
1833  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1834    #        4 - protected but ignored                #
1835  #                                                 #  #                                                 #
1836  ###################################################  ###################################################
1837  is_config_protected()  is_config_protected()
# Line 1371  is_config_protected() Line 1840  is_config_protected()
1840   local TEST   local TEST
1841   local PROTECTED   local PROTECTED
1842   local IFS   local IFS
1843     local i
1844     local x
1845    
1846   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1847    
1848   # file does not exist; it can be written   # file does not exist; it can be written
1849   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1850    
1851   # to be safe; it may be '§'   # to be safe; it may be '§'
1852   IFS=' '   IFS=' '
1853    
1854   # check ob in config protect   # check if config protected
1855   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1856   do   do
1857   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1858   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1859   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1860   then   then
1861   # setzen das es protected ist   # file is config proteced
1862   PROTECTED=TRUE   PROTECTED=TRUE
1863    
1864   # check ob nicht doch maskiert   # check if not masked
1865   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1866   do   do
1867   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1868   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1869   then   then
1870   PROTECTED=MASKED   PROTECTED=MASKED
1871   fi   fi
1872   done   done
1873    
1874     # check if not ignored
1875     for x in ${CONFIG_PROTECT_IGNORE}
1876     do
1877     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1878     if [[ ${TEST} != ${EXPFILE} ]]
1879     then
1880     PROTECTED=IGNORED
1881     fi
1882     done
1883   fi   fi
1884   done   done
1885    
# Line 1413  is_config_protected() Line 1894  is_config_protected()
1894   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1895   return 3   return 3
1896   ;;   ;;
1897     IGNORED)
1898     #echo "I'm protected, but ignored - keep me, del update"
1899     return 4
1900     ;;
1901   *)   *)
1902   #echo "delete me"   #echo "delete me"
1903   return 0   return 0
# Line 1430  is_config_protected() Line 1915  is_config_protected()
1915  ###################################################  ###################################################
1916  count_protected_files()  count_protected_files()
1917  {  {
1918   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1919     local dirname="${file%/*}"
1920     local filename="${file##*/}"
1921     local count
1922     local output
1923     local oldprotected
1924     local i
1925     local x
1926    
1927     # hack; do not honor a global set IFS like '§'
1928     local IFS
1929    
1930     count=0
1931    
1932     # check if there are already protected files
1933     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1934     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1935     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1936     do
1937     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1938     done
1939    
1940     # convert 0001 -> 1; 0120 -> 120 etc
1941     # use bash internal base functions to this task
1942     x="$((10#${count}))"
1943     for (( i=0; i<x; i++ ))
1944     do
1945     if [[ ${count:${i}:1} != 0 ]]
1946     then
1947     count="${count:${i}}"
1948     break
1949     fi
1950     done
1951    
1952     count="$(( ${count}+1 ))"
1953    
1954     # fill output up with zeros
1955     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1956     output="${output}${count}"
1957    
1958     echo "${output}"
1959  }  }
1960    
1961  # call with  # call with
# Line 1447  get_uninstall_candidates() Line 1972  get_uninstall_candidates()
1972   local list   local list
1973   local pcatdir   local pcatdir
1974   local protected   local protected
1975     local i
1976    
1977   # very basic getops   # very basic getops
1978   for i in $*   for i in $*
# Line 1601  virtuals_add() Line 2127  virtuals_add()
2127    
2128  #deletes pakages from virtual database  #deletes pakages from virtual database
2129  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2130  virtuals_del() {  virtuals_del()
2131    {
2132    
2133   local virtualname="$1"   local virtualname="$1"
2134   local pkgname="$2"   local pkgname="$2"
# Line 1708  minclude() Line 2235  minclude()
2235  {  {
2236   local i   local i
2237    
2238   if [[ -n $@ ]]   if [[ -n $* ]]
2239   then   then
2240   for i in $@   for i in $*
2241   do   do
2242   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2243   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2244   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2245   done   done
2246   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2247   fi   fi
2248  }  }
2249    
# Line 1724  sminclude() Line 2251  sminclude()
2251  {  {
2252   local i   local i
2253    
2254   if [ -n "$@" ]   if [[ -n $* ]]
2255   then   then
2256   for i in $@   for i in $*
2257   do   do
2258   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2259   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2260   done   done
2261   echo   [[ ${SILENT} = 1 ]] || echo
2262   fi   fi
2263  }  }
2264    
# Line 2035  get_value_from_magefile() Line 2562  get_value_from_magefile()
2562   local SDEPEND   local SDEPEND
2563   local PROVIDE   local PROVIDE
2564   local PKGTYPE   local PKGTYPE
2565     local SPLIT_PACKAGE_BASE
2566   local preinstall   local preinstall
2567   local postinstall   local postinstall
2568   local preremove   local preremove
# Line 2081  mage_install() Line 2609  mage_install()
2609   local count_current   local count_current
2610   local magefile   local magefile
2611   local src_install   local src_install
2612     local i
2613    
2614   # very basic getops   # very basic getops
2615   for i in $*   for i in $*
# Line 2154  mage_install() Line 2683  mage_install()
2683   echo B:${pbuild}   echo B:${pbuild}
2684   fi   fi
2685    
2686   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2687     then
2688     # basic svn compat
2689     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2690     then
2691     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2692     do
2693     smage2file="${i}"
2694     done
2695     else
2696     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2697     fi
2698    
2699     else
2700     # basic svn compat
2701     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2702     then
2703     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2704     do
2705     smage2file="${i}"
2706     done
2707     else
2708     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2709     fi
2710     fi
2711    
2712   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2713   then   then
2714   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "   echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
# Line 2171  mage_install() Line 2725  mage_install()
2725   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2726   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2727   then   then
2728     unpack_package "${magefile}"
2729   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
2730   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2731   fi   fi
# Line 2259  md5sum_packages() Line 2814  md5sum_packages()
2814   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2815   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2816   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2817   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2818   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2819    
2820   (( count_current++ ))   (( count_current++ ))
# Line 2269  md5sum_packages() Line 2824  md5sum_packages()
2824   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2825   then   then
2826   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2827   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2828   continue   continue
2829   fi   fi
2830    
# Line 2277  md5sum_packages() Line 2832  md5sum_packages()
2832   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2833   then   then
2834   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2835   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2836   continue   continue
2837   fi   fi
2838    
# Line 2285  md5sum_packages() Line 2840  md5sum_packages()
2840   then   then
2841   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2842   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2843   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2844   else   else
2845   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2846   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2325  uninstall_packages() Line 2880  uninstall_packages()
2880   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2881   can_pcat="${pcat}"   can_pcat="${pcat}"
2882   can_pname="${pname}"   can_pname="${pname}"
2883    
2884   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2885   then   then
2886   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2430  mage_uninstall() Line 2985  mage_uninstall()
2985   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2986   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2987    
2988   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2989   source ${magefile}   source ${magefile}
2990    
2991   ## preremove scripts   ## preremove scripts
# Line 2498  mage_uninstall() Line 3053  mage_uninstall()
3053   unset -f postremove   unset -f postremove
3054  }  }
3055    
3056  show_etc_update_mesg() {  # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3057    rerun_pkgfunctions()
3058    {
3059     local method
3060     local list
3061     local pcat
3062     local pname
3063     local pver
3064     local pbuild
3065     local magefile
3066     local i
3067    
3068     # very basic getops
3069     case $1 in
3070     --method) shift; method="$1" ;;
3071     esac
3072     shift
3073     local list="$@"
3074    
3075     # sanity check
3076     case ${method} in
3077     preinstall|postinstall) ;;
3078     preremove|postremove) ;;
3079     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3080     esac
3081    
3082     if [[ -n ${MROOT} ]]
3083     then
3084     echo -ne ${COLRED}
3085     echo "!! running in MROOT=${MROOT}"
3086     echo -ne ${COLDEFAULT}
3087     echo
3088     fi
3089    
3090     for pkg in ${list}
3091     do
3092     pcat=$(dep2pcat ${pkg})
3093     pname=$(magename2pname ${pkg})
3094     pver=$(magename2pver ${pkg})
3095     pbuild=$(magename2pbuild ${pkg})
3096     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3097    
3098     if [ -e ${magefile} ]
3099     then
3100     source ${magefile}
3101     if [ -n "$(typeset -f ${method})" ]
3102     then
3103     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3104     ${method}
3105     else
3106     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3107     fi
3108     unset -f preinstall postinstall preremove postremove
3109     else
3110     die "Magefile '${magefile}' does not exist."
3111     fi
3112     done
3113    }
3114    
3115    show_etc_update_mesg()
3116    {
3117   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3118    
3119   echo   echo
# Line 2524  pkgsearch() Line 3139  pkgsearch()
3139   local state   local state
3140   local descriptiom   local descriptiom
3141   local homepage   local homepage
3142     local license
3143   local i   local i
3144   local all_installed   local all_installed
3145   local ipver   local ipver
3146   local ipbuild   local ipbuild
3147     local latest_available
3148     local depsfull
3149     local sdepsfull
3150     local deps
3151     local sdeps
3152     local dep
3153     local sign
3154    
3155   # only names no versions   # only names no versions
3156   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 2545  pkgsearch() Line 3168  pkgsearch()
3168   # get highest version available   # get highest version available
3169   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3170    
3171   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3172   pver="$(magename2pver ${magefile})"   then
3173   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3174   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3175   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3176   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3177     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3178     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3179     license="$(get_value_from_magefile LICENSE ${magefile})"
3180    
3181     # all installed
3182     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3183     do
3184     ipver="$(magename2pver ${i})"
3185     ipbuild="$(magename2pbuild ${i})"
3186    
3187     if [[ -z ${all_installed} ]]
3188     then
3189     all_installed="${ipver}-${ipbuild}"
3190     else
3191     all_installed="${all_installed} ${ipver}-${ipbuild}"
3192     fi
3193     done
3194     [[ -z ${all_installed} ]] && all_installed="none"
3195    
3196     case ${state} in
3197     stable) state=${COLGREEN}"[s] ";;
3198     testing) state=${COLYELLOW}"[t] ";;
3199     unstable) state=${COLRED}"[u] ";;
3200     old) state=${COLGRAY}"[o] ";;
3201     esac
3202    
3203     latest_available="${pver}-${pbuild}"
3204     else
3205     # package is masked
3206     state="${COLRED}[m] "
3207     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3208     fi
3209    
3210     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3211     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3212    
3213   # all installed   while read sign dep
  for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})  
3214   do   do
3215   ipver="$(magename2pver ${i})"   case ${dep} in
3216   ipbuild="$(magename2pbuild ${i})"   "") continue;;
3217     esac
3218    
3219   if [[ -z ${all_installed} ]]   if [[ -z ${deps} ]]
3220   then   then
3221   all_installed="${ipver}-${ipbuild}"   deps="$(basename ${dep%-*})"
3222   else   else
3223   all_installed="${all_installed} ${ipver}-${ipbuild}"   deps="${deps} $(basename ${dep%-*})"
3224   fi   fi
3225   done   done << EOF
3226   [[ -z ${all_installed} ]] && all_installed="none"  ${depsfull}
3227    EOF
3228    
3229   case ${state} in   while read sign dep
3230   stable) state=${COLGREEN}"[s] ";;   do
3231   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
3232   unstable) state=${COLRED}"[u] ";;   "") continue;;
3233   old) state=${COLGRAY}"[o] ";;   esac
3234   esac  
3235     if [[ -z ${sdeps} ]]
3236     then
3237     sdeps="$(basename ${dep%-*})"
3238     else
3239     sdeps="${sdeps} $(basename ${dep%-*})"
3240     fi
3241     done << EOF
3242    ${sdepsfull}
3243    EOF
3244    
3245   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3246   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3247   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3248   echo "      Description: ${description}"   echo "      Description: ${description}"
3249   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3250     if [[ ! -z ${license} ]]
3251     then
3252     echo "      License:  ${license}"
3253     fi
3254     echo "      Depends:  ${deps}"
3255     echo "      SDepends: ${sdeps}"
3256   echo   echo
3257    
3258   unset pcat   unset pcat
# Line 2592  pkgsearch() Line 3266  pkgsearch()
3266   unset all_installed   unset all_installed
3267   unset ipver   unset ipver
3268   unset ipbuild   unset ipbuild
3269     unset depsfull
3270     unset sdepsfull
3271     unset deps
3272     unset sdeps
3273     unset dep
3274     unset sign
3275   done   done
3276  }  }
3277    
# Line 2611  export_inherits() Line 3291  export_inherits()
3291   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3292    
3293   # debug   # debug
3294   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3295    
3296   shift   shift
3297   done   done
# Line 2634  blacklisted() Line 3314  blacklisted()
3314   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable   [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3315   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing   [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3316    
3317   local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"   # support both types for the moment
3318     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3319     then
3320     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3321     else
3322     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3323     fi
3324    
3325   # return 0 if the list not exist; nothin is masked   # return 0 if the list not exist; nothin is masked
3326   [[ ! -f ${EXCLUDED} ]] && return 0   [[ ! -f ${EXCLUDED} ]] && return 0
# Line 2677  EOF Line 3363  EOF
3363   return 0   return 0
3364  }  }
3365    
3366    # need_busybox_support ${cmd}
3367    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3368    need_busybox_support()
3369    {
3370     local cmd
3371     local busybox
3372     cmd="$1"
3373    
3374     for busybox in {,/usr}/bin/busybox
3375     do
3376     if [[ -x ${busybox} ]]
3377     then
3378     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3379     then
3380     # needs busybox support
3381     return 0
3382     fi
3383     fi
3384     done
3385    
3386     # no busybox
3387     return 1
3388    }
3389    
3390    # busybox_filter_wget_options ${wget_opts}
3391    busybox_filter_wget_options()
3392    {
3393     local opts="$@"
3394     local i
3395     local fixed_opts
3396    
3397     if need_busybox_support wget
3398     then
3399     for i in ${opts}
3400     do
3401     # show only the allowed ones
3402     case ${i} in
3403     -c|--continue) fixed_opts+=" -c" ;;
3404     -s|--spider) fixed_opts+=" -s" ;;
3405     -q|--quiet) fixed_opts+=" -q" ;;
3406     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3407     --header) shift; fixed_opts+=" --header $1" ;;
3408     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3409     -P) shift; fixed_opts+=" -P $1" ;;
3410     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3411     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3412     # simply drop all other opts
3413     *) continue ;;
3414     esac
3415     done
3416    
3417     echo "${fixed_opts}"
3418     else
3419     echo "${opts}"
3420     fi
3421    }
3422    
3423    have_root_privileges()
3424    {
3425     local retval
3426    
3427     if [[ $(id -u) = 0 ]]
3428     then
3429     retval=0
3430     else
3431     retval=1
3432     fi
3433    
3434     return ${retval}
3435    }
3436    
3437    known_mage_feature()
3438    {
3439     local feature="$1"
3440     local retval
3441    
3442     case "${feature}" in
3443     autosvc|!autosvc) retval=0 ;;
3444     buildlog|!buildlog) retval=0 ;;
3445     ccache|!ccache) retval=0 ;;
3446     check|!check) retval=0 ;;
3447     compressdoc|!compressdoc) retval=0 ;;
3448     debug|!debug) retval=0 ;;
3449     distcc|!distcc) retval=0 ;;
3450     icecc|!icecc) retval=0 ;;
3451     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3452     libtool|!libtool) retval=0 ;;
3453     linuxsymlink|!linuxsymlink) retval=0 ;;
3454     pkgbuild|!pkgbuild) retval=0 ;;
3455     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3456     purge|!purge) retval=0 ;;
3457     qalint|!qalint) retval=0 ;;
3458     regentree|!regentree) retval=0 ;;
3459     resume|!resume) retval=0 ;;
3460     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3461     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3462     static|!static) retval=0 ;;
3463     stepbystep|!stepbystep) retval=0 ;;
3464     strip|!strip) retval=0 ;;
3465     verbose|!verbose) retval=0 ;;
3466     *) retval=1 ;;
3467     esac
3468    
3469     return "${retval}"
3470    }
3471    
3472    load_mage_features()
3473    {
3474     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3475     do
3476     FVERBOSE=off msetfeature ${i}
3477     done
3478    }
3479    
3480    msetfeature()
3481    {
3482     local feature
3483     local count
3484     local i
3485     local found
3486    
3487     for feature in $@
3488     do
3489     found=0
3490     count="${#MAGE_FEATURES_CURRENT[*]}"
3491    
3492     if ! known_mage_feature "${feature}"
3493     then
3494     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3495     return 3
3496     fi
3497    
3498     for ((i=0; i<count; i++))
3499     do
3500     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3501     then
3502     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3503     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3504     found=1
3505     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3506     then
3507     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3508     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3509     found=1
3510     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3511     then
3512     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3513     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3514     found=1
3515     fi
3516     done
3517    
3518     # if the feature was not found after proccessing the whole array
3519     # it was not declared. in this case enable it
3520     if [[ ${found} = 0 ]]
3521     then
3522     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3523     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3524     fi
3525    
3526     export MAGE_FEATURES_CURRENT
3527     done
3528    }
3529    
3530    mqueryfeature()
3531    {
3532     local feature="$1"
3533     local retval=1
3534     local i
3535    
3536     if known_mage_feature "${feature}"
3537     then
3538     for i in ${MAGE_FEATURES_CURRENT[*]}
3539     do
3540     if [[ ${i} = ${feature} ]]
3541     then
3542     retval=0
3543     break # found break here
3544     fi
3545     done
3546     else
3547     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3548     retval=3
3549     fi
3550    
3551     return ${retval}
3552    }
3553    
3554    mprintfeatures()
3555    {
3556     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3557     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3558     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3559    }

Legend:
Removed from v.419  
changed lines
  Added in v.2752