Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1675 by niro, Mon Feb 6 09:45:23 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 130  install_directories() Line 226  install_directories()
226   while read pathto posix user group   while read pathto posix user group
227   do   do
228   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
229   [[ ${VERBOSE} = on ]] && echo -e "\t>>> DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> DIR:  ${MROOT}${pathto}"
   
230    
231   # monitors /etc/env.d -> env-rebuild   # monitors /etc/env.d -> env-rebuild
232   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true   [[ ${pathto} = /etc/env.d ]] && export MAGE_ENV_REBUILD=true
# Line 198  install_files() Line 293  install_files()
293   is_config_protected "${pathto}"   is_config_protected "${pathto}"
294   retval="$?"   retval="$?"
295    
296   # 0 - not protected        #   # 0 - not protected         #
297   # 1 - error                #   # 1 - error                 #
298   # 2 - protected            #   # 2 - protected             #
299   # 3 - protected but masked #   # 3 - protected but masked  #
300     # 4 - protected but ignored #
301    
302   case ${retval} in   case ${retval} in
303   # file is not protected - (over)write it   # file is not protected - (over)write it
304   0|3)   0|3)
305   [[ ${VERBOSE} = on ]] && echo -e "\t>>> FILE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> FILE: ${MROOT}${pathto}"
306   install -m "${posix}" -o "${user}" -g "${group}" \   install -m "${posix}" -o "${user}" -g "${group}" \
307   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \   ${BUILDDIR}/${pkgname}/binfiles/"${pathto}" \
308   "${MROOT}${pathto}"   "${MROOT}${pathto}"
# Line 218  install_files() Line 314  install_files()
314   "${user}" \   "${user}" \
315   "${group}" \   "${group}" \
316   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
317   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
318   "${md5sum}"   "${md5sum}"
319   ;;   ;;
320    
321   # file is protected, write backup file   # file is protected, write backup file
322   2)   2)
323   if [[ ${VERBOSE} = on ]]   if mqueryfeature "verbose"
324   then   then
325   echo -en "${COLRED}"   echo -en "${COLRED}"
326   echo -n "! prot "   echo -n "! prot "
# Line 245  install_files() Line 341  install_files()
341   "${user}" \   "${user}" \
342   "${group}" \   "${group}" \
343   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
344   "${dest_protected}")" \   "${dest_protected}")" \
345   "${md5sum}"   "${md5sum}"
346    
347   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
348   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
349   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
350   ;;   ;;
351    
352     # file is protected but ignored, delete the update/do nothing
353     4)
354     if mqueryfeature "verbose"
355     then
356     echo -en "${COLRED}"
357     echo -n "! ignr "
358     echo -en "${COLDEFAULT}"
359     echo " === FILE: ${MROOT}${pathto}"
360     fi
361     # simply do nothing here - only fix mtime
362     fix_descriptor ${pkgname}/.files \
363     "${pathto}" \
364     "${posix}" \
365     "${user}" \
366     "${group}" \
367     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
368     "${MROOT}${pathto}")" \
369     "${md5sum}"
370     ;;
371   esac   esac
372   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
373    
# Line 294  install_symlinks() Line 410  install_symlinks()
410   while read pathto posix link mtime   while read pathto posix link mtime
411   do   do
412   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
413   [[ ${VERBOSE} = on ]] && echo -e "\t>>> LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> LINK: ${MROOT}${pathto}"
414    
415   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
416    
417   # fix mtime and db  # # fix mtime and db
418   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
419   "${pathto}" \  # "${pathto}" \
420   "${posix}" \  # "${posix}" \
421   "${link}" \  # "${link}" \
422   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
423   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
424    
425   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
426    
427   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
428   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
429   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
430    
431   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
432   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 442  install_blockdevices()
442   local pkgname="$1"   local pkgname="$1"
443   local pathto   local pathto
444   local posix   local posix
445     local user
446     local group
447   local IFS   local IFS
448    
449   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 457  install_blockdevices()
457   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
458   IFS=§   IFS=§
459    
460   while read pathto posix   while read pathto posix major minor user group
461   do   do
462   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
463   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
464    
465   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
466     # make it optional atm !!
467     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
468     then
469     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
470     fi
471   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
472    
473   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 484  install_characterdevices()
484   local pkgname="$1"   local pkgname="$1"
485   local pathto   local pathto
486   local posix   local posix
487     local major
488     local minor
489     local user
490     local group
491   local IFS   local IFS
492    
493   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 501  install_characterdevices()
501   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
502   IFS=§   IFS=§
503    
504   while read pathto posix   while read pathto posix major minor user group
505   do   do
506   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
507   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
508    
509   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
510    
511     # make it optional atm !!
512     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
513     then
514     chown "${user}:${group}" "${MROOT}${pathto}"
515     fi
516   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
517    
518   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
519   IFS=$'\n'   IFS=$'\n'
520  }  }
521    
522    ###################################################
523    # function install_fifos                          #
524    # install_fifos $PKGNAME                    #
525    ###################################################
526    install_fifos()
527    {
528     local pkgname="$1"
529     local pathto
530     local posix
531     local user
532     local group
533     local IFS
534    
535     # sanity checks; abort if not given
536     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
537    
538     # check needed global vars
539     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
540    
541     # make it optional atm !!
542     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
543     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
544    
545     # sets fieldseperator to "§" instead of " "
546     IFS=§
547    
548     while read pathto posix user group
549     do
550     [ -z "${pathto}" ] && continue
551     mqueryfeature "verbose" && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
552    
553     mkfifo -m "${posix}" "${MROOT}${pathto}"
554     chown "${user}:${group}" "${MROOT}${pathto}"
555     done < ${BUILDDIR}/${pkgname}/.fifo
556    
557     # very important: unsetting the '§' fieldseperator
558     IFS=$'\n'
559    }
560    
561    
562  ###################################################  ###################################################
563  # function build_doinstall                        #  # function build_doinstall                        #
564  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
565  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
566  ###################################################  ###################################################
567  build_doinstall()  build_doinstall()
568  {  {
# Line 398  build_doinstall() Line 570  build_doinstall()
570    
571   # sanity checks; abort if not given   # sanity checks; abort if not given
572   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
573    
574   # this is only a wrapper   # this is only a wrapper
575    
576   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 585  build_doinstall()
585   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
586   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
587   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
588     install_fifos ${pkgname} || die "install fifos ${pkgname}"
589  }  }
590    
591    
# Line 432  install_database_entry() Line 605  install_database_entry()
605   local magefile   local magefile
606   local dbrecorddir   local dbrecorddir
607   local provide   local provide
608     local i
609    
610   # very basic getops   # very basic getops
611   for i in $*   for i in $*
# Line 473  install_database_entry() Line 647  install_database_entry()
647    
648   # create fake file descriptors   # create fake file descriptors
649   # used by virtual and source packages   # used by virtual and source packages
650   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
651   do   do
652   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
653   done   done
# Line 492  install_database_entry() Line 665  install_database_entry()
665    
666   # normal packages needs these files   # normal packages needs these files
667   local i   local i
668   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
669   do   do
670   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
671   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
672     then
673     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
674     fi
675   done   done
676   ;;   ;;
677   esac   esac
# Line 504  install_database_entry() Line 680  install_database_entry()
680   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
681   if [ -n "${provide}" ]   if [ -n "${provide}" ]
682   then   then
683   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
684     do
685     virtuals_add "${i}" "${pcat}/${pname}"
686     done
687   fi   fi
688  }  }
689    
# Line 523  remove_database_entry() Line 702  remove_database_entry()
702   local magefile   local magefile
703   local dbrecorddir   local dbrecorddir
704   local provide   local provide
705     local i
706    
707   # very basic getops   # very basic getops
708   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 732  remove_database_entry()
732   # abort if mage file not exists   # abort if mage file not exists
733   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
734    
735   # first unregister virtuals   # remove virtuals only if no other exist
736   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
737   then   then
738   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
739     provide="$(get_value_from_magefile PROVIDE ${magefile})"
740     if [ -n "${provide}" ]
741     then
742     for i in ${provide}
743     do
744     virtuals_del "${i}" "${pcat}/${pname}"
745     done
746     fi
747   fi   fi
748    
749   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 753  remove_database_entry()
753   fi   fi
754  }  }
755    
756    # get the number of installed packages
757    count_installed_pkgs()
758    {
759     local pcat
760     local pname
761     local pkg
762     local i
763    
764     # very basic getops
765     for i in $*
766     do
767     case $1 in
768     --pcat|-c) shift; pcat="$1" ;;
769     --pname|-n) shift; pname="$1" ;;
770     esac
771     shift
772     done
773    
774     # sanity checks; abort if not given
775     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
776     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
777    
778     declare -i i=0
779     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
780     do
781     (( i++ ))
782     #echo "$i ${pkg}"
783     done
784    
785     # return the value
786     echo "${i}"
787    }
788    
789    
790  ###################################################  ###################################################
791  # function compare_mtime                          #  # function compare_mtime                          #
# Line 662  remove_symlinks() Line 882  remove_symlinks()
882   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
883   if [ ! -L "${MROOT}${pathto}" ]   if [ ! -L "${MROOT}${pathto}" ]
884   then   then
885   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
886   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === LINK: ${MROOT}${pathto}"
887   continue   continue
888   fi   fi
# Line 674  remove_symlinks() Line 894  remove_symlinks()
894   # 1=keep me   #   # 1=keep me   #
895   case ${retval} in   case ${retval} in
896   0)   0)
897   [[ ${VERBOSE} = on ]] && echo -e "\t<<< LINK: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< LINK: ${MROOT}${pathto}"
898   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
899   ;;   ;;
900    
901   1)   1)
902   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
903   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === LINK: ${MROOT}${pathto}"
904   ;;   ;;
905   esac   esac
# Line 726  remove_files() Line 946  remove_files()
946   done   done
947    
948   # sanity checks; abort if not given   # sanity checks; abort if not given
949   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
950   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
951   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
952   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
953   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
954    
955   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 964  remove_files()
964   do   do
965   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
966    
967   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
968   then   then
969   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
970   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
971   continue   continue
972   fi   fi
# Line 758  remove_files() Line 978  remove_files()
978   # 1=keep me   #   # 1=keep me   #
979   case ${retval} in   case ${retval} in
980   0)   0)
981   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
982   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
983   ;;   is_config_protected "${pathto}"
984     retval="$?"
985    
986     # 0 - not protected         #
987     # 1 - error                 #
988     # 2 - protected             #
989     # 3 - protected but masked  #
990     # 4 - protected but ignored #
991    
992     case ${retval} in
993     # file is not protected - delete it
994     0|3)
995     mqueryfeature "verbose" && echo -e "\t<<< FILE: ${MROOT}${pathto}"
996     rm "${MROOT}${pathto}"
997     ;;
998    
999     # file is protected, do not delete
1000     2)
1001     if mqueryfeature "verbose"
1002     then
1003     echo -en "${COLRED}"
1004     echo -n "! prot "
1005     echo -en "${COLDEFAULT}"
1006     echo " === FILE: ${MROOT}${pathto}"
1007     fi
1008     ;;
1009    
1010     # file is protected but ignored, delete the update/do nothing
1011     4)
1012     if mqueryfeature "verbose"
1013     then
1014     echo -en "${COLRED}"
1015     echo -n "! ignr "
1016     echo -en "${COLDEFAULT}"
1017     echo " === FILE: ${MROOT}${pathto}"
1018     fi
1019     # simply do nothing here
1020     ;;
1021     esac
1022     ;;
1023   1)   1)
1024   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1025   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
1026   ;;   ;;
1027   esac   esac
# Line 782  remove_blockdevices() Line 1040  remove_blockdevices()
1040  {  {
1041   local pathto   local pathto
1042   local posix   local posix
1043     local user
1044     local group
1045   local IFS   local IFS
1046   local pcat   local pcat
1047   local pname   local pname
# Line 805  remove_blockdevices() Line 1065  remove_blockdevices()
1065   done   done
1066    
1067   # sanity checks; abort if not given   # sanity checks; abort if not given
1068   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1069   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1070   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1071   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1072   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1073    
1074   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1079  remove_blockdevices()
1079   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1080   IFS=§   IFS=§
1081    
1082   while read pathto posix   while read pathto posix user group
1083   do   do
1084   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1085    
1086   [[ ${VERBOSE} = on ]] && echo -e "\t<<< PIPE: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< PIPE: ${MROOT}${pathto}"
1087   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1088   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes   done < ${MROOT}${INSTALLDB}/${pfull}/.pipes
1089    
# Line 840  remove_characterdevices() Line 1100  remove_characterdevices()
1100  {  {
1101   local pathto   local pathto
1102   local posix   local posix
1103     local user
1104     local group
1105   local IFS   local IFS
1106   local pcat   local pcat
1107   local pname   local pname
# Line 863  remove_characterdevices() Line 1125  remove_characterdevices()
1125   done   done
1126    
1127   # sanity checks; abort if not given   # sanity checks; abort if not given
1128   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1129   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1130   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1131   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1132   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1133    
1134   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1139  remove_characterdevices()
1139   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1140   IFS=§   IFS=§
1141    
1142   while read pathto posix   while read pathto posix user group
1143   do   do
1144   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1145    
1146   [[ ${VERBOSE} = on ]] && echo -e "\t<<< CHAR: ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< CHAR: ${MROOT}${pathto}"
1147   rm "${MROOT}${pathto}"   rm "${MROOT}${pathto}"
1148   done < ${MROOT}${INSTALLDB}/${pfull}/.char   done < ${MROOT}${INSTALLDB}/${pfull}/.char
1149    
# Line 891  remove_characterdevices() Line 1153  remove_characterdevices()
1153    
1154    
1155  ###################################################  ###################################################
1156    # function remove_fifos                           #
1157    # remove_fifos $PKGNAME                     #
1158    ###################################################
1159    remove_fifos()
1160    {
1161     local pathto
1162     local posix
1163     local user
1164     local group
1165     local IFS
1166     local pcat
1167     local pname
1168     local pver
1169     local pbuild
1170     local i
1171     local pfull
1172    
1173     IFS=$'\n'
1174    
1175     # very basic getops
1176     for i in $*
1177     do
1178     case $1 in
1179     --pcat|-c) shift; pcat="$1" ;;
1180     --pname|-n) shift; pname="$1" ;;
1181     --pver|-v) shift; pver="$1" ;;
1182     --pbuild|-b) shift; pbuild="$1" ;;
1183     esac
1184     shift
1185     done
1186    
1187     # sanity checks; abort if not given
1188     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1189     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1190     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1191     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1192     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1193    
1194     # check needed global vars
1195     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1196    
1197     # make it optional atm !!
1198     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1199     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1200    
1201     # sets fieldseperator to "§" instead of " "
1202     IFS=§
1203    
1204     while read pathto posix user group
1205     do
1206     [ -z "${pathto}" ] && continue
1207    
1208     mqueryfeature "verbose" && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1209     rm "${MROOT}${pathto}"
1210     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1211    
1212     # very important: unsetting the '§' fieldseperator
1213     IFS=$'\n'
1214    }
1215    
1216    
1217    ###################################################
1218  # function remove_direcories                      #  # function remove_direcories                      #
1219  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1220  ###################################################  ###################################################
# Line 921  remove_directories() Line 1245  remove_directories()
1245   done   done
1246    
1247   # sanity checks; abort if not given   # sanity checks; abort if not given
1248   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1249   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1250   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1251   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1252   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1253    
1254   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1256  remove_directories()
1256    
1257   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1258    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1259   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1260   IFS=§   IFS=§
1261    
1262   while read pathto posix   # reversed order is mandatory !
1263     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1264   do   do
1265   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1266    
1267   if [ ! -d "${MROOT}${pathto}" ]   if [ ! -d "${MROOT}${pathto}" ]
1268   then   then
1269   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1270   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1271   continue   continue
1272   fi   fi
# Line 953  remove_directories() Line 1274  remove_directories()
1274   # exclude .keep directories   # exclude .keep directories
1275   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1276   then   then
1277   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1278   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1279   continue   continue
1280   fi   fi
1281    
# Line 966  remove_directories() Line 1287  remove_directories()
1287    
1288   if rmdir "${MROOT}${pathto}" &> /dev/null   if rmdir "${MROOT}${pathto}" &> /dev/null
1289   then   then
1290   [[ ${VERBOSE} = on ]] && echo -e "\t<<< DIR:  ${MROOT}${pathto}"   mqueryfeature "verbose" && echo -e "\t<<< DIR:  ${MROOT}${pathto}"
1291   else   else
1292   [[ ${VERBOSE} = on ]] && \   mqueryfeature "verbose" && \
1293   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1294   fi   fi
1295   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1296    
1297   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1298   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1302  remove_directories()
1302  ###################################################  ###################################################
1303  # function build_douninstall                      #  # function build_douninstall                      #
1304  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1305  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1306  ###################################################  ###################################################
1307  build_douninstall()  build_douninstall()
1308  {  {
# Line 1015  build_douninstall() Line 1336  build_douninstall()
1336   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1337   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1338    
1339   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1340   do   do
1341   remove_${i} \   remove_${i} \
1342   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1026  build_douninstall() Line 1347  build_douninstall()
1347   done   done
1348  }  }
1349    
1350    # convertmirrors [uri]
1351    convertmirrors()
1352    {
1353     local uri="$1"
1354     local scheme
1355     local mirror
1356     local mirrors
1357     local addon
1358     local real_uri
1359     local output
1360    
1361     # needs
1362     [[ -z ${MIRRORS} ]] && die "convertmirrors(): no mirrors defined!"
1363     [[ -z ${SOURCEFORGE_MIRRORS} ]] && die "convertmirrors(): no sourceforge mirrors defined!"
1364     [[ -z ${GNU_MIRRORS} ]] && die "convertmirrors(): no gnu mirrors defined!"
1365     [[ -z ${GNOME_MIRRORS} ]] && die "convertmirrors(): no gnome mirrors defined!"
1366     [[ -z ${KDE_MIRRORS} ]] && die "convertmirrors(): no kde mirrors defined!"
1367    
1368     # check known uri schemes
1369     case ${uri} in
1370     http://*|https://*|ftp://*|ftps://*) mirrors="" ;;
1371     mirror://*) mirrors="${MIRRORS}"; scheme="mirror://"; addon="/sources" ;;
1372     package://*) mirrors="${MIRRORS}"; scheme="package://"; addon="/${PACKAGES_SERVER_PATH}" ;;
1373     gnu://*) mirrors="${GNU_MIRRORS}"; scheme="gnu://" ;;
1374     sourceforge://*) mirrors="${SOURCEFORGE_MIRRORS}"; scheme="sourceforge://" ;;
1375     gnome://*) mirrors="${GNOME_MIRRORS}"; scheme="gnome://" ;;
1376     kde://*) mirrors="${KDE_MIRRORS}"; scheme="kde://" ;;
1377     *) die "convertmirror(): unsupported uri scheme in '${uri}'!" ;;
1378     esac
1379    
1380     if [[ ! -z ${mirrors} ]]
1381     then
1382     for mirror in ${mirrors}
1383     do
1384     # add a whitespace to the output
1385     [[ -z ${output} ]] || output+=" "
1386     output+="${mirror}${addon}/${uri/${scheme}/}"
1387     done
1388     else
1389     output="${uri}"
1390     fi
1391    
1392     echo "${output}"
1393    }
1394    
1395    mdownload()
1396    {
1397     local i
1398     local uri
1399     local real_uris
1400     local mirror
1401     local outputfile
1402     local outputdir
1403     local retval
1404     local wget_opts
1405    
1406     # very basic getops
1407     for i in $*
1408     do
1409     case $1 in
1410     --uri|-u) shift; uri="$1" ;;
1411     --dir|-d) shift; outputdir="$1" ;;
1412     esac
1413     shift
1414     done
1415    
1416     # sanity checks; abort if not given
1417     [[ -z ${uri} ]] && die "mdownload(): no uri given!"
1418     [[ -z ${outputdir} ]] && die "mdownload(): no dir given!"
1419    
1420     # convert mirrored uris to the real ones
1421     real_uris="$(convertmirrors ${uri})"
1422    
1423     # verbose or not
1424     mqueryfeature "!verbose" && wget_opts+=" --quiet"
1425    
1426     # filter wget options if busybox was found
1427     wget_opts+=" $(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1428    
1429     # create outputdir
1430     [[ ! -d ${outputdir} ]] && install -d "${outputdir}"
1431    
1432     for mirror in ${real_uris}
1433     do
1434     # get the name of the output file
1435     outputfile="${mirror##*/}"
1436    
1437     wget ${wget_opts} --output-document="${outputdir}/${outputfile}" "${mirror}"
1438     retval="$?"
1439     if [[ ${retval} = 0 ]]
1440     then
1441     break
1442     else
1443     continue
1444     fi
1445     done
1446    
1447     # return wget retval
1448     return "${retval}"
1449    }
1450    
1451  # fetch_packages /path/to/mage/file1 /path/to/mage/file2  # fetch_packages /path/to/mage/file1 /path/to/mage/file2
1452  fetch_packages()  fetch_packages()
1453  {  {
1454     local i
1455   local list="$@"   local list="$@"
1456   local pkg   local pkg
1457   local mirr   local mirr
# Line 1037  fetch_packages() Line 1460  fetch_packages()
1460   local opt   local opt
1461   local count_current   local count_current
1462   local count_total   local count_total
1463     local wget_opts
1464    
1465     [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}."
1466    
1467   [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc."   # filter wget command if busybox was found
1468     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1469    
1470   # get count of total packages   # get count of total packages
1471   declare -i count_current=0   declare -i count_current=0
# Line 1078  fetch_packages() Line 1505  fetch_packages()
1505   continue   continue
1506   fi   fi
1507    
1508   for mirr in ${MIRRORS}   echo -ne " ${COLBLUE}***${COLDEFAULT}"
1509   do   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1510   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  
   
1511   if [ ! -f ${PKGDIR}/${pkg} ]   if [ ! -f ${PKGDIR}/${pkg} ]
1512   then   then
1513   die "Could not download ${pkg}"   die "Package '${pkg}' after download not found in '${PKGDIR}'"
1514   fi   fi
1515   done   done
1516    
# Line 1113  syncmage() Line 1522  syncmage()
1522  {  {
1523   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1524   then   then
1525   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1526   fi   fi
1527    
1528   local i   local i
1529   for i in ${RSYNC}   for i in ${RSYNC}
1530   do   do
1531   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1532   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1533   then   then
1534   break   break
# Line 1141  syncmage() Line 1537  syncmage()
1537   fi   fi
1538   done   done
1539    
1540   # clean up backup files (foo~)   # clean up backup files (foo~)
1541   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1542    
1543     # check if a newer mage version is available
1544     is_newer_mage_version_available
1545    }
1546    
1547    syncmage_tarball()
1548    {
1549     local latest_tarball
1550     local latest_md5
1551     local temp="$(mktemp -d)"
1552     local mirr mymirr
1553     local opt
1554     local tar_opts
1555     local wget_opts
1556    
1557     # try to get the md5 marked as latest on the server
1558     latest_md5="mage-latest.md5"
1559    
1560     # try to get the tarball marked as latest on the server
1561     latest_tarball="mage-latest.tar.bz2"
1562    
1563     # filter wget command if busybox was found
1564     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1565    
1566     for mirr in ${MIRRORS}
1567     do
1568     # path without distribution
1569     # (only for stable|testing|unstable and not DISTROTAG)
1570     case ${mirr##*/} in
1571     stable|testing|unstable) mymirr="${mirr%/*}";;
1572     *) mymirr="${mirr}";;
1573     esac
1574    
1575     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1576     echo "fetching latest md5 from ${mymirr} ..."
1577     mqueryfeature "!verbose" && opt="--quiet"
1578     wget \
1579     ${wget_opts} \
1580     --directory-prefix=${temp} \
1581     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1582    
1583     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1584     echo "fetching latest tarball from ${mymirr} ..."
1585     wget \
1586     ${wget_opts} \
1587     --directory-prefix=${temp} \
1588     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1589     if [[ $? = 0 ]]
1590     then
1591     break
1592     else
1593     continue
1594     fi
1595     done
1596    
1597     if [[ -f ${temp}/${latest_tarball} ]]
1598     then
1599     # check md5
1600     if [[ ! -f ${temp}/${latest_md5} ]]
1601     then
1602     die "md5 is missing ... aborting"
1603     else
1604     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1605     echo -n "checking md5sum... "
1606     mchecksum --rundir "${temp}" --file "${latest_md5}" --method md5 || die "md5 for ${latest_tarball} failed"
1607     fi
1608    
1609     if [[ -d ${MAGEDIR} ]]
1610     then
1611     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1612     echo "cleaning old mage-tree ${MAGEDIR}..."
1613     # honor mountpoints and empty dirs
1614     if mountpoint -q ${MAGEDIR}
1615     then
1616     if ! mcheckemptydir ${MAGEDIR}
1617     then
1618     find ${MAGEDIR} -mindepth 1 -maxdepth 1 | xarg --no-run-if-empty rm -r
1619     fi
1620     else
1621     rm -rf ${MAGEDIR}
1622     fi
1623     fi
1624    
1625     if need_busybox_support tar
1626     then
1627     tar_opts="xjf"
1628     else
1629     tar_opts="xjmf"
1630     fi
1631    
1632     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1633     echo "updating mage-tree from tarball ..."
1634     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1635     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1636    
1637   # check if an newer mage version is available   if [[ -d ${temp} ]]
1638   is_newer_mage_version_available   then
1639     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1640     echo "cleaning temp-files ..."
1641     rm -rf ${temp}
1642     fi
1643    
1644     # check if a newer mage version is available
1645     is_newer_mage_version_available
1646     else
1647     die "Could not fetch the latest tarball ... aborting"
1648     fi
1649  }  }
1650    
1651  cleanpkg()  cleanpkg()
# Line 1178  xtitleclean() Line 1678  xtitleclean()
1678  }  }
1679    
1680    
1681  # cuts full pathnames or versioniezed names down to basename  # unused?
1682  choppkgname()  #
1683  {  # # cuts full pathnames or versionized names down to basename
1684   #we want this only if full name was used  # choppkgname()
1685   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]  # {
1686   then  # #we want this only if full name was used
1687   #cuts ARCH and PBUILD  # if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1688   #ARCH comes from /etc/mage.rc  # then
1689   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")  # #cuts ARCH and PBUILD
1690    # #ARCH comes from ${MAGERC}
1691    # MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}$(print_distrotag)-r*.::g")
1692    #
1693    # #cuts version number
1694    # MAGENAME=$(basename ${MAGENAME%-*} .mage)
1695    # fi
1696    # }
1697    
  #cuts version number  
  MAGENAME=$(basename ${MAGENAME%-*} .mage)  
  fi  
 }  
1698    
1699  # get_categorie $PNAME, returns CATEGORIE  # get_categorie $PNAME, returns CATEGORIE
1700  # $1=pname  # $1=pname
# Line 1218  pname2pcat() Line 1721  pname2pcat()
1721  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1722  check_stable_package()  check_stable_package()
1723  {  {
1724     # first check if this magefile is not blacklisted
1725     blacklisted "$1" || return 1
1726    
1727   local STATE   local STATE
1728   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1729    
1730   # state testing   # state testing
1731   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1732   then   then
1733   case ${STATE} in   case ${STATE} in
1734   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1737  check_stable_package()
1737   fi   fi
1738    
1739   # state unstable   # state unstable
1740   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1741   then   then
1742   case ${STATE} in   case ${STATE} in
1743   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1763  get_highest_magefile()
1763   local PNAME="$2"   local PNAME="$2"
1764   local magefile   local magefile
1765    
1766   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1767     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1768   do   do
1769     [[ -z ${magefile} ]] && continue
1770   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1771   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1772   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1773   then   then
1774   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
1775   #for debug only   #for debug only
1776   [[ ${MAGEDEBUG} = on ]] && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"   mqueryfeature "debug" && echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}"
1777   fi   fi
1778   done   done
1779    
  # 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  
   
1780   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1781   return 0   return 0
1782  }  }
# Line 1304  get_highest_magefile() Line 1791  get_highest_magefile()
1791  #        1 - error                                #  #        1 - error                                #
1792  #        2 - protected                            #  #        2 - protected                            #
1793  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1794    #        4 - protected but ignored                #
1795  #                                                 #  #                                                 #
1796  ###################################################  ###################################################
1797  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1800  is_config_protected()
1800   local TEST   local TEST
1801   local PROTECTED   local PROTECTED
1802   local IFS   local IFS
1803     local i
1804     local x
1805    
1806   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1807    
1808   # file does not exist; it can be written   # file does not exist; it can be written
1809   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1810    
1811   # to be safe; it may be '§'   # to be safe; it may be '§'
1812   IFS=' '   IFS=' '
1813    
1814   # check ob in config protect   # check if config protected
1815   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1816   do   do
1817   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1818   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1819   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1820   then   then
1821   # setzen das es protected ist   # file is config proteced
1822   PROTECTED=TRUE   PROTECTED=TRUE
1823    
1824   # check ob nicht doch maskiert   # check if not masked
1825   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1826   do   do
1827   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1828   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1829   then   then
1830   PROTECTED=MASKED   PROTECTED=MASKED
1831   fi   fi
1832   done   done
1833    
1834     # check if not ignored
1835     for x in ${CONFIG_PROTECT_IGNORE}
1836     do
1837     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1838     if [[ ${TEST} != ${EXPFILE} ]]
1839     then
1840     PROTECTED=IGNORED
1841     fi
1842     done
1843   fi   fi
1844   done   done
1845    
# Line 1354  is_config_protected() Line 1854  is_config_protected()
1854   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1855   return 3   return 3
1856   ;;   ;;
1857     IGNORED)
1858     #echo "I'm protected, but ignored - keep me, del update"
1859     return 4
1860     ;;
1861   *)   *)
1862   #echo "delete me"   #echo "delete me"
1863   return 0   return 0
# Line 1371  is_config_protected() Line 1875  is_config_protected()
1875  ###################################################  ###################################################
1876  count_protected_files()  count_protected_files()
1877  {  {
1878   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1879     local dirname="${file%/*}"
1880     local filename="${file##*/}"
1881     local count
1882     local output
1883     local i
1884    
1885     declare -i count=0
1886    
1887     # check if there are already protected files
1888     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1889     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1890     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1891     do
1892     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1893     done
1894     (( count ++ ))
1895    
1896     # fill output up with zeros
1897     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1898     output="${output}${count}"
1899    
1900     echo "${output}"
1901  }  }
1902    
1903  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1914  get_uninstall_candidates()
1914   local list   local list
1915   local pcatdir   local pcatdir
1916   local protected   local protected
1917     local i
1918    
1919   # very basic getops   # very basic getops
1920   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1927  get_uninstall_candidates()
1927   shift   shift
1928   done   done
1929    
1930   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1931   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1932    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1933    
1934    
1935   # check needed global vars   # check needed global vars
1936   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1937    
1938   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1939   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1940    
1941   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1942   do   do
# Line 1493  virtuals_add() Line 2021  virtuals_add()
2021   local oldline   local oldline
2022   local line i   local line i
2023   local installed_file   local installed_file
2024     local OLDIFS
2025    
2026   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
2027   then   then
2028   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
2029   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2030   do   do
2031   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 2044  virtuals_add()
2044   # make a backup   # make a backup
2045   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
2046    
2047     OLDIFS="${IFS}"
2048   IFS=$'\n'   IFS=$'\n'
2049   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
2050   do   do
# Line 1526  virtuals_add() Line 2056  virtuals_add()
2056   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
2057   fi   fi
2058   done   done
2059     # unset IFS
2060   #unset IFS   IFS="${OLDIFS}"
2061   else   else
2062   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
2063   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
2064   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
2065   fi   fi
# Line 1539  virtuals_add() Line 2069  virtuals_add()
2069    
2070  #deletes pakages from virtual database  #deletes pakages from virtual database
2071  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
2072  virtuals_del() {  virtuals_del()
2073    {
2074    
2075   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
2076     local pkgname="$2"
2077   VIRTUAL_NAME=$1   local oldline
2078   PKG_NAME=$2   local method
2079     local line i x
2080   #first check if exists   local pkg_installed
2081   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
2082    
2083     # first check if exists
2084     if virtuals_read ${virtualname}
2085   then   then
2086   #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}
2087   declare -i x=0   declare -i x=0
2088   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
2089   do   do
2090   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
2091   then   then
2092   PKG_INSTALLED=true   pkg_installed=true
2093   fi   fi
2094   ((x++))   ((x++))
2095   done   done
2096    
2097   #abort if not installed   # abort if not installed
2098   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
2099   then   then
2100   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2101     echo "${pkgname} does not exists in ${virtualname}."
2102   return 0   return 0
2103   fi   fi
2104    
2105   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
2106   then   then
2107   METHOD=update   method=update
2108   else   else
2109   METHOD=delall   method=delall
2110   fi   fi
2111    
2112   #get the complete line   # get the complete line
2113   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
2114    
2115   #make a backup   # make a backup of the db
2116   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
2117    
2118   #parse virtualdb   # parse virtualdb
2119     OLDIFS="${IFS}"
2120   IFS=$'\n'   IFS=$'\n'
2121   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
2122   do   do
2123   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
2124   then   then
2125   #delall or update?   #delall or update?
2126   case ${METHOD} in   case ${method} in
2127   update)   update)
2128   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2129   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
2130   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
2131     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
2132   ;;   ;;
2133   delall)   delall)
2134   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2135   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
2136     # continue; do not write anything
2137   continue   continue
2138   ;;   ;;
2139   esac   esac
# Line 1603  virtuals_del() { Line 2141  virtuals_del() {
2141   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
2142   fi   fi
2143   done   done
2144   unset IFS   # unset IFS
2145     IFS="${OLDIFS}"
2146   else   else
2147   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2148     echo "${virtualname} does not exists in virtual database."
2149   fi   fi
2150  }  }
2151    
# Line 1637  minclude() Line 2177  minclude()
2177  {  {
2178   local i   local i
2179    
2180   if [ -n "$@" ]   if [[ -n $* ]]
2181   then   then
2182   for i in $@   for i in $*
2183   do   do
2184   [[ ${MAGEDEBUG} = on ]] && \   mqueryfeature "debug" && \
2185   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
2186   source ${MAGEDIR}/include/${i}.minc   source ${MAGEDIR}/include/${i}.minc
2187   done   done
2188   [[ ${MAGEDEBUG} = on ]] && echo   mqueryfeature "debug" && echo
2189   fi   fi
2190  }  }
2191    
# Line 1653  sminclude() Line 2193  sminclude()
2193  {  {
2194   local i   local i
2195    
2196   if [ -n "$@" ]   if [[ -n $* ]]
2197   then   then
2198   for i in $@   for i in $*
2199   do   do
2200   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2201   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2210  is_newer_mage_version_available()
2210   local newest_mage   local newest_mage
2211   local installed_mage   local installed_mage
2212    
2213   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2214   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2215    
2216   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2219  is_newer_mage_version_available()
2219   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2220   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2221   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2222   echo "or your current system installation may brake."   echo "or your current system installation may break."
2223   echo   echo
2224   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2225   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2491  get_value_from_magefile()
2491   local magefile="$2"   local magefile="$2"
2492   local value   local value
2493    
2494     [[ -z ${var} ]] && return 1
2495     [[ -z ${magefile} ]] && return 1
2496    
2497   # local all possible vars of a mage file   # local all possible vars of a mage file
2498   # to prevent bad issues   # to prevent bad issues
2499   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2504  get_value_from_magefile()
2504   local SDEPEND   local SDEPEND
2505   local PROVIDE   local PROVIDE
2506   local PKGTYPE   local PKGTYPE
2507     local MAGE_TARGETS
2508     local SPLIT_PACKAGE_BASE
2509   local preinstall   local preinstall
2510   local postinstall   local postinstall
2511     local preremove
2512     local postremove
2513    
2514   # sanity checks   # sanity checks
2515   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2519  get_value_from_magefile()
2519   source ${magefile}   source ${magefile}
2520   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2521   echo "${value}"   echo "${value}"
2522    
2523     # unset these functions
2524     unset -f preinstall
2525     unset -f postinstall
2526     unset -f preremove
2527     unset -f postremove
2528  }  }
2529    
2530  mage_install()  mage_install()
# Line 1988  mage_install() Line 2541  mage_install()
2541   local PKGTYPE   local PKGTYPE
2542   local preinstall   local preinstall
2543   local postinstall   local postinstall
2544     local preremove
2545     local postremove
2546    
2547   local pcat   local pcat
2548   local pname   local pname
# Line 1997  mage_install() Line 2552  mage_install()
2552   local count_current   local count_current
2553   local magefile   local magefile
2554   local src_install   local src_install
2555     local i
2556    
2557   # very basic getops   # very basic getops
2558   for i in $*   for i in $*
# Line 2070  mage_install() Line 2626  mage_install()
2626   echo B:${pbuild}   echo B:${pbuild}
2627   fi   fi
2628    
2629   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2630     then
2631     # basic svn compat
2632     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2633     then
2634     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2635     do
2636     smage2file="${i}"
2637     done
2638     else
2639     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2640     fi
2641    
2642     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2643     then
2644     # basic svn compat
2645     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2646     then
2647     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2648     do
2649     smage2file="${i}"
2650     done
2651     else
2652     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2653     fi
2654    
2655     else
2656     # basic svn compat
2657     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2658     then
2659     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2660     do
2661     smage2file="${i}"
2662     done
2663     else
2664     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2665     fi
2666     fi
2667    
2668   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2669   then   then
2670     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2671   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2672   else   else
2673   echo   echo
# Line 2086  mage_install() Line 2681  mage_install()
2681   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2682   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2683   then   then
2684   # show a verbose message on src-install   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  
2685   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2686   fi   fi
2687    
# Line 2149  mage_install() Line 2737  mage_install()
2737  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2738  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2739   echo "successfully installed."   echo "successfully installed."
2740    
2741     # unset these functions
2742     unset -f preinstall
2743     unset -f postinstall
2744     unset -f preremove
2745     unset -f postremove
2746  }  }
2747    
2748  md5sum_packages()  md5sum_packages()
# Line 2201  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 2253  uninstall_packages() Line 2847  uninstall_packages()
2847   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2848   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2849   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2850   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2851   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2852   echo   echo
2853   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2854   echo "( Press [CTRL+C] to abort )"   then
2855   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2856   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2857   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2858   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2859   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2860   sleep 1   do
2861   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2862   echo   sleep 1
2863   echo   done
2864     echo
2865     echo
2866     fi
2867    
2868   for pkg in ${list}   for pkg in ${list}
2869   do   do
# Line 2304  mage_uninstall() Line 2901  mage_uninstall()
2901   local PKGTYPE   local PKGTYPE
2902   local preinstall   local preinstall
2903   local postinstall   local postinstall
2904     local preremove
2905     local postremove
2906    
2907   local pcat   local pcat
2908   local pname   local pname
# Line 2339  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="${MAGEDIR}/${pcat}/${pname}/${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 2401  mage_uninstall() Line 3000  mage_uninstall()
3000  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
3001  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
3002   echo "successfully removed."   echo "successfully removed."
3003    
3004     # unset these functions
3005     unset -f preinstall
3006     unset -f postinstall
3007     unset -f preremove
3008     unset -f postremove
3009  }  }
3010    
3011  show_etc_update_mesg() {  show_etc_update_mesg()
3012    {
3013   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
3014    
3015   echo   echo
# Line 2415  show_etc_update_mesg() { Line 3021  show_etc_update_mesg() {
3021   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
3022   echo   echo
3023  }  }
3024    
3025    pkgsearch()
3026    {
3027     local string="$1"
3028     local result
3029     local pkg
3030     local pcat
3031     local pname
3032     local magefile
3033     local pver
3034     local pbuild
3035     local state
3036     local descriptiom
3037     local homepage
3038     local license
3039     local i
3040     local all_installed
3041     local ipver
3042     local ipbuild
3043     local latest_available
3044     local depsfull
3045     local sdepsfull
3046     local deps
3047     local sdeps
3048     local dep
3049     local sign
3050    
3051     # only names no versions
3052     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
3053     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
3054    
3055     # nothing found
3056     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
3057    
3058     for pkg in ${result}
3059     do
3060     # dirty, but does the job
3061     pcat="$(magename2pcat ${pkg}/foo)"
3062     pname="$(magename2pname ${pkg}-foo-foo)"
3063    
3064     # get highest version available
3065     magefile=$(get_highest_magefile ${pcat} ${pname})
3066    
3067     if [[ ! -z ${magefile} ]]
3068     then
3069     # now get all needed infos to print a nice output
3070     pver="$(magename2pver ${magefile})"
3071     pbuild="$(magename2pbuild ${magefile})"
3072     state="$(get_value_from_magefile STATE ${magefile})"
3073     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
3074     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
3075     license="$(get_value_from_magefile LICENSE ${magefile})"
3076    
3077     # all installed
3078     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
3079     do
3080     ipver="$(magename2pver ${i})"
3081     ipbuild="$(magename2pbuild ${i})"
3082    
3083     if [[ -z ${all_installed} ]]
3084     then
3085     all_installed="${ipver}-${ipbuild}"
3086     else
3087     all_installed="${all_installed} ${ipver}-${ipbuild}"
3088     fi
3089     done
3090     [[ -z ${all_installed} ]] && all_installed="none"
3091    
3092     case ${state} in
3093     stable) state=${COLGREEN}"[s] ";;
3094     testing) state=${COLYELLOW}"[t] ";;
3095     unstable) state=${COLRED}"[u] ";;
3096     old) state=${COLGRAY}"[o] ";;
3097     esac
3098    
3099     latest_available="${pver}-${pbuild}"
3100     else
3101     # package is masked
3102     state="${COLRED}[m] "
3103     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
3104     fi
3105    
3106     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
3107     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
3108    
3109     while read sign dep
3110     do
3111     case ${dep} in
3112     "") continue;;
3113     esac
3114    
3115     deps="${deps} $(basename ${dep%-*})"
3116     done << EOF
3117    ${depsfull}
3118    EOF
3119    
3120     while read sign dep
3121     do
3122     case ${dep} in
3123     "") continue;;
3124     esac
3125    
3126     sdeps="${sdeps} $(basename ${dep%-*})"
3127     done << EOF
3128    ${sdepsfull}
3129    EOF
3130    
3131     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
3132     echo -e "      Latest available:   ${latest_available}"
3133     echo "      Installed versions: ${all_installed}"
3134     echo "      Description: ${description}"
3135     echo "      Homepage: ${homepage}"
3136     if [[ ! -z ${license} ]]
3137     then
3138     echo "      License:  ${license}"
3139     fi
3140     echo "      Depends: ${deps}"
3141     echo "      SDepends: ${sdeps}"
3142     echo
3143    
3144     unset pcat
3145     unset pname
3146     unset magefile
3147     unset pver
3148     unset pbuild
3149     unset state
3150     unset descriptiom
3151     unset homepage
3152     unset all_installed
3153     unset ipver
3154     unset ipbuild
3155     unset depsfull
3156     unset sdepsfull
3157     unset deps
3158     unset sdeps
3159     unset dep
3160     unset sign
3161     done
3162    }
3163    
3164    export_inherits()
3165    {
3166     local include="$1"
3167     shift
3168    
3169     while [ "$1" ]
3170     do
3171     local functions="$1"
3172    
3173     # sanity checks
3174     [ -z "${include}" ] && die "export_inherits(): \$include not given."
3175     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
3176    
3177     eval "${functions}() { ${include}_${functions} ; }"
3178    
3179     # debug
3180     mqueryfeature "debug" && typeset -f "${functions}"
3181    
3182     shift
3183     done
3184    }
3185    
3186    mlibdir()
3187    {
3188     local libdir=lib
3189     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3190    
3191     echo "${libdir}"
3192    }
3193    
3194    ## blacklisted ${magefile}
3195    blacklisted()
3196    {
3197     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3198    
3199     # compat
3200     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3201     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3202    
3203     # support both types for the moment
3204     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3205     then
3206     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3207     else
3208     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3209     fi
3210    
3211     # return 0 if the list not exist; nothin is masked
3212     [[ ! -f ${EXCLUDED} ]] && return 0
3213    
3214     local MAGEFILE="$1"
3215    
3216     local PCAT="$(magename2pcat ${MAGEFILE})"
3217     local PNAME="$(magename2pname ${MAGEFILE})"
3218     local PVER="$(magename2pver ${MAGEFILE})"
3219     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3220    
3221     local EXPCAT EXPNAME EXPVER EXPBUILD
3222     while read EXPCAT EXPNAME EXPVER EXPBUILD
3223     do
3224     # ignore spaces and comments
3225             case "${EXPCAT}" in
3226                     \#*|"") continue ;;
3227             esac
3228    
3229     # exclude full pver
3230     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3231     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3232     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3233     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3234     then
3235     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3236     fi
3237    
3238     # exclude pcat/pname only
3239     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3240     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3241     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3242     then
3243     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3244     fi
3245     done << EOF
3246    $( cat ${EXCLUDED}; echo)
3247    EOF
3248    
3249     return 0
3250    }
3251    
3252    # need_busybox_support ${cmd}
3253    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3254    need_busybox_support()
3255    {
3256     local cmd
3257     cmd="$1"
3258    
3259     if [[ -x /bin/busybox ]]
3260     then
3261     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3262     then
3263     # needs busybox support
3264     return 0
3265     fi
3266     fi
3267    
3268     # no busybox
3269     return 1
3270    }
3271    
3272    # busybox_filter_wget_options ${wget_opts}
3273    busybox_filter_wget_options()
3274    {
3275     local opts="$@"
3276     local i
3277     local fixed_opts
3278    
3279     if need_busybox_support wget
3280     then
3281     for i in ${opts}
3282     do
3283     # show only the allowed ones
3284     case ${i} in
3285     -c|--continue) fixed_opts+=" -c" ;;
3286     -s|--spider) fixed_opts+=" -s" ;;
3287     -q|--quiet) fixed_opts+=" -q" ;;
3288     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3289     --header) shift; fixed_opts+=" --header $1" ;;
3290     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3291     -P) shift; fixed_opts+=" -P $1" ;;
3292     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3293     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3294     # simply drop all other opts
3295     *) continue ;;
3296     esac
3297     done
3298    
3299     echo "${fixed_opts}"
3300     else
3301     echo "${opts}"
3302     fi
3303    }
3304    
3305    have_root_privileges()
3306    {
3307     local retval
3308    
3309     if [[ $(id -u) = 0 ]]
3310     then
3311     retval=0
3312     else
3313     retval=1
3314     fi
3315    
3316     return ${retval}
3317    }
3318    
3319    known_mage_feature()
3320    {
3321     local feature="$1"
3322     local retval
3323    
3324     case "${feature}" in
3325     autosvc|!autosvc) retval=0 ;;
3326     buildlog|!buildlog) retval=0 ;;
3327     ccache|!ccache) retval=0 ;;
3328     check|!check) retval=0 ;;
3329     compressdoc|!compressdoc) retval=0 ;;
3330     debug|!debug) retval=0 ;;
3331     distcc|!distcc) retval=0 ;;
3332     kernelsrcunpack|!kernelsrcunpack) retval=0 ;;
3333     libtool|!libtool) retval=0 ;;
3334     linuxsymlink|!linuxsymlink) retval=0 ;;
3335     pkgbuild|!pkgbuild) retval=0 ;;
3336     pkgdistrotag|!pkgdistrotag) retval=0 ;;
3337     purge|!purge) retval=0 ;;
3338     qalint|!qalint) retval=0 ;;
3339     regentree|!regentree) retval=0 ;;
3340     resume|!resume) retval=0 ;;
3341     srcpkgbuild|!srcpkgbuild) retval=0 ;;
3342     srcpkgtarball|!srcpkgtarball) retval=0 ;;
3343     static|!static) retval=0 ;;
3344     stepbystep|!stepbystep) retval=0 ;;
3345     strip|!strip) retval=0 ;;
3346     verbose|!verbose) retval=0 ;;
3347     *) retval=1 ;;
3348     esac
3349    
3350     return "${retval}"
3351    }
3352    
3353    load_mage_features()
3354    {
3355     for i in ${MAGE_FEATURES_GLOBAL[*]} ${MAGE_FEATURES[*]}
3356     do
3357     FVERBOSE=off msetfeature ${i}
3358     done
3359    }
3360    
3361    msetfeature()
3362    {
3363     local feature
3364     local count
3365     local i
3366     local found
3367    
3368     for feature in $@
3369     do
3370     found=0
3371     count="${#MAGE_FEATURES_CURRENT[*]}"
3372    
3373     if ! known_mage_feature "${feature}"
3374     then
3375     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3376     return 3
3377     fi
3378    
3379     for ((i=0; i<count; i++))
3380     do
3381     if [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature} ]]
3382     then
3383     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' already enabled${COLDEFAULT}"
3384     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3385     found=1
3386     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = !${feature} ]]
3387     then
3388     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' currently disabled, enabling it!${COLDEFAULT}"
3389     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3390     found=1
3391     elif [[ ${MAGE_FEATURES_CURRENT[${i}]} = ${feature//!} ]]
3392     then
3393     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature//!}' currently enabled, disabling it!${COLDEFAULT}"
3394     MAGE_FEATURES_CURRENT[${i}]="${feature}"
3395     found=1
3396     fi
3397     done
3398    
3399     # if the feature was not found after proccessing the whole array
3400     # it was not declared. in this case enable it
3401     if [[ ${found} = 0 ]]
3402     then
3403     [[ ${FVERBOSE} = off ]] || echo -e "${COLBLUE}---${COLGREEN} Feature '${feature}' was not declared, enabling it!${COLDEFAULT}"
3404     MAGE_FEATURES_CURRENT=( ${MAGE_FEATURES_CURRENT[*]} "${feature}" )
3405     fi
3406    
3407     export MAGE_FEATURE_CURRENT
3408     done
3409    }
3410    
3411    mqueryfeature()
3412    {
3413     local feature="$1"
3414     local retval=1
3415     local i
3416    
3417     if known_mage_feature "${feature}"
3418     then
3419     for i in ${MAGE_FEATURES_CURRENT[*]}
3420     do
3421     if [[ ${i} = ${feature} ]]
3422     then
3423     retval=0
3424     break # found break here
3425     fi
3426     done
3427     else
3428     [[ ${FVERBOSE} = off ]] || echo -e "${COLRED}Unknown feature '${feature}', ignoring it${COLDEFAULT}"
3429     retval=3
3430     fi
3431    
3432     return ${retval}
3433    }
3434    
3435    mprintfeatures()
3436    {
3437     echo "Global features:  ${MAGE_FEATURES_GLOBAL[*]}"
3438     echo "Local features:   ${MAGE_FEATURES[*]}"
3439     echo "Current features: ${MAGE_FEATURES_CURRENT[*]}"
3440    }

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