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 248 by niro, Tue Sep 27 14:38:01 2005 UTC branches/mage-next/src/mage4.functions.sh.in revision 2720 by niro, Tue Jul 22 14:17:53 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.4 2005-09-27 14:38:01 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 $1 in
772     --pcat|-c) shift; pcat="$1" ;;
773     --pname|-n) shift; pname="$1" ;;
774     esac
775     shift
776     done
777    
778     # sanity checks; abort if not given
779     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
780     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
781    
782     declare -i i=0
783     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
784     do
785     (( i++ ))
786     #echo "$i ${pkg}"
787     done
788    
789     # return the value
790     echo "${i}"
791    }
792    
793    
794  ###################################################  ###################################################
795  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  compare_mtime() Line 811  compare_mtime()
811    
812   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
813    
814   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
815   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
816   then   x=$(stat -c %Y "${MROOT}${pathto}")
  # readlink -f resolves full path of linked file  
  x="$(readlink -f "${MROOT}${pathto}")"  
   
  # abort if target does not exists  
  # we keep safe here, theoretically the link can removed  
  [ ! -e "${x}" ] && return 1  
   
  x=$(stat -c %Y "${x}")  
  else  
  x=$(stat -c %Y "${MROOT}${pathto}")  
  fi  
817    
818   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
819    
# Line 662  remove_symlinks() Line 875  remove_symlinks()
875   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
876   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
877   then   then
878   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
879   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
880   continue   continue
881   fi   fi
# Line 674  remove_symlinks() Line 887  remove_symlinks()
887   # 1=keep me   #   # 1=keep me   #
888   case ${retval} in   case ${retval} in
889   0)   0)
890   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
891   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
892   ;;   ;;
893    
894   1)   1)
895   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
896   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
897   ;;   ;;
898   esac   esac
# Line 726  remove_files() Line 939  remove_files()
939   done   done
940    
941   # sanity checks; abort if not given   # sanity checks; abort if not given
942   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
943   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
944   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
945   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
946   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
947    
948   # check needed global vars   # check needed global vars
# Line 746  remove_files() Line 959  remove_files()
959    
960   if [ ! -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
961   then   then
962   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
963   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
964   continue   continue
965   fi   fi
# Line 758  remove_files() Line 971  remove_files()
971   # 1=keep me   #   # 1=keep me   #
972   case ${retval} in   case ${retval} in
973   0)   0)
974   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
975   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
976   ;;   is_config_protected "${pathto}"
977     retval="$?"
978    
979     # 0 - not protected         #
980     # 1 - error                 #
981     # 2 - protected             #
982     # 3 - protected but masked  #
983     # 4 - protected but ignored #
984    
985     case ${retval} in
986     # file is not protected - delete it
987     0|3)
988     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
989     rm "${MROOT}${pathto}"
990     ;;
991    
992     # file is protected, do not delete
993     2)
994     if mqueryfeature "verbose"
995     then
996     echo -en "${COLRED}"
997     echo -n "! prot "
998     echo -en "${COLDEFAULT}"
999     echo " === FILE: ${MROOT}${pathto}"
1000     fi
1001     ;;
1002    
1003     # file is protected but ignored, delete the update/do nothing
1004     4)
1005     if mqueryfeature "verbose"
1006     then
1007     echo -en "${COLRED}"
1008     echo -n "! ignr "
1009     echo -en "${COLDEFAULT}"
1010     echo " === FILE: ${MROOT}${pathto}"
1011     fi
1012     # simply do nothing here
1013     ;;
1014     esac
1015     ;;
1016   1)   1)
1017   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1018   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1019   ;;   ;;
1020   esac   esac
# Line 782  remove_blockdevices() Line 1033  remove_blockdevices()
1033  {  {
1034   local pathto   local pathto
1035   local posix   local posix
1036     local user
1037     local group
1038   local IFS   local IFS
1039   local pcat   local pcat
1040   local pname   local pname
# Line 805  remove_blockdevices() Line 1058  remove_blockdevices()
1058   done   done
1059    
1060   # sanity checks; abort if not given   # sanity checks; abort if not given
1061   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1062   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1063   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1064   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1065   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1066    
1067   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1072  remove_blockdevices()
1072   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1073   IFS=§   IFS=§
1074    
1075   while read pathto posix   while read pathto posix user group
1076   do   do
1077   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1078    
1079   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1080   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1081   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1082    
# Line 840  remove_characterdevices() Line 1093  remove_characterdevices()
1093  {  {
1094   local pathto   local pathto
1095   local posix   local posix
1096     local user
1097     local group
1098   local IFS   local IFS
1099   local pcat   local pcat
1100   local pname   local pname
# Line 863  remove_characterdevices() Line 1118  remove_characterdevices()
1118   done   done
1119    
1120   # sanity checks; abort if not given   # sanity checks; abort if not given
1121   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1122   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1123   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1124   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1125   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1126    
1127   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1132  remove_characterdevices()
1132   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1133   IFS=§   IFS=§
1134    
1135   while read pathto posix   while read pathto posix user group
1136   do   do
1137   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1138    
1139   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1140   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1141   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1142    
# Line 891  remove_characterdevices() Line 1146  remove_characterdevices()
1146    
1147    
1148  ###################################################  ###################################################
1149    # function remove_fifos                           #
1150    # remove_fifos $PKGNAME                     #
1151    ###################################################
1152    remove_fifos()
1153    {
1154     local pathto
1155     local posix
1156     local user
1157     local group
1158     local IFS
1159     local pcat
1160     local pname
1161     local pver
1162     local pbuild
1163     local i
1164     local pfull
1165    
1166     IFS=$'\n'
1167    
1168     # very basic getops
1169     for i in $*
1170     do
1171     case $1 in
1172     --pcat|-c) shift; pcat="$1" ;;
1173     --pname|-n) shift; pname="$1" ;;
1174     --pver|-v) shift; pver="$1" ;;
1175     --pbuild|-b) shift; pbuild="$1" ;;
1176     esac
1177     shift
1178     done
1179    
1180     # sanity checks; abort if not given
1181     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1182     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1183     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1184     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1185     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1186    
1187     # check needed global vars
1188     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1189    
1190     # make it optional atm !!
1191     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1192     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1193    
1194     # sets fieldseperator to "§" instead of " "
1195     IFS=§
1196    
1197     while read pathto posix user group
1198     do
1199     [ -z "${pathto}" ] && continue
1200    
1201     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1202     rm "${MROOT}${pathto}"
1203     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1204    
1205     # very important: unsetting the '§' fieldseperator
1206     IFS=$'\n'
1207    }
1208    
1209    
1210    ###################################################
1211  # function remove_direcories                      #  # function remove_direcories                      #
1212  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1213  ###################################################  ###################################################
# Line 921  remove_directories() Line 1238  remove_directories()
1238   done   done
1239    
1240   # sanity checks; abort if not given   # sanity checks; abort if not given
1241   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1242   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1243   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1244   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1245   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1246    
1247   # check needed global vars   # check needed global vars
# Line 942  remove_directories() Line 1259  remove_directories()
1259    
1260   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1261   then   then
1262   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1263   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1264   continue   continue
1265   fi   fi
# Line 950  remove_directories() Line 1267  remove_directories()
1267   # exclude .keep directories   # exclude .keep directories
1268   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1269   then   then
1270   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1271   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1272   continue   continue
1273   fi   fi
# Line 963  remove_directories() Line 1280  remove_directories()
1280    
1281   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1282   then   then
1283   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1284   else   else
1285   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1286   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1287   fi   fi
1288   done   done
# Line 978  remove_directories() Line 1295  remove_directories()
1295  ###################################################  ###################################################
1296  # function build_douninstall                      #  # function build_douninstall                      #
1297  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1298  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1299  ###################################################  ###################################################
1300  build_douninstall()  build_douninstall()
1301  {  {
# Line 1012  build_douninstall() Line 1329  build_douninstall()
1329   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1330   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1331    
1332   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1333   do   do
1334   remove_${i} \   remove_${i} \
1335   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1023  build_douninstall() Line 1340  build_douninstall()
1340   done   done
1341  }  }
1342    
1343    # convertmirrors [uri]
1344    convertmirrors()
1345    {
1346     local uri="$1"
1347     local scheme
1348     local mirror
1349     local mirrors
1350     local addon
1351     local real_uri
1352     local output
1353    
1354     # needs
1355     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1356     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1357     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1358     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1359     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1360    
1361     # check known uri schemes
1362     case ${uri} in
1363     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1364     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1365     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1366     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1367     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1368     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1369     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1370     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1371     esac
1372    
1373     if [[ ! -z ${mirrors} ]]
1374     then
1375     for mirror in ${mirrors}
1376     do
1377     # add a whitespace to the output
1378     [[ -z ${output} ]] || output+=" "
1379     output+="${mirror}${addon}/${uri/${scheme}/}"
1380     done
1381     else
1382     output="${uri}"
1383     fi
1384    
1385     echo "${output}"
1386    }
1387    
1388    mdownload()
1389    {
1390     local i
1391     local uri
1392     local real_uris
1393     local mirror
1394     local outputfile
1395     local outputdir
1396     local retval
1397     local wget_opts
1398    
1399     # very basic getops
1400     for i in $*
1401     do
1402     case $1 in
1403     --uri|-u) shift; uri="$1" ;;
1404     --dir|-d) shift; outputdir="$1" ;;
1405     esac
1406     shift
1407     done
1408    
1409     # sanity checks; abort if not given
1410     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1411     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1412    
1413     # convert mirrored uris to the real ones
1414     real_uris="$(convertmirrors ${uri})"
1415    
1416     # verbose or not
1417     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1418    
1419     # filter wget options if busybox was found
1420     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1421    
1422     # create outputdir
1423     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1424    
1425     for mirror in ${real_uris}
1426     do
1427     # get the name of the output file
1428     outputfile="${mirror##*/}"
1429    
1430     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1431     retval="$?"
1432     if [[ ${retval} = 0 ]]
1433     then
1434     break
1435     else
1436     continue
1437     fi
1438     done
1439    
1440     # return wget retval
1441     return "${retval}"
1442    }
1443    
1444  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1445  fetch_packages()  fetch_packages()
1446  {  {
1447     local i
1448   local list="$@"   local list="$@"
1449   local pkg   local pkgname
1450     local pkgfile
1451     local pcat
1452     local pname
1453   local mirr   local mirr
1454   local magefile   local magefile
1455   local md5file   local md5file
1456   local opt   local opt
1457   local count_current   local count_current
1458   local count_total   local count_total
1459     local wget_opts
1460     local fetching
1461    
1462     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1463    
1464   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1465     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1466    
1467   # get count of total packages   # get count of total packages
1468   declare -i count_current=0   declare -i count_current=0
# Line 1045  fetch_packages() Line 1472  fetch_packages()
1472    
1473   for magefile in ${list}   for magefile in ${list}
1474   do   do
1475   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1476     pkgfile="${pkgname}.${PKGSUFFIX}"
1477   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1478    
1479     pcat=$(magename2pcat ${magefile})
1480     pname=$(magename2pname ${magefile})
1481     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1482    
1483   (( count_current++ ))   (( count_current++ ))
1484   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1485    
1486   # abort on virtual pkg   # abort on virtual pkg
1487   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1488   then   then
1489   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1490   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1491   continue   continue
1492   fi   fi
1493    
# Line 1063  fetch_packages() Line 1495  fetch_packages()
1495   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1496   then   then
1497   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1498   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1499   continue   continue
1500   fi   fi
1501    
1502   # abort if already exist   # check if FETCHING is required
1503   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1504   then   then
1505   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1506   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1507   continue   if mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 &> /dev/null
  fi  
   
  for mirr in ${MIRRORS}  
  do  
  echo -ne " ${COLBLUE}***${COLDEFAULT}"  
  #echo -e " fetching (${count_current}/${count_total}): ${mirr}/${pkg} ... "  
  echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "  
  [[ ${VERBOSE} = off ]] && opt="--quiet"  
  wget \  
  --passive-ftp \  
  --tries 3 \  
  --continue \  
  --progress bar \  
  --directory-prefix=${PKGDIR} \  
  ${opt} ${mirr}/packages/${pkg}  
  if [[ $? = 0 ]]  
1508   then   then
1509   break   # md5's ok, no fetching required
1510     fetching=false
1511   else   else
1512   continue   fetching=true
1513   fi   fi
1514   done   fi
1515    
1516   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1517   then   then
1518   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1519     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1520     continue
1521     else
1522     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1523     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1524     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1525     fi
1526    
1527     # sanity check, not really needed but to be sure
1528     if [ ! -f ${PKGDIR}/${pkgfile} ]
1529     then
1530     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1531   fi   fi
1532   done   done
1533    
# Line 1110  syncmage() Line 1539  syncmage()
1539  {  {
1540   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1541   then   then
1542   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1543   fi   fi
1544    
1545   local i   local i
1546   for i in ${RSYNC}   for i in ${RSYNC}
1547   do   do
1548   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1549   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1550   then   then
1551   break   break
# Line 1139  syncmage() Line 1555  syncmage()
1555   done   done
1556    
1557   # clean up backup files (foo~)   # clean up backup files (foo~)
1558   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1559    
1560   # check if an newer mage version is available   # check if a newer mage version is available
1561   is_newer_mage_version_available   is_newer_mage_version_available
1562  }  }
1563    
1564  cleanpkg()  syncmage_tarball()
1565  {  {
1566   if [ -d "${PKGDIR}" ]   local latest_tarball
1567   then   local latest_md5
1568   echo -n "Removing downloaded packages... "   local temp="$(mktemp -d)"
1569   rm -rf ${PKGDIR}/*   local mirr mymirr
1570   echo "done."   local opt
1571   fi   local tar_opts
1572  }   local wget_opts
1573    
1574  xtitle()   # try to get the md5 marked as latest on the server
1575  {   latest_md5="mage-latest.md5"
  if [[ ${TERM} = xterm ]]  
  then  
  echo -ne "\033]0;Mage: $1\007"  
  fi  
  return 0  
 }  
1576    
1577     # try to get the tarball marked as latest on the server
1578     latest_tarball="mage-latest.tar.bz2"
1579    
1580  xtitleclean()   # filter wget command if busybox was found
1581  {   wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1582   if [[ ${TERM} = xterm ]]  
1583     for mirr in ${MIRRORS}
1584     do
1585     # path without distribution
1586     # (only for stable|testing|unstable and not DISTROTAG)
1587     case ${mirr##*/} in
1588     stable|testing|unstable) mymirr="${mirr%/*}";;
1589     *) mymirr="${mirr}";;
1590     esac
1591    
1592     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1593     echo "fetching latest md5 from ${mymirr} ..."
1594     mqueryfeature "!verbose" && opt="--quiet"
1595     wget \
1596     ${wget_opts} \
1597     --directory-prefix=${temp} \
1598     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1599    
1600     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1601     echo "fetching latest tarball from ${mymirr} ..."
1602     wget \
1603     ${wget_opts} \
1604     --directory-prefix=${temp} \
1605     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1606     if [[ $? = 0 ]]
1607     then
1608     break
1609     else
1610     continue
1611     fi
1612     done
1613    
1614     if [[ -f ${temp}/${latest_tarball} ]]
1615   then   then
1616   echo -ne "\033]0;\007"   # check md5
1617     if [[ ! -f ${temp}/${latest_md5} ]]
1618     then
1619     die "md5 is missing ... aborting"
1620     else
1621     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1622     echo -n "checking md5sum... "
1623     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1624     fi
1625    
1626     if [[ -d ${MAGEDIR} ]]
1627     then
1628     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1629     echo "cleaning old mage-tree ${MAGEDIR}..."
1630     # honor mountpoints and empty dirs
1631     if mountpoint -q ${MAGEDIR}
1632     then
1633     if ! mcheckemptydir ${MAGEDIR}
1634     then
1635     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1636     fi
1637     else
1638     rm -rf ${MAGEDIR}
1639     fi
1640     fi
1641    
1642     if need_busybox_support tar
1643     then
1644     tar_opts="xjf"
1645     else
1646     tar_opts="xjmf"
1647     fi
1648    
1649     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1650     echo "updating mage-tree from tarball ..."
1651     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1652     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1653    
1654     if [[ -d ${temp} ]]
1655     then
1656     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1657     echo "cleaning temp-files ..."
1658     rm -rf ${temp}
1659     fi
1660    
1661     # check if a newer mage version is available
1662     is_newer_mage_version_available
1663     else
1664     die "Could not fetch the latest tarball ... aborting"
1665   fi   fi
  return 0  
1666  }  }
1667    
1668    cleanpkg()
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
1669  {  {
1670   #we want this only if full name was used   if [ -d "${PKGDIR}" ]
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
1671   then   then
1672   #cuts ARCH and PBUILD   echo -n "Removing downloaded packages... "
1673   #ARCH comes from /etc/mage.rc   rm -rf ${PKGDIR}/*
1674   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   echo "done."
   
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
1675   fi   fi
1676  }  }
1677    
1678    # unused?
1679    #
1680    # # cuts full pathnames or versionized names down to basename
1681    # choppkgname()
1682    # {
1683    # #we want this only if full name was used
1684    # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1685    # then
1686    # #cuts ARCH and PBUILD
1687    # #ARCH comes from ${MAGERC}
1688    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1689    #
1690    # #cuts version number
1691    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1692    # fi
1693    # }
1694    
1695    
1696  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1697  # $1=pname  # $1=pname
1698  # ret 0=ok, 1=not_found  # ret 0=ok, 1=not_found
# Line 1215  pname2pcat() Line 1718  pname2pcat()
1718  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1719  check_stable_package()  check_stable_package()
1720  {  {
1721     # first check if this magefile is not blacklisted
1722     blacklisted "$1" || return 1
1723    
1724   local STATE   local STATE
1725   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1726    
1727   # state testing   # state testing
1728   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1729   then   then
1730   case ${STATE} in   case ${STATE} in
1731   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1734  check_stable_package()
1734   fi   fi
1735    
1736   # state unstable   # state unstable
1737   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1738   then   then
1739   case ${STATE} in   case ${STATE} in
1740   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1254  get_highest_magefile() Line 1760  get_highest_magefile()
1760   local PNAME="$2"   local PNAME="$2"
1761   local magefile   local magefile
1762    
1763   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1764     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1765   do   do
1766     [[ -z ${magefile} ]] && continue
1767   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1768   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1769   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1770   then   then
1771   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1772   #for debug only   #for debug only
1773   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1774   fi   fi
1775   done   done
1776    
  # stop here if HIGHEST_MAGEFILE is zero  
  # this package must be unstable or old  
  if [ -z "${HIGHEST_MAGEFILE}" ]  
  then  
  echo  
  echo -n "All packages named "  
  echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  
  echo -n " are marked "  
  echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  
  echo "."  
  echo "You need to declare USE_UNSTABLE=true to install this."  
  echo  
  echo "Example:"  
  echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  
  echo  
  echo "Be warned that these packages are not stable and may cause serious problems."  
  echo "You should know what you are doing, so don't complain about any damage."  
  echo  
  return 1  
  fi  
   
1777   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1778   return 0   return 0
1779  }  }
# Line 1301  get_highest_magefile() Line 1788  get_highest_magefile()
1788  #        1 - error                                #  #        1 - error                                #
1789  #        2 - protected                            #  #        2 - protected                            #
1790  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1791    #        4 - protected but ignored                #
1792  #                                                 #  #                                                 #
1793  ###################################################  ###################################################
1794  is_config_protected()  is_config_protected()
# Line 1309  is_config_protected() Line 1797  is_config_protected()
1797   local TEST   local TEST
1798   local PROTECTED   local PROTECTED
1799   local IFS   local IFS
1800     local i
1801     local x
1802    
1803   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1804    
1805   # file does not exist; it can be written   # file does not exist; it can be written
1806   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1807    
1808   # to be safe; it may be '§'   # to be safe; it may be '§'
1809   IFS=' '   IFS=' '
1810    
1811   # check ob in config protect   # check if config protected
1812   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1813   do   do
1814   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1815   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1816   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1817   then   then
1818   # setzen das es protected ist   # file is config proteced
1819   PROTECTED=TRUE   PROTECTED=TRUE
1820    
1821   # check ob nicht doch maskiert   # check if not masked
1822   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1823   do   do
1824   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1825   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1826     then
1827     PROTECTED=MASKED
1828     fi
1829     done
1830    
1831     # check if not ignored
1832     for x in ${CONFIG_PROTECT_IGNORE}
1833     do
1834     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1835     if [[ ${TEST} != ${EXPFILE} ]]
1836   then   then
1837   PROTECTED=MASKED   PROTECTED=IGNORED
1838   fi   fi
1839   done   done
1840   fi   fi
# Line 1351  is_config_protected() Line 1851  is_config_protected()
1851   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1852   return 3   return 3
1853   ;;   ;;
1854     IGNORED)
1855     #echo "I'm protected, but ignored - keep me, del update"
1856     return 4
1857     ;;
1858   *)   *)
1859   #echo "delete me"   #echo "delete me"
1860   return 0   return 0
# Line 1368  is_config_protected() Line 1872  is_config_protected()
1872  ###################################################  ###################################################
1873  count_protected_files()  count_protected_files()
1874  {  {
1875   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1876     local dirname="${file%/*}"
1877     local filename="${file##*/}"
1878     local count
1879     local output
1880     local oldprotected
1881     local i
1882     local x
1883    
1884     # hack; do not honor a global set IFS like '§'
1885     local IFS
1886    
1887     count=0
1888    
1889     # check if there are already protected files
1890     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1891     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1892     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1893     do
1894     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1895     done
1896    
1897     # convert 0001 -> 1; 0120 -> 120 etc
1898     # use bash internal base functions to this task
1899     x="$((10#${count}))"
1900     for (( i=0; i<x; i++ ))
1901     do
1902     if [[ ${count:${i}:1} != 0 ]]
1903     then
1904     count="${count:${i}}"
1905     break
1906     fi
1907     done
1908    
1909     count="$(( ${count}+1 ))"
1910    
1911     # fill output up with zeros
1912     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1913     output="${output}${count}"
1914    
1915     echo "${output}"
1916  }  }
1917    
1918  # call with  # call with
# Line 1385  get_uninstall_candidates() Line 1929  get_uninstall_candidates()
1929   local list   local list
1930   local pcatdir   local pcatdir
1931   local protected   local protected
1932     local i
1933    
1934   # very basic getops   # very basic getops
1935   for i in $*   for i in $*
# Line 1397  get_uninstall_candidates() Line 1942  get_uninstall_candidates()
1942   shift   shift
1943   done   done
1944    
1945   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1946   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1947    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1948    
1949    
1950   # check needed global vars   # check needed global vars
1951   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1952    
1953   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1954   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1955    
1956   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1957   do   do
# Line 1490  virtuals_add() Line 2036  virtuals_add()
2036   local oldline   local oldline
2037   local line i   local line i
2038   local installed_file   local installed_file
2039     local OLDIFS
2040    
2041   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2042   then   then
2043   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2044   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2045   do   do
2046   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 2059  virtuals_add()
2059   # make a backup   # make a backup
2060   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2061    
2062     OLDIFS="${IFS}"
2063   IFS=$'\n'   IFS=$'\n'
2064   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2065   do   do
# Line 1523  virtuals_add() Line 2071  virtuals_add()
2071   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2072   fi   fi
2073   done   done
2074     # unset IFS
2075   #unset IFS   IFS="${OLDIFS}"
2076   else   else
2077   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2078   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2079   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2080   fi   fi
# Line 1536  virtuals_add() Line 2084  virtuals_add()
2084    
2085  #deletes pakages from virtual database  #deletes pakages from virtual database
2086  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2087  virtuals_del() {  virtuals_del()
2088    {
2089    
2090   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2091     local pkgname="$2"
2092   VIRTUAL_NAME=$1   local oldline
2093   PKG_NAME=$2   local method
2094     local line i x
2095   #first check if exists   local pkg_installed
2096   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2097    
2098     # first check if exists
2099     if virtuals_read ${virtualname}
2100   then   then
2101   #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}
2102   declare -i x=0   declare -i x=0
2103   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2104   do   do
2105   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2106   then   then
2107   PKG_INSTALLED=true   pkg_installed=true
2108   fi   fi
2109   ((x++))   ((x++))
2110   done   done
2111    
2112   #abort if not installed   # abort if not installed
2113   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2114   then   then
2115   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2116     echo "${pkgname} does not exists in ${virtualname}."
2117   return 0   return 0
2118   fi   fi
2119    
2120   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2121   then   then
2122   METHOD=update   method=update
2123   else   else
2124   METHOD=delall   method=delall
2125   fi   fi
2126    
2127   #get the complete line   # get the complete line
2128   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2129    
2130   #make a backup   # make a backup of the db
2131   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2132    
2133   #parse virtualdb   # parse virtualdb
2134     OLDIFS="${IFS}"
2135   IFS=$'\n'   IFS=$'\n'
2136   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2137   do   do
2138   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2139   then   then
2140   #delall or update?   #delall or update?
2141   case ${METHOD} in   case ${method} in
2142   update)   update)
2143   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2144   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2145   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2146     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2147   ;;   ;;
2148   delall)   delall)
2149   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2150   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2151     # continue; do not write anything
2152   continue   continue
2153   ;;   ;;
2154   esac   esac
# Line 1600  virtuals_del() { Line 2156  virtuals_del() {
2156   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2157   fi   fi
2158   done   done
2159   unset IFS   # unset IFS
2160     IFS="${OLDIFS}"
2161   else   else
2162   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2163     echo "${virtualname} does not exists in virtual database."
2164   fi   fi
2165  }  }
2166    
# Line 1634  minclude() Line 2192  minclude()
2192  {  {
2193   local i   local i
2194    
2195   if [ -n "$@" ]   if [[ -n $* ]]
2196   then   then
2197   for i in $@   for i in $*
2198   do   do
2199   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2200   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2201   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2202   done   done
2203   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2204   fi   fi
2205  }  }
2206    
# Line 1650  sminclude() Line 2208  sminclude()
2208  {  {
2209   local i   local i
2210    
2211   if [ -n "$@" ]   if [[ -n $* ]]
2212   then   then
2213   for i in $@   for i in $*
2214   do   do
2215   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2216   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2217   done   done
2218   echo   [[ ${SILENT} = 1 ]] || echo
2219   fi   fi
2220  }  }
2221    
# Line 1667  is_newer_mage_version_available() Line 2225  is_newer_mage_version_available()
2225   local newest_mage   local newest_mage
2226   local installed_mage   local installed_mage
2227    
2228   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2229   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2230    
2231   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1676  is_newer_mage_version_available() Line 2234  is_newer_mage_version_available()
2234   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2235   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2236   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2237   echo "or your current system installation may brake."   echo "or your current system installation may break."
2238   echo   echo
2239   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2240   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1684  is_newer_mage_version_available() Line 2242  is_newer_mage_version_available()
2242   fi   fi
2243  }  }
2244    
   
2245  # returns pname from pkgname  # returns pname from pkgname
2246  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2247  pkgname2pname()  pkgname2pname()
# Line 1948  get_value_from_magefile() Line 2505  get_value_from_magefile()
2505   local magefile="$2"   local magefile="$2"
2506   local value   local value
2507    
2508     [[ -z ${var} ]] && return 1
2509     [[ -z ${magefile} ]] && return 1
2510    
2511   # local all possible vars of a mage file   # local all possible vars of a mage file
2512   # to prevent bad issues   # to prevent bad issues
2513   local PKGNAME   local PKGNAME
# Line 1958  get_value_from_magefile() Line 2518  get_value_from_magefile()
2518   local SDEPEND   local SDEPEND
2519   local PROVIDE   local PROVIDE
2520   local PKGTYPE   local PKGTYPE
2521     local SPLIT_PACKAGE_BASE
2522   local preinstall   local preinstall
2523   local postinstall   local postinstall
2524   local preremove   local preremove
# Line 1972  get_value_from_magefile() Line 2533  get_value_from_magefile()
2533   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2534   echo "${value}"   echo "${value}"
2535    
2536   unset preinstall   # unset these functions
2537   unset postinstall   unset -f preinstall
2538   unset preremove   unset -f postinstall
2539   unset postremove   unset -f preremove
2540     unset -f postremove
2541  }  }
2542    
2543  mage_install()  mage_install()
# Line 2003  mage_install() Line 2565  mage_install()
2565   local count_current   local count_current
2566   local magefile   local magefile
2567   local src_install   local src_install
2568     local i
2569    
2570   # very basic getops   # very basic getops
2571   for i in $*   for i in $*
# Line 2076  mage_install() Line 2639  mage_install()
2639   echo B:${pbuild}   echo B:${pbuild}
2640   fi   fi
2641    
2642   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2643     then
2644     # basic svn compat
2645     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2646     then
2647     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2648     do
2649     smage2file="${i}"
2650     done
2651     else
2652     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2653     fi
2654    
2655     else
2656     # basic svn compat
2657     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2658     then
2659     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2660     do
2661     smage2file="${i}"
2662     done
2663     else
2664     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2665     fi
2666     fi
2667    
2668   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2669   then   then
2670     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2671   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2672   else   else
2673   echo   echo
# Line 2092  mage_install() Line 2681  mage_install()
2681   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2682   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2683   then   then
2684   # show a verbose message on src-install   unpack_package "${magefile}"
2685   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  
2686   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2687   fi   fi
2688    
# Line 2143  mage_install() Line 2726  mage_install()
2726   then   then
2727   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2728   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2729   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2730   echo "done." || echo "failure."   echo "done." || echo "failure."
2731   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2732   fi   fi
# Line 2156  mage_install() Line 2739  mage_install()
2739  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2740   echo "successfully installed."   echo "successfully installed."
2741    
2742   unset preinstall   # unset these functions
2743   unset postinstall   unset -f preinstall
2744   unset preremove   unset -f postinstall
2745   unset postremove   unset -f preremove
2746     unset -f postremove
2747  }  }
2748    
2749  md5sum_packages()  md5sum_packages()
# Line 2186  md5sum_packages() Line 2770  md5sum_packages()
2770   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2771   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2772   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2773   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2774   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2775    
2776   (( count_current++ ))   (( count_current++ ))
# Line 2196  md5sum_packages() Line 2780  md5sum_packages()
2780   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2781   then   then
2782   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2783   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2784   continue   continue
2785   fi   fi
2786    
# Line 2204  md5sum_packages() Line 2788  md5sum_packages()
2788   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2789   then   then
2790   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2791   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2792   continue   continue
2793   fi   fi
2794    
# Line 2212  md5sum_packages() Line 2796  md5sum_packages()
2796   then   then
2797   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2798   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2799   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2800   else   else
2801   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2802   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2252  uninstall_packages() Line 2836  uninstall_packages()
2836   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2837   can_pcat="${pcat}"   can_pcat="${pcat}"
2838   can_pname="${pname}"   can_pname="${pname}"
2839    
2840   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2841   then   then
2842   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2355  mage_uninstall() Line 2939  mage_uninstall()
2939   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2940   echo -n "removing: "   echo -n "removing: "
2941   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2942   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2943    
2944   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2945   source ${magefile}   source ${magefile}
2946    
2947   ## preremove scripts   ## preremove scripts
# Line 2407  mage_uninstall() Line 2991  mage_uninstall()
2991   then   then
2992   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2993   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2994   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2995   echo "done." || echo "failure."   echo "done." || echo "failure."
2996   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2997   fi   fi
# Line 2418  mage_uninstall() Line 3002  mage_uninstall()
3002  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3003   echo "successfully removed."   echo "successfully removed."
3004    
3005   unset preinstall   # unset these functions
3006   unset postinstall   unset -f preinstall
3007   unset preremove   unset -f postinstall
3008   unset postremove   unset -f preremove
3009     unset -f postremove
3010    }
3011    
3012    # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3013    rerun_pkgfunctions()
3014    {
3015     local method
3016     local list
3017     local pcat
3018     local pname
3019     local pver
3020     local pbuild
3021     local magefile
3022     local i
3023    
3024     # very basic getops
3025     case $1 in
3026     --method) shift; method="$1" ;;
3027     esac
3028     shift
3029     local list="$@"
3030    
3031     # sanity check
3032     case ${method} in
3033     preinstall|postinstall) ;;
3034     preremove|postremove) ;;
3035     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3036     esac
3037    
3038     if [[ -n ${MROOT} ]]
3039     then
3040     echo -ne ${COLRED}
3041     echo "!! running in MROOT=${MROOT}"
3042     echo -ne ${COLDEFAULT}
3043     echo
3044     fi
3045    
3046     for pkg in ${list}
3047     do
3048     pcat=$(dep2pcat ${pkg})
3049     pname=$(magename2pname ${pkg})
3050     pver=$(magename2pver ${pkg})
3051     pbuild=$(magename2pbuild ${pkg})
3052     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3053    
3054     if [ -e ${magefile} ]
3055     then
3056     source ${magefile}
3057     if [ -n "$(typeset -f ${method})" ]
3058     then
3059     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3060     ${method}
3061     else
3062     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3063     fi
3064     unset -f preinstall postinstall preremove postremove
3065     else
3066     die "Magefile '${magefile}' does not exist."
3067     fi
3068     done
3069  }  }
3070    
3071  show_etc_update_mesg() {  show_etc_update_mesg()
3072    {
3073   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3074    
3075   echo   echo
# Line 2450  pkgsearch() Line 3095  pkgsearch()
3095   local state   local state
3096   local descriptiom   local descriptiom
3097   local homepage   local homepage
3098     local license
3099   local i   local i
3100   local all_installed   local all_installed
3101   local ipver   local ipver
3102   local ipbuild   local ipbuild
3103     local latest_available
3104     local depsfull
3105     local sdepsfull
3106     local deps
3107     local sdeps
3108     local dep
3109     local sign
3110    
3111   # only names no versions   # only names no versions
3112   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')"
3113   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3114    
3115   # nothing found   # nothing found
3116   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2471  pkgsearch() Line 3124  pkgsearch()
3124   # get highest version available   # get highest version available
3125   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3126    
3127   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3128   pver="$(magename2pver ${magefile})"   then
3129   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3130   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3131   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3132   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3133     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3134     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3135     license="$(get_value_from_magefile LICENSE ${magefile})"
3136    
3137     # all installed
3138     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3139     do
3140     ipver="$(magename2pver ${i})"
3141     ipbuild="$(magename2pbuild ${i})"
3142    
3143     if [[ -z ${all_installed} ]]
3144     then
3145     all_installed="${ipver}-${ipbuild}"
3146     else
3147     all_installed="${all_installed} ${ipver}-${ipbuild}"
3148     fi
3149     done
3150     [[ -z ${all_installed} ]] && all_installed="none"
3151    
3152     case ${state} in
3153     stable) state=${COLGREEN}"[s] ";;
3154     testing) state=${COLYELLOW}"[t] ";;
3155     unstable) state=${COLRED}"[u] ";;
3156     old) state=${COLGRAY}"[o] ";;
3157     esac
3158    
3159     latest_available="${pver}-${pbuild}"
3160     else
3161     # package is masked
3162     state="${COLRED}[m] "
3163     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3164     fi
3165    
3166   # all installed   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3167   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3168    
3169     while read sign dep
3170   do   do
3171   ipver="$(magename2pver ${i})"   case ${dep} in
3172   ipbuild="$(magename2pbuild ${i})"   "") continue;;
3173     esac
3174    
3175   if [[ -z ${all_installed} ]]   if [[ -z ${deps} ]]
3176   then   then
3177   all_installed="${ipver}-${ipbuild}"   deps="$(basename ${dep%-*})"
3178   else   else
3179   all_installed="${all_installed} ${ipver}-${ipbuild}"   deps="${deps} $(basename ${dep%-*})"
3180   fi   fi
3181   done   done << EOF
3182   [[ -z ${all_installed} ]] && all_installed="none"  ${depsfull}
3183    EOF
3184    
3185   case ${state} in   while read sign dep
3186   stable) state=${COLGREEN}"[s] ";;   do
3187   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
3188   unstable) state=${COLRED}"[u] ";;   "") continue;;
3189   old) state=${COLGRAY}"[o] ";;   esac
3190   esac  
3191     if [[ -z ${sdeps} ]]
3192     then
3193     sdeps="$(basename ${dep%-*})"
3194     else
3195     sdeps="${sdeps} $(basename ${dep%-*})"
3196     fi
3197     done << EOF
3198    ${sdepsfull}
3199    EOF
3200    
3201   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3202   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3203   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3204   echo "      Description: ${description}"   echo "      Description: ${description}"
3205   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3206     if [[ ! -z ${license} ]]
3207     then
3208     echo "      License:  ${license}"
3209     fi
3210     echo "      Depends:  ${deps}"
3211     echo "      SDepends: ${sdeps}"
3212   echo   echo
3213    
3214   unset pcat   unset pcat
# Line 2518  pkgsearch() Line 3222  pkgsearch()
3222   unset all_installed   unset all_installed
3223   unset ipver   unset ipver
3224   unset ipbuild   unset ipbuild
3225     unset depsfull
3226     unset sdepsfull
3227     unset deps
3228     unset sdeps
3229     unset dep
3230     unset sign
3231     done
3232    }
3233    
3234    export_inherits()
3235    {
3236     local include="$1"
3237     shift
3238    
3239     while [ "$1" ]
3240     do
3241     local functions="$1"
3242    
3243     # sanity checks
3244     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3245     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3246    
3247     eval "${functions}() { ${include}_${functions} ; }"
3248    
3249     # debug
3250     mqueryfeature "debug" && typeset -f "${functions}"
3251    
3252     shift
3253     done
3254    }
3255    
3256    mlibdir()
3257    {
3258     local libdir=lib
3259     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3260    
3261     echo "${libdir}"
3262    }
3263    
3264    ## blacklisted ${magefile}
3265    blacklisted()
3266    {
3267     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3268    
3269     # compat
3270     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3271     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3272    
3273     # support both types for the moment
3274     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3275     then
3276     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3277     else
3278     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3279     fi
3280    
3281     # return 0 if the list not exist; nothin is masked
3282     [[ ! -f ${EXCLUDED} ]] && return 0
3283    
3284     local MAGEFILE="$1"
3285    
3286     local PCAT="$(magename2pcat ${MAGEFILE})"
3287     local PNAME="$(magename2pname ${MAGEFILE})"
3288     local PVER="$(magename2pver ${MAGEFILE})"
3289     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3290    
3291     local EXPCAT EXPNAME EXPVER EXPBUILD
3292     while read EXPCAT EXPNAME EXPVER EXPBUILD
3293     do
3294     # ignore spaces and comments
3295             case "${EXPCAT}" in
3296                     \#*|"") continue ;;
3297             esac
3298    
3299     # exclude full pver
3300     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3301     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3302     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3303     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3304     then
3305     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3306     fi
3307    
3308     # exclude pcat/pname only
3309     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3310     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3311     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3312     then
3313     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3314     fi
3315     done << EOF
3316    $( cat ${EXCLUDED}; echo)
3317    EOF
3318    
3319     return 0
3320    }
3321    
3322    # need_busybox_support ${cmd}
3323    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3324    need_busybox_support()
3325    {
3326     local cmd
3327     local busybox
3328     cmd="$1"
3329    
3330     for busybox in {,/usr}/bin/busybox
3331     do
3332     if [[ -x ${busybox} ]]
3333     then
3334     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3335     then
3336     # needs busybox support
3337     return 0
3338     fi
3339     fi
3340     done
3341    
3342     # no busybox
3343     return 1
3344    }
3345    
3346    # busybox_filter_wget_options ${wget_opts}
3347    busybox_filter_wget_options()
3348    {
3349     local opts="$@"
3350     local i
3351     local fixed_opts
3352    
3353     if need_busybox_support wget
3354     then
3355     for i in ${opts}
3356     do
3357     # show only the allowed ones
3358     case ${i} in
3359     -c|--continue) fixed_opts+=" -c" ;;
3360     -s|--spider) fixed_opts+=" -s" ;;
3361     -q|--quiet) fixed_opts+=" -q" ;;
3362     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3363     --header) shift; fixed_opts+=" --header $1" ;;
3364     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3365     -P) shift; fixed_opts+=" -P $1" ;;
3366     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3367     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3368     # simply drop all other opts
3369     *) continue ;;
3370     esac
3371     done
3372    
3373     echo "${fixed_opts}"
3374     else
3375     echo "${opts}"
3376     fi
3377    }
3378    
3379    have_root_privileges()
3380    {
3381     local retval
3382    
3383     if [[ $(id -u) = 0 ]]
3384     then
3385     retval=0
3386     else
3387     retval=1
3388     fi
3389    
3390     return ${retval}
3391    }
3392    
3393    known_mage_feature()
3394    {
3395     local feature="$1"
3396     local retval
3397    
3398     case "${feature}" in
3399     autosvc|!autosvc) retval=0 ;;
3400     buildlog|!buildlog) retval=0 ;;
3401     ccache|!ccache) retval=0 ;;
3402     check|!check) retval=0 ;;
3403     compressdoc|!compressdoc) retval=0 ;;
3404     debug|!debug) retval=0 ;;
3405     distcc|!distcc) retval=0 ;;
3406     icecc|!icecc) retval=0 ;;
3407     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3408     libtool|!libtool) retval=0 ;;
3409     linuxsymlink|!linuxsymlink) retval=0 ;;
3410     multilib|!multilib) reval=0 ;;
3411     pkgbuild|!pkgbuild) retval=0 ;;
3412     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3413     pkgmetadata|!pkgmetadata) retval=0 ;;
3414     purge|!purge) retval=0 ;;
3415     qalint|!qalint) retval=0 ;;
3416     regentree|!regentree) retval=0 ;;
3417     resume|!resume) retval=0 ;;
3418     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3419     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3420     static|!static) retval=0 ;;
3421     stepbystep|!stepbystep) retval=0 ;;
3422     strip|!strip) retval=0 ;;
3423     verbose|!verbose) retval=0 ;;
3424     *) retval=1 ;;
3425     esac
3426    
3427     return "${retval}"
3428    }
3429    
3430    load_mage_features()
3431    {
3432     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3433     do
3434     FVERBOSE=off msetfeature ${i}
3435     done
3436    }
3437    
3438    msetfeature()
3439    {
3440     local feature
3441     local count
3442     local i
3443     local found
3444    
3445     for feature in $@
3446     do
3447     found=0
3448     count="${#MAGE_FEATURES_CURRENT[*]}"
3449    
3450     if ! known_mage_feature "${feature}"
3451     then
3452     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3453     return 3
3454     fi
3455    
3456     for ((i=0; i<count; i++))
3457     do
3458     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3459     then
3460     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3461     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3462     found=1
3463     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3464     then
3465     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3466     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3467     found=1
3468     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3469     then
3470     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3471     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3472     found=1
3473     fi
3474     done
3475    
3476     # if the feature was not found after proccessing the whole array
3477     # it was not declared. in this case enable it
3478     if [[ ${found} = 0 ]]
3479     then
3480     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3481     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3482     fi
3483    
3484     export MAGE_FEATURES_CURRENT
3485   done   done
3486  }  }
3487    
3488    mqueryfeature()
3489    {
3490     local feature="$1"
3491     local retval=1
3492     local i
3493    
3494     if known_mage_feature "${feature}"
3495     then
3496     for i in ${MAGE_FEATURES_CURRENT[*]}
3497     do
3498     if [[ ${i} = ${feature} ]]
3499     then
3500     retval=0
3501     break # found break here
3502     fi
3503     done
3504     else
3505     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3506     retval=3
3507     fi
3508    
3509     return ${retval}
3510    }
3511    
3512    mprintfeatures()
3513    {
3514     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3515     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3516     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3517    }

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