Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 2371 by niro, Mon Jan 6 14:09:10 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.1 2005-09-09 16:35:38 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 361  install_characterdevices() Line 512  install_characterdevices()
512   local pkgname="$1"   local pkgname="$1"
513   local pathto   local pathto
514   local posix   local posix
515     local major
516     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 374  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   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   mknode -m ${posix} -c "${MROOT}${pathto}"   # 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 398  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 413  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 432  install_database_entry() Line 633  install_database_entry()
633   local magefile   local magefile
634   local dbrecorddir   local dbrecorddir
635   local provide   local provide
636     local i
637    
638   # very basic getops   # very basic getops
639   for i in $*   for i in $*
# Line 473  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   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
679   do   do
680   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
681   done   done
# Line 492  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 504  install_database_entry() Line 708  install_database_entry()
708   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
709   if [ -n "${provide}" ]   if [ -n "${provide}" ]
710   then   then
711   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
712     do
713     virtuals_add "${i}" "${pcat}/${pname}"
714     done
715   fi   fi
716  }  }
717    
# Line 523  remove_database_entry() Line 730  remove_database_entry()
730   local magefile   local magefile
731   local dbrecorddir   local dbrecorddir
732   local provide   local provide
733     local i
734    
735   # very basic getops   # very basic getops
736   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 760  remove_database_entry()
760   # abort if mage file not exists   # abort if mage file not exists
761   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
762    
763   # first unregister virtuals   # remove virtuals only if no other exist
764   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
765   then   then
766   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
767     provide="$(get_value_from_magefile PROVIDE ${magefile})"
768     if [ -n "${provide}" ]
769     then
770     for i in ${provide}
771     do
772     virtuals_del "${i}" "${pcat}/${pname}"
773     done
774     fi
775   fi   fi
776    
777   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 781  remove_database_entry()
781   fi   fi
782  }  }
783    
784    # get the number of installed packages
785    count_installed_pkgs()
786    {
787     local pcat
788     local pname
789     local pkg
790     local i
791    
792     # very basic getops
793     for i in $*
794     do
795     case $1 in
796     --pcat|-c) shift; pcat="$1" ;;
797     --pname|-n) shift; pname="$1" ;;
798     esac
799     shift
800     done
801    
802     # sanity checks; abort if not given
803     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
804     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
805    
806     declare -i i=0
807     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
808     do
809     (( i++ ))
810     #echo "$i ${pkg}"
811     done
812    
813     # return the value
814     echo "${i}"
815    }
816    
817    
818  ###################################################  ###################################################
819  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  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 662  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 674  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 726  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 744  remove_files() Line 981  remove_files()
981   do   do
982   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
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 758  remove_files() Line 995  remove_files()
995   # 1=keep me   #   # 1=keep me   #
996   case ${retval} in   case ${retval} in
997   0)   0)
998   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
999   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
1000   ;;   is_config_protected "${pathto}"
1001     retval="$?"
1002    
1003     # 0 - not protected         #
1004     # 1 - error                 #
1005     # 2 - protected             #
1006     # 3 - protected but masked  #
1007     # 4 - protected but ignored #
1008    
1009     case ${retval} in
1010     # file is not protected - delete it
1011     0|3)
1012     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
1013     rm "${MROOT}${pathto}"
1014     ;;
1015    
1016     # file is protected, do not delete
1017     2)
1018     if mqueryfeature "verbose"
1019     then
1020     echo -en "${COLRED}"
1021     echo -n "! prot "
1022     echo -en "${COLDEFAULT}"
1023     echo " === FILE: ${MROOT}${pathto}"
1024     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
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 782  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 805  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 819  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 840  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 863  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 877  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 891  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 921  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 932  remove_directories() Line 1273  remove_directories()
1273    
1274   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1275    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1276   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1277   IFS=§   IFS=§
1278    
1279   while read pathto posix   # reversed order is mandatory !
1280     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1281   do   do
1282   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
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 953  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
1298    
# Line 966  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 < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1313    
1314   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1315   IFS=$'\n'   IFS=$'\n'
# Line 981  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 1015  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 1026  build_douninstall() Line 1364  build_douninstall()
1364   done   done
1365  }  }
1366    
1367  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # convertmirrors [uri]
1368  fetch_packages()  convertmirrors()
1369  {  {
1370   local list="$@"   local uri="$1"
1371   local pkg   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
1469    fetch_packages()
1470    {
1471     local i
1472     local list="$@"
1473     local pkgname
1474     local pkgfile
1475     local pcat
1476     local pname
1477   local mirr   local mirr
1478   local magefile   local magefile
1479   local md5file   local md5file
1480   local opt   local opt
1481   local count_current   local count_current
1482   local count_total   local count_total
1483     local wget_opts
1484     local fetching
1485    
1486     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1487    
1488   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1489     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1490    
1491   # get count of total packages   # get count of total packages
1492   declare -i count_current=0   declare -i count_current=0
# Line 1048  fetch_packages() Line 1496  fetch_packages()
1496    
1497   for magefile in ${list}   for magefile in ${list}
1498   do   do
1499   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1500     pkgfile="${pkgname}.${PKGSUFFIX}"
1501   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1502    
1503     pcat=$(magename2pcat ${magefile})
1504     pname=$(magename2pname ${magefile})
1505     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1506    
1507   (( count_current++ ))   (( count_current++ ))
1508   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1509    
1510   # abort on virtual pkg   # abort on virtual pkg
1511   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1512   then   then
1513   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1514   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1515   continue   continue
1516   fi   fi
1517    
# Line 1066  fetch_packages() Line 1519  fetch_packages()
1519   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1520   then   then
1521   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1522   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1523   continue   continue
1524   fi   fi
1525    
1526   # abort if already exist   # check if FETCHING is required
1527   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1528   then   then
1529   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1530   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1531   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
  fi  
   
  for mirr in ${MIRRORS}  
  do  
  echo -ne " ${COLBLUE}***${COLDEFAULT}"  
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  --passive-ftp \  
  --tries 3 \  
  --continue \  
  --progress bar \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/packages/${pkg}  
  if [[ $? = 0 ]]  
1532   then   then
1533   break   # md5's ok, no fetching required
1534     fetching=false
1535   else   else
1536   continue   fetching=true
1537   fi   fi
1538   done   fi
1539    
1540   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1541   then   then
1542   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1543     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1544     continue
1545     else
1546     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1547     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1548     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1549     fi
1550    
1551     # sanity check, not really needed but to be sure
1552     if [ ! -f ${PKGDIR}/${pkgfile} ]
1553     then
1554     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1555   fi   fi
1556   done   done
1557    
# Line 1113  syncmage() Line 1563  syncmage()
1563  {  {
1564   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1565   then   then
1566   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1567   fi   fi
1568    
1569   local i   local i
1570   for i in ${RSYNC}   for i in ${RSYNC}
1571   do   do
1572   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1573   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1574   then   then
1575   break   break
# Line 1142  syncmage() Line 1579  syncmage()
1579   done   done
1580    
1581   # clean up backup files (foo~)   # clean up backup files (foo~)
1582   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1583    
1584   # check if an newer mage version is available   # check if a newer mage version is available
1585   is_newer_mage_version_available   is_newer_mage_version_available
1586  }  }
1587    
1588    syncmage_tarball()
1589    {
1590     local latest_tarball
1591     local latest_md5
1592     local temp="$(mktemp -d)"
1593     local mirr mymirr
1594     local opt
1595     local tar_opts
1596     local wget_opts
1597    
1598     # try to get the md5 marked as latest on the server
1599     latest_md5="mage-latest.md5"
1600    
1601     # try to get the tarball marked as latest on the server
1602     latest_tarball="mage-latest.tar.bz2"
1603    
1604     # filter wget command if busybox was found
1605     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1606    
1607     for mirr in ${MIRRORS}
1608     do
1609     # path without distribution
1610     # (only for stable|testing|unstable and not DISTROTAG)
1611     case ${mirr##*/} in
1612     stable|testing|unstable) mymirr="${mirr%/*}";;
1613     *) mymirr="${mirr}";;
1614     esac
1615    
1616     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1617     echo "fetching latest md5 from ${mymirr} ..."
1618     mqueryfeature "!verbose" && opt="--quiet"
1619     wget \
1620     ${wget_opts} \
1621     --directory-prefix=${temp} \
1622     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1623    
1624     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1625     echo "fetching latest tarball from ${mymirr} ..."
1626     wget \
1627     ${wget_opts} \
1628     --directory-prefix=${temp} \
1629     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1630     if [[ $? = 0 ]]
1631     then
1632     break
1633     else
1634     continue
1635     fi
1636     done
1637    
1638     if [[ -f ${temp}/${latest_tarball} ]]
1639     then
1640     # check md5
1641     if [[ ! -f ${temp}/${latest_md5} ]]
1642     then
1643     die "md5 is missing ... aborting"
1644     else
1645     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1646     echo -n "checking md5sum... "
1647     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1648     fi
1649    
1650     if [[ -d ${MAGEDIR} ]]
1651     then
1652     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1653     echo "cleaning old mage-tree ${MAGEDIR}..."
1654     # honor mountpoints and empty dirs
1655     if mountpoint -q ${MAGEDIR}
1656     then
1657     if ! mcheckemptydir ${MAGEDIR}
1658     then
1659     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1660     fi
1661     else
1662     rm -rf ${MAGEDIR}
1663     fi
1664     fi
1665    
1666     if need_busybox_support tar
1667     then
1668     tar_opts="xjf"
1669     else
1670     tar_opts="xjmf"
1671     fi
1672    
1673     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1674     echo "updating mage-tree from tarball ..."
1675     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1676     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1677    
1678     if [[ -d ${temp} ]]
1679     then
1680     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1681     echo "cleaning temp-files ..."
1682     rm -rf ${temp}
1683     fi
1684    
1685     # check if a newer mage version is available
1686     is_newer_mage_version_available
1687     else
1688     die "Could not fetch the latest tarball ... aborting"
1689     fi
1690    }
1691    
1692  cleanpkg()  cleanpkg()
1693  {  {
1694   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1178  xtitleclean() Line 1719  xtitleclean()
1719  }  }
1720    
1721    
1722  # cuts full pathnames or versioniezed names down to basename  # unused?
1723  choppkgname()  #
1724  {  # # cuts full pathnames or versionized names down to basename
1725   #we want this only if full name was used  # choppkgname()
1726   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1727   then  # #we want this only if full name was used
1728   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1729   #ARCH comes from /etc/mage.rc  # then
1730   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1731    # #ARCH comes from ${MAGERC}
1732    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1733    #
1734    # #cuts version number
1735    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1736    # fi
1737    # }
1738    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1739    
1740  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1741  # $1=pname  # $1=pname
# Line 1218  pname2pcat() Line 1762  pname2pcat()
1762  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1763  check_stable_package()  check_stable_package()
1764  {  {
1765     # first check if this magefile is not blacklisted
1766     blacklisted "$1" || return 1
1767    
1768   local STATE   local STATE
1769   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1770    
1771   # state testing   # state testing
1772   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1773   then   then
1774   case ${STATE} in   case ${STATE} in
1775   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1778  check_stable_package()
1778   fi   fi
1779    
1780   # state unstable   # state unstable
1781   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1782   then   then
1783   case ${STATE} in   case ${STATE} in
1784   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1804  get_highest_magefile()
1804   local PNAME="$2"   local PNAME="$2"
1805   local magefile   local magefile
1806    
1807   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1808     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1809   do   do
1810     [[ -z ${magefile} ]] && continue
1811   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1812   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1813   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1814   then   then
1815   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1816   #for debug only   #for debug only
1817   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1818   fi   fi
1819   done   done
1820    
  # 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  
   
1821   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1822   return 0   return 0
1823  }  }
# Line 1304  get_highest_magefile() Line 1832  get_highest_magefile()
1832  #        1 - error                                #  #        1 - error                                #
1833  #        2 - protected                            #  #        2 - protected                            #
1834  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1835    #        4 - protected but ignored                #
1836  #                                                 #  #                                                 #
1837  ###################################################  ###################################################
1838  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1841  is_config_protected()
1841   local TEST   local TEST
1842   local PROTECTED   local PROTECTED
1843   local IFS   local IFS
1844     local i
1845     local x
1846    
1847   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1848    
1849   # file does not exist; it can be written   # file does not exist; it can be written
1850   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1851    
1852   # to be safe; it may be '§'   # to be safe; it may be '§'
1853   IFS=' '   IFS=' '
1854    
1855   # check ob in config protect   # check if config protected
1856   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1857   do   do
1858   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1859   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1860   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1861   then   then
1862   # setzen das es protected ist   # file is config proteced
1863   PROTECTED=TRUE   PROTECTED=TRUE
1864    
1865   # check ob nicht doch maskiert   # check if not masked
1866   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1867   do   do
1868   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1869   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1870   then   then
1871   PROTECTED=MASKED   PROTECTED=MASKED
1872   fi   fi
1873   done   done
1874    
1875     # check if not ignored
1876     for x in ${CONFIG_PROTECT_IGNORE}
1877     do
1878     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1879     if [[ ${TEST} != ${EXPFILE} ]]
1880     then
1881     PROTECTED=IGNORED
1882     fi
1883     done
1884   fi   fi
1885   done   done
1886    
# Line 1354  is_config_protected() Line 1895  is_config_protected()
1895   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1896   return 3   return 3
1897   ;;   ;;
1898     IGNORED)
1899     #echo "I'm protected, but ignored - keep me, del update"
1900     return 4
1901     ;;
1902   *)   *)
1903   #echo "delete me"   #echo "delete me"
1904   return 0   return 0
# Line 1371  is_config_protected() Line 1916  is_config_protected()
1916  ###################################################  ###################################################
1917  count_protected_files()  count_protected_files()
1918  {  {
1919   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1920     local dirname="${file%/*}"
1921     local filename="${file##*/}"
1922     local count
1923     local output
1924     local oldprotected
1925     local i
1926     local x
1927    
1928     # hack; do not honor a global set IFS like '§'
1929     local IFS
1930    
1931     count=0
1932    
1933     # check if there are already protected files
1934     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1935     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1936     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1937     do
1938     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1939     done
1940    
1941     # convert 0001 -> 1; 0120 -> 120 etc
1942     # use bash internal base functions to this task
1943     x="$((10#${count}))"
1944     for (( i=0; i<x; i++ ))
1945     do
1946     if [[ ${count:${i}:1} != 0 ]]
1947     then
1948     count="${count:${i}}"
1949     break
1950     fi
1951     done
1952    
1953     count="$(( ${count}+1 ))"
1954    
1955     # fill output up with zeros
1956     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1957     output="${output}${count}"
1958    
1959     echo "${output}"
1960  }  }
1961    
1962  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1973  get_uninstall_candidates()
1973   local list   local list
1974   local pcatdir   local pcatdir
1975   local protected   local protected
1976     local i
1977    
1978   # very basic getops   # very basic getops
1979   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1986  get_uninstall_candidates()
1986   shift   shift
1987   done   done
1988    
1989   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1990   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1991    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1992    
1993    
1994   # check needed global vars   # check needed global vars
1995   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1996    
1997   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1998   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1999    
2000   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
2001   do   do
# Line 1493  virtuals_add() Line 2080  virtuals_add()
2080   local oldline   local oldline
2081   local line i   local line i
2082   local installed_file   local installed_file
2083     local OLDIFS
2084    
2085   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2086   then   then
2087   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2088   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2089   do   do
2090   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2103  virtuals_add()
2103   # make a backup   # make a backup
2104   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2105    
2106     OLDIFS="${IFS}"
2107   IFS=$'\n'   IFS=$'\n'
2108   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2109   do   do
# Line 1526  virtuals_add() Line 2115  virtuals_add()
2115   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2116   fi   fi
2117   done   done
2118     # unset IFS
2119   #unset IFS   IFS="${OLDIFS}"
2120   else   else
2121   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2122   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2123   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2124   fi   fi
# Line 1539  virtuals_add() Line 2128  virtuals_add()
2128    
2129  #deletes pakages from virtual database  #deletes pakages from virtual database
2130  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2131  virtuals_del() {  virtuals_del()
2132    {
2133    
2134   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2135     local pkgname="$2"
2136   VIRTUAL_NAME=$1   local oldline
2137   PKG_NAME=$2   local method
2138     local line i x
2139   #first check if exists   local pkg_installed
2140   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2141    
2142     # first check if exists
2143     if virtuals_read ${virtualname}
2144   then   then
2145   #get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}   # get method -> delall or update and check if ${PKG_NAME} exists in ${VIRTUAL_NAME}
2146   declare -i x=0   declare -i x=0
2147   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2148   do   do
2149   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2150   then   then
2151   PKG_INSTALLED=true   pkg_installed=true
2152   fi   fi
2153   ((x++))   ((x++))
2154   done   done
2155    
2156   #abort if not installed   # abort if not installed
2157   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2158   then   then
2159   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2160     echo "${pkgname} does not exists in ${virtualname}."
2161   return 0   return 0
2162   fi   fi
2163    
2164   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2165   then   then
2166   METHOD=update   method=update
2167   else   else
2168   METHOD=delall   method=delall
2169   fi   fi
2170    
2171   #get the complete line   # get the complete line
2172   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2173    
2174   #make a backup   # make a backup of the db
2175   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2176    
2177   #parse virtualdb   # parse virtualdb
2178     OLDIFS="${IFS}"
2179   IFS=$'\n'   IFS=$'\n'
2180   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2181   do   do
2182   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2183   then   then
2184   #delall or update?   #delall or update?
2185   case ${METHOD} in   case ${method} in
2186   update)   update)
2187   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2188   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2189   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2190     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2191   ;;   ;;
2192   delall)   delall)
2193   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2194   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2195     # continue; do not write anything
2196   continue   continue
2197   ;;   ;;
2198   esac   esac
# Line 1603  virtuals_del() { Line 2200  virtuals_del() {
2200   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2201   fi   fi
2202   done   done
2203   unset IFS   # unset IFS
2204     IFS="${OLDIFS}"
2205   else   else
2206   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2207     echo "${virtualname} does not exists in virtual database."
2208   fi   fi
2209  }  }
2210    
# Line 1637  minclude() Line 2236  minclude()
2236  {  {
2237   local i   local i
2238    
2239   if [ -n "$@" ]   if [[ -n $* ]]
2240   then   then
2241   for i in $@   for i in $*
2242   do   do
2243   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2244   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2245   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2246   done   done
2247   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2248   fi   fi
2249  }  }
2250    
# Line 1653  sminclude() Line 2252  sminclude()
2252  {  {
2253   local i   local i
2254    
2255   if [ -n "$@" ]   if [[ -n $* ]]
2256   then   then
2257   for i in $@   for i in $*
2258   do   do
2259   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2260   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2261   done   done
2262   echo   [[ ${SILENT} = 1 ]] || echo
2263   fi   fi
2264  }  }
2265    
# Line 1670  is_newer_mage_version_available() Line 2269  is_newer_mage_version_available()
2269   local newest_mage   local newest_mage
2270   local installed_mage   local installed_mage
2271    
2272   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2273   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2274    
2275   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2278  is_newer_mage_version_available()
2278   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2279   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2280   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2281   echo "or your current system installation may brake."   echo "or your current system installation may break."
2282   echo   echo
2283   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2284   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2550  get_value_from_magefile()
2550   local magefile="$2"   local magefile="$2"
2551   local value   local value
2552    
2553     [[ -z ${var} ]] && return 1
2554     [[ -z ${magefile} ]] && return 1
2555    
2556   # local all possible vars of a mage file   # local all possible vars of a mage file
2557   # to prevent bad issues   # to prevent bad issues
2558   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2563  get_value_from_magefile()
2563   local SDEPEND   local SDEPEND
2564   local PROVIDE   local PROVIDE
2565   local PKGTYPE   local PKGTYPE
2566     local SPLIT_PACKAGE_BASE
2567   local preinstall   local preinstall
2568   local postinstall   local postinstall
2569     local preremove
2570     local postremove
2571    
2572   # sanity checks   # sanity checks
2573   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2577  get_value_from_magefile()
2577   source ${magefile}   source ${magefile}
2578   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2579   echo "${value}"   echo "${value}"
2580    
2581     # unset these functions
2582     unset -f preinstall
2583     unset -f postinstall
2584     unset -f preremove
2585     unset -f postremove
2586  }  }
2587    
2588  mage_install()  mage_install()
# Line 1988  mage_install() Line 2599  mage_install()
2599   local PKGTYPE   local PKGTYPE
2600   local preinstall   local preinstall
2601   local postinstall   local postinstall
2602     local preremove
2603     local postremove
2604    
2605   local pcat   local pcat
2606   local pname   local pname
# Line 1997  mage_install() Line 2610  mage_install()
2610   local count_current   local count_current
2611   local magefile   local magefile
2612   local src_install   local src_install
2613     local i
2614    
2615   # very basic getops   # very basic getops
2616   for i in $*   for i in $*
# Line 2070  mage_install() Line 2684  mage_install()
2684   echo B:${pbuild}   echo B:${pbuild}
2685   fi   fi
2686    
2687   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2688     then
2689     # basic svn compat
2690     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2691     then
2692     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2693     do
2694     smage2file="${i}"
2695     done
2696     else
2697     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2698     fi
2699    
2700     else
2701     # basic svn compat
2702     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2703     then
2704     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2705     do
2706     smage2file="${i}"
2707     done
2708     else
2709     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2710     fi
2711     fi
2712    
2713   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2714   then   then
2715     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2716   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2717   else   else
2718   echo   echo
# Line 2086  mage_install() Line 2726  mage_install()
2726   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2727   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2728   then   then
2729   # show a verbose message on src-install   unpack_package "${magefile}"
2730   if [[ ${src_install} = true ]]   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
  then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "merging files: "  
  echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  
  echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"  
  fi  
2731   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2732   fi   fi
2733    
# Line 2149  mage_install() Line 2783  mage_install()
2783  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2784  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2785   echo "successfully installed."   echo "successfully installed."
2786    
2787     # unset these functions
2788     unset -f preinstall
2789     unset -f postinstall
2790     unset -f preremove
2791     unset -f postremove
2792  }  }
2793    
2794  md5sum_packages()  md5sum_packages()
# Line 2175  md5sum_packages() Line 2815  md5sum_packages()
2815   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2816   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2817   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2818   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2819   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2820    
2821   (( count_current++ ))   (( count_current++ ))
# Line 2185  md5sum_packages() Line 2825  md5sum_packages()
2825   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2826   then   then
2827   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2828   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2829   continue   continue
2830   fi   fi
2831    
# Line 2193  md5sum_packages() Line 2833  md5sum_packages()
2833   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2834   then   then
2835   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2836   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2837   continue   continue
2838   fi   fi
2839    
# Line 2201  md5sum_packages() Line 2841  md5sum_packages()
2841   then   then
2842   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2843   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2844   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2845   else   else
2846   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2847   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2241  uninstall_packages() Line 2881  uninstall_packages()
2881   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2882   can_pcat="${pcat}"   can_pcat="${pcat}"
2883   can_pname="${pname}"   can_pname="${pname}"
2884    
2885   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2886   then   then
2887   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2253  uninstall_packages() Line 2893  uninstall_packages()
2893   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2894   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2895   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2896   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2897   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2898   echo   echo
2899   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2900   echo "( Press [CTRL+C] to abort )"   then
2901   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2902   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2903   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2904   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2905   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2906   sleep 1   do
2907   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2908   echo   sleep 1
2909   echo   done
2910     echo
2911     echo
2912     fi
2913    
2914   for pkg in ${list}   for pkg in ${list}
2915   do   do
# Line 2304  mage_uninstall() Line 2947  mage_uninstall()
2947   local PKGTYPE   local PKGTYPE
2948   local preinstall   local preinstall
2949   local postinstall   local postinstall
2950     local preremove
2951     local postremove
2952    
2953   local pcat   local pcat
2954   local pname   local pname
# Line 2339  mage_uninstall() Line 2984  mage_uninstall()
2984   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2985   echo -n "removing: "   echo -n "removing: "
2986   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2987   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2988    
2989   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2990   source ${magefile}   source ${magefile}
2991    
2992   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 3046  mage_uninstall()
3046  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
3047  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3048   echo "successfully removed."   echo "successfully removed."
3049    
3050     # unset these functions
3051     unset -f preinstall
3052     unset -f postinstall
3053     unset -f preremove
3054     unset -f postremove
3055    }
3056    
3057    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3058    rerun_pkgfunctions()
3059    {
3060     local method
3061     local list
3062     local pcat
3063     local pname
3064     local pver
3065     local pbuild
3066     local magefile
3067     local i
3068    
3069     # very basic getops
3070     for i in $*
3071     do
3072     case $1 in
3073     --method) shift; method="$1" ;;
3074     esac
3075     shift
3076     done
3077     local list="$@"
3078    
3079     # sanity check
3080     case ${method} in
3081     preinstall|postinstall) ;;
3082     preremove|postremove) ;;
3083     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3084     esac
3085    
3086     if [[ -n ${MROOT} ]]
3087     then
3088     echo -ne ${COLRED}
3089     echo "!! running in MROOT=${MROOT}"
3090     echo -ne ${COLDEFAULT}
3091     echo
3092     fi
3093    
3094     for pkg in ${list}
3095     do
3096     pcat=$(dep2pcat ${pkg})
3097     pname=$(magename2pname ${pkg})
3098     pver=$(magename2pver ${pkg})
3099     pbuild=$(magename2pbuild ${pkg})
3100     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3101    
3102     if [ -e ${magefile} ]
3103     then
3104     source ${magefile}
3105     if [ -n "$(typeset -f ${method})" ]
3106     then
3107     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3108     ${method}
3109     else
3110     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3111     fi
3112     unset -f preinstall postinstall preremove postremove
3113     else
3114     die "Magefile '${magefile}' does not exist."
3115     fi
3116     done
3117  }  }
3118    
3119  show_etc_update_mesg() {  show_etc_update_mesg()
3120    {
3121   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3122    
3123   echo   echo
# Line 2415  show_etc_update_mesg() { Line 3129  show_etc_update_mesg() {
3129   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
3130   echo   echo
3131  }  }
3132    
3133    pkgsearch()
3134    {
3135     local string="$1"
3136     local result
3137     local pkg
3138     local pcat
3139     local pname
3140     local magefile
3141     local pver
3142     local pbuild
3143     local state
3144     local descriptiom
3145     local homepage
3146     local license
3147     local i
3148     local all_installed
3149     local ipver
3150     local ipbuild
3151     local latest_available
3152     local depsfull
3153     local sdepsfull
3154     local deps
3155     local sdeps
3156     local dep
3157     local sign
3158    
3159     # only names no versions
3160     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3161     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3162    
3163     # nothing found
3164     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
3165    
3166     for pkg in ${result}
3167     do
3168     # dirty, but does the job
3169     pcat="$(magename2pcat ${pkg}/foo)"
3170     pname="$(magename2pname ${pkg}-foo-foo)"
3171    
3172     # get highest version available
3173     magefile=$(get_highest_magefile ${pcat} ${pname})
3174    
3175     if [[ ! -z ${magefile} ]]
3176     then
3177     # now get all needed infos to print a nice output
3178     pver="$(magename2pver ${magefile})"
3179     pbuild="$(magename2pbuild ${magefile})"
3180     state="$(get_value_from_magefile STATE ${magefile})"
3181     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3182     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3183     license="$(get_value_from_magefile LICENSE ${magefile})"
3184    
3185     # all installed
3186     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3187     do
3188     ipver="$(magename2pver ${i})"
3189     ipbuild="$(magename2pbuild ${i})"
3190    
3191     if [[ -z ${all_installed} ]]
3192     then
3193     all_installed="${ipver}-${ipbuild}"
3194     else
3195     all_installed="${all_installed} ${ipver}-${ipbuild}"
3196     fi
3197     done
3198     [[ -z ${all_installed} ]] && all_installed="none"
3199    
3200     case ${state} in
3201     stable) state=${COLGREEN}"[s] ";;
3202     testing) state=${COLYELLOW}"[t] ";;
3203     unstable) state=${COLRED}"[u] ";;
3204     old) state=${COLGRAY}"[o] ";;
3205     esac
3206    
3207     latest_available="${pver}-${pbuild}"
3208     else
3209     # package is masked
3210     state="${COLRED}[m] "
3211     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3212     fi
3213    
3214     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3215     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3216    
3217     while read sign dep
3218     do
3219     case ${dep} in
3220     "") continue;;
3221     esac
3222    
3223     if [[ -z ${deps} ]]
3224     then
3225     deps="$(basename ${dep%-*})"
3226     else
3227     deps="${deps} $(basename ${dep%-*})"
3228     fi
3229     done << EOF
3230    ${depsfull}
3231    EOF
3232    
3233     while read sign dep
3234     do
3235     case ${dep} in
3236     "") continue;;
3237     esac
3238    
3239     if [[ -z ${sdeps} ]]
3240     then
3241     sdeps="$(basename ${dep%-*})"
3242     else
3243     sdeps="${sdeps} $(basename ${dep%-*})"
3244     fi
3245     done << EOF
3246    ${sdepsfull}
3247    EOF
3248    
3249     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3250     echo -e "      Latest available:   ${latest_available}"
3251     echo "      Installed versions: ${all_installed}"
3252     echo "      Description: ${description}"
3253     echo "      Homepage: ${homepage}"
3254     if [[ ! -z ${license} ]]
3255     then
3256     echo "      License:  ${license}"
3257     fi
3258     echo "      Depends:  ${deps}"
3259     echo "      SDepends: ${sdeps}"
3260     echo
3261    
3262     unset pcat
3263     unset pname
3264     unset magefile
3265     unset pver
3266     unset pbuild
3267     unset state
3268     unset descriptiom
3269     unset homepage
3270     unset all_installed
3271     unset ipver
3272     unset ipbuild
3273     unset depsfull
3274     unset sdepsfull
3275     unset deps
3276     unset sdeps
3277     unset dep
3278     unset sign
3279     done
3280    }
3281    
3282    export_inherits()
3283    {
3284     local include="$1"
3285     shift
3286    
3287     while [ "$1" ]
3288     do
3289     local functions="$1"
3290    
3291     # sanity checks
3292     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3293     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3294    
3295     eval "${functions}() { ${include}_${functions} ; }"
3296    
3297     # debug
3298     mqueryfeature "debug" && typeset -f "${functions}"
3299    
3300     shift
3301     done
3302    }
3303    
3304    mlibdir()
3305    {
3306     local libdir=lib
3307     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3308    
3309     echo "${libdir}"
3310    }
3311    
3312    ## blacklisted ${magefile}
3313    blacklisted()
3314    {
3315     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3316    
3317     # compat
3318     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3319     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3320    
3321     # support both types for the moment
3322     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3323     then
3324     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3325     else
3326     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3327     fi
3328    
3329     # return 0 if the list not exist; nothin is masked
3330     [[ ! -f ${EXCLUDED} ]] && return 0
3331    
3332     local MAGEFILE="$1"
3333    
3334     local PCAT="$(magename2pcat ${MAGEFILE})"
3335     local PNAME="$(magename2pname ${MAGEFILE})"
3336     local PVER="$(magename2pver ${MAGEFILE})"
3337     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3338    
3339     local EXPCAT EXPNAME EXPVER EXPBUILD
3340     while read EXPCAT EXPNAME EXPVER EXPBUILD
3341     do
3342     # ignore spaces and comments
3343             case "${EXPCAT}" in
3344                     \#*|"") continue ;;
3345             esac
3346    
3347     # exclude full pver
3348     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3349     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3350     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3351     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3352     then
3353     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3354     fi
3355    
3356     # exclude pcat/pname only
3357     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3358     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3359     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3360     then
3361     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3362     fi
3363     done << EOF
3364    $( cat ${EXCLUDED}; echo)
3365    EOF
3366    
3367     return 0
3368    }
3369    
3370    # need_busybox_support ${cmd}
3371    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3372    need_busybox_support()
3373    {
3374     local cmd
3375     local busybox
3376     cmd="$1"
3377    
3378     for busybox in {,/usr}/bin/busybox
3379     do
3380     if [[ -x ${busybox} ]]
3381     then
3382     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3383     then
3384     # needs busybox support
3385     return 0
3386     fi
3387     fi
3388     done
3389    
3390     # no busybox
3391     return 1
3392    }
3393    
3394    # busybox_filter_wget_options ${wget_opts}
3395    busybox_filter_wget_options()
3396    {
3397     local opts="$@"
3398     local i
3399     local fixed_opts
3400    
3401     if need_busybox_support wget
3402     then
3403     for i in ${opts}
3404     do
3405     # show only the allowed ones
3406     case ${i} in
3407     -c|--continue) fixed_opts+=" -c" ;;
3408     -s|--spider) fixed_opts+=" -s" ;;
3409     -q|--quiet) fixed_opts+=" -q" ;;
3410     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3411     --header) shift; fixed_opts+=" --header $1" ;;
3412     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3413     -P) shift; fixed_opts+=" -P $1" ;;
3414     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3415     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3416     # simply drop all other opts
3417     *) continue ;;
3418     esac
3419     done
3420    
3421     echo "${fixed_opts}"
3422     else
3423     echo "${opts}"
3424     fi
3425    }
3426    
3427    have_root_privileges()
3428    {
3429     local retval
3430    
3431     if [[ $(id -u) = 0 ]]
3432     then
3433     retval=0
3434     else
3435     retval=1
3436     fi
3437    
3438     return ${retval}
3439    }
3440    
3441    known_mage_feature()
3442    {
3443     local feature="$1"
3444     local retval
3445    
3446     case "${feature}" in
3447     autosvc|!autosvc) retval=0 ;;
3448     buildlog|!buildlog) retval=0 ;;
3449     ccache|!ccache) retval=0 ;;
3450     check|!check) retval=0 ;;
3451     compressdoc|!compressdoc) retval=0 ;;
3452     debug|!debug) retval=0 ;;
3453     distcc|!distcc) retval=0 ;;
3454     icecc|!icecc) retval=0 ;;
3455     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3456     libtool|!libtool) retval=0 ;;
3457     linuxsymlink|!linuxsymlink) retval=0 ;;
3458     pkgbuild|!pkgbuild) retval=0 ;;
3459     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3460     purge|!purge) retval=0 ;;
3461     qalint|!qalint) retval=0 ;;
3462     regentree|!regentree) retval=0 ;;
3463     resume|!resume) retval=0 ;;
3464     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3465     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3466     static|!static) retval=0 ;;
3467     stepbystep|!stepbystep) retval=0 ;;
3468     strip|!strip) retval=0 ;;
3469     verbose|!verbose) retval=0 ;;
3470     *) retval=1 ;;
3471     esac
3472    
3473     return "${retval}"
3474    }
3475    
3476    load_mage_features()
3477    {
3478     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3479     do
3480     FVERBOSE=off msetfeature ${i}
3481     done
3482    }
3483    
3484    msetfeature()
3485    {
3486     local feature
3487     local count
3488     local i
3489     local found
3490    
3491     for feature in $@
3492     do
3493     found=0
3494     count="${#MAGE_FEATURES_CURRENT[*]}"
3495    
3496     if ! known_mage_feature "${feature}"
3497     then
3498     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3499     return 3
3500     fi
3501    
3502     for ((i=0; i<count; i++))
3503     do
3504     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3505     then
3506     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3507     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3508     found=1
3509     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3510     then
3511     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3512     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3513     found=1
3514     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3515     then
3516     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3517     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3518     found=1
3519     fi
3520     done
3521    
3522     # if the feature was not found after proccessing the whole array
3523     # it was not declared. in this case enable it
3524     if [[ ${found} = 0 ]]
3525     then
3526     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3527     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3528     fi
3529    
3530     export MAGE_FEATURE_CURRENT
3531     done
3532    }
3533    
3534    mqueryfeature()
3535    {
3536     local feature="$1"
3537     local retval=1
3538     local i
3539    
3540     if known_mage_feature "${feature}"
3541     then
3542     for i in ${MAGE_FEATURES_CURRENT[*]}
3543     do
3544     if [[ ${i} = ${feature} ]]
3545     then
3546     retval=0
3547     break # found break here
3548     fi
3549     done
3550     else
3551     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3552     retval=3
3553     fi
3554    
3555     return ${retval}
3556    }
3557    
3558    mprintfeatures()
3559    {
3560     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3561     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3562     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3563    }

Legend:
Removed from v.226  
changed lines
  Added in v.2371