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 294 by niro, Sun Dec 4 11:54:15 2005 UTC branches/mage-next/src/mage4.functions.sh.in revision 2753 by niro, Thu Aug 14 14:29:11 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.11 2005-12-04 11:54:15 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 474  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   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char .fifo
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 557  remove_database_entry() Line 737  remove_database_entry()
737   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
738    
739   # remove virtuals only if no other exist   # remove virtuals only if no other exist
740   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]   if [[ $(count_installed_pkgs --pcat=${pcat} --pname=${pname}) -le 1 ]]
741   then   then
742   # first unregister virtuals   # first unregister virtuals
743   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
# Line 586  count_installed_pkgs() Line 766  count_installed_pkgs()
766   local i   local i
767    
768   # very basic getops   # very basic getops
769   for i in $*   for i in $@
770   do   do
771   case $1 in   case ${i} in
772   --pcat|-c) shift; pcat="$1" ;;   --pcat*) pcat="${i#*=}" ;;
773   --pname|-n) shift; pname="$1" ;;   --pname*) pname="${i#*=}" ;;
774   esac   esac
  shift  
775   done   done
776    
777   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 631  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 706  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 718  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 770  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 790  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 807  remove_files() Line 975  remove_files()
975   is_config_protected "${pathto}"   is_config_protected "${pathto}"
976   retval="$?"   retval="$?"
977    
978   # 0 - not protected        #   # 0 - not protected         #
979   # 1 - error                #   # 1 - error                 #
980   # 2 - protected            #   # 2 - protected             #
981   # 3 - protected but masked #   # 3 - protected but masked  #
982     # 4 - protected but ignored #
983    
984   case ${retval} in   case ${retval} in
985   # file is not protected - delete it   # file is not protected - delete it
986   0|3)   0|3)
987   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
988   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
989   ;;   ;;
990    
991   # file is protected, do not delete   # file is protected, do not delete
992   2)   2)
993   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
994   then   then
995   echo -en "${COLRED}"   echo -en "${COLRED}"
996   echo -n "! prot "   echo -n "! prot "
# Line 829  remove_files() Line 998  remove_files()
998   echo " === FILE: ${MROOT}${pathto}"   echo " === FILE: ${MROOT}${pathto}"
999   fi   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   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 851  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 874  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 888  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 909  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 932  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 946  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 960  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 990  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 1011  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 1019  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 1032  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 1047  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 1081  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 1092  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://*) 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     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1430     retval="$?"
1431     if [[ ${retval} = 0 ]]
1432     then
1433     break
1434     else
1435     continue
1436     fi
1437     done
1438    
1439     # return wget retval
1440     return "${retval}"
1441    }
1442    
1443  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1444  fetch_packages()  fetch_packages()
1445  {  {
1446     local i
1447   local list="$@"   local list="$@"
1448   local pkg   local pkgname
1449     local pkgfile
1450     local pcat
1451     local pname
1452   local mirr   local mirr
1453   local magefile   local magefile
1454   local md5file   local md5file
1455   local opt   local opt
1456   local count_current   local count_current
1457   local count_total   local count_total
1458     local wget_opts
1459     local fetching
1460    
1461     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1462    
1463   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1464     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1465    
1466   # get count of total packages   # get count of total packages
1467   declare -i count_current=0   declare -i count_current=0
# Line 1114  fetch_packages() Line 1471  fetch_packages()
1471    
1472   for magefile in ${list}   for magefile in ${list}
1473   do   do
1474   pkg="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
1475     pkgfile="${pkgname}.${PKGSUFFIX}"
1476   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
1477    
1478     pcat=$(magename2pcat ${magefile})
1479     pname=$(magename2pname ${magefile})
1480     md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
1481    
1482   (( count_current++ ))   (( count_current++ ))
1483   xtitle "[ (${count_current}/${count_total}) Fetching ${pkg} ]"   xtitle "[ (${count_current}/${count_total}) Fetching ${pkgfile} ]"
1484    
1485   # abort on virtual pkg   # abort on virtual pkg
1486   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
1487   then   then
1488   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1489   echo " !fetch virtual (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch virtual (${count_current}/${count_total}): ${pkgname} ... "
1490   continue   continue
1491   fi   fi
1492    
# Line 1132  fetch_packages() Line 1494  fetch_packages()
1494   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
1495   then   then
1496   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
1497   echo " !fetch sources (${count_current}/${count_total}): ${pkg/.${PKGSUFFIX}/} ... "   echo " !fetch sources (${count_current}/${count_total}): ${pkgname} ... "
1498   continue   continue
1499   fi   fi
1500    
1501   # abort if already exist   # check if FETCHING is required
1502   if [ -f ${PKGDIR}/${pkg} ]   if [ ! -f "${md5file}" ]
1503   then   then
1504   echo -ne " ${COLBLUE}***${COLDEFAULT}"   fetching=true
1505   echo " fetch complete (${count_current}/${count_total}): ${pkg} ... "   else
1506   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_SERVER_PATH}/${pkg}  
  if [[ $? = 0 ]]  
1507   then   then
1508   break   # md5's ok, no fetching required
1509     fetching=false
1510   else   else
1511   continue   fetching=true
1512   fi   fi
1513   done   fi
1514    
1515   if [ ! -f ${PKGDIR}/${pkg} ]   if [[ ${fetching} = false ]]
1516   then   then
1517   die "Could not download ${pkg}"   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1518     echo " fetch complete (${count_current}/${count_total}): ${pkgfile} ... "
1519     continue
1520     else
1521     echo -ne " ${COLBLUE}***${COLDEFAULT}"
1522     echo -e " fetching (${count_current}/${count_total}): ${pkgfile} ... "
1523     mdownload --uri "package://${pkgfile}" --dir "${PKGDIR}" || die "Could not download ${pkgfile}"
1524     fi
1525    
1526     # sanity check, not really needed but to be sure
1527     if [ ! -f ${PKGDIR}/${pkgfile} ]
1528     then
1529     die "Package '${pkgfile}' after download not found in '${PKGDIR}'"
1530   fi   fi
1531   done   done
1532    
# Line 1179  syncmage() Line 1538  syncmage()
1538  {  {
1539   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1540   then   then
1541   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1542   fi   fi
1543    
1544   local i   local i
1545   for i in ${RSYNC}   for i in ${RSYNC}
1546   do   do
1547   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
1548   --recursive \   if [[ $? = 0 ]]
1549   --links \   then
1550   --perms \   break
1551   --times \   else
1552   --devices \   continue
1553   --timeout=600 \   fi
1554   --verbose \   done
1555   --compress \  
1556   --progress \   # clean up backup files (foo~)
1557   --stats \   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1558   --delete \  
1559   --delete-after \   # check if a newer mage version is available
1560   ${i} ${MAGEDIR}   is_newer_mage_version_available
1561    }
1562    
1563    syncmage_tarball()
1564    {
1565     local latest_tarball
1566     local latest_md5
1567     local temp="$(mktemp -d)"
1568     local mirr mymirr
1569     local opt
1570     local tar_opts
1571     local wget_opts
1572    
1573     # try to get the md5 marked as latest on the server
1574     latest_md5="mage-latest.md5"
1575    
1576     # try to get the tarball marked as latest on the server
1577     latest_tarball="mage-latest.tar.bz2"
1578    
1579     # filter wget command if busybox was found
1580     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1581    
1582     for mirr in ${MIRRORS}
1583     do
1584     # path without distribution
1585     # (only for stable|testing|unstable and not DISTROTAG)
1586     case ${mirr##*/} in
1587     stable|testing|unstable) mymirr="${mirr%/*}";;
1588     *) mymirr="${mirr}";;
1589     esac
1590    
1591     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1592     echo "fetching latest md5 from ${mymirr} ..."
1593     mqueryfeature "!verbose" && opt="--quiet"
1594     wget \
1595     ${wget_opts} \
1596     --directory-prefix=${temp} \
1597     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1598    
1599     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1600     echo "fetching latest tarball from ${mymirr} ..."
1601     wget \
1602     ${wget_opts} \
1603     --directory-prefix=${temp} \
1604     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1605   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1606   then   then
1607   break   break
1608   else   else
1609   continue   continue
1610   fi   fi
1611   done   done
1612    
1613   # clean up backup files (foo~)   if [[ -f ${temp}/${latest_tarball} ]]
1614   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   then
1615     # check md5
1616     if [[ ! -f ${temp}/${latest_md5} ]]
1617     then
1618     die "md5 is missing ... aborting"
1619     else
1620     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1621     echo -n "checking md5sum... "
1622     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1623     fi
1624    
1625     if [[ -d ${MAGEDIR} ]]
1626     then
1627     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1628     echo "cleaning old mage-tree ${MAGEDIR}..."
1629     # honor mountpoints and empty dirs
1630     if mountpoint -q ${MAGEDIR}
1631     then
1632     if ! mcheckemptydir ${MAGEDIR}
1633     then
1634     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xargs --no-run-if-empty rm -r
1635     fi
1636     else
1637     rm -rf ${MAGEDIR}
1638     fi
1639     fi
1640    
1641     if need_busybox_support tar
1642     then
1643     tar_opts="xjf"
1644     else
1645     tar_opts="xjmf"
1646     fi
1647    
1648     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1649     echo "updating mage-tree from tarball ..."
1650     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1651     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1652    
1653     if [[ -d ${temp} ]]
1654     then
1655     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1656     echo "cleaning temp-files ..."
1657     rm -rf ${temp}
1658     fi
1659    
1660   # check if an newer mage version is available   # check if a newer mage version is available
1661   is_newer_mage_version_available   is_newer_mage_version_available
1662     else
1663     die "Could not fetch the latest tarball ... aborting"
1664     fi
1665  }  }
1666    
1667  cleanpkg()  cleanpkg()
# Line 1224  cleanpkg() Line 1674  cleanpkg()
1674   fi   fi
1675  }  }
1676    
1677  xtitle()  # unused?
1678  {  #
1679   if [[ ${TERM} = xterm ]]  # # cuts full pathnames or versionized names down to basename
1680   then  # choppkgname()
1681   echo -ne "\033]0;Mage: $1\007"  # {
1682   fi  # #we want this only if full name was used
1683   return 0  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1684  }  # then
1685    # #cuts ARCH and PBUILD
1686    # #ARCH comes from ${MAGERC}
1687  xtitleclean()  # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1688  {  #
1689   if [[ ${TERM} = xterm ]]  # #cuts version number
1690   then  # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1691   echo -ne "\033]0;\007"  # fi
1692   fi  # }
  return 0  
 }  
   
   
 # cuts full pathnames or versioniezed names down to basename  
 choppkgname()  
 {  
  #we want this only if full name was used  
  if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  
  then  
  #cuts ARCH and PBUILD  
  #ARCH comes from /etc/mage.rc  
  MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  
1693    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1694    
1695  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1696  # $1=pname  # $1=pname
# Line 1284  pname2pcat() Line 1717  pname2pcat()
1717  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1718  check_stable_package()  check_stable_package()
1719  {  {
1720     # first check if this magefile is not blacklisted
1721     blacklisted "$1" || return 1
1722    
1723   local STATE   local STATE
1724   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1725    
# Line 1323  get_highest_magefile() Line 1759  get_highest_magefile()
1759   local PNAME="$2"   local PNAME="$2"
1760   local magefile   local magefile
1761    
1762   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1763     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1764   do   do
1765     [[ -z ${magefile} ]] && continue
1766   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1767   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1768   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1769   then   then
1770   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1771   #for debug only   #for debug only
1772   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" >&2
1773   fi   fi
1774   done   done
1775    
  # 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  
   
1776   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1777   return 0   return 0
1778  }  }
# Line 1370  get_highest_magefile() Line 1787  get_highest_magefile()
1787  #        1 - error                                #  #        1 - error                                #
1788  #        2 - protected                            #  #        2 - protected                            #
1789  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1790    #        4 - protected but ignored                #
1791  #                                                 #  #                                                 #
1792  ###################################################  ###################################################
1793  is_config_protected()  is_config_protected()
# Line 1378  is_config_protected() Line 1796  is_config_protected()
1796   local TEST   local TEST
1797   local PROTECTED   local PROTECTED
1798   local IFS   local IFS
1799     local i
1800     local x
1801    
1802   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1803    
1804   # file does not exist; it can be written   # file does not exist; it can be written
1805   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1806    
1807   # to be safe; it may be '§'   # to be safe; it may be '§'
1808   IFS=' '   IFS=' '
1809    
1810   # check ob in config protect   # check if config protected
1811   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1812   do   do
1813   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1814   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1815   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1816   then   then
1817   # setzen das es protected ist   # file is config proteced
1818   PROTECTED=TRUE   PROTECTED=TRUE
1819    
1820   # check ob nicht doch maskiert   # check if not masked
1821   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1822   do   do
1823   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1824   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1825   then   then
1826   PROTECTED=MASKED   PROTECTED=MASKED
1827   fi   fi
1828   done   done
1829    
1830     # check if not ignored
1831     for x in ${CONFIG_PROTECT_IGNORE}
1832     do
1833     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1834     if [[ ${TEST} != ${EXPFILE} ]]
1835     then
1836     PROTECTED=IGNORED
1837     fi
1838     done
1839   fi   fi
1840   done   done
1841    
# Line 1420  is_config_protected() Line 1850  is_config_protected()
1850   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1851   return 3   return 3
1852   ;;   ;;
1853     IGNORED)
1854     #echo "I'm protected, but ignored - keep me, del update"
1855     return 4
1856     ;;
1857   *)   *)
1858   #echo "delete me"   #echo "delete me"
1859   return 0   return 0
# Line 1437  is_config_protected() Line 1871  is_config_protected()
1871  ###################################################  ###################################################
1872  count_protected_files()  count_protected_files()
1873  {  {
1874   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1875     local dirname="${file%/*}"
1876     local filename="${file##*/}"
1877     local count
1878     local output
1879     local oldprotected
1880     local i
1881     local x
1882    
1883     # hack; do not honor a global set IFS like '§'
1884     local IFS
1885    
1886     count=0
1887    
1888     # check if there are already protected files
1889     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1890     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1891     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1892     do
1893     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1894     done
1895    
1896     # convert 0001 -> 1; 0120 -> 120 etc
1897     # use bash internal base functions to this task
1898     x="$((10#${count}))"
1899     for (( i=0; i<x; i++ ))
1900     do
1901     if [[ ${count:${i}:1} != 0 ]]
1902     then
1903     count="${count:${i}}"
1904     break
1905     fi
1906     done
1907    
1908     count="$(( ${count}+1 ))"
1909    
1910     # fill output up with zeros
1911     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1912     output="${output}${count}"
1913    
1914     echo "${output}"
1915  }  }
1916    
1917  # call with  # call with
# Line 1454  get_uninstall_candidates() Line 1928  get_uninstall_candidates()
1928   local list   local list
1929   local pcatdir   local pcatdir
1930   local protected   local protected
1931     local i
1932    
1933   # very basic getops   # very basic getops
1934   for i in $*   for i in $*
# Line 1466  get_uninstall_candidates() Line 1941  get_uninstall_candidates()
1941   shift   shift
1942   done   done
1943    
1944   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1945   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1946    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1947    
1948    
1949   # check needed global vars   # check needed global vars
1950   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1951    
1952   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1953   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1954    
1955   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1956   do   do
# Line 1563  virtuals_add() Line 2039  virtuals_add()
2039    
2040   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2041   then   then
2042   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2043   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2044   do   do
2045   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1607  virtuals_add() Line 2083  virtuals_add()
2083    
2084  #deletes pakages from virtual database  #deletes pakages from virtual database
2085  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2086  virtuals_del() {  virtuals_del()
2087    {
2088    
2089   local virtualname="$1"   local virtualname="$1"
2090   local pkgname="$2"   local pkgname="$2"
# Line 1714  minclude() Line 2191  minclude()
2191  {  {
2192   local i   local i
2193    
2194   if [ -n "$@" ]   if [[ -n $* ]]
2195   then   then
2196   for i in $@   for i in $*
2197   do   do
2198   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2199   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2200   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2201   done   done
2202   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2203   fi   fi
2204  }  }
2205    
# Line 1730  sminclude() Line 2207  sminclude()
2207  {  {
2208   local i   local i
2209    
2210   if [ -n "$@" ]   if [[ -n $* ]]
2211   then   then
2212   for i in $@   for i in $*
2213   do   do
2214   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2215   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
2216   done   done
2217   echo   [[ ${SILENT} = 1 ]] || echo
2218   fi   fi
2219  }  }
2220    
# Line 1756  is_newer_mage_version_available() Line 2233  is_newer_mage_version_available()
2233   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2234   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2235   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2236   echo "or your current system installation may brake."   echo "or your current system installation may break."
2237   echo   echo
2238   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2239   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1764  is_newer_mage_version_available() Line 2241  is_newer_mage_version_available()
2241   fi   fi
2242  }  }
2243    
   
2244  # returns pname from pkgname  # returns pname from pkgname
2245  # pkgname2pname $PKGNAME  # pkgname2pname $PKGNAME
2246  pkgname2pname()  pkgname2pname()
# Line 2028  get_value_from_magefile() Line 2504  get_value_from_magefile()
2504   local magefile="$2"   local magefile="$2"
2505   local value   local value
2506    
2507     [[ -z ${var} ]] && return 1
2508     [[ -z ${magefile} ]] && return 1
2509    
2510   # local all possible vars of a mage file   # local all possible vars of a mage file
2511   # to prevent bad issues   # to prevent bad issues
2512   local PKGNAME   local PKGNAME
# Line 2038  get_value_from_magefile() Line 2517  get_value_from_magefile()
2517   local SDEPEND   local SDEPEND
2518   local PROVIDE   local PROVIDE
2519   local PKGTYPE   local PKGTYPE
2520     local SPLIT_PACKAGE_BASE
2521   local preinstall   local preinstall
2522   local postinstall   local postinstall
2523   local preremove   local preremove
# Line 2084  mage_install() Line 2564  mage_install()
2564   local count_current   local count_current
2565   local magefile   local magefile
2566   local src_install   local src_install
2567     local i
2568    
2569   # very basic getops   # very basic getops
2570   for i in $*   for i in $*
# Line 2157  mage_install() Line 2638  mage_install()
2638   echo B:${pbuild}   echo B:${pbuild}
2639   fi   fi
2640    
2641   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${SPLIT_PACKAGE_BASE} ]]
2642     then
2643     # basic svn compat
2644     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2645     then
2646     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2647     do
2648     smage2file="${i}"
2649     done
2650     else
2651     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2652     fi
2653    
2654     else
2655     # basic svn compat
2656     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2657     then
2658     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2659     do
2660     smage2file="${i}"
2661     done
2662     else
2663     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2664     fi
2665     fi
2666    
2667   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2668   then   then
2669     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2670   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2671   else   else
2672   echo   echo
# Line 2173  mage_install() Line 2680  mage_install()
2680   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2681   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2682   then   then
2683   # show a verbose message on src-install   unpack_package "${magefile}"
2684   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  
2685   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2686   fi   fi
2687    
# Line 2224  mage_install() Line 2725  mage_install()
2725   then   then
2726   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2727   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2728   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2729   echo "done." || echo "failure."   echo "done." || echo "failure."
2730   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2731   fi   fi
# Line 2268  md5sum_packages() Line 2769  md5sum_packages()
2769   pname=$(magename2pname ${magefile})   pname=$(magename2pname ${magefile})
2770   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"   pkgname="$(get_value_from_magefile PKGNAME ${magefile})"
2771   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"   md5file="${MAGEDIR}/${pcat}/${pname}/md5/${pkgname}.md5"
2772   pkgfile="$(get_value_from_magefile PKGNAME ${magefile}).${PKGSUFFIX}"   pkgfile="${pkgname}.${PKGSUFFIX}"
2773   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"   pkgtype="$(get_value_from_magefile PKGTYPE ${magefile})"
2774    
2775   (( count_current++ ))   (( count_current++ ))
# Line 2278  md5sum_packages() Line 2779  md5sum_packages()
2779   if [[ ${pkgtype} = virtual ]]   if [[ ${pkgtype} = virtual ]]
2780   then   then
2781   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2782   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum virtual (${count_current}/${count_total}): ${pkgname} ... "
2783   continue   continue
2784   fi   fi
2785    
# Line 2286  md5sum_packages() Line 2787  md5sum_packages()
2787   if [[ ${pkgtype} = sources ]]   if [[ ${pkgtype} = sources ]]
2788   then   then
2789   echo -ne " ${COLBLUE}---${COLDEFAULT}"   echo -ne " ${COLBLUE}---${COLDEFAULT}"
2790   echo " !md5sum sources (${count_current}/${count_total}): ${pkgfile/.${PKGSUFFIX}/} ... "   echo " !md5sum sources (${count_current}/${count_total}): ${pkgname} ... "
2791   continue   continue
2792   fi   fi
2793    
# Line 2294  md5sum_packages() Line 2795  md5sum_packages()
2795   then   then
2796   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2797   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2798   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2799   else   else
2800   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2801   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2334  uninstall_packages() Line 2835  uninstall_packages()
2835   pbuild=$(magename2pbuild ${pkg})   pbuild=$(magename2pbuild ${pkg})
2836   can_pcat="${pcat}"   can_pcat="${pcat}"
2837   can_pname="${pname}"   can_pname="${pname}"
2838    
2839   if [ -z "${can_ver_list}" ]   if [ -z "${can_ver_list}" ]
2840   then   then
2841   can_ver_list=" ${pver}-${pbuild}"   can_ver_list=" ${pver}-${pbuild}"
# Line 2437  mage_uninstall() Line 2938  mage_uninstall()
2938   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2939   echo -n "removing: "   echo -n "removing: "
2940   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2941   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2942    
2943   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2944   source ${magefile}   source ${magefile}
2945    
2946   ## preremove scripts   ## preremove scripts
# Line 2489  mage_uninstall() Line 2990  mage_uninstall()
2990   then   then
2991   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2992   echo -n "rebuilding environment ... "   echo -n "rebuilding environment ... "
2993   ${MLIBDIR}/env-rebuild.sh > /dev/null && \   ${MLIBDIR}/env-rebuild > /dev/null && \
2994   echo "done." || echo "failure."   echo "done." || echo "failure."
2995   unset MAGE_ENV_REBUILD   unset MAGE_ENV_REBUILD
2996   fi   fi
# Line 2507  mage_uninstall() Line 3008  mage_uninstall()
3008   unset -f postremove   unset -f postremove
3009  }  }
3010    
3011  show_etc_update_mesg() {  # rerun_pkgfunctions [method] pkg1 pkg2 pkg3
3012    rerun_pkgfunctions()
3013    {
3014     local method
3015     local list
3016     local pcat
3017     local pname
3018     local pver
3019     local pbuild
3020     local magefile
3021     local i
3022    
3023     # very basic getops
3024     case $1 in
3025     --method) shift; method="$1" ;;
3026     esac
3027     shift
3028     local list="$@"
3029    
3030     # sanity check
3031     case ${method} in
3032     preinstall|postinstall) ;;
3033     preremove|postremove) ;;
3034     *) die "rerun_pkgfunctions(): Unknown method '${method}'." ;;
3035     esac
3036    
3037     if [[ -n ${MROOT} ]]
3038     then
3039     echo -ne ${COLRED}
3040     echo "!! running in MROOT=${MROOT}"
3041     echo -ne ${COLDEFAULT}
3042     echo
3043     fi
3044    
3045     for pkg in ${list}
3046     do
3047     pcat=$(dep2pcat ${pkg})
3048     pname=$(magename2pname ${pkg})
3049     pver=$(magename2pver ${pkg})
3050     pbuild=$(magename2pbuild ${pkg})
3051     magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
3052    
3053     if [ -e ${magefile} ]
3054     then
3055     source ${magefile}
3056     if [ -n "$(typeset -f ${method})" ]
3057     then
3058     echo -e " ${COLBLUE}***${COLDEFAULT} running ${method} for ${pkg} ... "
3059     ${method}
3060     else
3061     echo "No ${method}() for pkg '${pkg}' defined. Doing nothing."
3062     fi
3063     unset -f preinstall postinstall preremove postremove
3064     else
3065     die "Magefile '${magefile}' does not exist."
3066     fi
3067     done
3068    }
3069    
3070    show_etc_update_mesg()
3071    {
3072   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3073    
3074   echo   echo
# Line 2533  pkgsearch() Line 3094  pkgsearch()
3094   local state   local state
3095   local descriptiom   local descriptiom
3096   local homepage   local homepage
3097     local license
3098   local i   local i
3099   local all_installed   local all_installed
3100   local ipver   local ipver
3101   local ipbuild   local ipbuild
3102     local latest_available
3103     local depsfull
3104     local sdepsfull
3105     local deps
3106     local sdeps
3107     local dep
3108     local sign
3109    
3110   # only names no versions   # only names no versions
3111   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')"
3112   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3113    
3114   # nothing found   # nothing found
3115   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2554  pkgsearch() Line 3123  pkgsearch()
3123   # get highest version available   # get highest version available
3124   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
3125    
3126   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
3127   pver="$(magename2pver ${magefile})"   then
3128   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
3129   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
3130   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
3131   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
3132     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3133     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3134     license="$(get_value_from_magefile LICENSE ${magefile})"
3135    
3136     # all installed
3137     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3138     do
3139     ipver="$(magename2pver ${i})"
3140     ipbuild="$(magename2pbuild ${i})"
3141    
3142     if [[ -z ${all_installed} ]]
3143     then
3144     all_installed="${ipver}-${ipbuild}"
3145     else
3146     all_installed="${all_installed} ${ipver}-${ipbuild}"
3147     fi
3148     done
3149     [[ -z ${all_installed} ]] && all_installed="none"
3150    
3151     case ${state} in
3152     stable) state=${COLGREEN}"[s] ";;
3153     testing) state=${COLYELLOW}"[t] ";;
3154     unstable) state=${COLRED}"[u] ";;
3155     old) state=${COLGRAY}"[o] ";;
3156     esac
3157    
3158     latest_available="${pver}-${pbuild}"
3159     else
3160     # package is masked
3161     state="${COLRED}[m] "
3162     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3163     fi
3164    
3165   # all installed   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3166   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3167    
3168     while read sign dep
3169   do   do
3170   ipver="$(magename2pver ${i})"   case ${dep} in
3171   ipbuild="$(magename2pbuild ${i})"   "") continue;;
3172     esac
3173    
3174   if [[ -z ${all_installed} ]]   if [[ -z ${deps} ]]
3175   then   then
3176   all_installed="${ipver}-${ipbuild}"   deps="$(basename ${dep%-*})"
3177   else   else
3178   all_installed="${all_installed} ${ipver}-${ipbuild}"   deps="${deps} $(basename ${dep%-*})"
3179   fi   fi
3180   done   done << EOF
3181   [[ -z ${all_installed} ]] && all_installed="none"  ${depsfull}
3182    EOF
3183    
3184   case ${state} in   while read sign dep
3185   stable) state=${COLGREEN}"[s] ";;   do
3186   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
3187   unstable) state=${COLRED}"[u] ";;   "") continue;;
3188   old) state=${COLGRAY}"[o] ";;   esac
3189   esac  
3190     if [[ -z ${sdeps} ]]
3191     then
3192     sdeps="$(basename ${dep%-*})"
3193     else
3194     sdeps="${sdeps} $(basename ${dep%-*})"
3195     fi
3196     done << EOF
3197    ${sdepsfull}
3198    EOF
3199    
3200   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3201   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
3202   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
3203   echo "      Description: ${description}"   echo "      Description: ${description}"
3204   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
3205     if [[ ! -z ${license} ]]
3206     then
3207     echo "      License:  ${license}"
3208     fi
3209     echo "      Depends:  ${deps}"
3210     echo "      SDepends: ${sdeps}"
3211   echo   echo
3212    
3213   unset pcat   unset pcat
# Line 2601  pkgsearch() Line 3221  pkgsearch()
3221   unset all_installed   unset all_installed
3222   unset ipver   unset ipver
3223   unset ipbuild   unset ipbuild
3224     unset depsfull
3225     unset sdepsfull
3226     unset deps
3227     unset sdeps
3228     unset dep
3229     unset sign
3230   done   done
3231  }  }
3232    
# Line 2620  export_inherits() Line 3246  export_inherits()
3246   eval "${functions}() { ${include}_${functions} ; }"   eval "${functions}() { ${include}_${functions} ; }"
3247    
3248   # debug   # debug
3249   [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"   mqueryfeature "debug" && typeset -f "${functions}"
3250    
3251   shift   shift
3252   done   done
3253  }  }
3254    
3255    mlibdir()
3256    {
3257     local libdir=lib
3258     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3259    
3260     echo "${libdir}"
3261    }
3262    
3263    ## blacklisted ${magefile}
3264    blacklisted()
3265    {
3266     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3267    
3268     # compat
3269     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3270     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3271    
3272     # support both types for the moment
3273     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3274     then
3275     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3276     else
3277     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3278     fi
3279    
3280     # return 0 if the list not exist; nothin is masked
3281     [[ ! -f ${EXCLUDED} ]] && return 0
3282    
3283     local MAGEFILE="$1"
3284    
3285     local PCAT="$(magename2pcat ${MAGEFILE})"
3286     local PNAME="$(magename2pname ${MAGEFILE})"
3287     local PVER="$(magename2pver ${MAGEFILE})"
3288     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3289    
3290     local EXPCAT EXPNAME EXPVER EXPBUILD
3291     while read EXPCAT EXPNAME EXPVER EXPBUILD
3292     do
3293     # ignore spaces and comments
3294             case "${EXPCAT}" in
3295                     \#*|"") continue ;;
3296             esac
3297    
3298     # exclude full pver
3299     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3300     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3301     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3302     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3303     then
3304     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3305     fi
3306    
3307     # exclude pcat/pname only
3308     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3309     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3310     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3311     then
3312     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3313     fi
3314     done << EOF
3315    $( cat ${EXCLUDED}; echo)
3316    EOF
3317    
3318     return 0
3319    }
3320    
3321    # need_busybox_support ${cmd}
3322    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3323    need_busybox_support()
3324    {
3325     local cmd
3326     local busybox
3327     cmd="$1"
3328    
3329     for busybox in {,/usr}/bin/busybox
3330     do
3331     if [[ -x ${busybox} ]]
3332     then
3333     if [[ $(readlink $(type -P ${cmd})) = ${busybox} ]]
3334     then
3335     # needs busybox support
3336     return 0
3337     fi
3338     fi
3339     done
3340    
3341     # no busybox
3342     return 1
3343    }
3344    
3345    # busybox_filter_wget_options ${wget_opts}
3346    busybox_filter_wget_options()
3347    {
3348     local opts="$@"
3349     local i
3350     local fixed_opts
3351    
3352     if need_busybox_support wget
3353     then
3354     for i in ${opts}
3355     do
3356     # show only the allowed ones
3357     case ${i} in
3358     -c|--continue) fixed_opts+=" -c" ;;
3359     -s|--spider) fixed_opts+=" -s" ;;
3360     -q|--quiet) fixed_opts+=" -q" ;;
3361     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3362     --header) shift; fixed_opts+=" --header $1" ;;
3363     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3364     -P) shift; fixed_opts+=" -P $1" ;;
3365     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3366     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3367     # simply drop all other opts
3368     *) continue ;;
3369     esac
3370     done
3371    
3372     echo "${fixed_opts}"
3373     else
3374     echo "${opts}"
3375     fi
3376    }
3377    
3378    have_root_privileges()
3379    {
3380     local retval
3381    
3382     if [[ $(id -u) = 0 ]]
3383     then
3384     retval=0
3385     else
3386     retval=1
3387     fi
3388    
3389     return ${retval}
3390    }
3391    
3392    known_mage_feature()
3393    {
3394     local feature="$1"
3395     local retval
3396    
3397     case "${feature}" in
3398     autosvc|!autosvc) retval=0 ;;
3399     buildlog|!buildlog) retval=0 ;;
3400     ccache|!ccache) retval=0 ;;
3401     check|!check) retval=0 ;;
3402     compressdoc|!compressdoc) retval=0 ;;
3403     debug|!debug) retval=0 ;;
3404     distcc|!distcc) retval=0 ;;
3405     icecc|!icecc) retval=0 ;;
3406     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3407     libtool|!libtool) retval=0 ;;
3408     linuxsymlink|!linuxsymlink) retval=0 ;;
3409     multilib|!multilib) reval=0 ;;
3410     pkgbuild|!pkgbuild) retval=0 ;;
3411     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3412     pkgmetadata|!pkgmetadata) retval=0 ;;
3413     purge|!purge) retval=0 ;;
3414     qalint|!qalint) retval=0 ;;
3415     regentree|!regentree) retval=0 ;;
3416     resume|!resume) retval=0 ;;
3417     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3418     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3419     static|!static) retval=0 ;;
3420     stepbystep|!stepbystep) retval=0 ;;
3421     strip|!strip) retval=0 ;;
3422     verbose|!verbose) retval=0 ;;
3423     *) retval=1 ;;
3424     esac
3425    
3426     return "${retval}"
3427    }
3428    
3429    load_mage_features()
3430    {
3431     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3432     do
3433     FVERBOSE=off msetfeature ${i}
3434     done
3435    }
3436    
3437    msetfeature()
3438    {
3439     local feature
3440     local count
3441     local i
3442     local found
3443    
3444     for feature in $@
3445     do
3446     found=0
3447     count="${#MAGE_FEATURES_CURRENT[*]}"
3448    
3449     if ! known_mage_feature "${feature}"
3450     then
3451     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3452     return 3
3453     fi
3454    
3455     for ((i=0; i<count; i++))
3456     do
3457     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3458     then
3459     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3460     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3461     found=1
3462     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3463     then
3464     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3465     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3466     found=1
3467     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3468     then
3469     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3470     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3471     found=1
3472     fi
3473     done
3474    
3475     # if the feature was not found after proccessing the whole array
3476     # it was not declared. in this case enable it
3477     if [[ ${found} = 0 ]]
3478     then
3479     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3480     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3481     fi
3482    
3483     export MAGE_FEATURES_CURRENT
3484     done
3485    }
3486    
3487    mqueryfeature()
3488    {
3489     local feature="$1"
3490     local retval=1
3491     local i
3492    
3493     if known_mage_feature "${feature}"
3494     then
3495     for i in ${MAGE_FEATURES_CURRENT[*]}
3496     do
3497     if [[ ${i} = ${feature} ]]
3498     then
3499     retval=0
3500     break # found break here
3501     fi
3502     done
3503     else
3504     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3505     retval=3
3506     fi
3507    
3508     return ${retval}
3509    }
3510    
3511    mprintfeatures()
3512    {
3513     echo -e "${COLRED}Global features:${COLDEFAULT} ${MAGE_FEATURES_GLOBAL[*]}"
3514     echo -e "${COLYELLOW}Local features:${COLDEFAULT} ${MAGE_FEATURES[*]}"
3515     echo -e "${COLGREEN}Current features:${COLDEFAULT} ${MAGE_FEATURES_CURRENT[*]}"
3516    }

Legend:
Removed from v.294  
changed lines
  Added in v.2753