Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1758 by niro, Sat Feb 18 13:48:34 2012 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.1 2005-09-09 16:35:38 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.38 2008-10-05 10:32:24 niro Exp $
4    
5    COLRED="\033[1;6m\033[31m"
6    COLGREEN="\033[1;6m\033[32m"
7    COLYELLOW="\033[1;6m\033[33m"
8    COLBLUE="\033[1;6m\033[34m"
9    COLMAGENTA="\033[1;6m\033[35m"
10    COLWHITE="\033[1;6m\033[37m"
11    COLGRAY="\033[0;6m\033[37m"
12    COLBOLD="\033[1m"
13    COLDEFAULT="\033[0m"
14    
15    if [[ ${NOCOLORS} = true ]]
16    then
17     COLRED=""
18     COLGREEN=""
19     COLYELLOW=""
20     COLBLUE=""
21     COLMAGENTA=""
22     COLWHITE=""
23     COLGRAY=""
24     COLBOLD=""
25     COLDEFAULT=""
26    fi
27    
28  mage_setup()  mage_setup()
29  {  {
# Line 15  mage_setup() Line 38  mage_setup()
38   return 0   return 0
39  }  }
40    
41    mchecksum()
42    {
43     local i
44     local rundir
45     local file
46     local method
47     local cmd
48     local retval
49    
50     # very basic getops
51     for i in $*
52     do
53     case $1 in
54     --rundir|-r) shift; rundir="$1" ;;
55     --file|-f) shift; file="$1" ;;
56     --method|-m) shift; method="$1" ;;
57     esac
58     shift
59     done
60    
61     # sanity checks
62     [[ -z ${rundir} ]] && die "mchecksum(): rundir missing"
63     [[ -z ${file} ]] && die "mchecksum(): file missing"
64     [[ -z ${method} ]] && die "mchecksum(): method missing"
65    
66     case ${method} in
67     md5) cmd="md5sum" ;;
68     sha256) cmd="sha256sum" ;;
69     *) die "mchecksum(): unknown method '${method}'" ;;
70     esac
71    
72     if [[ -d ${rundir} ]]
73     then
74     pushd ${rundir} &> /dev/null
75     # be verbose here
76     ${cmd} -c ${file} #&> /dev/null
77     retval="$?"
78     popd &> /dev/null
79     else
80     retval=1
81     fi
82    
83     return "${retval}"
84    }
85    
86    mcheckemptydir()
87    {
88     local dir="$1"
89     local retval=1
90    
91     if [[ ! -d ${dir} ]]
92     then
93     echo "mcheckemptydir(): '${dir}' is not a directory!"
94     retval=3
95     else
96     shopt -s nullglob dotglob
97     files=( ${dir}/* )
98     (( ${#files[*]} )) || retval=0
99     shopt -u nullglob dotglob
100     fi
101    
102     return ${retval}
103    }
104    
105  unpack_packages()  unpack_packages()
106  {  {
107   local list="$@"   local list="$@"
# Line 23  unpack_packages() Line 110  unpack_packages()
110   local pkgtype   local pkgtype
111   local count_current   local count_current
112   local count_total   local count_total
113     local tar_opts
114    
115   # get count of total packages   # get count of total packages
116   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 142  unpack_packages()
142   continue   continue
143   fi   fi
144    
145     # busybox?
146     if need_busybox_support tar
147     then
148     tar_opts="xjf"
149     else
150     tar_opts="xjmf"
151     fi
152    
153   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
154   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
155   done   done
156    
157   # add a crlf for a better view   # add a crlf for a better view
# Line 75  fix_mtime() Line 171  fix_mtime()
171   mtime=$(stat -c %Y "${reference}")   mtime=$(stat -c %Y "${reference}")
172   touch \   touch \
173   --no-create \   --no-create \
174     --no-dereference \
175   --time=mtime \   --time=mtime \
176   --reference "${reference}" \   --reference="${reference}" \
177   "${pathto}"   "${pathto}"
178    
179   echo "${mtime}"   echo "${mtime}"
# Line 130  install_directories() Line 227  install_directories()
227   while read pathto posix user group   while read pathto posix user group
228   do   do
229   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
230   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
231    
232   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
233   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 294  install_files()
294   is_config_protected "${pathto}"   is_config_protected "${pathto}"
295   retval="$?"   retval="$?"
296    
297   # 0 - not protected        #   # 0 - not protected         #
298   # 1 - error                #   # 1 - error                 #
299   # 2 - protected            #   # 2 - protected             #
300   # 3 - protected but masked #   # 3 - protected but masked  #
301     # 4 - protected but ignored #
302    
303   case ${retval} in   case ${retval} in
304   # file is not protected - (over)write it   # file is not protected - (over)write it
305   0|3)   0|3)
306   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
307   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
308   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
309   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 315  install_files()
315   "${user}" \   "${user}" \
316   "${group}" \   "${group}" \
317   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
318   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
319   "${md5sum}"   "${md5sum}"
320   ;;   ;;
321    
322   # file is protected, write backup file   # file is protected, write backup file
323   2)   2)
324   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
325   then   then
326   echo -en "${COLRED}"   echo -en "${COLRED}"
327   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 342  install_files()
342   "${user}" \   "${user}" \
343   "${group}" \   "${group}" \
344   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
345   "${dest_protected}")" \   "${dest_protected}")" \
346   "${md5sum}"   "${md5sum}"
347    
348   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
349   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
350   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
351   ;;   ;;
352    
353     # file is protected but ignored, delete the update/do nothing
354     4)
355     if mqueryfeature "verbose"
356     then
357     echo -en "${COLRED}"
358     echo -n "! ignr "
359     echo -en "${COLDEFAULT}"
360     echo " === FILE: ${MROOT}${pathto}"
361     fi
362     # simply do nothing here - only fix mtime
363     fix_descriptor ${pkgname}/.files \
364     "${pathto}" \
365     "${posix}" \
366     "${user}" \
367     "${group}" \
368     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
369     "${MROOT}${pathto}")" \
370     "${md5sum}"
371     ;;
372   esac   esac
373   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
374    
# Line 294  install_symlinks() Line 411  install_symlinks()
411   while read pathto posix link mtime   while read pathto posix link mtime
412   do   do
413   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
414   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
415    
416   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
417    
418   # fix mtime and db   # fix mtime and db
419   fix_descriptor ${pkgname}/.symlinks \   fix_descriptor ${pkgname}/.symlinks \
420   "${pathto}" \   "${pathto}" \
421   "${posix}" \   "${posix}" \
422   "${link}" \   "${link}" \
423   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
424   "${MROOT}${pathto}")"   "${MROOT}${pathto}")"
425    
426   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
427    
428   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
429   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
430   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
431    
432   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
433   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 443  install_blockdevices()
443   local pkgname="$1"   local pkgname="$1"
444   local pathto   local pathto
445   local posix   local posix
446     local user
447     local group
448   local IFS   local IFS
449    
450   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 458  install_blockdevices()
458   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
459   IFS=§   IFS=§
460    
461   while read pathto posix   while read pathto posix major minor user group
462   do   do
463   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
464   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
465    
466   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
467     # make it optional atm !!
468     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
469     then
470     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
471     fi
472   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
473    
474   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 485  install_characterdevices()
485   local pkgname="$1"   local pkgname="$1"
486   local pathto   local pathto
487   local posix   local posix
488     local major
489     local minor
490     local user
491     local group
492   local IFS   local IFS
493    
494   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 502  install_characterdevices()
502   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
503   IFS=§   IFS=§
504    
505   while read pathto posix   while read pathto posix major minor user group
506   do   do
507   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
508   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
509    
510   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
511    
512     # make it optional atm !!
513     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
514     then
515     chown "${user}:${group}" "${MROOT}${pathto}"
516     fi
517   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
518    
519   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
520   IFS=$'\n'   IFS=$'\n'
521  }  }
522    
523    ###################################################
524    # function install_fifos                          #
525    # install_fifos $PKGNAME                    #
526    ###################################################
527    install_fifos()
528    {
529     local pkgname="$1"
530     local pathto
531     local posix
532     local user
533     local group
534     local IFS
535    
536     # sanity checks; abort if not given
537     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
538    
539     # check needed global vars
540     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
541    
542     # make it optional atm !!
543     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
544     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
545    
546     # sets fieldseperator to "§" instead of " "
547     IFS=§
548    
549     while read pathto posix user group
550     do
551     [ -z "${pathto}" ] && continue
552     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
553    
554     mkfifo -m "${posix}" "${MROOT}${pathto}"
555     chown "${user}:${group}" "${MROOT}${pathto}"
556     done < ${BUILDDIR}/${pkgname}/.fifo
557    
558     # very important: unsetting the '§' fieldseperator
559     IFS=$'\n'
560    }
561    
562    
563  ###################################################  ###################################################
564  # function build_doinstall                        #  # function build_doinstall                        #
565  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
566  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
567  ###################################################  ###################################################
568  build_doinstall()  build_doinstall()
569  {  {
# Line 398  build_doinstall() Line 571  build_doinstall()
571    
572   # sanity checks; abort if not given   # sanity checks; abort if not given
573   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
574    
575   # this is only a wrapper   # this is only a wrapper
576    
577   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 586  build_doinstall()
586   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
587   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
588   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
589     install_fifos ${pkgname} || die "install fifos ${pkgname}"
590  }  }
591    
592    
# Line 432  install_database_entry() Line 606  install_database_entry()
606   local magefile   local magefile
607   local dbrecorddir   local dbrecorddir
608   local provide   local provide
609     local i
610    
611   # very basic getops   # very basic getops
612   for i in $*   for i in $*
# Line 473  install_database_entry() Line 648  install_database_entry()
648    
649   # create fake file descriptors   # create fake file descriptors
650   # used by virtual and source packages   # used by virtual and source packages
651   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
652   do   do
653   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
654   done   done
# Line 492  install_database_entry() Line 666  install_database_entry()
666    
667   # normal packages needs these files   # normal packages needs these files
668   local i   local i
669   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
670   do   do
671   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
672   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
673     then
674     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
675     fi
676   done   done
677   ;;   ;;
678   esac   esac
# Line 504  install_database_entry() Line 681  install_database_entry()
681   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
682   if [ -n "${provide}" ]   if [ -n "${provide}" ]
683   then   then
684   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
685     do
686     virtuals_add "${i}" "${pcat}/${pname}"
687     done
688   fi   fi
689  }  }
690    
# Line 523  remove_database_entry() Line 703  remove_database_entry()
703   local magefile   local magefile
704   local dbrecorddir   local dbrecorddir
705   local provide   local provide
706     local i
707    
708   # very basic getops   # very basic getops
709   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 733  remove_database_entry()
733   # abort if mage file not exists   # abort if mage file not exists
734   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
735    
736   # first unregister virtuals   # remove virtuals only if no other exist
737   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
738   then   then
739   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
740     provide="$(get_value_from_magefile PROVIDE ${magefile})"
741     if [ -n "${provide}" ]
742     then
743     for i in ${provide}
744     do
745     virtuals_del "${i}" "${pcat}/${pname}"
746     done
747     fi
748   fi   fi
749    
750   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 754  remove_database_entry()
754   fi   fi
755  }  }
756    
757    # get the number of installed packages
758    count_installed_pkgs()
759    {
760     local pcat
761     local pname
762     local pkg
763     local i
764    
765     # very basic getops
766     for i in $*
767     do
768     case $1 in
769     --pcat|-c) shift; pcat="$1" ;;
770     --pname|-n) shift; pname="$1" ;;
771     esac
772     shift
773     done
774    
775     # sanity checks; abort if not given
776     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
777     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
778    
779     declare -i i=0
780     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
781     do
782     (( i++ ))
783     #echo "$i ${pkg}"
784     done
785    
786     # return the value
787     echo "${i}"
788    }
789    
790    
791  ###################################################  ###################################################
792  # function compare_mtime                          #  # function compare_mtime                          #
# Line 587  compare_mtime() Line 808  compare_mtime()
808    
809   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"   mtime="$(stat -c %Y ${MROOT}${INSTALLDB}/${pfull}/.mtime)"
810    
811   # if $pathto is a symlink than compare linked binary   # no extra handlink for symlinks anymore as fix_mtime
812   if [ -L "${MROOT}${pathto}" ]   # uses --no-dereference, compare directly
813   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  
814    
815   [[ ${mtime} = ${x} ]] && return 0   [[ ${mtime} = ${x} ]] && return 0
816    
# Line 662  remove_symlinks() Line 872  remove_symlinks()
872   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
873   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
874   then   then
875   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
876   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
877   continue   continue
878   fi   fi
# Line 674  remove_symlinks() Line 884  remove_symlinks()
884   # 1=keep me   #   # 1=keep me   #
885   case ${retval} in   case ${retval} in
886   0)   0)
887   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
888   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
889   ;;   ;;
890    
891   1)   1)
892   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
893   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
894   ;;   ;;
895   esac   esac
# Line 726  remove_files() Line 936  remove_files()
936   done   done
937    
938   # sanity checks; abort if not given   # sanity checks; abort if not given
939   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
940   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
941   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
942   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
943   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
944    
945   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 954  remove_files()
954   do   do
955   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
956    
957   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
958   then   then
959   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
960   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
961   continue   continue
962   fi   fi
# Line 758  remove_files() Line 968  remove_files()
968   # 1=keep me   #   # 1=keep me   #
969   case ${retval} in   case ${retval} in
970   0)   0)
971   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
972   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
973   ;;   is_config_protected "${pathto}"
974     retval="$?"
975    
976     # 0 - not protected         #
977     # 1 - error                 #
978     # 2 - protected             #
979     # 3 - protected but masked  #
980     # 4 - protected but ignored #
981    
982     case ${retval} in
983     # file is not protected - delete it
984     0|3)
985     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
986     rm "${MROOT}${pathto}"
987     ;;
988    
989     # file is protected, do not delete
990     2)
991     if mqueryfeature "verbose"
992     then
993     echo -en "${COLRED}"
994     echo -n "! prot "
995     echo -en "${COLDEFAULT}"
996     echo " === FILE: ${MROOT}${pathto}"
997     fi
998     ;;
999    
1000     # file is protected but ignored, delete the update/do nothing
1001     4)
1002     if mqueryfeature "verbose"
1003     then
1004     echo -en "${COLRED}"
1005     echo -n "! ignr "
1006     echo -en "${COLDEFAULT}"
1007     echo " === FILE: ${MROOT}${pathto}"
1008     fi
1009     # simply do nothing here
1010     ;;
1011     esac
1012     ;;
1013   1)   1)
1014   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1015   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1016   ;;   ;;
1017   esac   esac
# Line 782  remove_blockdevices() Line 1030  remove_blockdevices()
1030  {  {
1031   local pathto   local pathto
1032   local posix   local posix
1033     local user
1034     local group
1035   local IFS   local IFS
1036   local pcat   local pcat
1037   local pname   local pname
# Line 805  remove_blockdevices() Line 1055  remove_blockdevices()
1055   done   done
1056    
1057   # sanity checks; abort if not given   # sanity checks; abort if not given
1058   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1059   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1060   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1061   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1062   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1063    
1064   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1069  remove_blockdevices()
1069   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1070   IFS=§   IFS=§
1071    
1072   while read pathto posix   while read pathto posix user group
1073   do   do
1074   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1075    
1076   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1077   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1078   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1079    
# Line 840  remove_characterdevices() Line 1090  remove_characterdevices()
1090  {  {
1091   local pathto   local pathto
1092   local posix   local posix
1093     local user
1094     local group
1095   local IFS   local IFS
1096   local pcat   local pcat
1097   local pname   local pname
# Line 863  remove_characterdevices() Line 1115  remove_characterdevices()
1115   done   done
1116    
1117   # sanity checks; abort if not given   # sanity checks; abort if not given
1118   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1119   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1120   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1121   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1122   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1123    
1124   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1129  remove_characterdevices()
1129   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1130   IFS=§   IFS=§
1131    
1132   while read pathto posix   while read pathto posix user group
1133   do   do
1134   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1135    
1136   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1137   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1138   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1139    
# Line 891  remove_characterdevices() Line 1143  remove_characterdevices()
1143    
1144    
1145  ###################################################  ###################################################
1146    # function remove_fifos                           #
1147    # remove_fifos $PKGNAME                     #
1148    ###################################################
1149    remove_fifos()
1150    {
1151     local pathto
1152     local posix
1153     local user
1154     local group
1155     local IFS
1156     local pcat
1157     local pname
1158     local pver
1159     local pbuild
1160     local i
1161     local pfull
1162    
1163     IFS=$'\n'
1164    
1165     # very basic getops
1166     for i in $*
1167     do
1168     case $1 in
1169     --pcat|-c) shift; pcat="$1" ;;
1170     --pname|-n) shift; pname="$1" ;;
1171     --pver|-v) shift; pver="$1" ;;
1172     --pbuild|-b) shift; pbuild="$1" ;;
1173     esac
1174     shift
1175     done
1176    
1177     # sanity checks; abort if not given
1178     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1179     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1180     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1181     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1182     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1183    
1184     # check needed global vars
1185     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1186    
1187     # make it optional atm !!
1188     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1189     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1190    
1191     # sets fieldseperator to "§" instead of " "
1192     IFS=§
1193    
1194     while read pathto posix user group
1195     do
1196     [ -z "${pathto}" ] && continue
1197    
1198     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1199     rm "${MROOT}${pathto}"
1200     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1201    
1202     # very important: unsetting the '§' fieldseperator
1203     IFS=$'\n'
1204    }
1205    
1206    
1207    ###################################################
1208  # function remove_direcories                      #  # function remove_direcories                      #
1209  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1210  ###################################################  ###################################################
# Line 921  remove_directories() Line 1235  remove_directories()
1235   done   done
1236    
1237   # sanity checks; abort if not given   # sanity checks; abort if not given
1238   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1239   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1240   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1241   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1242   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1243    
1244   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1246  remove_directories()
1246    
1247   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1248    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1249   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1250   IFS=§   IFS=§
1251    
1252   while read pathto posix   # reversed order is mandatory !
1253     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1254   do   do
1255   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1256    
1257   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1258   then   then
1259   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1260   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1261   continue   continue
1262   fi   fi
# Line 953  remove_directories() Line 1264  remove_directories()
1264   # exclude .keep directories   # exclude .keep directories
1265   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1266   then   then
1267   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1268   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1269   continue   continue
1270   fi   fi
1271    
# Line 966  remove_directories() Line 1277  remove_directories()
1277    
1278   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1279   then   then
1280   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1281   else   else
1282   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1283   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1284   fi   fi
1285   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1286    
1287   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1288   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1292  remove_directories()
1292  ###################################################  ###################################################
1293  # function build_douninstall                      #  # function build_douninstall                      #
1294  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1295  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1296  ###################################################  ###################################################
1297  build_douninstall()  build_douninstall()
1298  {  {
# Line 1015  build_douninstall() Line 1326  build_douninstall()
1326   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1327   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1328    
1329   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1330   do   do
1331   remove_${i} \   remove_${i} \
1332   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1026  build_douninstall() Line 1337  build_douninstall()
1337   done   done
1338  }  }
1339    
1340    # convertmirrors [uri]
1341    convertmirrors()
1342    {
1343     local uri="$1"
1344     local scheme
1345     local mirror
1346     local mirrors
1347     local addon
1348     local real_uri
1349     local output
1350    
1351     # needs
1352     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1353     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1354     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1355     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1356     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1357    
1358     # check known uri schemes
1359     case ${uri} in
1360     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1361     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1362     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1363     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1364     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1365     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1366     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1367     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1368     esac
1369    
1370     if [[ ! -z ${mirrors} ]]
1371     then
1372     for mirror in ${mirrors}
1373     do
1374     # add a whitespace to the output
1375     [[ -z ${output} ]] || output+=" "
1376     output+="${mirror}${addon}/${uri/${scheme}/}"
1377     done
1378     else
1379     output="${uri}"
1380     fi
1381    
1382     echo "${output}"
1383    }
1384    
1385    mdownload()
1386    {
1387     local i
1388     local uri
1389     local real_uris
1390     local mirror
1391     local outputfile
1392     local outputdir
1393     local retval
1394     local wget_opts
1395    
1396     # very basic getops
1397     for i in $*
1398     do
1399     case $1 in
1400     --uri|-u) shift; uri="$1" ;;
1401     --dir|-d) shift; outputdir="$1" ;;
1402     esac
1403     shift
1404     done
1405    
1406     # sanity checks; abort if not given
1407     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1408     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1409    
1410     # convert mirrored uris to the real ones
1411     real_uris="$(convertmirrors ${uri})"
1412    
1413     # verbose or not
1414     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1415    
1416     # filter wget options if busybox was found
1417     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1418    
1419     # create outputdir
1420     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1421    
1422     for mirror in ${real_uris}
1423     do
1424     # get the name of the output file
1425     outputfile="${mirror##*/}"
1426    
1427     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1428     retval="$?"
1429     if [[ ${retval} = 0 ]]
1430     then
1431     break
1432     else
1433     continue
1434     fi
1435     done
1436    
1437     # return wget retval
1438     return "${retval}"
1439    }
1440    
1441  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1442  fetch_packages()  fetch_packages()
1443  {  {
1444     local i
1445   local list="$@"   local list="$@"
1446   local pkg   local pkg
1447   local mirr   local mirr
# Line 1037  fetch_packages() Line 1450  fetch_packages()
1450   local opt   local opt
1451   local count_current   local count_current
1452   local count_total   local count_total
1453     local wget_opts
1454    
1455   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1456    
1457     # filter wget command if busybox was found
1458     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1459    
1460   # get count of total packages   # get count of total packages
1461   declare -i count_current=0   declare -i count_current=0
# Line 1078  fetch_packages() Line 1495  fetch_packages()
1495   continue   continue
1496   fi   fi
1497    
1498   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1499   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1500   echo -ne " ${COLBLUE}***${COLDEFAULT}"   mdownload --uri "package://${pkg}" --dir "${PKGDIR}" || die "Could not download ${pkg}"
  #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 ]]  
  then  
  break  
  else  
  continue  
  fi  
  done  
   
1501   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1502   then   then
1503   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1504   fi   fi
1505   done   done
1506    
# Line 1113  syncmage() Line 1512  syncmage()
1512  {  {
1513   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1514   then   then
1515   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1516   fi   fi
1517    
1518   local i   local i
1519   for i in ${RSYNC}   for i in ${RSYNC}
1520   do   do
1521   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1522   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1523   then   then
1524   break   break
# Line 1142  syncmage() Line 1528  syncmage()
1528   done   done
1529    
1530   # clean up backup files (foo~)   # clean up backup files (foo~)
1531   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1532    
1533   # check if an newer mage version is available   # check if a newer mage version is available
1534   is_newer_mage_version_available   is_newer_mage_version_available
1535  }  }
1536    
1537    syncmage_tarball()
1538    {
1539     local latest_tarball
1540     local latest_md5
1541     local temp="$(mktemp -d)"
1542     local mirr mymirr
1543     local opt
1544     local tar_opts
1545     local wget_opts
1546    
1547     # try to get the md5 marked as latest on the server
1548     latest_md5="mage-latest.md5"
1549    
1550     # try to get the tarball marked as latest on the server
1551     latest_tarball="mage-latest.tar.bz2"
1552    
1553     # filter wget command if busybox was found
1554     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1555    
1556     for mirr in ${MIRRORS}
1557     do
1558     # path without distribution
1559     # (only for stable|testing|unstable and not DISTROTAG)
1560     case ${mirr##*/} in
1561     stable|testing|unstable) mymirr="${mirr%/*}";;
1562     *) mymirr="${mirr}";;
1563     esac
1564    
1565     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1566     echo "fetching latest md5 from ${mymirr} ..."
1567     mqueryfeature "!verbose" && opt="--quiet"
1568     wget \
1569     ${wget_opts} \
1570     --directory-prefix=${temp} \
1571     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1572    
1573     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1574     echo "fetching latest tarball from ${mymirr} ..."
1575     wget \
1576     ${wget_opts} \
1577     --directory-prefix=${temp} \
1578     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1579     if [[ $? = 0 ]]
1580     then
1581     break
1582     else
1583     continue
1584     fi
1585     done
1586    
1587     if [[ -f ${temp}/${latest_tarball} ]]
1588     then
1589     # check md5
1590     if [[ ! -f ${temp}/${latest_md5} ]]
1591     then
1592     die "md5 is missing ... aborting"
1593     else
1594     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1595     echo -n "checking md5sum... "
1596     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1597     fi
1598    
1599     if [[ -d ${MAGEDIR} ]]
1600     then
1601     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1602     echo "cleaning old mage-tree ${MAGEDIR}..."
1603     # honor mountpoints and empty dirs
1604     if mountpoint -q ${MAGEDIR}
1605     then
1606     if ! mcheckemptydir ${MAGEDIR}
1607     then
1608     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r
1609     fi
1610     else
1611     rm -rf ${MAGEDIR}
1612     fi
1613     fi
1614    
1615     if need_busybox_support tar
1616     then
1617     tar_opts="xjf"
1618     else
1619     tar_opts="xjmf"
1620     fi
1621    
1622     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1623     echo "updating mage-tree from tarball ..."
1624     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1625     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1626    
1627     if [[ -d ${temp} ]]
1628     then
1629     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1630     echo "cleaning temp-files ..."
1631     rm -rf ${temp}
1632     fi
1633    
1634     # check if a newer mage version is available
1635     is_newer_mage_version_available
1636     else
1637     die "Could not fetch the latest tarball ... aborting"
1638     fi
1639    }
1640    
1641  cleanpkg()  cleanpkg()
1642  {  {
1643   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1178  xtitleclean() Line 1668  xtitleclean()
1668  }  }
1669    
1670    
1671  # cuts full pathnames or versioniezed names down to basename  # unused?
1672  choppkgname()  #
1673  {  # # cuts full pathnames or versionized names down to basename
1674   #we want this only if full name was used  # choppkgname()
1675   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1676   then  # #we want this only if full name was used
1677   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1678   #ARCH comes from /etc/mage.rc  # then
1679   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1680    # #ARCH comes from ${MAGERC}
1681    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1682    #
1683    # #cuts version number
1684    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1685    # fi
1686    # }
1687    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1688    
1689  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1690  # $1=pname  # $1=pname
# Line 1218  pname2pcat() Line 1711  pname2pcat()
1711  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1712  check_stable_package()  check_stable_package()
1713  {  {
1714     # first check if this magefile is not blacklisted
1715     blacklisted "$1" || return 1
1716    
1717   local STATE   local STATE
1718   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1719    
1720   # state testing   # state testing
1721   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1722   then   then
1723   case ${STATE} in   case ${STATE} in
1724   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1727  check_stable_package()
1727   fi   fi
1728    
1729   # state unstable   # state unstable
1730   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1731   then   then
1732   case ${STATE} in   case ${STATE} in
1733   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1753  get_highest_magefile()
1753   local PNAME="$2"   local PNAME="$2"
1754   local magefile   local magefile
1755    
1756   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1757     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1758   do   do
1759     [[ -z ${magefile} ]] && continue
1760   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1761   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1762   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1763   then   then
1764   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1765   #for debug only   #for debug only
1766   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1767   fi   fi
1768   done   done
1769    
  # 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  
   
1770   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1771   return 0   return 0
1772  }  }
# Line 1304  get_highest_magefile() Line 1781  get_highest_magefile()
1781  #        1 - error                                #  #        1 - error                                #
1782  #        2 - protected                            #  #        2 - protected                            #
1783  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1784    #        4 - protected but ignored                #
1785  #                                                 #  #                                                 #
1786  ###################################################  ###################################################
1787  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1790  is_config_protected()
1790   local TEST   local TEST
1791   local PROTECTED   local PROTECTED
1792   local IFS   local IFS
1793     local i
1794     local x
1795    
1796   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1797    
1798   # file does not exist; it can be written   # file does not exist; it can be written
1799   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1800    
1801   # to be safe; it may be '§'   # to be safe; it may be '§'
1802   IFS=' '   IFS=' '
1803    
1804   # check ob in config protect   # check if config protected
1805   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1806   do   do
1807   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1808   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1809   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1810   then   then
1811   # setzen das es protected ist   # file is config proteced
1812   PROTECTED=TRUE   PROTECTED=TRUE
1813    
1814   # check ob nicht doch maskiert   # check if not masked
1815   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1816   do   do
1817   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1818   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1819   then   then
1820   PROTECTED=MASKED   PROTECTED=MASKED
1821   fi   fi
1822   done   done
1823    
1824     # check if not ignored
1825     for x in ${CONFIG_PROTECT_IGNORE}
1826     do
1827     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1828     if [[ ${TEST} != ${EXPFILE} ]]
1829     then
1830     PROTECTED=IGNORED
1831     fi
1832     done
1833   fi   fi
1834   done   done
1835    
# Line 1354  is_config_protected() Line 1844  is_config_protected()
1844   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1845   return 3   return 3
1846   ;;   ;;
1847     IGNORED)
1848     #echo "I'm protected, but ignored - keep me, del update"
1849     return 4
1850     ;;
1851   *)   *)
1852   #echo "delete me"   #echo "delete me"
1853   return 0   return 0
# Line 1371  is_config_protected() Line 1865  is_config_protected()
1865  ###################################################  ###################################################
1866  count_protected_files()  count_protected_files()
1867  {  {
1868   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1869     local dirname="${file%/*}"
1870     local filename="${file##*/}"
1871     local count
1872     local output
1873     local oldprotected
1874     local i
1875     local x
1876    
1877     # hack; do not honor a global set IFS like '§'
1878     local IFS
1879    
1880     count=0
1881    
1882     # check if there are already protected files
1883     for oldprotected in $(find ${dirname} -iname "._cfg????_${filename}" |
1884     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1885     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1886     do
1887     count="$(echo ${oldprotected} | sed 's:.*\/._cfg\(.*\)_.*:\1:')"
1888     done
1889    
1890     # dirty hack to convert 0001 -> 1; 0120 -> 120 etc
1891     x="${#count}"
1892     for (( i=0; i<x; i++ ))
1893     do
1894     if [[ ${count:${i}:1} != 0 ]]
1895     then
1896     count="${count:${i}}"
1897     break
1898     fi
1899     done
1900    
1901     count="${count}+1"
1902    
1903     # fill output up with zeros
1904     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1905     output="${output}${count}"
1906    
1907     echo "${output}"
1908  }  }
1909    
1910  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1921  get_uninstall_candidates()
1921   local list   local list
1922   local pcatdir   local pcatdir
1923   local protected   local protected
1924     local i
1925    
1926   # very basic getops   # very basic getops
1927   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1934  get_uninstall_candidates()
1934   shift   shift
1935   done   done
1936    
1937   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1938   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1939    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1940    
1941    
1942   # check needed global vars   # check needed global vars
1943   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1944    
1945   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1946   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1947    
1948   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1949   do   do
# Line 1493  virtuals_add() Line 2028  virtuals_add()
2028   local oldline   local oldline
2029   local line i   local line i
2030   local installed_file   local installed_file
2031     local OLDIFS
2032    
2033   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2034   then   then
2035   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2036   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2037   do   do
2038   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2051  virtuals_add()
2051   # make a backup   # make a backup
2052   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2053    
2054     OLDIFS="${IFS}"
2055   IFS=$'\n'   IFS=$'\n'
2056   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2057   do   do
# Line 1526  virtuals_add() Line 2063  virtuals_add()
2063   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2064   fi   fi
2065   done   done
2066     # unset IFS
2067   #unset IFS   IFS="${OLDIFS}"
2068   else   else
2069   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2070   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2071   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2072   fi   fi
# Line 1539  virtuals_add() Line 2076  virtuals_add()
2076    
2077  #deletes pakages from virtual database  #deletes pakages from virtual database
2078  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2079  virtuals_del() {  virtuals_del()
2080    {
2081    
2082   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2083     local pkgname="$2"
2084   VIRTUAL_NAME=$1   local oldline
2085   PKG_NAME=$2   local method
2086     local line i x
2087   #first check if exists   local pkg_installed
2088   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2089    
2090     # first check if exists
2091     if virtuals_read ${virtualname}
2092   then   then
2093   #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}
2094   declare -i x=0   declare -i x=0
2095   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2096   do   do
2097   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2098   then   then
2099   PKG_INSTALLED=true   pkg_installed=true
2100   fi   fi
2101   ((x++))   ((x++))
2102   done   done
2103    
2104   #abort if not installed   # abort if not installed
2105   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2106   then   then
2107   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2108     echo "${pkgname} does not exists in ${virtualname}."
2109   return 0   return 0
2110   fi   fi
2111    
2112   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2113   then   then
2114   METHOD=update   method=update
2115   else   else
2116   METHOD=delall   method=delall
2117   fi   fi
2118    
2119   #get the complete line   # get the complete line
2120   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2121    
2122   #make a backup   # make a backup of the db
2123   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2124    
2125   #parse virtualdb   # parse virtualdb
2126     OLDIFS="${IFS}"
2127   IFS=$'\n'   IFS=$'\n'
2128   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2129   do   do
2130   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2131   then   then
2132   #delall or update?   #delall or update?
2133   case ${METHOD} in   case ${method} in
2134   update)   update)
2135   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2136   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2137   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2138     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2139   ;;   ;;
2140   delall)   delall)
2141   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2142   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2143     # continue; do not write anything
2144   continue   continue
2145   ;;   ;;
2146   esac   esac
# Line 1603  virtuals_del() { Line 2148  virtuals_del() {
2148   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2149   fi   fi
2150   done   done
2151   unset IFS   # unset IFS
2152     IFS="${OLDIFS}"
2153   else   else
2154   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2155     echo "${virtualname} does not exists in virtual database."
2156   fi   fi
2157  }  }
2158    
# Line 1637  minclude() Line 2184  minclude()
2184  {  {
2185   local i   local i
2186    
2187   if [ -n "$@" ]   if [[ -n $* ]]
2188   then   then
2189   for i in $@   for i in $*
2190   do   do
2191   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2192   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2193   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2194   done   done
2195   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2196   fi   fi
2197  }  }
2198    
# Line 1653  sminclude() Line 2200  sminclude()
2200  {  {
2201   local i   local i
2202    
2203   if [ -n "$@" ]   if [[ -n $* ]]
2204   then   then
2205   for i in $@   for i in $*
2206   do   do
2207   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2208   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2217  is_newer_mage_version_available()
2217   local newest_mage   local newest_mage
2218   local installed_mage   local installed_mage
2219    
2220   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2221   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2222    
2223   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2226  is_newer_mage_version_available()
2226   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2227   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2228   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2229   echo "or your current system installation may brake."   echo "or your current system installation may break."
2230   echo   echo
2231   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2232   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2498  get_value_from_magefile()
2498   local magefile="$2"   local magefile="$2"
2499   local value   local value
2500    
2501     [[ -z ${var} ]] && return 1
2502     [[ -z ${magefile} ]] && return 1
2503    
2504   # local all possible vars of a mage file   # local all possible vars of a mage file
2505   # to prevent bad issues   # to prevent bad issues
2506   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2511  get_value_from_magefile()
2511   local SDEPEND   local SDEPEND
2512   local PROVIDE   local PROVIDE
2513   local PKGTYPE   local PKGTYPE
2514     local MAGE_TARGETS
2515     local SPLIT_PACKAGE_BASE
2516   local preinstall   local preinstall
2517   local postinstall   local postinstall
2518     local preremove
2519     local postremove
2520    
2521   # sanity checks   # sanity checks
2522   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2526  get_value_from_magefile()
2526   source ${magefile}   source ${magefile}
2527   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2528   echo "${value}"   echo "${value}"
2529    
2530     # unset these functions
2531     unset -f preinstall
2532     unset -f postinstall
2533     unset -f preremove
2534     unset -f postremove
2535  }  }
2536    
2537  mage_install()  mage_install()
# Line 1988  mage_install() Line 2548  mage_install()
2548   local PKGTYPE   local PKGTYPE
2549   local preinstall   local preinstall
2550   local postinstall   local postinstall
2551     local preremove
2552     local postremove
2553    
2554   local pcat   local pcat
2555   local pname   local pname
# Line 1997  mage_install() Line 2559  mage_install()
2559   local count_current   local count_current
2560   local magefile   local magefile
2561   local src_install   local src_install
2562     local i
2563    
2564   # very basic getops   # very basic getops
2565   for i in $*   for i in $*
# Line 2070  mage_install() Line 2633  mage_install()
2633   echo B:${pbuild}   echo B:${pbuild}
2634   fi   fi
2635    
2636   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2637     then
2638     # basic svn compat
2639     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2640     then
2641     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2642     do
2643     smage2file="${i}"
2644     done
2645     else
2646     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2647     fi
2648    
2649     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2650     then
2651     # basic svn compat
2652     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2653     then
2654     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2655     do
2656     smage2file="${i}"
2657     done
2658     else
2659     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2660     fi
2661    
2662     else
2663     # basic svn compat
2664     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2665     then
2666     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2667     do
2668     smage2file="${i}"
2669     done
2670     else
2671     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2672     fi
2673     fi
2674    
2675   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2676   then   then
2677     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2678   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2679   else   else
2680   echo   echo
# Line 2086  mage_install() Line 2688  mage_install()
2688   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2689   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2690   then   then
2691   # show a verbose message on src-install   echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... "
  if [[ ${src_install} = true ]]  
  then  
  echo -ne "${COLBLUE} *** ${COLDEFAULT}"  
  echo -ne "merging files: "  
  echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  
  echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"  
  fi  
2692   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2693   fi   fi
2694    
# Line 2149  mage_install() Line 2744  mage_install()
2744  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2745  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2746   echo "successfully installed."   echo "successfully installed."
2747    
2748     # unset these functions
2749     unset -f preinstall
2750     unset -f postinstall
2751     unset -f preremove
2752     unset -f postremove
2753  }  }
2754    
2755  md5sum_packages()  md5sum_packages()
# Line 2201  md5sum_packages() Line 2802  md5sum_packages()
2802   then   then
2803   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2804   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2805   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   mchecksum --rundir "${PKGDIR}" --file "${md5file}" --method md5 || die "md5 for ${pkgfile} failed"
2806   else   else
2807   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2808   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2253  uninstall_packages() Line 2854  uninstall_packages()
2854   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2855   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2856   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2857   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2858   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2859   echo   echo
2860   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2861   echo "( Press [CTRL+C] to abort )"   then
2862   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2863   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2864   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2865   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2866   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2867   sleep 1   do
2868   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2869   echo   sleep 1
2870   echo   done
2871     echo
2872     echo
2873     fi
2874    
2875   for pkg in ${list}   for pkg in ${list}
2876   do   do
# Line 2304  mage_uninstall() Line 2908  mage_uninstall()
2908   local PKGTYPE   local PKGTYPE
2909   local preinstall   local preinstall
2910   local postinstall   local postinstall
2911     local preremove
2912     local postremove
2913    
2914   local pcat   local pcat
2915   local pname   local pname
# Line 2339  mage_uninstall() Line 2945  mage_uninstall()
2945   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2946   echo -n "removing: "   echo -n "removing: "
2947   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2948   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2949    
2950   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2951   source ${magefile}   source ${magefile}
2952    
2953   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 3007  mage_uninstall()
3007  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
3008  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3009   echo "successfully removed."   echo "successfully removed."
3010    
3011     # unset these functions
3012     unset -f preinstall
3013     unset -f postinstall
3014     unset -f preremove
3015     unset -f postremove
3016  }  }
3017    
3018  show_etc_update_mesg() {  show_etc_update_mesg()
3019    {
3020   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3021    
3022   echo   echo
# Line 2415  show_etc_update_mesg() { Line 3028  show_etc_update_mesg() {
3028   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
3029   echo   echo
3030  }  }
3031    
3032    pkgsearch()
3033    {
3034     local string="$1"
3035     local result
3036     local pkg
3037     local pcat
3038     local pname
3039     local magefile
3040     local pver
3041     local pbuild
3042     local state
3043     local descriptiom
3044     local homepage
3045     local license
3046     local i
3047     local all_installed
3048     local ipver
3049     local ipbuild
3050     local latest_available
3051     local depsfull
3052     local sdepsfull
3053     local deps
3054     local sdeps
3055     local dep
3056     local sign
3057    
3058     # only names no versions
3059     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3060     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3061    
3062     # nothing found
3063     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
3064    
3065     for pkg in ${result}
3066     do
3067     # dirty, but does the job
3068     pcat="$(magename2pcat ${pkg}/foo)"
3069     pname="$(magename2pname ${pkg}-foo-foo)"
3070    
3071     # get highest version available
3072     magefile=$(get_highest_magefile ${pcat} ${pname})
3073    
3074     if [[ ! -z ${magefile} ]]
3075     then
3076     # now get all needed infos to print a nice output
3077     pver="$(magename2pver ${magefile})"
3078     pbuild="$(magename2pbuild ${magefile})"
3079     state="$(get_value_from_magefile STATE ${magefile})"
3080     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3081     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3082     license="$(get_value_from_magefile LICENSE ${magefile})"
3083    
3084     # all installed
3085     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3086     do
3087     ipver="$(magename2pver ${i})"
3088     ipbuild="$(magename2pbuild ${i})"
3089    
3090     if [[ -z ${all_installed} ]]
3091     then
3092     all_installed="${ipver}-${ipbuild}"
3093     else
3094     all_installed="${all_installed} ${ipver}-${ipbuild}"
3095     fi
3096     done
3097     [[ -z ${all_installed} ]] && all_installed="none"
3098    
3099     case ${state} in
3100     stable) state=${COLGREEN}"[s] ";;
3101     testing) state=${COLYELLOW}"[t] ";;
3102     unstable) state=${COLRED}"[u] ";;
3103     old) state=${COLGRAY}"[o] ";;
3104     esac
3105    
3106     latest_available="${pver}-${pbuild}"
3107     else
3108     # package is masked
3109     state="${COLRED}[m] "
3110     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3111     fi
3112    
3113     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3114     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3115    
3116     while read sign dep
3117     do
3118     case ${dep} in
3119     "") continue;;
3120     esac
3121    
3122     deps="${deps} $(basename ${dep%-*})"
3123     done << EOF
3124    ${depsfull}
3125    EOF
3126    
3127     while read sign dep
3128     do
3129     case ${dep} in
3130     "") continue;;
3131     esac
3132    
3133     sdeps="${sdeps} $(basename ${dep%-*})"
3134     done << EOF
3135    ${sdepsfull}
3136    EOF
3137    
3138     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3139     echo -e "      Latest available:   ${latest_available}"
3140     echo "      Installed versions: ${all_installed}"
3141     echo "      Description: ${description}"
3142     echo "      Homepage: ${homepage}"
3143     if [[ ! -z ${license} ]]
3144     then
3145     echo "      License:  ${license}"
3146     fi
3147     echo "      Depends: ${deps}"
3148     echo "      SDepends: ${sdeps}"
3149     echo
3150    
3151     unset pcat
3152     unset pname
3153     unset magefile
3154     unset pver
3155     unset pbuild
3156     unset state
3157     unset descriptiom
3158     unset homepage
3159     unset all_installed
3160     unset ipver
3161     unset ipbuild
3162     unset depsfull
3163     unset sdepsfull
3164     unset deps
3165     unset sdeps
3166     unset dep
3167     unset sign
3168     done
3169    }
3170    
3171    export_inherits()
3172    {
3173     local include="$1"
3174     shift
3175    
3176     while [ "$1" ]
3177     do
3178     local functions="$1"
3179    
3180     # sanity checks
3181     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3182     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3183    
3184     eval "${functions}() { ${include}_${functions} ; }"
3185    
3186     # debug
3187     mqueryfeature "debug" && typeset -f "${functions}"
3188    
3189     shift
3190     done
3191    }
3192    
3193    mlibdir()
3194    {
3195     local libdir=lib
3196     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3197    
3198     echo "${libdir}"
3199    }
3200    
3201    ## blacklisted ${magefile}
3202    blacklisted()
3203    {
3204     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3205    
3206     # compat
3207     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3208     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3209    
3210     # support both types for the moment
3211     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3212     then
3213     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3214     else
3215     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3216     fi
3217    
3218     # return 0 if the list not exist; nothin is masked
3219     [[ ! -f ${EXCLUDED} ]] && return 0
3220    
3221     local MAGEFILE="$1"
3222    
3223     local PCAT="$(magename2pcat ${MAGEFILE})"
3224     local PNAME="$(magename2pname ${MAGEFILE})"
3225     local PVER="$(magename2pver ${MAGEFILE})"
3226     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3227    
3228     local EXPCAT EXPNAME EXPVER EXPBUILD
3229     while read EXPCAT EXPNAME EXPVER EXPBUILD
3230     do
3231     # ignore spaces and comments
3232             case "${EXPCAT}" in
3233                     \#*|"") continue ;;
3234             esac
3235    
3236     # exclude full pver
3237     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3238     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3239     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3240     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3241     then
3242     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3243     fi
3244    
3245     # exclude pcat/pname only
3246     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3247     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3248     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3249     then
3250     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3251     fi
3252     done << EOF
3253    $( cat ${EXCLUDED}; echo)
3254    EOF
3255    
3256     return 0
3257    }
3258    
3259    # need_busybox_support ${cmd}
3260    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3261    need_busybox_support()
3262    {
3263     local cmd
3264     cmd="$1"
3265    
3266     if [[ -x /bin/busybox ]]
3267     then
3268     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3269     then
3270     # needs busybox support
3271     return 0
3272     fi
3273     fi
3274    
3275     # no busybox
3276     return 1
3277    }
3278    
3279    # busybox_filter_wget_options ${wget_opts}
3280    busybox_filter_wget_options()
3281    {
3282     local opts="$@"
3283     local i
3284     local fixed_opts
3285    
3286     if need_busybox_support wget
3287     then
3288     for i in ${opts}
3289     do
3290     # show only the allowed ones
3291     case ${i} in
3292     -c|--continue) fixed_opts+=" -c" ;;
3293     -s|--spider) fixed_opts+=" -s" ;;
3294     -q|--quiet) fixed_opts+=" -q" ;;
3295     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3296     --header) shift; fixed_opts+=" --header $1" ;;
3297     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3298     -P) shift; fixed_opts+=" -P $1" ;;
3299     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3300     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3301     # simply drop all other opts
3302     *) continue ;;
3303     esac
3304     done
3305    
3306     echo "${fixed_opts}"
3307     else
3308     echo "${opts}"
3309     fi
3310    }
3311    
3312    have_root_privileges()
3313    {
3314     local retval
3315    
3316     if [[ $(id -u) = 0 ]]
3317     then
3318     retval=0
3319     else
3320     retval=1
3321     fi
3322    
3323     return ${retval}
3324    }
3325    
3326    known_mage_feature()
3327    {
3328     local feature="$1"
3329     local retval
3330    
3331     case "${feature}" in
3332     autosvc|!autosvc) retval=0 ;;
3333     buildlog|!buildlog) retval=0 ;;
3334     ccache|!ccache) retval=0 ;;
3335     check|!check) retval=0 ;;
3336     compressdoc|!compressdoc) retval=0 ;;
3337     debug|!debug) retval=0 ;;
3338     distcc|!distcc) retval=0 ;;
3339     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3340     libtool|!libtool) retval=0 ;;
3341     linuxsymlink|!linuxsymlink) retval=0 ;;
3342     pkgbuild|!pkgbuild) retval=0 ;;
3343     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3344     purge|!purge) retval=0 ;;
3345     qalint|!qalint) retval=0 ;;
3346     regentree|!regentree) retval=0 ;;
3347     resume|!resume) retval=0 ;;
3348     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3349     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3350     static|!static) retval=0 ;;
3351     stepbystep|!stepbystep) retval=0 ;;
3352     strip|!strip) retval=0 ;;
3353     verbose|!verbose) retval=0 ;;
3354     *) retval=1 ;;
3355     esac
3356    
3357     return "${retval}"
3358    }
3359    
3360    load_mage_features()
3361    {
3362     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3363     do
3364     FVERBOSE=off msetfeature ${i}
3365     done
3366    }
3367    
3368    msetfeature()
3369    {
3370     local feature
3371     local count
3372     local i
3373     local found
3374    
3375     for feature in $@
3376     do
3377     found=0
3378     count="${#MAGE_FEATURES_CURRENT[*]}"
3379    
3380     if ! known_mage_feature "${feature}"
3381     then
3382     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3383     return 3
3384     fi
3385    
3386     for ((i=0; i<count; i++))
3387     do
3388     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3389     then
3390     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3391     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3392     found=1
3393     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3394     then
3395     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3396     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3397     found=1
3398     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3399     then
3400     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3401     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3402     found=1
3403     fi
3404     done
3405    
3406     # if the feature was not found after proccessing the whole array
3407     # it was not declared. in this case enable it
3408     if [[ ${found} = 0 ]]
3409     then
3410     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3411     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3412     fi
3413    
3414     export MAGE_FEATURE_CURRENT
3415     done
3416    }
3417    
3418    mqueryfeature()
3419    {
3420     local feature="$1"
3421     local retval=1
3422     local i
3423    
3424     if known_mage_feature "${feature}"
3425     then
3426     for i in ${MAGE_FEATURES_CURRENT[*]}
3427     do
3428     if [[ ${i} = ${feature} ]]
3429     then
3430     retval=0
3431     break # found break here
3432     fi
3433     done
3434     else
3435     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3436     retval=3
3437     fi
3438    
3439     return ${retval}
3440    }
3441    
3442    mprintfeatures()
3443    {
3444     echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"
3445     echo "Local features:   ${MAGE_FEATURES[*]}"
3446     echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"
3447    }

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