Magellan Linux

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

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

trunk/mage/usr/lib/mage/mage4.functions.sh revision 258 by niro, Tue Oct 4 14:35:21 2005 UTC branches/mage-next/src/mage4.functions.sh.in revision 2868 by niro, Thu Mar 19 15:29:17 2015 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.7 2005-10-04 14:35:21 niro Exp $  # $Id$
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 15  mage_setup() Line 15  mage_setup()
15   return 0   return 0
16  }  }
17    
18    mchecksum()
19    {
20     local i
21     local rundir
22     local file
23     local method
24     local cmd
25     local retval
26     local sum
27     local dest
28    
29     # very basic getops
30     for i in $*
31     do
32     case $1 in
33     --rundir|-r) shift; rundir="$1" ;;
34     --file|-f) shift; file="$1" ;;
35     --method|-m) shift; method="$1" ;;
36     esac
37     shift
38     done
39    
40     # sanity checks
41     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
42     [[ -z ${file} ]] && die "mchecksum(): file missing"
43     [[ -z ${method} ]] && die "mchecksum(): method missing"
44    
45     case ${method} in
46     md5) cmd="md5sum" ;;
47     sha256) cmd="sha256sum" ;;
48     *) die "mchecksum(): unknown method '${method}'" ;;
49     esac
50    
51     if [[ -d ${rundir} ]]
52     then
53     pushd ${rundir} &> /dev/null
54    
55     # all file must be non-zero
56     retval=0
57     while read sum dest
58     do
59     if [ ! -s ${dest} ]
60     then
61     echo "${dest}: file is empty ;("
62     retval=127
63     fi
64     done < ${file}
65     if [[ ${retval} != 127 ]]
66     then
67     # be verbose here
68     ${cmd} -c ${file} #&> /dev/null
69     retval="$?"
70     fi
71    
72     popd &> /dev/null
73     else
74     retval=1
75     fi
76    
77     return "${retval}"
78    }
79    
80    mcheckemptydir()
81    {
82     local dir="$1"
83     local retval=1
84    
85     if [[ ! -d ${dir} ]]
86     then
87     echo "mcheckemptydir(): '${dir}' is not a directory!"
88     retval=3
89     else
90     shopt -s nullglob dotglob
91     files=( ${dir}/* )
92     (( ${#files[*]} )) || retval=0
93     shopt -u nullglob dotglob
94     fi
95    
96     return ${retval}
97    }
98    
99    unpack_package()
100    {
101     local magefile="$1"
102     local pkgname
103     local pkgfile
104     local pkgtype
105     local tar_opts
106    
107     pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
108     pkgfile="${pkgname}.${PKGSUFFIX}"
109     pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
110    
111     xtitle "[ Unpacking ${pkg} ]"
112    
113     # abort on virtual pkg
114     if [[ ${pkgtype} = virtual ]]
115     then
116     echo -ne " ${COLBLUE}---${COLDEFAULT}"
117     echo " !unpack virtual ${pkgname} ... "
118     continue
119     fi
120    
121     # abort on sources pkg
122     if [[ ${pkgtype} = sources ]]
123     then
124     echo -ne " ${COLBLUE}---${COLDEFAULT}"
125     echo " !unpack sources ${pkgname} ... "
126     continue
127     fi
128    
129     # busybox?
130     if need_busybox_support tar
131     then
132     tar_opts="xjf"
133     else
134     tar_opts="xjmf"
135     fi
136    
137     echo -e " ${COLBLUE}***${COLDEFAULT} unpacking ${pkgfile} ... "
138     tar ${tar_opts} ${PKGDIR}/${pkgfile} -C ${BUILDDIR} || die "Unpacking package ${pkgfile}"
139    }
140    
141  unpack_packages()  unpack_packages()
142  {  {
143   local list="$@"   local list="$@"
144   local magefile   local magefile
  local pkg  
  local pkgtype  
145   local count_current   local count_current
146   local count_total   local count_total
147     local tar_opts
148    
149   # get count of total packages   # get count of total packages
150   declare -i count_current=0   declare -i count_current=0
# Line 32  unpack_packages() Line 154  unpack_packages()
154    
155   for magefile in ${list}   for magefile in ${list}
156   do   do
157   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   unpack_package "${magefile}"
  pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"  
   
158   (( count_current++ ))   (( count_current++ ))
  xtitle "[ (${count_current}/${count_total}) Unpacking ${pkg} ]"  
   
  # abort on virtual pkg  
  if [[ ${pkgtype} = virtual ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  # abort on sources pkg  
  if [[ ${pkgtype} = sources ]]  
  then  
  echo -ne " ${COLBLUE}---${COLDEFAULT}"  
  echo " !unpack sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "  
  continue  
  fi  
   
  echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "  
  tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"  
159   done   done
160    
161   # add a crlf for a better view   # add a crlf for a better view
162   if [ ${count_total} -gt 1 ]; then echo; fi   if [ ${count_total} -gt 1 ]; then echo; fi
163  }  }
164    
   
165  # fix_mtime path/to/$mtime/reffile $pathto/file  # fix_mtime path/to/$mtime/reffile $pathto/file
166  # creates a given reference file and fixes given file  # creates a given reference file and fixes given file
167  # returns new mtime  # returns new mtime
# Line 75  fix_mtime() Line 174  fix_mtime()
174   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
175   touch \   touch \
176   --no-create \   --no-create \
177     --no-dereference \
178   --time=mtime \   --time=mtime \
179   --reference "${reference}" \   --reference="${reference}" \
180   "${pathto}"   "${pathto}"
181    
182   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 230  install_directories()
230   while read pathto posix user group   while read pathto posix user group
231   do   do
232   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
233   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
234    
235   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
236   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 297  install_files()
297   is_config_protected "${pathto}"   is_config_protected "${pathto}"
298   retval="$?"   retval="$?"
299    
300   # 0 - not protected        #   # 0 - not protected         #
301   # 1 - error                #   # 1 - error                 #
302   # 2 - protected            #   # 2 - protected             #
303   # 3 - protected but masked #   # 3 - protected but masked  #
304     # 4 - protected but ignored #
305    
306   case ${retval} in   case ${retval} in
307   # file is not protected - (over)write it   # file is not protected - (over)write it
308   0|3)   0|3)
309   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
310   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
311   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
312   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 318  install_files()
318   "${user}" \   "${user}" \
319   "${group}" \   "${group}" \
320   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
321   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
322   "${md5sum}"   "${md5sum}"
323   ;;   ;;
324    
325   # file is protected, write backup file   # file is protected, write backup file
326   2)   2)
327   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
328   then   then
329   echo -en "${COLRED}"   echo -en "${COLRED}"
330   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 345  install_files()
345   "${user}" \   "${user}" \
346   "${group}" \   "${group}" \
347   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
348   "${dest_protected}")" \   "${dest_protected}")" \
349   "${md5sum}"   "${md5sum}"
350    
351   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
352   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
353   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
354   ;;   ;;
355    
356     # file is protected but ignored, delete the update/do nothing
357     4)
358     if mqueryfeature "verbose"
359     then
360     echo -en "${COLRED}"
361     echo -n "! ignr "
362     echo -en "${COLDEFAULT}"
363     echo " === FILE: ${MROOT}${pathto}"
364     fi
365     # simply do nothing here - only fix mtime
366     fix_descriptor ${pkgname}/.files \
367     "${pathto}" \
368     "${posix}" \
369     "${user}" \
370     "${group}" \
371     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
372     "${MROOT}${pathto}")" \
373     "${md5sum}"
374     ;;
375   esac   esac
376   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
377    
# Line 294  install_symlinks() Line 414  install_symlinks()
414   while read pathto posix link mtime   while read pathto posix link mtime
415   do   do
416   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
417   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
418    
419   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
420    
421   # fix mtime and db   # fix mtime and db
422   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
423   "${pathto}" \   "${pathto}" \
424   "${posix}" \   "${posix}" \
425   "${link}" \   "${link}" \
426   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
427   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
428    
429   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
430    
431   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
432   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
433   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
434    
435   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
436   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 446  install_blockdevices()
446   local pkgname="$1"   local pkgname="$1"
447   local pathto   local pathto
448   local posix   local posix
449     local user
450     local group
451   local IFS   local IFS
452    
453   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 461  install_blockdevices()
461   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
462   IFS=§   IFS=§
463    
464   while read pathto posix   while read pathto posix major minor user group
465   do   do
466   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
467   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
468    
469   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
470     # make it optional atm !!
471     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
472     then
473     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
474     fi
475   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
476    
477   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 488  install_characterdevices()
488   local pkgname="$1"   local pkgname="$1"
489   local pathto   local pathto
490   local posix   local posix
491     local major
492     local minor
493     local user
494     local group
495   local IFS   local IFS
496    
497   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 505  install_characterdevices()
505   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
506   IFS=§   IFS=§
507    
508   while read pathto posix   while read pathto posix major minor user group
509   do   do
510   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
511   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
512    
513     mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
514    
515   mknode -m ${posix} -c "${MROOT}${pathto}"   # make it optional atm !!
516     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
517     then
518     chown "${user}:${group}" "${MROOT}${pathto}"
519     fi
520   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
521    
522   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
523   IFS=$'\n'   IFS=$'\n'
524  }  }
525    
526    ###################################################
527    # function install_fifos                          #
528    # install_fifos $PKGNAME                    #
529    ###################################################
530    install_fifos()
531    {
532     local pkgname="$1"
533     local pathto
534     local posix
535     local user
536     local group
537     local IFS
538    
539     # sanity checks; abort if not given
540     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
541    
542     # check needed global vars
543     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
544    
545     # make it optional atm !!
546     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
547     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
548    
549     # sets fieldseperator to "§" instead of " "
550     IFS=§
551    
552     while read pathto posix user group
553     do
554     [ -z "${pathto}" ] && continue
555     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
556    
557     mkfifo -m "${posix}" "${MROOT}${pathto}"
558     chown "${user}:${group}" "${MROOT}${pathto}"
559     done < ${BUILDDIR}/${pkgname}/.fifo
560    
561     # very important: unsetting the '§' fieldseperator
562     IFS=$'\n'
563    }
564    
565    
566  ###################################################  ###################################################
567  # function build_doinstall                        #  # function build_doinstall                        #
568  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
569  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
570  ###################################################  ###################################################
571  build_doinstall()  build_doinstall()
572  {  {
# Line 398  build_doinstall() Line 574  build_doinstall()
574    
575   # sanity checks; abort if not given   # sanity checks; abort if not given
576   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
577    
578   # this is only a wrapper   # this is only a wrapper
579    
580   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 589  build_doinstall()
589   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
590   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
591   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
592     install_fifos ${pkgname} || die "install fifos ${pkgname}"
593  }  }
594    
595    
# Line 432  install_database_entry() Line 609  install_database_entry()
609   local magefile   local magefile
610   local dbrecorddir   local dbrecorddir
611   local provide   local provide
612     local i
613    
614   # very basic getops   # very basic getops
615   for i in $*   for i in $*
# Line 473  install_database_entry() Line 651  install_database_entry()
651    
652   # create fake file descriptors   # create fake file descriptors
653   # used by virtual and source packages   # used by virtual and source packages
654   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
655   do   do
656   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
657   done   done
# Line 492  install_database_entry() Line 669  install_database_entry()
669    
670   # normal packages needs these files   # normal packages needs these files
671   local i   local i
672   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
673   do   do
674   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
675   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
676     then
677     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
678     fi
679   done   done
680   ;;   ;;
681   esac   esac
# Line 504  install_database_entry() Line 684  install_database_entry()
684   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
685   if [ -n "${provide}" ]   if [ -n "${provide}" ]
686   then   then
687   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
688     do
689     virtuals_add "${i}" "${pcat}/${pname}"
690     done
691   fi   fi
692  }  }
693    
# Line 523  remove_database_entry() Line 706  remove_database_entry()
706   local magefile   local magefile
707   local dbrecorddir   local dbrecorddir
708   local provide   local provide
709     local i
710    
711   # very basic getops   # very basic getops
712   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 736  remove_database_entry()
736   # abort if mage file not exists   # abort if mage file not exists
737   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
738    
739   # first unregister virtuals   # remove virtuals only if no other exist
740   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
741   then   then
742   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
743     provide="$(get_value_from_magefile PROVIDE ${magefile})"
744     if [ -n "${provide}" ]
745     then
746     for i in ${provide}
747     do
748     virtuals_del "${i}" "${pcat}/${pname}"
749     done
750     fi
751   fi   fi
752    
753   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 757  remove_database_entry()
757   fi   fi
758  }  }
759    
760    # get the number of installed packages
761    count_installed_pkgs()
762    {
763     local pcat
764     local pname
765     local pkg
766     local i
767    
768     # very basic getops
769     for i in $@
770     do
771     case ${i} in
772     --pcat*) pcat="${i#*=}" ;;
773     --pname*) pname="${i#*=}" ;;
774     esac
775     done
776    
777     # sanity checks; abort if not given
778     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
779     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
780    
781     declare -i i=0
782     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
783     do
784     (( i++ ))
785     #echo "$i ${pkg}"
786     done
787    
788     # return the value
789     echo "${i}"
790    }
791    
792    
793  ###################################################  ###################################################
794  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  compare_mtime() Line 810  compare_mtime()
810    
811   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
812    
813   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
814   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
815   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  
816    
817   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
818    
# Line 662  remove_symlinks() Line 874  remove_symlinks()
874   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
875   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
876   then   then
877   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
878   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
879   continue   continue
880   fi   fi
# Line 674  remove_symlinks() Line 886  remove_symlinks()
886   # 1=keep me   #   # 1=keep me   #
887   case ${retval} in   case ${retval} in
888   0)   0)
889   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
890   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
891   ;;   ;;
892    
893   1)   1)
894   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
895   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
896   ;;   ;;
897   esac   esac
# Line 726  remove_files() Line 938  remove_files()
938   done   done
939    
940   # sanity checks; abort if not given   # sanity checks; abort if not given
941   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
942   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
943   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
944   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
945   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
946    
947   # check needed global vars   # check needed global vars
# Line 746  remove_files() Line 958  remove_files()
958    
959   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
960   then   then
961   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
962   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
963   continue   continue
964   fi   fi
# Line 758  remove_files() Line 970  remove_files()
970   # 1=keep me   #   # 1=keep me   #
971   case ${retval} in   case ${retval} in
972   0)   0)
973   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
974   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
975   ;;   is_config_protected "${pathto}"
976     retval="$?"
977    
978     # 0 - not protected         #
979     # 1 - error                 #
980     # 2 - protected             #
981     # 3 - protected but masked  #
982     # 4 - protected but ignored #
983    
984     case ${retval} in
985     # file is not protected - delete it
986     0|3)
987     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
988     rm "${MROOT}${pathto}"
989     ;;
990    
991     # file is protected, do not delete
992     2)
993     if mqueryfeature "verbose"
994     then
995     echo -en "${COLRED}"
996     echo -n "! prot "
997     echo -en "${COLDEFAULT}"
998     echo " === FILE: ${MROOT}${pathto}"
999     fi
1000     ;;
1001    
1002     # file is protected but ignored, delete the update/do nothing
1003     4)
1004     if mqueryfeature "verbose"
1005     then
1006     echo -en "${COLRED}"
1007     echo -n "! ignr "
1008     echo -en "${COLDEFAULT}"
1009     echo " === FILE: ${MROOT}${pathto}"
1010     fi
1011     # simply do nothing here
1012     ;;
1013     esac
1014     ;;
1015   1)   1)
1016   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1017   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1018   ;;   ;;
1019   esac   esac
# Line 782  remove_blockdevices() Line 1032  remove_blockdevices()
1032  {  {
1033   local pathto   local pathto
1034   local posix   local posix
1035     local user
1036     local group
1037   local IFS   local IFS
1038   local pcat   local pcat
1039   local pname   local pname
# Line 805  remove_blockdevices() Line 1057  remove_blockdevices()
1057   done   done
1058    
1059   # sanity checks; abort if not given   # sanity checks; abort if not given
1060   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1061   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1062   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1063   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1064   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1065    
1066   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1071  remove_blockdevices()
1071   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1072   IFS=§   IFS=§
1073    
1074   while read pathto posix   while read pathto posix user group
1075   do   do
1076   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1077    
1078   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1079   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1080   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1081    
# Line 840  remove_characterdevices() Line 1092  remove_characterdevices()
1092  {  {
1093   local pathto   local pathto
1094   local posix   local posix
1095     local user
1096     local group
1097   local IFS   local IFS
1098   local pcat   local pcat
1099   local pname   local pname
# Line 863  remove_characterdevices() Line 1117  remove_characterdevices()
1117   done   done
1118    
1119   # sanity checks; abort if not given   # sanity checks; abort if not given
1120   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1121   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1122   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1123   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1124   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1125    
1126   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1131  remove_characterdevices()
1131   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1132   IFS=§   IFS=§
1133    
1134   while read pathto posix   while read pathto posix user group
1135   do   do
1136   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1137    
1138   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1139   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1140   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1141    
# Line 891  remove_characterdevices() Line 1145  remove_characterdevices()
1145    
1146    
1147  ###################################################  ###################################################
1148    # function remove_fifos                           #
1149    # remove_fifos $PKGNAME                     #
1150    ###################################################
1151    remove_fifos()
1152    {
1153     local pathto
1154     local posix
1155     local user
1156     local group
1157     local IFS
1158     local pcat
1159     local pname
1160     local pver
1161     local pbuild
1162     local i
1163     local pfull
1164    
1165     IFS=$'\n'
1166    
1167     # very basic getops
1168     for i in $*
1169     do
1170     case $1 in
1171     --pcat|-c) shift; pcat="$1" ;;
1172     --pname|-n) shift; pname="$1" ;;
1173     --pver|-v) shift; pver="$1" ;;
1174     --pbuild|-b) shift; pbuild="$1" ;;
1175     esac
1176     shift
1177     done
1178    
1179     # sanity checks; abort if not given
1180     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1181     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1182     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1183     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1184     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1185    
1186     # check needed global vars
1187     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1188    
1189     # make it optional atm !!
1190     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1191     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1192    
1193     # sets fieldseperator to "§" instead of " "
1194     IFS=§
1195    
1196     while read pathto posix user group
1197     do
1198     [ -z "${pathto}" ] && continue
1199    
1200     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1201     rm "${MROOT}${pathto}"
1202     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1203    
1204     # very important: unsetting the '§' fieldseperator
1205     IFS=$'\n'
1206    }
1207    
1208    
1209    ###################################################
1210  # function remove_direcories                      #  # function remove_direcories                      #
1211  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1212  ###################################################  ###################################################
# Line 921  remove_directories() Line 1237  remove_directories()
1237   done   done
1238    
1239   # sanity checks; abort if not given   # sanity checks; abort if not given
1240   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1241   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1242   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1243   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1244   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1245    
1246   # check needed global vars   # check needed global vars
# Line 942  remove_directories() Line 1258  remove_directories()
1258    
1259   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1260   then   then
1261   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1262   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1263   continue   continue
1264   fi   fi
# Line 950  remove_directories() Line 1266  remove_directories()
1266   # exclude .keep directories   # exclude .keep directories
1267   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1268   then   then
1269   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1270   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1271   continue   continue
1272   fi   fi
# Line 963  remove_directories() Line 1279  remove_directories()
1279    
1280   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1281   then   then
1282   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1283   else   else
1284   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1285   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1286   fi   fi
1287   done   done
# Line 978  remove_directories() Line 1294  remove_directories()
1294  ###################################################  ###################################################
1295  # function build_douninstall                      #  # function build_douninstall                      #
1296  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1297  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1298  ###################################################  ###################################################
1299  build_douninstall()  build_douninstall()
1300  {  {
# Line 1012  build_douninstall() Line 1328  build_douninstall()
1328   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1329   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1330    
1331   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1332   do   do
1333   remove_${i} \   remove_${i} \
1334   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1023  build_douninstall() Line 1339  build_douninstall()
1339   done   done
1340  }  }
1341    
1342    # convertmirrors [uri]
1343    convertmirrors()
1344    {
1345     local uri="$1"
1346     local scheme
1347     local mirror
1348     local mirrors
1349     local addon
1350     local real_uri
1351     local output
1352    
1353     # needs
1354     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1355     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1356     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1357     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1358     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1359    
1360     # check known uri schemes
1361     case ${uri} in
1362     http://*|https://*|ftp://*|ftps://*|file://*) mirrors="" ;;
1363     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1364     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1365     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1366     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1367     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1368     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1369     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1370     esac
1371    
1372     if [[ ! -z ${mirrors} ]]
1373     then
1374     for mirror in ${mirrors}
1375     do
1376     # add a whitespace to the output
1377     [[ -z ${output} ]] || output+=" "
1378     output+="${mirror}${addon}/${uri/${scheme}/}"
1379     done
1380     else
1381     output="${uri}"
1382     fi
1383    
1384     echo "${output}"
1385    }
1386    
1387    mdownload()
1388    {
1389     local i
1390     local uri
1391     local real_uris
1392     local mirror
1393     local outputfile
1394     local outputdir
1395     local retval
1396     local wget_opts
1397    
1398     # very basic getops
1399     for i in $*
1400     do
1401     case $1 in
1402     --uri|-u) shift; uri="$1" ;;
1403     --dir|-d) shift; outputdir="$1" ;;
1404     esac
1405     shift
1406     done
1407    
1408     # sanity checks; abort if not given
1409     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1410     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1411    
1412     # convert mirrored uris to the real ones
1413     real_uris="$(convertmirrors ${uri})"
1414    
1415     # verbose or not
1416     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1417    
1418     # filter wget options if busybox was found
1419     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1420    
1421     # create outputdir
1422     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1423    
1424     for mirror in ${real_uris}
1425     do
1426     # get the name of the output file
1427     outputfile="${mirror##*/}"
1428    
1429     case ${mirror} in
1430     file://*)
1431     cp -v "${mirror//file:\/\/}" "${outputdir}/${outputfile}"
1432     retval="$?"
1433     ;;
1434     *)
1435     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1436     retval="$?"
1437     ;;
1438     esac
1439    
1440     if [[ ${retval} = 0 ]]
1441     then
1442     break
1443     else
1444     continue
1445     fi
1446     done
1447    
1448     # return wget retval
1449     return "${retval}"
1450    }
1451    
1452  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1453  fetch_packages()  fetch_packages()
1454  {  {
1455     local i
1456   local list="$@"   local list="$@"
1457   local pkg   local pkgname
1458     local pkgfile
1459     local pcat
1460     local pname
1461   local mirr   local mirr
1462   local magefile   local magefile
1463   local md5file   local md5file
1464   local opt   local opt
1465   local count_current   local count_current
1466   local count_total   local count_total
1467     local wget_opts
1468     local fetching
1469    
1470     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1471    
1472   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1473     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1474    
1475   # get count of total packages   # get count of total packages
1476   declare -i count_current=0   declare -i count_current=0
# Line 1045  fetch_packages() Line 1480  fetch_packages()
1480    
1481   for magefile in ${list}   for magefile in ${list}
1482   do   do
1483   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1484     pkgfile="${pkgname}.${PKGSUFFIX}"
1485   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1486    
1487     pcat=$(magename2pcat ${magefile})
1488     pname=$(magename2pname ${magefile})
1489     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1490    
1491   (( count_current++ ))   (( count_current++ ))
1492   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1493    
1494   # abort on virtual pkg   # abort on virtual pkg
1495   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1496   then   then
1497   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1498   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1499   continue   continue
1500   fi   fi
1501    
# Line 1063  fetch_packages() Line 1503  fetch_packages()
1503   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1504   then   then
1505   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1506   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1507   continue   continue
1508   fi   fi
1509    
1510   # abort if already exist   # check if FETCHING is required
1511   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1512   then   then
1513   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1514   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1515   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 ]]  
1516   then   then
1517   break   # md5's ok, no fetching required
1518     fetching=false
1519   else   else
1520   continue   fetching=true
1521   fi   fi
1522   done   fi
1523    
1524   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1525   then   then
1526   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1527     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1528     continue
1529     else
1530     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1531     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1532     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1533     fi
1534    
1535     # sanity check, not really needed but to be sure
1536     if [ ! -f ${PKGDIR}/${pkgfile} ]
1537     then
1538     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1539   fi   fi
1540   done   done
1541    
# Line 1110  syncmage() Line 1547  syncmage()
1547  {  {
1548   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1549   then   then
1550   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1551   fi   fi
1552    
1553   local i   local i
1554   for i in ${RSYNC}   for i in ${RSYNC}
1555   do   do
1556   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1557   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1558   then   then
1559   break   break
# Line 1139  syncmage() Line 1563  syncmage()
1563   done   done
1564    
1565   # clean up backup files (foo~)   # clean up backup files (foo~)
1566   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1567    
1568   # check if an newer mage version is available   # check if a newer mage version is available
1569   is_newer_mage_version_available   is_newer_mage_version_available
1570  }  }
1571    
1572  cleanpkg()  syncmage_tarball()
1573  {  {
1574   if [ -d "${PKGDIR}" ]   local latest_tarball
1575   then   local latest_md5
1576   echo -n "Removing downloaded packages... "   local temp="$(mktemp -d)"
1577   rm -rf ${PKGDIR}/*   local mirr mymirr
1578   echo "done."   local opt
1579   fi   local tar_opts
1580  }   local wget_opts
1581    
1582  xtitle()   # try to get the md5 marked as latest on the server
1583  {   latest_md5="mage-latest.md5"
  if [[ ${TERM} = xterm ]]  
  then  
  echo -ne "\033]0;Mage: $1\007"  
  fi  
  return 0  
 }  
1584    
1585     # try to get the tarball marked as latest on the server
1586     latest_tarball="mage-latest.tar.bz2"
1587    
1588  xtitleclean()   # filter wget command if busybox was found
1589  {   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1590   if [[ ${TERM} = xterm ]]  
1591     for mirr in ${MIRRORS}
1592     do
1593     # path without distribution
1594     # (only for stable|testing|unstable and not DISTROTAG)
1595     case ${mirr##*/} in
1596     stable|testing|unstable) mymirr="${mirr%/*}";;
1597     *) mymirr="${mirr}";;
1598     esac
1599    
1600     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1601     echo "fetching latest md5 from ${mymirr} ..."
1602     mqueryfeature "!verbose" && opt="--quiet"
1603     wget \
1604     ${wget_opts} \
1605     --directory-prefix=${temp} \
1606     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1607    
1608     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1609     echo "fetching latest tarball from ${mymirr} ..."
1610     wget \
1611     ${wget_opts} \
1612     --directory-prefix=${temp} \
1613     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1614     if [[ $? = 0 ]]
1615     then
1616     break
1617     else
1618     continue
1619     fi
1620     done
1621    
1622     if [[ -f ${temp}/${latest_tarball} ]]
1623   then   then
1624   echo -ne "\033]0;\007"   # check md5
1625     if [[ ! -f ${temp}/${latest_md5} ]]
1626     then
1627     die "md5 is missing ... aborting"
1628     else
1629     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1630     echo -n "checking md5sum... "
1631     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1632     fi
1633    
1634     if [[ -d ${MAGEDIR} ]]
1635     then
1636     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1637     echo "cleaning old mage-tree ${MAGEDIR}..."
1638     # honor mountpoints and empty dirs
1639     if mountpoint -q ${MAGEDIR}
1640     then
1641     if ! mcheckemptydir ${MAGEDIR}
1642     then
1643     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1644     fi
1645     else
1646     rm -rf ${MAGEDIR}
1647     fi
1648     fi
1649    
1650     if need_busybox_support tar
1651     then
1652     tar_opts="xjf"
1653     else
1654     tar_opts="xjmf"
1655     fi
1656    
1657     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1658     echo "updating mage-tree from tarball ..."
1659     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1660     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1661    
1662     if [[ -d ${temp} ]]
1663     then
1664     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1665     echo "cleaning temp-files ..."
1666     rm -rf ${temp}
1667     fi
1668    
1669     # check if a newer mage version is available
1670     is_newer_mage_version_available
1671     else
1672     die "Could not fetch the latest tarball ... aborting"
1673   fi   fi
  return 0  
1674  }  }
1675    
1676    cleanpkg()
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
1677  {  {
1678   #we want this only if full name was used   if [ -d "${PKGDIR}" ]
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
1679   then   then
1680   #cuts ARCH and PBUILD   echo -n "Removing downloaded packages... "
1681   #ARCH comes from /etc/mage.rc   rm -rf ${PKGDIR}/*
1682   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   echo "done."
   
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
1683   fi   fi
1684  }  }
1685    
1686    # unused?
1687    #
1688    # # cuts full pathnames or versionized names down to basename
1689    # choppkgname()
1690    # {
1691    # #we want this only if full name was used
1692    # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1693    # then
1694    # #cuts ARCH and PBUILD
1695    # #ARCH comes from ${MAGERC}
1696    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1697    #
1698    # #cuts version number
1699    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1700    # fi
1701    # }
1702    
1703    
1704  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1705  # $1=pname  # $1=pname
1706  # ret 0=ok, 1=not_found  # ret 0=ok, 1=not_found
# Line 1209  pname2pcat() Line 1720  pname2pcat()
1720   done   done
1721    
1722   echo "${categorie}"   echo "${categorie}"
1723  }  }
1724    
1725  # check_stable_package /path/to/foo.mage  # get_highest_magefile ${PCAT} ${PNAME}
1726  # returns 0=stable 1=unstable  # returns $HIGHEST_MAGEFILE
1727  check_stable_package()  get_highest_magefile()
1728  {  {
1729   local STATE   local pcat="$1"
1730   STATE="$(get_value_from_magefile STATE "$1")"   local pname="$2"
   
  # state testing  
  if [[ ${USE_TESTING} = true ]]  
  then  
  case ${STATE} in  
  testing|stable) return 0 ;;  
  *) return 1 ;;  
  esac  
  fi  
   
  # state unstable  
  if [[ ${USE_UNSTABLE} = true ]]  
  then  
  case ${STATE} in  
  unstable|testing|stable) return 0 ;;  
  *) return 1 ;;  
  esac  
  fi  
   
  # no use_state given = stable  
  case ${STATE} in  
  stable) return 0 ;;  
  *) return 1 ;;  
  esac  
 }  
   
   
 # get_highest_magefile ${PCAT} ${PNAME}  
 # fake at moment returns only stable pkgs (must set to be one)  
 # return $HIGHEST_MAGEFILE  
 get_highest_magefile()  
 {  
  local HIGHEST_MAGEFILE  
  local PCAT="$1"  
  local PNAME="$2"  
  local magefile  
   
  for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)  
  do  
  # we exclude subdirs (for stuff like a md5sum dir)  
  [ -d ${magefile} ] && continue  
  if check_stable_package ${magefile}  
  then  
  HIGHEST_MAGEFILE=${magefile}  
  #for debug only  
  [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"  
  fi  
  done  
   
  # 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  
1731    
1732   echo "${HIGHEST_MAGEFILE}"   ${MLIBDIR}/highest_magefile ${MAGEDIR}/${pcat}/${pname}
1733   return 0   return 0
1734  }  }
1735    
   
1736  ###################################################  ###################################################
1737  # function is_config_protected                    #  # function is_config_protected                    #
1738  #       is_config_protected /path/to/file         #  #       is_config_protected /path/to/file         #
# Line 1301  get_highest_magefile() Line 1742  get_highest_magefile()
1742  #        1 - error                                #  #        1 - error                                #
1743  #        2 - protected                            #  #        2 - protected                            #
1744  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1745    #        4 - protected but ignored                #
1746  #                                                 #  #                                                 #
1747  ###################################################  ###################################################
1748  is_config_protected()  is_config_protected()
# Line 1309  is_config_protected() Line 1751  is_config_protected()
1751   local TEST   local TEST
1752   local PROTECTED   local PROTECTED
1753   local IFS   local IFS
1754     local i
1755     local x
1756    
1757   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1758    
1759   # file does not exist; it can be written   # file does not exist; it can be written
1760   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1761    
1762   # to be safe; it may be '§'   # to be safe; it may be '§'
1763   IFS=' '   IFS=' '
1764    
1765   # check ob in config protect   # check if config protected
1766   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1767   do   do
1768   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1769   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1770   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1771   then   then
1772   # setzen das es protected ist   # file is config proteced
1773   PROTECTED=TRUE   PROTECTED=TRUE
1774    
1775   # check ob nicht doch maskiert   # check if not masked
1776   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1777   do   do
1778   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1779   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1780   then   then
1781   PROTECTED=MASKED   PROTECTED=MASKED
1782   fi   fi
1783   done   done
1784    
1785     # check if not ignored
1786     for x in ${CONFIG_PROTECT_IGNORE}
1787     do
1788     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1789     if [[ ${TEST} != ${EXPFILE} ]]
1790     then
1791     PROTECTED=IGNORED
1792     fi
1793     done
1794   fi   fi
1795   done   done
1796    
# Line 1351  is_config_protected() Line 1805  is_config_protected()
1805   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1806   return 3   return 3
1807   ;;   ;;
1808     IGNORED)
1809     #echo "I'm protected, but ignored - keep me, del update"
1810     return 4
1811     ;;
1812   *)   *)
1813   #echo "delete me"   #echo "delete me"
1814   return 0   return 0
# Line 1368  is_config_protected() Line 1826  is_config_protected()
1826  ###################################################  ###################################################
1827  count_protected_files()  count_protected_files()
1828  {  {
1829   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1830     local dirname="${file%/*}"
1831     local filename="${file##*/}"
1832     local count
1833     local output
1834     local oldprotected
1835     local i
1836     local x
1837    
1838     # hack; do not honor a global set IFS like '§'
1839     local IFS
1840    
1841     count=0
1842    
1843     # check if there are already protected files
1844     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1845     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1846     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1847     do
1848     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1849     done
1850    
1851     # convert 0001 -> 1; 0120 -> 120 etc
1852     # use bash internal base functions to this task
1853     x="$((10#${count}))"
1854     for (( i=0; i<x; i++ ))
1855     do
1856     if [[ ${count:${i}:1} != 0 ]]
1857     then
1858     count="${count:${i}}"
1859     break
1860     fi
1861     done
1862    
1863     count="$(( ${count}+1 ))"
1864    
1865     # fill output up with zeros
1866     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1867     output="${output}${count}"
1868    
1869     echo "${output}"
1870  }  }
1871    
1872  # call with  # call with
# Line 1385  get_uninstall_candidates() Line 1883  get_uninstall_candidates()
1883   local list   local list
1884   local pcatdir   local pcatdir
1885   local protected   local protected
1886     local i
1887    
1888   # very basic getops   # very basic getops
1889   for i in $*   for i in $*
# Line 1397  get_uninstall_candidates() Line 1896  get_uninstall_candidates()
1896   shift   shift
1897   done   done
1898    
1899   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1900   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1901    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1902    
1903    
1904   # check needed global vars   # check needed global vars
1905   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1906    
1907   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1908   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1909    
1910   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1911   do   do
# Line 1490  virtuals_add() Line 1990  virtuals_add()
1990   local oldline   local oldline
1991   local line i   local line i
1992   local installed_file   local installed_file
1993     local OLDIFS
1994    
1995   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1996   then   then
1997   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1998   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1999   do   do
2000   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 2013  virtuals_add()
2013   # make a backup   # make a backup
2014   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2015    
2016     OLDIFS="${IFS}"
2017   IFS=$'\n'   IFS=$'\n'
2018   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2019   do   do
# Line 1523  virtuals_add() Line 2025  virtuals_add()
2025   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2026   fi   fi
2027   done   done
2028     # unset IFS
2029   #unset IFS   IFS="${OLDIFS}"
2030   else   else
2031   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2032   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2033   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2034   fi   fi
# Line 1536  virtuals_add() Line 2038  virtuals_add()
2038    
2039  #deletes pakages from virtual database  #deletes pakages from virtual database
2040  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2041  virtuals_del() {  virtuals_del()
2042    {
2043    
2044   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2045     local pkgname="$2"
2046   VIRTUAL_NAME=$1   local oldline
2047   PKG_NAME=$2   local method
2048     local line i x
2049   #first check if exists   local pkg_installed
2050   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2051    
2052     # first check if exists
2053     if virtuals_read ${virtualname}
2054   then   then
2055   #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}
2056   declare -i x=0   declare -i x=0
2057   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2058   do   do
2059   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2060   then   then
2061   PKG_INSTALLED=true   pkg_installed=true
2062   fi   fi
2063   ((x++))   ((x++))
2064   done   done
2065    
2066   #abort if not installed   # abort if not installed
2067   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2068   then   then
2069   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2070     echo "${pkgname} does not exists in ${virtualname}."
2071   return 0   return 0
2072   fi   fi
2073    
2074   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2075   then   then
2076   METHOD=update   method=update
2077   else   else
2078   METHOD=delall   method=delall
2079   fi   fi
2080    
2081   #get the complete line   # get the complete line
2082   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2083    
2084   #make a backup   # make a backup of the db
2085   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2086    
2087   #parse virtualdb   # parse virtualdb
2088     OLDIFS="${IFS}"
2089   IFS=$'\n'   IFS=$'\n'
2090   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2091   do   do
2092   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2093   then   then
2094   #delall or update?   #delall or update?
2095   case ${METHOD} in   case ${method} in
2096   update)   update)
2097   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2098   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2099   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2100     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2101   ;;   ;;
2102   delall)   delall)
2103   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2104   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2105     # continue; do not write anything
2106   continue   continue
2107   ;;   ;;
2108   esac   esac
# Line 1600  virtuals_del() { Line 2110  virtuals_del() {
2110   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2111   fi   fi
2112   done   done
2113   unset IFS   # unset IFS
2114     IFS="${OLDIFS}"
2115   else   else
2116   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2117     echo "${virtualname} does not exists in virtual database."
2118   fi   fi
2119  }  }
2120    
# Line 1634  minclude() Line 2146  minclude()
2146  {  {
2147   local i   local i
2148    
2149   if [ -n "$@" ]   if [[ -n $* ]]
2150   then   then
2151   for i in $@   for i in $*
2152   do   do
2153   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2154   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2155   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2156   done   done
2157   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2158   fi   fi
2159  }  }
2160    
# Line 1650  sminclude() Line 2162  sminclude()
2162  {  {
2163   local i   local i
2164    
2165   if [ -n "$@" ]   if [[ -n $* ]]
2166   then   then
2167   for i in $@   for i in $*
2168   do   do
2169   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2170   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2171   done   done
2172   echo   [[ ${SILENT} = 1 ]] || echo
2173   fi   fi
2174  }  }
2175    
# Line 1676  is_newer_mage_version_available() Line 2188  is_newer_mage_version_available()
2188   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2189   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2190   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2191   echo "or your current system installation may brake."   echo "or your current system installation may break."
2192   echo   echo
2193   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2194   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1684  is_newer_mage_version_available() Line 2196  is_newer_mage_version_available()
2196   fi   fi
2197  }  }
2198    
   
2199  # returns pname from pkgname  # returns pname from pkgname
2200  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2201  pkgname2pname()  pkgname2pname()
# Line 1948  get_value_from_magefile() Line 2459  get_value_from_magefile()
2459   local magefile="$2"   local magefile="$2"
2460   local value   local value
2461    
2462     [[ -z ${var} ]] && return 1
2463     [[ -z ${magefile} ]] && return 1
2464    
2465   # local all possible vars of a mage file   # local all possible vars of a mage file
2466   # to prevent bad issues   # to prevent bad issues
2467   local PKGNAME   local PKGNAME
# Line 1958  get_value_from_magefile() Line 2472  get_value_from_magefile()
2472   local SDEPEND   local SDEPEND
2473   local PROVIDE   local PROVIDE
2474   local PKGTYPE   local PKGTYPE
2475     local SPLIT_PACKAGE_BASE
2476   local preinstall   local preinstall
2477   local postinstall   local postinstall
2478   local preremove   local preremove
# Line 2004  mage_install() Line 2519  mage_install()
2519   local count_current   local count_current
2520   local magefile   local magefile
2521   local src_install   local src_install
2522     local i
2523    
2524   # very basic getops   # very basic getops
2525   for i in $*   for i in $*
# Line 2077  mage_install() Line 2593  mage_install()
2593   echo B:${pbuild}   echo B:${pbuild}
2594   fi   fi
2595    
2596   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2597     then
2598     # basic svn compat
2599     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2600     then
2601     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2602     do
2603     smage2file="${i}"
2604     done
2605     else
2606     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2607     fi
2608    
2609     else
2610     # basic svn compat
2611     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2612     then
2613     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2614     do
2615     smage2file="${i}"
2616     done
2617     else
2618     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2619     fi
2620     fi
2621    
2622   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2623   then   then
2624     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2625   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2626   else   else
2627   echo   echo
# Line 2093  mage_install() Line 2635  mage_install()
2635   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2636   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2637   then   then
2638   # show a verbose message on src-install   unpack_package "${magefile}"
2639   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  
2640   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2641   fi   fi
2642    
# Line 2144  mage_install() Line 2680  mage_install()
2680   then   then
2681   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2682   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2683   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2684   echo "done." || echo "failure."   echo "done." || echo "failure."
2685   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2686   fi   fi
# Line 2188  md5sum_packages() Line 2724  md5sum_packages()
2724   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2725   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2726   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2727   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2728   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2729    
2730   (( count_current++ ))   (( count_current++ ))
# Line 2198  md5sum_packages() Line 2734  md5sum_packages()
2734   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2735   then   then
2736   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2737   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2738   continue   continue
2739   fi   fi
2740    
# Line 2206  md5sum_packages() Line 2742  md5sum_packages()
2742   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2743   then   then
2744   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2745   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2746   continue   continue
2747   fi   fi
2748    
# Line 2214  md5sum_packages() Line 2750  md5sum_packages()
2750   then   then
2751   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2752   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2753   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2754   else   else
2755   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2756   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2254  uninstall_packages() Line 2790  uninstall_packages()
2790   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2791   can_pcat="${pcat}"   can_pcat="${pcat}"
2792   can_pname="${pname}"   can_pname="${pname}"
2793    
2794   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2795   then   then
2796   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2357  mage_uninstall() Line 2893  mage_uninstall()
2893   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2894   echo -n "removing: "   echo -n "removing: "
2895   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2896   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2897    
2898   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2899   source ${magefile}   source ${magefile}
2900    
2901   ## preremove scripts   ## preremove scripts
# Line 2409  mage_uninstall() Line 2945  mage_uninstall()
2945   then   then
2946   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2947   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2948   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2949   echo "done." || echo "failure."   echo "done." || echo "failure."
2950   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2951   fi   fi
# Line 2427  mage_uninstall() Line 2963  mage_uninstall()
2963   unset -f postremove   unset -f postremove
2964  }  }
2965    
2966  show_etc_update_mesg() {  # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
2967    rerun_pkgfunctions()
2968    {
2969     local method
2970     local list
2971     local pcat
2972     local pname
2973     local pver
2974     local pbuild
2975     local magefile
2976     local i
2977    
2978     # very basic getops
2979     case $1 in
2980     --method) shift; method="$1" ;;
2981     esac
2982     shift
2983     local list="$@"
2984    
2985     # sanity check
2986     case ${method} in
2987     preinstall|postinstall) ;;
2988     preremove|postremove) ;;
2989     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
2990     esac
2991    
2992     if [[ -n ${MROOT} ]]
2993     then
2994     echo -ne ${COLRED}
2995     echo "!! running in MROOT=${MROOT}"
2996     echo -ne ${COLDEFAULT}
2997     echo
2998     fi
2999    
3000     for pkg in ${list}
3001     do
3002     pcat=$(dep2pcat ${pkg})
3003     pname=$(magename2pname ${pkg})
3004     pver=$(magename2pver ${pkg})
3005     pbuild=$(magename2pbuild ${pkg})
3006     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3007    
3008     if [ -e ${magefile} ]
3009     then
3010     source ${magefile}
3011     if [ -n "$(typeset -f ${method})" ]
3012     then
3013     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3014     ${method}
3015     else
3016     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3017     fi
3018     unset -f preinstall postinstall preremove postremove
3019     else
3020     die "Magefile '${magefile}' does not exist."
3021     fi
3022     done
3023    }
3024    
3025    show_etc_update_mesg()
3026    {
3027   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3028    
3029   echo   echo
# Line 2453  pkgsearch() Line 3049  pkgsearch()
3049   local state   local state
3050   local descriptiom   local descriptiom
3051   local homepage   local homepage
3052     local license
3053   local i   local i
3054   local all_installed   local all_installed
3055   local ipver   local ipver
3056   local ipbuild   local ipbuild
3057     local latest_available
3058     local depsfull
3059     local sdepsfull
3060     local deps
3061     local sdeps
3062     local dep
3063     local sign
3064    
3065   # only names no versions   # only names no versions
3066   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3067   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3068    
3069   # nothing found   # nothing found
3070   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2474  pkgsearch() Line 3078  pkgsearch()
3078   # get highest version available   # get highest version available
3079   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3080    
3081   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3082   pver="$(magename2pver ${magefile})"   then
3083   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3084   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3085   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3086   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3087     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3088     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3089     license="$(get_value_from_magefile LICENSE ${magefile})"
3090    
3091     # all installed
3092     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3093     do
3094     ipver="$(magename2pver ${i})"
3095     ipbuild="$(magename2pbuild ${i})"
3096    
3097     if [[ -z ${all_installed} ]]
3098     then
3099     all_installed="${ipver}-${ipbuild}"
3100     else
3101     all_installed="${all_installed} ${ipver}-${ipbuild}"
3102     fi
3103     done
3104     [[ -z ${all_installed} ]] && all_installed="none"
3105    
3106     case ${state} in
3107     stable) state=${COLGREEN}"[s] ";;
3108     testing) state=${COLYELLOW}"[t] ";;
3109     unstable) state=${COLRED}"[u] ";;
3110     old) state=${COLGRAY}"[o] ";;
3111     esac
3112    
3113     latest_available="${pver}-${pbuild}"
3114     else
3115     # package is masked
3116     state="${COLRED}[m] "
3117     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3118     fi
3119    
3120   # all installed   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3121   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3122    
3123     while read sign dep
3124   do   do
3125   ipver="$(magename2pver ${i})"   case ${dep} in
3126   ipbuild="$(magename2pbuild ${i})"   "") continue;;
3127     esac
3128    
3129   if [[ -z ${all_installed} ]]   if [[ -z ${deps} ]]
3130   then   then
3131   all_installed="${ipver}-${ipbuild}"   deps="$(basename ${dep%-*})"
3132   else   else
3133   all_installed="${all_installed} ${ipver}-${ipbuild}"   deps="${deps} $(basename ${dep%-*})"
3134   fi   fi
3135   done   done << EOF
3136   [[ -z ${all_installed} ]] && all_installed="none"  ${depsfull}
3137    EOF
3138    
3139   case ${state} in   while read sign dep
3140   stable) state=${COLGREEN}"[s] ";;   do
3141   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
3142   unstable) state=${COLRED}"[u] ";;   "") continue;;
3143   old) state=${COLGRAY}"[o] ";;   esac
3144   esac  
3145     if [[ -z ${sdeps} ]]
3146     then
3147     sdeps="$(basename ${dep%-*})"
3148     else
3149     sdeps="${sdeps} $(basename ${dep%-*})"
3150     fi
3151     done << EOF
3152    ${sdepsfull}
3153    EOF
3154    
3155   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3156   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3157   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3158   echo "      Description: ${description}"   echo "      Description: ${description}"
3159   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3160     if [[ ! -z ${license} ]]
3161     then
3162     echo "      License:  ${license}"
3163     fi
3164     echo "      Depends:  ${deps}"
3165     echo "      SDepends: ${sdeps}"
3166   echo   echo
3167    
3168   unset pcat   unset pcat
# Line 2521  pkgsearch() Line 3176  pkgsearch()
3176   unset all_installed   unset all_installed
3177   unset ipver   unset ipver
3178   unset ipbuild   unset ipbuild
3179     unset depsfull
3180     unset sdepsfull
3181     unset deps
3182     unset sdeps
3183     unset dep
3184     unset sign
3185   done   done
3186  }  }
3187    
# Line 2540  export_inherits() Line 3201  export_inherits()
3201   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3202    
3203   # debug   # debug
3204   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3205    
3206   shift   shift
3207   done   done
3208  }  }
3209    
3210    mlibdir()
3211    {
3212     local libdir=lib
3213     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3214    
3215     echo "${libdir}"
3216    }
3217    
3218    ## blacklisted ${magefile}
3219    blacklisted()
3220    {
3221     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3222    
3223     # compat
3224     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3225     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3226    
3227     # support both types for the moment
3228     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3229     then
3230     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3231     else
3232     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3233     fi
3234    
3235     # return 0 if the list not exist; nothin is masked
3236     [[ ! -f ${EXCLUDED} ]] && return 0
3237    
3238     local MAGEFILE="$1"
3239    
3240     local PCAT="$(magename2pcat ${MAGEFILE})"
3241     local PNAME="$(magename2pname ${MAGEFILE})"
3242     local PVER="$(magename2pver ${MAGEFILE})"
3243     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3244    
3245     local EXPCAT EXPNAME EXPVER EXPBUILD
3246     while read EXPCAT EXPNAME EXPVER EXPBUILD
3247     do
3248     # ignore spaces and comments
3249             case "${EXPCAT}" in
3250                     \#*|"") continue ;;
3251             esac
3252    
3253     # exclude full pver
3254     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3255     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3256     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3257     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3258     then
3259     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3260     fi
3261    
3262     # exclude pcat/pname only
3263     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3264     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3265     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3266     then
3267     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3268     fi
3269     done << EOF
3270    $( cat ${EXCLUDED}; echo)
3271    EOF
3272    
3273     return 0
3274    }
3275    
3276    # need_busybox_support ${cmd}
3277    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3278    need_busybox_support()
3279    {
3280     local cmd
3281     local busybox
3282     cmd="$1"
3283    
3284     for busybox in {,/usr}/bin/busybox
3285     do
3286     if [[ -x ${busybox} ]]
3287     then
3288     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3289     then
3290     # needs busybox support
3291     return 0
3292     fi
3293     fi
3294     done
3295    
3296     # no busybox
3297     return 1
3298    }
3299    
3300    # busybox_filter_wget_options ${wget_opts}
3301    busybox_filter_wget_options()
3302    {
3303     local opts="$@"
3304     local i
3305     local fixed_opts
3306    
3307     if need_busybox_support wget
3308     then
3309     for i in ${opts}
3310     do
3311     # show only the allowed ones
3312     case ${i} in
3313     -c|--continue) fixed_opts+=" -c" ;;
3314     -s|--spider) fixed_opts+=" -s" ;;
3315     -q|--quiet) fixed_opts+=" -q" ;;
3316     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3317     --header) shift; fixed_opts+=" --header $1" ;;
3318     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3319     -P) shift; fixed_opts+=" -P $1" ;;
3320     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3321     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3322     # simply drop all other opts
3323     *) continue ;;
3324     esac
3325     done
3326    
3327     echo "${fixed_opts}"
3328     else
3329     echo "${opts}"
3330     fi
3331    }
3332    
3333    have_root_privileges()
3334    {
3335     local retval
3336    
3337     if [[ $(id -u) = 0 ]]
3338     then
3339     retval=0
3340     else
3341     retval=1
3342     fi
3343    
3344     return ${retval}
3345    }
3346    
3347    known_mage_feature()
3348    {
3349     local feature="$1"
3350     local retval
3351    
3352     case "${feature}" in
3353     autosvc|!autosvc) retval=0 ;;
3354     buildlog|!buildlog) retval=0 ;;
3355     ccache|!ccache) retval=0 ;;
3356     check|!check) retval=0 ;;
3357     compressdoc|!compressdoc) retval=0 ;;
3358     debug|!debug) retval=0 ;;
3359     distcc|!distcc) retval=0 ;;
3360     icecc|!icecc) retval=0 ;;
3361     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3362     libtool|!libtool) retval=0 ;;
3363     linuxsymlink|!linuxsymlink) retval=0 ;;
3364     multilib|!multilib) reval=0 ;;
3365     pkgbuild|!pkgbuild) retval=0 ;;
3366     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3367     pkgmetadata|!pkgmetadata) retval=0 ;;
3368     purge|!purge) retval=0 ;;
3369     qalint|!qalint) retval=0 ;;
3370     regentree|!regentree) retval=0 ;;
3371     resume|!resume) retval=0 ;;
3372     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3373     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3374     static|!static) retval=0 ;;
3375     stepbystep|!stepbystep) retval=0 ;;
3376     strip|!strip) retval=0 ;;
3377     verbose|!verbose) retval=0 ;;
3378     *) retval=1 ;;
3379     esac
3380    
3381     return "${retval}"
3382    }
3383    
3384    load_mage_features()
3385    {
3386     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3387     do
3388     FVERBOSE=off msetfeature ${i}
3389     done
3390    }
3391    
3392    msetfeature()
3393    {
3394     local feature
3395     local count
3396     local i
3397     local found
3398    
3399     for feature in $@
3400     do
3401     found=0
3402     count="${#MAGE_FEATURES_CURRENT[*]}"
3403    
3404     if ! known_mage_feature "${feature}"
3405     then
3406     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3407     return 3
3408     fi
3409    
3410     for ((i=0; i<count; i++))
3411     do
3412     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3413     then
3414     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3415     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3416     found=1
3417     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3418     then
3419     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3420     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3421     found=1
3422     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3423     then
3424     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3425     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3426     found=1
3427     fi
3428     done
3429    
3430     # if the feature was not found after proccessing the whole array
3431     # it was not declared. in this case enable it
3432     if [[ ${found} = 0 ]]
3433     then
3434     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3435     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3436     fi
3437    
3438     export MAGE_FEATURES_CURRENT
3439     done
3440    }
3441    
3442    mqueryfeature()
3443    {
3444     local feature="$1"
3445     local retval=1
3446     local i
3447    
3448     if known_mage_feature "${feature}"
3449     then
3450     for i in ${MAGE_FEATURES_CURRENT[*]}
3451     do
3452     if [[ ${i} = ${feature} ]]
3453     then
3454     retval=0
3455     break # found break here
3456     fi
3457     done
3458     else
3459     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3460     retval=3
3461     fi
3462    
3463     return ${retval}
3464    }
3465    
3466    mprintfeatures()
3467    {
3468     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3469     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3470     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3471    }

Legend:
Removed from v.258  
changed lines
  Added in v.2868