Magellan Linux

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

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

revision 252 by niro, Sun Oct 2 14:09:41 2005 UTC revision 1547 by niro, Tue Dec 27 09:58:03 2011 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.6 2005-10-02 14:09:41 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 23  unpack_packages() Line 46  unpack_packages()
46   local pkgtype   local pkgtype
47   local count_current   local count_current
48   local count_total   local count_total
49     local tar_opts
50    
51   # get count of total packages   # get count of total packages
52   declare -i count_current=0   declare -i count_current=0
# Line 54  unpack_packages() Line 78  unpack_packages()
78   continue   continue
79   fi   fi
80    
81     # busybox?
82     if need_busybox_support tar
83     then
84     tar_opts="xjf"
85     else
86     tar_opts="xjmf"
87     fi
88    
89   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "   echo -e " ${COLBLUE}***${COLDEFAULT} unpacking (${count_current}/${count_total}): ${pkg} ... "
90   tar xjmf ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"   tar ${tar_opts} ${PKGDIR}/${pkg} -C ${BUILDDIR} || die "Unpacking package ${pkg}"
91   done   done
92    
93   # add a crlf for a better view   # add a crlf for a better view
# Line 198  install_files() Line 230  install_files()
230   is_config_protected "${pathto}"   is_config_protected "${pathto}"
231   retval="$?"   retval="$?"
232    
233   # 0 - not protected        #   # 0 - not protected         #
234   # 1 - error                #   # 1 - error                 #
235   # 2 - protected            #   # 2 - protected             #
236   # 3 - protected but masked #   # 3 - protected but masked  #
237     # 4 - protected but ignored #
238    
239   case ${retval} in   case ${retval} in
240   # file is not protected - (over)write it   # file is not protected - (over)write it
# Line 218  install_files() Line 251  install_files()
251   "${user}" \   "${user}" \
252   "${group}" \   "${group}" \
253   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
254   "${MROOT}${pathto}")" \   "${MROOT}${pathto}")" \
255   "${md5sum}"   "${md5sum}"
256   ;;   ;;
257    
# Line 245  install_files() Line 278  install_files()
278   "${user}" \   "${user}" \
279   "${group}" \   "${group}" \
280   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
281   "${dest_protected}")" \   "${dest_protected}")" \
282   "${md5sum}"   "${md5sum}"
283    
284   # update global MAGE_PROTECT_COUNTER   # update global MAGE_PROTECT_COUNTER
285   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
286   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
287   ;;   ;;
288    
289     # file is protected but ignored, delete the update/do nothing
290     4)
291     if [[ ${VERBOSE} = on ]]
292     then
293     echo -en "${COLRED}"
294     echo -n "! ignr "
295     echo -en "${COLDEFAULT}"
296     echo " === FILE: ${MROOT}${pathto}"
297     fi
298     # simply do nothing here - only fix mtime
299     fix_descriptor ${pkgname}/.files \
300     "${pathto}" \
301     "${posix}" \
302     "${user}" \
303     "${group}" \
304     "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
305     "${MROOT}${pathto}")" \
306     "${md5sum}"
307     ;;
308   esac   esac
309   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
310    
# Line 298  install_symlinks() Line 351  install_symlinks()
351    
352   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
353    
354   # fix mtime and db  # # fix mtime and db
355   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
356   "${pathto}" \  # "${pathto}" \
357   "${posix}" \  # "${posix}" \
358   "${link}" \  # "${link}" \
359   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
360   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
361    
362   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
363    
364   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
365   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
366   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
367    
368   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
369   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 379  install_blockdevices()
379   local pkgname="$1"   local pkgname="$1"
380   local pathto   local pathto
381   local posix   local posix
382     local user
383     local group
384   local IFS   local IFS
385    
386   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 394  install_blockdevices()
394   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
395   IFS=§   IFS=§
396    
397   while read pathto posix   while read pathto posix major minor user group
398   do   do
399   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
400   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
401    
402   mkfifo -m "${posix}" "${MROOT}$pathto"   mknod -m "${posix}" "${MROOT}${pathto}"
403     # make it optional atm !!
404     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
405     then
406     chown "${user}:${group}" "${MROOT}${pathto}" b "${major}" "${minor}"
407     fi
408   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
409    
410   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 421  install_characterdevices()
421   local pkgname="$1"   local pkgname="$1"
422   local pathto   local pathto
423   local posix   local posix
424     local major
425     local minor
426     local user
427     local group
428   local IFS   local IFS
429    
430   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 438  install_characterdevices()
438   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
439   IFS=§   IFS=§
440    
441   while read pathto posix   while read pathto posix major minor user group
442   do   do
443   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
444   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
445    
446   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" b "${major}" "${minor}"
447    
448     # make it optional atm !!
449     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
450     then
451     chown "${user}:${group}" "${MROOT}${pathto}"
452     fi
453   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
454    
455   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
456   IFS=$'\n'   IFS=$'\n'
457  }  }
458    
459    ###################################################
460    # function install_fifos                          #
461    # install_fifos $PKGNAME                    #
462    ###################################################
463    install_fifos()
464    {
465     local pkgname="$1"
466     local pathto
467     local posix
468     local user
469     local group
470     local IFS
471    
472     # sanity checks; abort if not given
473     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
474    
475     # check needed global vars
476     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
477    
478     # make it optional atm !!
479     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
480     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
481    
482     # sets fieldseperator to "§" instead of " "
483     IFS=§
484    
485     while read pathto posix user group
486     do
487     [ -z "${pathto}" ] && continue
488     [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
489    
490     mkfifo -m "${posix}" "${MROOT}${pathto}"
491     chown "${user}:${group}" "${MROOT}${pathto}"
492     done < ${BUILDDIR}/${pkgname}/.fifo
493    
494     # very important: unsetting the '§' fieldseperator
495     IFS=$'\n'
496    }
497    
498    
499  ###################################################  ###################################################
500  # function build_doinstall                        #  # function build_doinstall                        #
501  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
502  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
503  ###################################################  ###################################################
504  build_doinstall()  build_doinstall()
505  {  {
# Line 398  build_doinstall() Line 507  build_doinstall()
507    
508   # sanity checks; abort if not given   # sanity checks; abort if not given
509   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."   [ -z "${pkgname}" ] && die "build_doinstall() \$pkgname not given."
510    
511   # this is only a wrapper   # this is only a wrapper
512    
513   # NOTE:   # NOTE:
# Line 413  build_doinstall() Line 522  build_doinstall()
522   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
523   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
524   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
525     install_fifos ${pkgname} || die "install fifos ${pkgname}"
526  }  }
527    
528    
# Line 432  install_database_entry() Line 542  install_database_entry()
542   local magefile   local magefile
543   local dbrecorddir   local dbrecorddir
544   local provide   local provide
545     local i
546    
547   # very basic getops   # very basic getops
548   for i in $*   for i in $*
# Line 473  install_database_entry() Line 584  install_database_entry()
584    
585   # create fake file descriptors   # create fake file descriptors
586   # used by virtual and source packages   # used by virtual and source packages
587   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
588   do   do
589   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
590   done   done
# Line 492  install_database_entry() Line 602  install_database_entry()
602    
603   # normal packages needs these files   # normal packages needs these files
604   local i   local i
605   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
606   do   do
607   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   # make .fifo optional atm
608   ${dbrecorddir}/${i}   if [[ -f ${BUILDDIR}/${pkgname}/${i} ]]
609     then
610     install -m 0644 ${BUILDDIR}/${pkgname}/${i} ${dbrecorddir}/${i}
611     fi
612   done   done
613   ;;   ;;
614   esac   esac
# Line 504  install_database_entry() Line 617  install_database_entry()
617   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
618   if [ -n "${provide}" ]   if [ -n "${provide}" ]
619   then   then
620   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
621     do
622     virtuals_add "${i}" "${pcat}/${pname}"
623     done
624   fi   fi
625  }  }
626    
# Line 523  remove_database_entry() Line 639  remove_database_entry()
639   local magefile   local magefile
640   local dbrecorddir   local dbrecorddir
641   local provide   local provide
642     local i
643    
644   # very basic getops   # very basic getops
645   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 669  remove_database_entry()
669   # abort if mage file not exists   # abort if mage file not exists
670   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
671    
672   # first unregister virtuals   # remove virtuals only if no other exist
673   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
674   then   then
675   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
676     provide="$(get_value_from_magefile PROVIDE ${magefile})"
677     if [ -n "${provide}" ]
678     then
679     for i in ${provide}
680     do
681     virtuals_del "${i}" "${pcat}/${pname}"
682     done
683     fi
684   fi   fi
685    
686   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 690  remove_database_entry()
690   fi   fi
691  }  }
692    
693    # get the number of installed packages
694    count_installed_pkgs()
695    {
696     local pcat
697     local pname
698     local pkg
699     local i
700    
701     # very basic getops
702     for i in $*
703     do
704     case $1 in
705     --pcat|-c) shift; pcat="$1" ;;
706     --pname|-n) shift; pname="$1" ;;
707     esac
708     shift
709     done
710    
711     # sanity checks; abort if not given
712     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
713     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
714    
715     declare -i i=0
716     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
717     do
718     (( i++ ))
719     #echo "$i ${pkg}"
720     done
721    
722     # return the value
723     echo "${i}"
724    }
725    
726    
727  ###################################################  ###################################################
728  # function compare_mtime                          #  # function compare_mtime                          #
# Line 726  remove_files() Line 883  remove_files()
883   done   done
884    
885   # sanity checks; abort if not given   # sanity checks; abort if not given
886   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
887   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
888   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
889   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
890   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
891    
892   # check needed global vars   # check needed global vars
# Line 758  remove_files() Line 915  remove_files()
915   # 1=keep me   #   # 1=keep me   #
916   case ${retval} in   case ${retval} in
917   0)   0)
918   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
919   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
920   ;;   is_config_protected "${pathto}"
921     retval="$?"
922    
923     # 0 - not protected         #
924     # 1 - error                 #
925     # 2 - protected             #
926     # 3 - protected but masked  #
927     # 4 - protected but ignored #
928    
929     case ${retval} in
930     # file is not protected - delete it
931     0|3)
932     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
933     rm "${MROOT}${pathto}"
934     ;;
935    
936     # file is protected, do not delete
937     2)
938     if [[ ${VERBOSE} = on ]]
939     then
940     echo -en "${COLRED}"
941     echo -n "! prot "
942     echo -en "${COLDEFAULT}"
943     echo " === FILE: ${MROOT}${pathto}"
944     fi
945     ;;
946    
947     # file is protected but ignored, delete the update/do nothing
948     4)
949     if [[ ${VERBOSE} = on ]]
950     then
951     echo -en "${COLRED}"
952     echo -n "! ignr "
953     echo -en "${COLDEFAULT}"
954     echo " === FILE: ${MROOT}${pathto}"
955     fi
956     # simply do nothing here
957     ;;
958     esac
959     ;;
960   1)   1)
961   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
962   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 782  remove_blockdevices() Line 977  remove_blockdevices()
977  {  {
978   local pathto   local pathto
979   local posix   local posix
980     local user
981     local group
982   local IFS   local IFS
983   local pcat   local pcat
984   local pname   local pname
# Line 805  remove_blockdevices() Line 1002  remove_blockdevices()
1002   done   done
1003    
1004   # sanity checks; abort if not given   # sanity checks; abort if not given
1005   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
1006   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
1007   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
1008   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
1009   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1010    
1011   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 1016  remove_blockdevices()
1016   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1017   IFS=§   IFS=§
1018    
1019   while read pathto posix   while read pathto posix user group
1020   do   do
1021   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1022    
# Line 840  remove_characterdevices() Line 1037  remove_characterdevices()
1037  {  {
1038   local pathto   local pathto
1039   local posix   local posix
1040     local user
1041     local group
1042   local IFS   local IFS
1043   local pcat   local pcat
1044   local pname   local pname
# Line 863  remove_characterdevices() Line 1062  remove_characterdevices()
1062   done   done
1063    
1064   # sanity checks; abort if not given   # sanity checks; abort if not given
1065   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1066   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1067   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1068   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1069   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1070    
1071   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1076  remove_characterdevices()
1076   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1077   IFS=§   IFS=§
1078    
1079   while read pathto posix   while read pathto posix user group
1080   do   do
1081   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1082    
# Line 891  remove_characterdevices() Line 1090  remove_characterdevices()
1090    
1091    
1092  ###################################################  ###################################################
1093    # function remove_fifos                           #
1094    # remove_fifos $PKGNAME                     #
1095    ###################################################
1096    remove_fifos()
1097    {
1098     local pathto
1099     local posix
1100     local user
1101     local group
1102     local IFS
1103     local pcat
1104     local pname
1105     local pver
1106     local pbuild
1107     local i
1108     local pfull
1109    
1110     IFS=$'\n'
1111    
1112     # very basic getops
1113     for i in $*
1114     do
1115     case $1 in
1116     --pcat|-c) shift; pcat="$1" ;;
1117     --pname|-n) shift; pname="$1" ;;
1118     --pver|-v) shift; pver="$1" ;;
1119     --pbuild|-b) shift; pbuild="$1" ;;
1120     esac
1121     shift
1122     done
1123    
1124     # sanity checks; abort if not given
1125     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1126     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1127     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1128     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1129     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1130    
1131     # check needed global vars
1132     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1133    
1134     # make it optional atm !!
1135     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1136     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1137    
1138     # sets fieldseperator to "§" instead of " "
1139     IFS=§
1140    
1141     while read pathto posix user group
1142     do
1143     [ -z "${pathto}" ] && continue
1144    
1145     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1146     rm "${MROOT}${pathto}"
1147     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1148    
1149     # very important: unsetting the '§' fieldseperator
1150     IFS=$'\n'
1151    }
1152    
1153    
1154    ###################################################
1155  # function remove_direcories                      #  # function remove_direcories                      #
1156  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1157  ###################################################  ###################################################
# Line 921  remove_directories() Line 1182  remove_directories()
1182   done   done
1183    
1184   # sanity checks; abort if not given   # sanity checks; abort if not given
1185   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1186   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1187   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1188   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1189   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1190    
1191   # check needed global vars   # check needed global vars
# Line 978  remove_directories() Line 1239  remove_directories()
1239  ###################################################  ###################################################
1240  # function build_douninstall                      #  # function build_douninstall                      #
1241  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1242  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1243  ###################################################  ###################################################
1244  build_douninstall()  build_douninstall()
1245  {  {
# Line 1012  build_douninstall() Line 1273  build_douninstall()
1273   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1274   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1275    
1276   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1277   do   do
1278   remove_${i} \   remove_${i} \
1279   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1034  fetch_packages() Line 1295  fetch_packages()
1295   local opt   local opt
1296   local count_current   local count_current
1297   local count_total   local count_total
1298     local wget_opts
1299    
1300   [ -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}."
1301    
1302     # filter wget command if busybox was found
1303     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1304    
1305   # get count of total packages   # get count of total packages
1306   declare -i count_current=0   declare -i count_current=0
# Line 1082  fetch_packages() Line 1347  fetch_packages()
1347   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1348   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1349   wget \   wget \
1350   --passive-ftp \   ${wget_opts} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1351   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1352   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1353   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1354   then   then
1355   break   break
# Line 1110  syncmage() Line 1372  syncmage()
1372  {  {
1373   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1374   then   then
1375   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1376   fi   fi
1377    
1378   local i   local i
1379   for i in ${RSYNC}   for i in ${RSYNC}
1380   do   do
1381   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1382   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1383   then   then
1384   break   break
# Line 1139  syncmage() Line 1388  syncmage()
1388   done   done
1389    
1390   # clean up backup files (foo~)   # clean up backup files (foo~)
1391   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name \*~ -exec rm '{}' ';'
1392    
1393   # check if an newer mage version is available   # check if a newer mage version is available
1394   is_newer_mage_version_available   is_newer_mage_version_available
1395  }  }
1396    
1397    syncmage_tarball()
1398    {
1399     local latest_tarball
1400     local latest_md5
1401     local temp="$(mktemp -d)"
1402     local mirr mymirr
1403     local opt
1404     local tar_opts
1405     local wget_opts
1406    
1407     # try to get the md5 marked as latest on the server
1408     latest_md5="mage-latest.md5"
1409    
1410     # try to get the tarball marked as latest on the server
1411     latest_tarball="mage-latest.tar.bz2"
1412    
1413     # filter wget command if busybox was found
1414     wget_opts="$(busybox_filter_wget_options ${WGET_FETCH_OPTIONS})"
1415    
1416     for mirr in ${MIRRORS}
1417     do
1418     # path without distribution
1419     mymirr="${mirr%/*}"
1420    
1421     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1422     echo "fetching latest md5 from ${mymirr} ..."
1423     [[ ${VERBOSE} = off ]] && opt="--quiet"
1424     wget \
1425     ${wget_opts} \
1426     --directory-prefix=${temp} \
1427     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1428    
1429     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1430     echo "fetching latest tarball from ${mymirr} ..."
1431     wget \
1432     ${wget_opts} \
1433     --directory-prefix=${temp} \
1434     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1435     if [[ $? = 0 ]]
1436     then
1437     break
1438     else
1439     continue
1440     fi
1441     done
1442    
1443     if [[ -f ${temp}/${latest_tarball} ]]
1444     then
1445     # check md5
1446     if [[ ! -f ${temp}/${latest_md5} ]]
1447     then
1448     die "md5 is missing ... aborting"
1449     else
1450     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1451     echo -n "checking md5sum... "
1452     ( cd ${temp}; md5sum -c ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1453     fi
1454    
1455     if [[ -d ${MAGEDIR} ]]
1456     then
1457     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1458     echo "cleaning old mage-tree ${MAGEDIR}..."
1459     rm -rf ${MAGEDIR}
1460     fi
1461    
1462     if need_busybox_support tar
1463     then
1464     tar_opts="xjf"
1465     else
1466     tar_opts="xjmf"
1467     fi
1468    
1469     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1470     echo "updating mage-tree from tarball ..."
1471     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1472     tar ${tar_opts} ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1473    
1474     if [[ -d ${temp} ]]
1475     then
1476     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1477     echo "cleaning temp-files ..."
1478     rm -rf ${temp}
1479     fi
1480    
1481     # check if a newer mage version is available
1482     is_newer_mage_version_available
1483     else
1484     die "Could not fetch the latest tarball ... aborting"
1485     fi
1486    }
1487    
1488  cleanpkg()  cleanpkg()
1489  {  {
1490   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1182  choppkgname() Line 1522  choppkgname()
1522   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1523   then   then
1524   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1525   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1526   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1527    
1528   #cuts version number   #cuts version number
# Line 1215  pname2pcat() Line 1555  pname2pcat()
1555  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1556  check_stable_package()  check_stable_package()
1557  {  {
1558     # first check if this magefile is not blacklisted
1559     blacklisted "$1" || return 1
1560    
1561   local STATE   local STATE
1562   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1563    
1564   # state testing   # state testing
1565   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1566   then   then
1567   case ${STATE} in   case ${STATE} in
1568   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1571  check_stable_package()
1571   fi   fi
1572    
1573   # state unstable   # state unstable
1574   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1575   then   then
1576   case ${STATE} in   case ${STATE} in
1577   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1254  get_highest_magefile() Line 1597  get_highest_magefile()
1597   local PNAME="$2"   local PNAME="$2"
1598   local magefile   local magefile
1599    
1600   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1601     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/* 2> /dev/null)
1602   do   do
1603     [[ -z ${magefile} ]] && continue
1604   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1605   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1606   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1607   then   then
1608   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1266  get_highest_magefile() Line 1611  get_highest_magefile()
1611   fi   fi
1612   done   done
1613    
1614   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1615   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1616   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1617   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1618   echo  # then
1619   echo -n "All packages named "  # echo
1620   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1621   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1622   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1623   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1624   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1625   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1626   echo "Example:"  # echo
1627   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1628   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1629   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1630   echo "You should know what you are doing, so don't complain about any damage."  # echo "Be warned that these packages are not stable and may cause serious problems."
1631   echo  # echo "You should know what you are doing, so don't complain about any damage."
1632   return 1  # echo
1633   fi  # return 1
1634    # fi
1635    
1636   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1637   return 0   return 0
# Line 1301  get_highest_magefile() Line 1647  get_highest_magefile()
1647  #        1 - error                                #  #        1 - error                                #
1648  #        2 - protected                            #  #        2 - protected                            #
1649  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1650    #        4 - protected but ignored                #
1651  #                                                 #  #                                                 #
1652  ###################################################  ###################################################
1653  is_config_protected()  is_config_protected()
# Line 1309  is_config_protected() Line 1656  is_config_protected()
1656   local TEST   local TEST
1657   local PROTECTED   local PROTECTED
1658   local IFS   local IFS
1659     local i
1660     local x
1661    
1662   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1663    
1664   # file does not exist; it can be written   # file does not exist; it can be written
1665   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1666    
1667   # to be safe; it may be '§'   # to be safe; it may be '§'
1668   IFS=' '   IFS=' '
1669    
1670   # check ob in config protect   # check if config protected
1671   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1672   do   do
1673   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1674   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1675   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1676   then   then
1677   # setzen das es protected ist   # file is config proteced
1678   PROTECTED=TRUE   PROTECTED=TRUE
1679    
1680   # check ob nicht doch maskiert   # check if not masked
1681   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1682   do   do
1683   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1684   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1685   then   then
1686   PROTECTED=MASKED   PROTECTED=MASKED
1687   fi   fi
1688   done   done
1689    
1690     # check if not ignored
1691     for x in ${CONFIG_PROTECT_IGNORE}
1692     do
1693     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1694     if [[ ${TEST} != ${EXPFILE} ]]
1695     then
1696     PROTECTED=IGNORED
1697     fi
1698     done
1699   fi   fi
1700   done   done
1701    
# Line 1351  is_config_protected() Line 1710  is_config_protected()
1710   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1711   return 3   return 3
1712   ;;   ;;
1713     IGNORED)
1714     #echo "I'm protected, but ignored - keep me, del update"
1715     return 4
1716     ;;
1717   *)   *)
1718   #echo "delete me"   #echo "delete me"
1719   return 0   return 0
# Line 1368  is_config_protected() Line 1731  is_config_protected()
1731  ###################################################  ###################################################
1732  count_protected_files()  count_protected_files()
1733  {  {
1734   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1735     local dirname="${file%/*}"
1736     local filename="${file##*/}"
1737     local count
1738     local output
1739     local i
1740    
1741     declare -i count=0
1742    
1743     # check if there are already protected files
1744     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1745     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1746     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1747     do
1748     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1749     done
1750     (( count ++ ))
1751    
1752     # fill output up with zeros
1753     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1754     output="${output}${count}"
1755    
1756     echo "${output}"
1757  }  }
1758    
1759  # call with  # call with
# Line 1385  get_uninstall_candidates() Line 1770  get_uninstall_candidates()
1770   local list   local list
1771   local pcatdir   local pcatdir
1772   local protected   local protected
1773     local i
1774    
1775   # very basic getops   # very basic getops
1776   for i in $*   for i in $*
# Line 1397  get_uninstall_candidates() Line 1783  get_uninstall_candidates()
1783   shift   shift
1784   done   done
1785    
1786   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1787   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1788    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1789    
1790    
1791   # check needed global vars   # check needed global vars
1792   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1793    
1794   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1795   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1796    
1797   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1798   do   do
# Line 1490  virtuals_add() Line 1877  virtuals_add()
1877   local oldline   local oldline
1878   local line i   local line i
1879   local installed_file   local installed_file
1880     local OLDIFS
1881    
1882   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1883   then   then
1884   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1885   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1886   do   do
1887   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 1900  virtuals_add()
1900   # make a backup   # make a backup
1901   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1902    
1903     OLDIFS="${IFS}"
1904   IFS=$'\n'   IFS=$'\n'
1905   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1906   do   do
# Line 1523  virtuals_add() Line 1912  virtuals_add()
1912   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1913   fi   fi
1914   done   done
1915     # unset IFS
1916   #unset IFS   IFS="${OLDIFS}"
1917   else   else
1918   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1919   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1920   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1921   fi   fi
# Line 1536  virtuals_add() Line 1925  virtuals_add()
1925    
1926  #deletes pakages from virtual database  #deletes pakages from virtual database
1927  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1928  virtuals_del() {  virtuals_del()
1929    {
1930    
1931   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1932     local pkgname="$2"
1933   VIRTUAL_NAME=$1   local oldline
1934   PKG_NAME=$2   local method
1935     local line i x
1936   #first check if exists   local pkg_installed
1937   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1938    
1939     # first check if exists
1940     if virtuals_read ${virtualname}
1941   then   then
1942   #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}
1943   declare -i x=0   declare -i x=0
1944   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1945   do   do
1946   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1947   then   then
1948   PKG_INSTALLED=true   pkg_installed=true
1949   fi   fi
1950   ((x++))   ((x++))
1951   done   done
1952    
1953   #abort if not installed   # abort if not installed
1954   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1955   then   then
1956   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1957     echo "${pkgname} does not exists in ${virtualname}."
1958   return 0   return 0
1959   fi   fi
1960    
1961   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1962   then   then
1963   METHOD=update   method=update
1964   else   else
1965   METHOD=delall   method=delall
1966   fi   fi
1967    
1968   #get the complete line   # get the complete line
1969   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1970    
1971   #make a backup   # make a backup of the db
1972   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1973    
1974   #parse virtualdb   # parse virtualdb
1975     OLDIFS="${IFS}"
1976   IFS=$'\n'   IFS=$'\n'
1977   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1978   do   do
1979   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1980   then   then
1981   #delall or update?   #delall or update?
1982   case ${METHOD} in   case ${method} in
1983   update)   update)
1984   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1985   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1986   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1987     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1988   ;;   ;;
1989   delall)   delall)
1990   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1991   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1992     # continue; do not write anything
1993   continue   continue
1994   ;;   ;;
1995   esac   esac
# Line 1600  virtuals_del() { Line 1997  virtuals_del() {
1997   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1998   fi   fi
1999   done   done
2000   unset IFS   # unset IFS
2001     IFS="${OLDIFS}"
2002   else   else
2003   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2004     echo "${virtualname} does not exists in virtual database."
2005   fi   fi
2006  }  }
2007    
# Line 1634  minclude() Line 2033  minclude()
2033  {  {
2034   local i   local i
2035    
2036   if [ -n "$@" ]   if [[ -n $* ]]
2037   then   then
2038   for i in $@   for i in $*
2039   do   do
2040   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
2041   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1650  sminclude() Line 2049  sminclude()
2049  {  {
2050   local i   local i
2051    
2052   if [ -n "$@" ]   if [[ -n $* ]]
2053   then   then
2054   for i in $@   for i in $*
2055   do   do
2056   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
2057   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1676  is_newer_mage_version_available() Line 2075  is_newer_mage_version_available()
2075   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2076   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2077   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2078   echo "or your current system installation may brake."   echo "or your current system installation may break."
2079   echo   echo
2080   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2081   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1948  get_value_from_magefile() Line 2347  get_value_from_magefile()
2347   local magefile="$2"   local magefile="$2"
2348   local value   local value
2349    
2350     [[ -z ${var} ]] && return 1
2351     [[ -z ${magefile} ]] && return 1
2352    
2353   # local all possible vars of a mage file   # local all possible vars of a mage file
2354   # to prevent bad issues   # to prevent bad issues
2355   local PKGNAME   local PKGNAME
# Line 1958  get_value_from_magefile() Line 2360  get_value_from_magefile()
2360   local SDEPEND   local SDEPEND
2361   local PROVIDE   local PROVIDE
2362   local PKGTYPE   local PKGTYPE
2363     local MAGE_TARGETS
2364     local SPLIT_PACKAGE_BASE
2365   local preinstall   local preinstall
2366   local postinstall   local postinstall
2367   local preremove   local preremove
# Line 1972  get_value_from_magefile() Line 2376  get_value_from_magefile()
2376   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2377   echo "${value}"   echo "${value}"
2378    
2379   unset preinstall   # unset these functions
2380   unset postinstall   unset -f preinstall
2381   unset preremove   unset -f postinstall
2382   unset postremove   unset -f preremove
2383     unset -f postremove
2384  }  }
2385    
2386  mage_install()  mage_install()
# Line 2003  mage_install() Line 2408  mage_install()
2408   local count_current   local count_current
2409   local magefile   local magefile
2410   local src_install   local src_install
2411     local i
2412    
2413   # very basic getops   # very basic getops
2414   for i in $*   for i in $*
# Line 2076  mage_install() Line 2482  mage_install()
2482   echo B:${pbuild}   echo B:${pbuild}
2483   fi   fi
2484    
2485   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2486     then
2487     # basic svn compat
2488     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2489     then
2490     for i in ${SMAGESCRIPTSDIR}/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2491     do
2492     smage2file="${i}"
2493     done
2494     else
2495     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2496     fi
2497    
2498     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2499     then
2500     # basic svn compat
2501     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2502     then
2503     for i in ${SMAGESCRIPTSDIR}/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2504     do
2505     smage2file="${i}"
2506     done
2507     else
2508     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2509     fi
2510    
2511     else
2512     # basic svn compat
2513     if [[ -d ${SMAGESCRIPTSDIR}/.svn ]]
2514     then
2515     for i in ${SMAGESCRIPTSDIR}/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2516     do
2517     smage2file="${i}"
2518     done
2519     else
2520     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2521     fi
2522     fi
2523    
2524   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2525   then   then
2526     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2527   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2528   else   else
2529   echo   echo
# Line 2092  mage_install() Line 2537  mage_install()
2537   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2538   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2539   then   then
2540   # 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  
2541   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2542   fi   fi
2543    
# Line 2156  mage_install() Line 2594  mage_install()
2594  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2595   echo "successfully installed."   echo "successfully installed."
2596    
2597   unset preinstall   # unset these functions
2598   unset postinstall   unset -f preinstall
2599   unset preremove   unset -f postinstall
2600   unset postremove   unset -f preremove
2601     unset -f postremove
2602  }  }
2603    
2604  md5sum_packages()  md5sum_packages()
# Line 2212  md5sum_packages() Line 2651  md5sum_packages()
2651   then   then
2652   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
2653   echo -ne "checking md5sum (${count_current}/${count_total}): "   echo -ne "checking md5sum (${count_current}/${count_total}): "
2654   ( cd ${PKGDIR}; md5sum --check ${md5file}) || die "md5 for ${pkgfile} failed"   ( cd ${PKGDIR}; md5sum -c ${md5file}) || die "md5 for ${pkgfile} failed"
2655   else   else
2656   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2657   echo -e "!! no md5sum file found for ${pkgfile} :("   echo -e "!! no md5sum file found for ${pkgfile} :("
# Line 2355  mage_uninstall() Line 2794  mage_uninstall()
2794   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2795   echo -n "removing: "   echo -n "removing: "
2796   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2797   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2798    
2799   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2800   source ${magefile}   source ${magefile}
2801    
2802   ## preremove scripts   ## preremove scripts
# Line 2418  mage_uninstall() Line 2857  mage_uninstall()
2857  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2858   echo "successfully removed."   echo "successfully removed."
2859    
2860   unset preinstall   # unset these functions
2861   unset postinstall   unset -f preinstall
2862   unset preremove   unset -f postinstall
2863   unset postremove   unset -f preremove
2864     unset -f postremove
2865  }  }
2866    
2867  show_etc_update_mesg() {  show_etc_update_mesg()
2868    {
2869   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2870    
2871   echo   echo
# Line 2454  pkgsearch() Line 2895  pkgsearch()
2895   local all_installed   local all_installed
2896   local ipver   local ipver
2897   local ipbuild   local ipbuild
2898     local latest_available
2899     local depsfull
2900     local sdepsfull
2901     local deps
2902     local sdeps
2903     local dep
2904     local sign
2905    
2906   # only names no versions   # only names no versions
2907   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2908   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2909    
2910   # nothing found   # nothing found
2911   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2471  pkgsearch() Line 2919  pkgsearch()
2919   # get highest version available   # get highest version available
2920   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
2921    
2922   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
2923   pver="$(magename2pver ${magefile})"   then
2924   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
2925   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
2926   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
2927   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
2928     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2929     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2930    
2931     # all installed
2932     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2933     do
2934     ipver="$(magename2pver ${i})"
2935     ipbuild="$(magename2pbuild ${i})"
2936    
2937     if [[ -z ${all_installed} ]]
2938     then
2939     all_installed="${ipver}-${ipbuild}"
2940     else
2941     all_installed="${all_installed} ${ipver}-${ipbuild}"
2942     fi
2943     done
2944     [[ -z ${all_installed} ]] && all_installed="none"
2945    
2946     case ${state} in
2947     stable) state=${COLGREEN}"[s] ";;
2948     testing) state=${COLYELLOW}"[t] ";;
2949     unstable) state=${COLRED}"[u] ";;
2950     old) state=${COLGRAY}"[o] ";;
2951     esac
2952    
2953   # all installed   latest_available="${pver}-${pbuild}"
2954   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   else
2955   do   # package is masked
2956   ipver="$(magename2pver ${i})"   state="${COLRED}[m] "
2957   ipbuild="$(magename2pbuild ${i})"   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2958     fi
2959    
2960   if [[ -z ${all_installed} ]]   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2961   then   sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
  all_installed="${ipver}-${ipbuild}"  
  else  
  all_installed="${all_installed} ${ipver}-${ipbuild}"  
  fi  
  done  
  [[ -z ${all_installed} ]] && all_installed="none"  
2962    
2963   case ${state} in   while read sign dep
2964   stable) state=${COLGREEN}"[s] ";;   do
2965   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
2966   unstable) state=${COLRED}"[u] ";;   "") continue;;
2967   old) state=${COLGRAY}"[o] ";;   esac
2968   esac  
2969     deps="${deps} $(basename ${dep%-*})"
2970     done << EOF
2971    ${depsfull}
2972    EOF
2973    
2974     while read sign dep
2975     do
2976     case ${dep} in
2977     "") continue;;
2978     esac
2979    
2980     sdeps="${sdeps} $(basename ${dep%-*})"
2981     done << EOF
2982    ${sdepsfull}
2983    EOF
2984    
2985   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2986   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
2987   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
2988   echo "      Description: ${description}"   echo "      Description: ${description}"
2989   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
2990     echo "      Depends: ${deps}"
2991     echo "      SDepends: ${sdeps}"
2992   echo   echo
2993    
2994   unset pcat   unset pcat
# Line 2518  pkgsearch() Line 3002  pkgsearch()
3002   unset all_installed   unset all_installed
3003   unset ipver   unset ipver
3004   unset ipbuild   unset ipbuild
3005     unset depsfull
3006     unset sdepsfull
3007     unset deps
3008     unset sdeps
3009     unset dep
3010     unset sign
3011   done   done
3012  }  }
3013    
# Line 2542  export_inherits() Line 3032  export_inherits()
3032   shift   shift
3033   done   done
3034  }  }
3035    
3036    mlibdir()
3037    {
3038     local libdir=lib
3039     [[ ${ARCH} = x86_64 ]] && libdir=lib64
3040    
3041     echo "${libdir}"
3042    }
3043    
3044    ## blacklisted ${magefile}
3045    blacklisted()
3046    {
3047     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
3048    
3049     # compat
3050     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
3051     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
3052    
3053     # support both types for the moment
3054     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
3055     then
3056     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
3057     else
3058     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3059     fi
3060    
3061     # return 0 if the list not exist; nothin is masked
3062     [[ ! -f ${EXCLUDED} ]] && return 0
3063    
3064     local MAGEFILE="$1"
3065    
3066     local PCAT="$(magename2pcat ${MAGEFILE})"
3067     local PNAME="$(magename2pname ${MAGEFILE})"
3068     local PVER="$(magename2pver ${MAGEFILE})"
3069     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3070    
3071     local EXPCAT EXPNAME EXPVER EXPBUILD
3072     while read EXPCAT EXPNAME EXPVER EXPBUILD
3073     do
3074     # ignore spaces and comments
3075             case "${EXPCAT}" in
3076                     \#*|"") continue ;;
3077             esac
3078    
3079     # exclude full pver
3080     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3081     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3082     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3083     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3084     then
3085     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3086     fi
3087    
3088     # exclude pcat/pname only
3089     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3090     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3091     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3092     then
3093     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3094     fi
3095     done << EOF
3096    $( cat ${EXCLUDED}; echo)
3097    EOF
3098    
3099     return 0
3100    }
3101    
3102    # need_busybox_support ${cmd}
3103    # return 0 (no error = needs busybox support) or return 1 (error = no busybox support required)
3104    need_busybox_support()
3105    {
3106     local cmd
3107     cmd="$1"
3108    
3109     if [[ -x /bin/busybox ]]
3110     then
3111     if [[ $(readlink $(which ${cmd})) = /bin/busybox ]]
3112     then
3113     # needs busybox support
3114     return 0
3115     fi
3116     fi
3117    
3118     # no busybox
3119     return 1
3120    }
3121    
3122    # busybox_filter_wget_options ${wget_opts}
3123    busybox_filter_wget_options()
3124    {
3125     local opts="$@"
3126     local i
3127     local fixed_opts
3128    
3129     if need_busybox_support wget
3130     then
3131     for i in ${opts}
3132     do
3133     # show only the allowed ones
3134     case ${i} in
3135     -c|--continue) fixed_opts+=" -c" ;;
3136     -s|--spider) fixed_opts+=" -s" ;;
3137     -q|--quiet) fixed_opts+=" -q" ;;
3138     -O|--output-document) shift; fixed_opts+=" -O $1" ;;
3139     --header) shift; fixed_opts+=" --header $1" ;;
3140     -Y|--proxy) shift; fixed_opts+=" -Y $1" ;;
3141     -P) shift; fixed_opts+=" -P $1" ;;
3142     --no-check-certificate) fixed_opts+=" --no-check-certificate ${i}" ;;
3143     -U|--user-agent) shift; fixed_opts+=" -U ${i}" ;;
3144     # simply drop all other opts
3145     *) continue ;;
3146     esac
3147     done
3148    
3149     echo "${fixed_opts}"
3150     else
3151     echo "${opts}"
3152     fi
3153    }
3154    
3155    have_root_privileges()
3156    {
3157     local retval
3158    
3159     if [[ $(id -u) = 0 ]]
3160     then
3161     retval=0
3162     else
3163     retval=1
3164     fi
3165    
3166     return ${retval}
3167    }

Legend:
Removed from v.252  
changed lines
  Added in v.1547