Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1211 by niro, Fri Jan 28 21:39:01 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.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  mage_setup()  mage_setup()
6  {  {
# Line 198  install_files() Line 198  install_files()
198   is_config_protected "${pathto}"   is_config_protected "${pathto}"
199   retval="$?"   retval="$?"
200    
201   # 0 - not protected        #   # 0 - not protected         #
202   # 1 - error                #   # 1 - error                 #
203   # 2 - protected            #   # 2 - protected             #
204   # 3 - protected but masked #   # 3 - protected but masked  #
205     # 4 - protected but ignored #
206    
207   case ${retval} in   case ${retval} in
208   # file is not protected - (over)write it   # file is not protected - (over)write it
# Line 252  install_files() Line 253  install_files()
253   (( MAGE_PROTECT_COUNTER++ ))   (( MAGE_PROTECT_COUNTER++ ))
254   export MAGE_PROTECT_COUNTER   export MAGE_PROTECT_COUNTER
255   ;;   ;;
256    
257     # file is protected but ignored, delete the update/do nothing
258     4)
259     if [[ ${VERBOSE} = on ]]
260     then
261     echo -en "${COLRED}"
262     echo -n "! ignr "
263     echo -en "${COLDEFAULT}"
264     echo " === FILE: ${MROOT}${pathto}"
265     fi
266     # simply do nothing here
267     ;;
268   esac   esac
269   done < ${BUILDDIR}/${pkgname}/.files   done < ${BUILDDIR}/${pkgname}/.files
270    
# Line 298  install_symlinks() Line 311  install_symlinks()
311    
312   ln -snf "${link}" "${MROOT}${pathto}"   ln -snf "${link}" "${MROOT}${pathto}"
313    
314   # fix mtime and db  # # fix mtime and db
315   fix_descriptor ${pkgname}/.symlinks \  # fix_descriptor ${pkgname}/.symlinks \
316   "${pathto}" \  # "${pathto}" \
317   "${posix}" \  # "${posix}" \
318   "${link}" \  # "${link}" \
319   "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \  # "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \
320   "${MROOT}${pathto}")"  # "${MROOT}${pathto}")"
321    
322   done < ${BUILDDIR}/${pkgname}/.symlinks   done < ${BUILDDIR}/${pkgname}/.symlinks
323    
324   # now copy the fixed file over the old one  # # now copy the fixed file over the old one
325   [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \  # [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \
326   cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}  # cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,}
327    
328   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
329   IFS=$'\n'   IFS=$'\n'
# Line 326  install_blockdevices() Line 339  install_blockdevices()
339   local pkgname="$1"   local pkgname="$1"
340   local pathto   local pathto
341   local posix   local posix
342     local user
343     local group
344   local IFS   local IFS
345    
346   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 339  install_blockdevices() Line 354  install_blockdevices()
354   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
355   IFS=§   IFS=§
356    
357   while read pathto posix   while read pathto posix user group
358   do   do
359   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
360   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> PIPE: ${MROOT}${pathto}"
361    
362   mkfifo -m "${posix}" "${MROOT}$pathto"   mkfifo -m "${posix}" "${MROOT}${pathto}"
363     # make it optional atm !!
364     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
365     then
366     chown "${user}:${group}" "${MROOT}${pathto}"
367     fi
368   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
369    
370   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 381  install_characterdevices()
381   local pkgname="$1"   local pkgname="$1"
382   local pathto   local pathto
383   local posix   local posix
384     local major
385     local minor
386     local user
387     local group
388   local IFS   local IFS
389    
390   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 398  install_characterdevices()
398   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
399   IFS=§   IFS=§
400    
401   while read pathto posix   while read pathto posix major minor user group
402   do   do
403   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
404   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
405    
406   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}
407    
408     # make it optional atm !!
409     if [[ ! -z ${user} ]] && [[ ! -z ${group} ]]
410     then
411     chown "${user}:${group}" "${MROOT}${pathto}"
412     fi
413   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
414    
415   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
416   IFS=$'\n'   IFS=$'\n'
417  }  }
418    
419    ###################################################
420    # function install_fifos                          #
421    # install_fifos $PKGNAME                    #
422    ###################################################
423    install_fifos()
424    {
425     local pkgname="$1"
426     local pathto
427     local posix
428     local user
429     local group
430     local IFS
431    
432     # sanity checks; abort if not given
433     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
434    
435     # check needed global vars
436     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
437    
438     # make it optional atm !!
439     #[ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
440     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && return
441    
442     # sets fieldseperator to "§" instead of " "
443     IFS=§
444    
445     while read pathto posix user group
446     do
447     [ -z "${pathto}" ] && continue
448     [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
449    
450     mkfifo -m "${posix}" "${MROOT}${pathto}"
451     chown "${user}:${group}" "${MROOT}${pathto}"
452     done < ${BUILDDIR}/${pkgname}/.fifo
453    
454     # very important: unsetting the '§' fieldseperator
455     IFS=$'\n'
456    }
457    
458    
459  ###################################################  ###################################################
460  # function build_doinstall                        #  # function build_doinstall                        #
461  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
462  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
463  ###################################################  ###################################################
464  build_doinstall()  build_doinstall()
465  {  {
# Line 413  build_doinstall() Line 482  build_doinstall()
482   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
483   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
484   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
485     install_fifos ${pkgname} || die "install fifos ${pkgname}"
486  }  }
487    
488    
# Line 432  install_database_entry() Line 502  install_database_entry()
502   local magefile   local magefile
503   local dbrecorddir   local dbrecorddir
504   local provide   local provide
505     local i
506    
507   # very basic getops   # very basic getops
508   for i in $*   for i in $*
# Line 473  install_database_entry() Line 544  install_database_entry()
544    
545   # create fake file descriptors   # create fake file descriptors
546   # used by virtual and source packages   # used by virtual and source packages
547   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
548   do   do
549   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
550   done   done
# Line 492  install_database_entry() Line 562  install_database_entry()
562    
563   # normal packages needs these files   # normal packages needs these files
564   local i   local i
565   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
566   do   do
567   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \
568   ${dbrecorddir}/${i}   ${dbrecorddir}/${i}
# Line 504  install_database_entry() Line 574  install_database_entry()
574   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
575   if [ -n "${provide}" ]   if [ -n "${provide}" ]
576   then   then
577   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
578     do
579     virtuals_add "${i}" "${pcat}/${pname}"
580     done
581   fi   fi
582  }  }
583    
# Line 523  remove_database_entry() Line 596  remove_database_entry()
596   local magefile   local magefile
597   local dbrecorddir   local dbrecorddir
598   local provide   local provide
599     local i
600    
601   # very basic getops   # very basic getops
602   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 626  remove_database_entry()
626   # abort if mage file not exists   # abort if mage file not exists
627   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
628    
629   # first unregister virtuals   # remove virtuals only if no other exist
630   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
631   then   then
632   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
633     provide="$(get_value_from_magefile PROVIDE ${magefile})"
634     if [ -n "${provide}" ]
635     then
636     for i in ${provide}
637     do
638     virtuals_del "${i}" "${pcat}/${pname}"
639     done
640     fi
641   fi   fi
642    
643   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 647  remove_database_entry()
647   fi   fi
648  }  }
649    
650    # get the number of installed packages
651    count_installed_pkgs()
652    {
653     local pcat
654     local pname
655     local pkg
656     local i
657    
658     # very basic getops
659     for i in $*
660     do
661     case $1 in
662     --pcat|-c) shift; pcat="$1" ;;
663     --pname|-n) shift; pname="$1" ;;
664     esac
665     shift
666     done
667    
668     # sanity checks; abort if not given
669     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
670     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
671    
672     declare -i i=0
673     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
674     do
675     (( i++ ))
676     #echo "$i ${pkg}"
677     done
678    
679     # return the value
680     echo "${i}"
681    }
682    
683    
684  ###################################################  ###################################################
685  # function compare_mtime                          #  # function compare_mtime                          #
# Line 726  remove_files() Line 840  remove_files()
840   done   done
841    
842   # sanity checks; abort if not given   # sanity checks; abort if not given
843   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
844   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
845   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
846   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
847   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
848    
849   # check needed global vars   # check needed global vars
# Line 744  remove_files() Line 858  remove_files()
858   do   do
859   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
860    
861   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
862   then   then
863   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
864   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 758  remove_files() Line 872  remove_files()
872   # 1=keep me   #   # 1=keep me   #
873   case ${retval} in   case ${retval} in
874   0)   0)
875   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
876   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
877   ;;   is_config_protected "${pathto}"
878     retval="$?"
879    
880     # 0 - not protected         #
881     # 1 - error                 #
882     # 2 - protected             #
883     # 3 - protected but masked  #
884     # 4 - protected but ignored #
885    
886     case ${retval} in
887     # file is not protected - delete it
888     0|3)
889     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
890     rm "${MROOT}${pathto}"
891     ;;
892    
893     # file is protected, do not delete
894     2)
895     if [[ ${VERBOSE} = on ]]
896     then
897     echo -en "${COLRED}"
898     echo -n "! prot "
899     echo -en "${COLDEFAULT}"
900     echo " === FILE: ${MROOT}${pathto}"
901     fi
902     ;;
903    
904     # file is protected but ignored, delete the update/do nothing
905     4)
906     if [[ ${VERBOSE} = on ]]
907     then
908     echo -en "${COLRED}"
909     echo -n "! ignr "
910     echo -en "${COLDEFAULT}"
911     echo " === FILE: ${MROOT}${pathto}"
912     fi
913     # simply do nothing here
914     ;;
915     esac
916     ;;
917   1)   1)
918   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
919   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 782  remove_blockdevices() Line 934  remove_blockdevices()
934  {  {
935   local pathto   local pathto
936   local posix   local posix
937     local user
938     local group
939   local IFS   local IFS
940   local pcat   local pcat
941   local pname   local pname
# Line 805  remove_blockdevices() Line 959  remove_blockdevices()
959   done   done
960    
961   # sanity checks; abort if not given   # sanity checks; abort if not given
962   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
963   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
964   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
965   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
966   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
967    
968   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 973  remove_blockdevices()
973   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
974   IFS=§   IFS=§
975    
976   while read pathto posix   while read pathto posix user group
977   do   do
978   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
979    
# Line 840  remove_characterdevices() Line 994  remove_characterdevices()
994  {  {
995   local pathto   local pathto
996   local posix   local posix
997     local user
998     local group
999   local IFS   local IFS
1000   local pcat   local pcat
1001   local pname   local pname
# Line 863  remove_characterdevices() Line 1019  remove_characterdevices()
1019   done   done
1020    
1021   # sanity checks; abort if not given   # sanity checks; abort if not given
1022   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1023   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1024   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1025   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1026   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1027    
1028   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1033  remove_characterdevices()
1033   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1034   IFS=§   IFS=§
1035    
1036   while read pathto posix   while read pathto posix user group
1037   do   do
1038   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1039    
# Line 891  remove_characterdevices() Line 1047  remove_characterdevices()
1047    
1048    
1049  ###################################################  ###################################################
1050    # function remove_fifos                           #
1051    # remove_fifos $PKGNAME                     #
1052    ###################################################
1053    remove_fifos()
1054    {
1055     local pathto
1056     local posix
1057     local user
1058     local group
1059     local IFS
1060     local pcat
1061     local pname
1062     local pver
1063     local pbuild
1064     local i
1065     local pfull
1066    
1067     IFS=$'\n'
1068    
1069     # very basic getops
1070     for i in $*
1071     do
1072     case $1 in
1073     --pcat|-c) shift; pcat="$1" ;;
1074     --pname|-n) shift; pname="$1" ;;
1075     --pver|-v) shift; pver="$1" ;;
1076     --pbuild|-b) shift; pbuild="$1" ;;
1077     esac
1078     shift
1079     done
1080    
1081     # sanity checks; abort if not given
1082     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1083     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1084     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1085     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1086     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1087    
1088     # check needed global vars
1089     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1090    
1091     # make it optional atm !!
1092     #[ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1093     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && return
1094    
1095     # sets fieldseperator to "§" instead of " "
1096     IFS=§
1097    
1098     while read pathto posix user group
1099     do
1100     [ -z "${pathto}" ] && continue
1101    
1102     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1103     rm "${MROOT}${pathto}"
1104     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1105    
1106     # very important: unsetting the '§' fieldseperator
1107     IFS=$'\n'
1108    }
1109    
1110    
1111    ###################################################
1112  # function remove_direcories                      #  # function remove_direcories                      #
1113  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1114  ###################################################  ###################################################
# Line 921  remove_directories() Line 1139  remove_directories()
1139   done   done
1140    
1141   # sanity checks; abort if not given   # sanity checks; abort if not given
1142   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1143   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1144   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1145   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1146   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1147    
1148   # check needed global vars   # check needed global vars
# Line 932  remove_directories() Line 1150  remove_directories()
1150    
1151   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1152    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1153   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1154   IFS=§   IFS=§
1155    
1156   while read pathto posix   # reversed order is mandatory !
1157     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1158   do   do
1159   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1160    
# Line 954  remove_directories() Line 1169  remove_directories()
1169   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1170   then   then
1171   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1172   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1173   continue   continue
1174   fi   fi
1175    
# Line 971  remove_directories() Line 1186  remove_directories()
1186   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1187   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1188   fi   fi
1189   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1190    
1191   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1192   IFS=$'\n'   IFS=$'\n'
# Line 981  remove_directories() Line 1196  remove_directories()
1196  ###################################################  ###################################################
1197  # function build_douninstall                      #  # function build_douninstall                      #
1198  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1199  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1200  ###################################################  ###################################################
1201  build_douninstall()  build_douninstall()
1202  {  {
# Line 1015  build_douninstall() Line 1230  build_douninstall()
1230   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1231   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1232    
1233   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1234   do   do
1235   remove_${i} \   remove_${i} \
1236   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1038  fetch_packages() Line 1253  fetch_packages()
1253   local count_current   local count_current
1254   local count_total   local count_total
1255    
1256   [ -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}."
1257    
1258   # get count of total packages   # get count of total packages
1259   declare -i count_current=0   declare -i count_current=0
# Line 1085  fetch_packages() Line 1300  fetch_packages()
1300   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1301   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1302   wget \   wget \
1303   --passive-ftp \   ${WGET_FETCH_OPTIONS} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1304   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1305   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1306   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1307   then   then
1308   break   break
# Line 1113  syncmage() Line 1325  syncmage()
1325  {  {
1326   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1327   then   then
1328   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1329   fi   fi
1330    
1331   local i   local i
1332   for i in ${RSYNC}   for i in ${RSYNC}
1333   do   do
1334   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1335   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1336   then   then
1337   break   break
# Line 1144  syncmage() Line 1343  syncmage()
1343   # clean up backup files (foo~)   # clean up backup files (foo~)
1344   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name *~ -exec rm '{}' ';'
1345    
1346   # check if an newer mage version is available   # check if a newer mage version is available
1347   is_newer_mage_version_available   is_newer_mage_version_available
1348  }  }
1349    
1350    syncmage_tarball()
1351    {
1352     local latest_tarball
1353     local latest_md5
1354     local temp="$(mktemp -d)"
1355     local mirr mymirr
1356     local opt
1357    
1358     # try to get the md5 marked as latest on the server
1359     latest_md5="mage-latest.md5"
1360    
1361     # try to get the tarball marked as latest on the server
1362     latest_tarball="mage-latest.tar.bz2"
1363    
1364     for mirr in ${MIRRORS}
1365     do
1366     # path without distribution
1367     mymirr="${mirr%/*}"
1368    
1369     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1370     echo "fetching latest md5 from ${mymirr} ..."
1371     [[ ${VERBOSE} = off ]] && opt="--quiet"
1372     wget \
1373     ${WGET_FETCH_OPTIONS} \
1374     --directory-prefix=${temp} \
1375     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1376    
1377     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1378     echo "fetching latest tarball from ${mymirr} ..."
1379     wget \
1380     ${WGET_FETCH_OPTIONS} \
1381     --directory-prefix=${temp} \
1382     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1383     if [[ $? = 0 ]]
1384     then
1385     break
1386     else
1387     continue
1388     fi
1389     done
1390    
1391     if [[ -f ${temp}/${latest_tarball} ]]
1392     then
1393     # check md5
1394     if [[ ! -f ${temp}/${latest_md5} ]]
1395     then
1396     die "md5 is missing ... aborting"
1397     else
1398     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1399     echo -n "checking md5sum... "
1400     ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1401     fi
1402    
1403     if [[ -d ${MAGEDIR} ]]
1404     then
1405     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1406     echo "cleaning old mage-tree ${MAGEDIR}..."
1407     rm -rf ${MAGEDIR}
1408     fi
1409    
1410     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1411     echo "updating mage-tree from tarball ..."
1412     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1413     tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1414    
1415     if [[ -d ${temp} ]]
1416     then
1417     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1418     echo "cleaning temp-files ..."
1419     rm -rf ${temp}
1420     fi
1421    
1422     # check if a newer mage version is available
1423     is_newer_mage_version_available
1424     else
1425     die "Could not fetch the latest tarball ... aborting"
1426     fi
1427    }
1428    
1429  cleanpkg()  cleanpkg()
1430  {  {
1431   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1185  choppkgname() Line 1463  choppkgname()
1463   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1464   then   then
1465   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1466   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1467   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1468    
1469   #cuts version number   #cuts version number
# Line 1218  pname2pcat() Line 1496  pname2pcat()
1496  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1497  check_stable_package()  check_stable_package()
1498  {  {
1499     # first check if this magefile is not blacklisted
1500     blacklisted "$1" || return 1
1501    
1502   local STATE   local STATE
1503   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1504    
1505   # state testing   # state testing
1506   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1507   then   then
1508   case ${STATE} in   case ${STATE} in
1509   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1512  check_stable_package()
1512   fi   fi
1513    
1514   # state unstable   # state unstable
1515   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1516   then   then
1517   case ${STATE} in   case ${STATE} in
1518   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1538  get_highest_magefile()
1538   local PNAME="$2"   local PNAME="$2"
1539   local magefile   local magefile
1540    
1541   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1542     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)
1543   do   do
1544     [[ -z ${magefile} ]] && continue
1545   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1546   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1547   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1548   then   then
1549   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1269  get_highest_magefile() Line 1552  get_highest_magefile()
1552   fi   fi
1553   done   done
1554    
1555   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1556   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1557   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1558   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1559   echo  # then
1560   echo -n "All packages named "  # echo
1561   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1562   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1563   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1564   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1565   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1566   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1567   echo "Example:"  # echo
1568   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1569   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1570   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1571   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."
1572   echo  # echo "You should know what you are doing, so don't complain about any damage."
1573   return 1  # echo
1574   fi  # return 1
1575    # fi
1576    
1577   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1578   return 0   return 0
# Line 1304  get_highest_magefile() Line 1588  get_highest_magefile()
1588  #        1 - error                                #  #        1 - error                                #
1589  #        2 - protected                            #  #        2 - protected                            #
1590  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1591    #        4 - protected but ignored                #
1592  #                                                 #  #                                                 #
1593  ###################################################  ###################################################
1594  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1597  is_config_protected()
1597   local TEST   local TEST
1598   local PROTECTED   local PROTECTED
1599   local IFS   local IFS
1600     local i
1601     local x
1602    
1603   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1604    
1605   # file does not exist; it can be written   # file does not exist; it can be written
1606   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1607    
1608   # to be safe; it may be '§'   # to be safe; it may be '§'
1609   IFS=' '   IFS=' '
1610    
1611   # check ob in config protect   # check if config protected
1612   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1613   do   do
1614   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1615   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1616   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1617   then   then
1618   # setzen das es protected ist   # file is config proteced
1619   PROTECTED=TRUE   PROTECTED=TRUE
1620    
1621   # check ob nicht doch maskiert   # check if not masked
1622   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1623   do   do
1624   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1625   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1626   then   then
1627   PROTECTED=MASKED   PROTECTED=MASKED
1628   fi   fi
1629   done   done
1630    
1631     # check if not ignored
1632     for x in ${CONFIG_PROTECT_IGNORE}
1633     do
1634     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1635     if [[ ${TEST} != ${EXPFILE} ]]
1636     then
1637     PROTECTED=IGNORED
1638     fi
1639     done
1640   fi   fi
1641   done   done
1642    
# Line 1354  is_config_protected() Line 1651  is_config_protected()
1651   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1652   return 3   return 3
1653   ;;   ;;
1654     IGNORED)
1655     #echo "I'm protected, but ignored - keep me, del update"
1656     return 4
1657     ;;
1658   *)   *)
1659   #echo "delete me"   #echo "delete me"
1660   return 0   return 0
# Line 1371  is_config_protected() Line 1672  is_config_protected()
1672  ###################################################  ###################################################
1673  count_protected_files()  count_protected_files()
1674  {  {
1675   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1676     local dirname="${file%/*}"
1677     local filename="${file##*/}"
1678     local count
1679     local output
1680     local i
1681    
1682     declare -i count=0
1683    
1684     # check if there are already protected files
1685     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1686     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1687     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1688     do
1689     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1690     done
1691     (( count ++ ))
1692    
1693     # fill output up with zeros
1694     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1695     output="${output}${count}"
1696    
1697     echo "${output}"
1698  }  }
1699    
1700  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1711  get_uninstall_candidates()
1711   local list   local list
1712   local pcatdir   local pcatdir
1713   local protected   local protected
1714     local i
1715    
1716   # very basic getops   # very basic getops
1717   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1724  get_uninstall_candidates()
1724   shift   shift
1725   done   done
1726    
1727   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1728   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1729    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1730    
1731    
1732   # check needed global vars   # check needed global vars
1733   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1734    
1735   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1736   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1737    
1738   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1739   do   do
# Line 1493  virtuals_add() Line 1818  virtuals_add()
1818   local oldline   local oldline
1819   local line i   local line i
1820   local installed_file   local installed_file
1821     local OLDIFS
1822    
1823   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1824   then   then
1825   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1826   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1827   do   do
1828   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 1841  virtuals_add()
1841   # make a backup   # make a backup
1842   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1843    
1844     OLDIFS="${IFS}"
1845   IFS=$'\n'   IFS=$'\n'
1846   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1847   do   do
# Line 1526  virtuals_add() Line 1853  virtuals_add()
1853   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1854   fi   fi
1855   done   done
1856     # unset IFS
1857   #unset IFS   IFS="${OLDIFS}"
1858   else   else
1859   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1860   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1861   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1862   fi   fi
# Line 1539  virtuals_add() Line 1866  virtuals_add()
1866    
1867  #deletes pakages from virtual database  #deletes pakages from virtual database
1868  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1869  virtuals_del() {  virtuals_del()
1870    {
1871    
1872   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1873     local pkgname="$2"
1874   VIRTUAL_NAME=$1   local oldline
1875   PKG_NAME=$2   local method
1876     local line i x
1877   #first check if exists   local pkg_installed
1878   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1879    
1880     # first check if exists
1881     if virtuals_read ${virtualname}
1882   then   then
1883   #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}
1884   declare -i x=0   declare -i x=0
1885   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1886   do   do
1887   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1888   then   then
1889   PKG_INSTALLED=true   pkg_installed=true
1890   fi   fi
1891   ((x++))   ((x++))
1892   done   done
1893    
1894   #abort if not installed   # abort if not installed
1895   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1896   then   then
1897   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1898     echo "${pkgname} does not exists in ${virtualname}."
1899   return 0   return 0
1900   fi   fi
1901    
1902   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1903   then   then
1904   METHOD=update   method=update
1905   else   else
1906   METHOD=delall   method=delall
1907   fi   fi
1908    
1909   #get the complete line   # get the complete line
1910   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1911    
1912   #make a backup   # make a backup of the db
1913   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1914    
1915   #parse virtualdb   # parse virtualdb
1916     OLDIFS="${IFS}"
1917   IFS=$'\n'   IFS=$'\n'
1918   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1919   do   do
1920   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1921   then   then
1922   #delall or update?   #delall or update?
1923   case ${METHOD} in   case ${method} in
1924   update)   update)
1925   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1926   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1927   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1928     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1929   ;;   ;;
1930   delall)   delall)
1931   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1932   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1933     # continue; do not write anything
1934   continue   continue
1935   ;;   ;;
1936   esac   esac
# Line 1603  virtuals_del() { Line 1938  virtuals_del() {
1938   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1939   fi   fi
1940   done   done
1941   unset IFS   # unset IFS
1942     IFS="${OLDIFS}"
1943   else   else
1944   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1945     echo "${virtualname} does not exists in virtual database."
1946   fi   fi
1947  }  }
1948    
# Line 1637  minclude() Line 1974  minclude()
1974  {  {
1975   local i   local i
1976    
1977   if [ -n "$@" ]   if [[ -n $* ]]
1978   then   then
1979   for i in $@   for i in $*
1980   do   do
1981   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
1982   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1653  sminclude() Line 1990  sminclude()
1990  {  {
1991   local i   local i
1992    
1993   if [ -n "$@" ]   if [[ -n $* ]]
1994   then   then
1995   for i in $@   for i in $*
1996   do   do
1997   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1998   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 2007  is_newer_mage_version_available()
2007   local newest_mage   local newest_mage
2008   local installed_mage   local installed_mage
2009    
2010   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
2011   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
2012    
2013   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 2016  is_newer_mage_version_available()
2016   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2017   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2018   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2019   echo "or your current system installation may brake."   echo "or your current system installation may break."
2020   echo   echo
2021   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2022   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2288  get_value_from_magefile()
2288   local magefile="$2"   local magefile="$2"
2289   local value   local value
2290    
2291     [[ -z ${var} ]] && return 1
2292     [[ -z ${magefile} ]] && return 1
2293    
2294   # local all possible vars of a mage file   # local all possible vars of a mage file
2295   # to prevent bad issues   # to prevent bad issues
2296   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2301  get_value_from_magefile()
2301   local SDEPEND   local SDEPEND
2302   local PROVIDE   local PROVIDE
2303   local PKGTYPE   local PKGTYPE
2304     local MAGE_TARGETS
2305     local SPLIT_PACKAGE_BASE
2306   local preinstall   local preinstall
2307   local postinstall   local postinstall
2308     local preremove
2309     local postremove
2310    
2311   # sanity checks   # sanity checks
2312   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2316  get_value_from_magefile()
2316   source ${magefile}   source ${magefile}
2317   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2318   echo "${value}"   echo "${value}"
2319    
2320     # unset these functions
2321     unset -f preinstall
2322     unset -f postinstall
2323     unset -f preremove
2324     unset -f postremove
2325  }  }
2326    
2327  mage_install()  mage_install()
# Line 1988  mage_install() Line 2338  mage_install()
2338   local PKGTYPE   local PKGTYPE
2339   local preinstall   local preinstall
2340   local postinstall   local postinstall
2341     local preremove
2342     local postremove
2343    
2344   local pcat   local pcat
2345   local pname   local pname
# Line 1997  mage_install() Line 2349  mage_install()
2349   local count_current   local count_current
2350   local magefile   local magefile
2351   local src_install   local src_install
2352     local i
2353    
2354   # very basic getops   # very basic getops
2355   for i in $*   for i in $*
# Line 2070  mage_install() Line 2423  mage_install()
2423   echo B:${pbuild}   echo B:${pbuild}
2424   fi   fi
2425    
2426   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2427     then
2428     # basic svn compat
2429     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2430     then
2431     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2432     do
2433     smage2file="${i}"
2434     done
2435     else
2436     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2437     fi
2438    
2439     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2440     then
2441     # basic svn compat
2442     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2443     then
2444     for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2445     do
2446     smage2file="${i}"
2447     done
2448     else
2449     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2450     fi
2451    
2452     else
2453     # basic svn compat
2454     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2455     then
2456     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2457     do
2458     smage2file="${i}"
2459     done
2460     else
2461     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2462     fi
2463     fi
2464    
2465   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2466   then   then
2467     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2468   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2469   else   else
2470   echo   echo
# Line 2086  mage_install() Line 2478  mage_install()
2478   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2479   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2480   then   then
2481   # 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  
2482   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2483   fi   fi
2484    
# Line 2149  mage_install() Line 2534  mage_install()
2534  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2535  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2536   echo "successfully installed."   echo "successfully installed."
2537    
2538     # unset these functions
2539     unset -f preinstall
2540     unset -f postinstall
2541     unset -f preremove
2542     unset -f postremove
2543  }  }
2544    
2545  md5sum_packages()  md5sum_packages()
# Line 2253  uninstall_packages() Line 2644  uninstall_packages()
2644   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2645   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2646   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2647   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2648   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2649   echo   echo
2650   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2651   echo "( Press [CTRL+C] to abort )"   then
2652   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2653   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2654   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2655   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2656   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2657   sleep 1   do
2658   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2659   echo   sleep 1
2660   echo   done
2661     echo
2662     echo
2663     fi
2664    
2665   for pkg in ${list}   for pkg in ${list}
2666   do   do
# Line 2304  mage_uninstall() Line 2698  mage_uninstall()
2698   local PKGTYPE   local PKGTYPE
2699   local preinstall   local preinstall
2700   local postinstall   local postinstall
2701     local preremove
2702     local postremove
2703    
2704   local pcat   local pcat
2705   local pname   local pname
# Line 2339  mage_uninstall() Line 2735  mage_uninstall()
2735   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2736   echo -n "removing: "   echo -n "removing: "
2737   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2738   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2739    
2740   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2741   source ${magefile}   source ${magefile}
2742    
2743   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2797  mage_uninstall()
2797  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2798  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2799   echo "successfully removed."   echo "successfully removed."
2800    
2801     # unset these functions
2802     unset -f preinstall
2803     unset -f postinstall
2804     unset -f preremove
2805     unset -f postremove
2806  }  }
2807    
2808  show_etc_update_mesg() {  show_etc_update_mesg()
2809    {
2810   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2811    
2812   echo   echo
# Line 2415  show_etc_update_mesg() { Line 2818  show_etc_update_mesg() {
2818   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
2819   echo   echo
2820  }  }
2821    
2822    pkgsearch()
2823    {
2824     local string="$1"
2825     local result
2826     local pkg
2827     local pcat
2828     local pname
2829     local magefile
2830     local pver
2831     local pbuild
2832     local state
2833     local descriptiom
2834     local homepage
2835     local i
2836     local all_installed
2837     local ipver
2838     local ipbuild
2839     local latest_available
2840     local depsfull
2841     local sdepsfull
2842     local deps
2843     local sdeps
2844     local dep
2845     local sign
2846    
2847     # only names no versions
2848     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2849     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2850    
2851     # nothing found
2852     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2853    
2854     for pkg in ${result}
2855     do
2856     # dirty, but does the job
2857     pcat="$(magename2pcat ${pkg}/foo)"
2858     pname="$(magename2pname ${pkg}-foo-foo)"
2859    
2860     # get highest version available
2861     magefile=$(get_highest_magefile ${pcat} ${pname})
2862    
2863     if [[ ! -z ${magefile} ]]
2864     then
2865     # now get all needed infos to print a nice output
2866     pver="$(magename2pver ${magefile})"
2867     pbuild="$(magename2pbuild ${magefile})"
2868     state="$(get_value_from_magefile STATE ${magefile})"
2869     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2870     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2871    
2872     # all installed
2873     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2874     do
2875     ipver="$(magename2pver ${i})"
2876     ipbuild="$(magename2pbuild ${i})"
2877    
2878     if [[ -z ${all_installed} ]]
2879     then
2880     all_installed="${ipver}-${ipbuild}"
2881     else
2882     all_installed="${all_installed} ${ipver}-${ipbuild}"
2883     fi
2884     done
2885     [[ -z ${all_installed} ]] && all_installed="none"
2886    
2887     case ${state} in
2888     stable) state=${COLGREEN}"[s] ";;
2889     testing) state=${COLYELLOW}"[t] ";;
2890     unstable) state=${COLRED}"[u] ";;
2891     old) state=${COLGRAY}"[o] ";;
2892     esac
2893    
2894     latest_available="${pver}-${pbuild}"
2895     else
2896     # package is masked
2897     state="${COLRED}[m] "
2898     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2899     fi
2900    
2901     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2902     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
2903    
2904     while read sign dep
2905     do
2906     case ${dep} in
2907     "") continue;;
2908     esac
2909    
2910     deps="${deps} $(basename ${dep%-*})"
2911     done << EOF
2912    ${depsfull}
2913    EOF
2914    
2915     while read sign dep
2916     do
2917     case ${dep} in
2918     "") continue;;
2919     esac
2920    
2921     sdeps="${sdeps} $(basename ${dep%-*})"
2922     done << EOF
2923    ${sdepsfull}
2924    EOF
2925    
2926     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2927     echo -e "      Latest available:   ${latest_available}"
2928     echo "      Installed versions: ${all_installed}"
2929     echo "      Description: ${description}"
2930     echo "      Homepage: ${homepage}"
2931     echo "      Depends: ${deps}"
2932     echo "      SDepends: ${sdeps}"
2933     echo
2934    
2935     unset pcat
2936     unset pname
2937     unset magefile
2938     unset pver
2939     unset pbuild
2940     unset state
2941     unset descriptiom
2942     unset homepage
2943     unset all_installed
2944     unset ipver
2945     unset ipbuild
2946     unset depsfull
2947     unset sdepsfull
2948     unset deps
2949     unset sdeps
2950     unset dep
2951     unset sign
2952     done
2953    }
2954    
2955    export_inherits()
2956    {
2957     local include="$1"
2958     shift
2959    
2960     while [ "$1" ]
2961     do
2962     local functions="$1"
2963    
2964     # sanity checks
2965     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2966     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2967    
2968     eval "${functions}() { ${include}_${functions} ; }"
2969    
2970     # debug
2971     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2972    
2973     shift
2974     done
2975    }
2976    
2977    mlibdir()
2978    {
2979     local libdir=lib
2980     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2981    
2982     echo "${libdir}"
2983    }
2984    
2985    ## blacklisted ${magefile}
2986    blacklisted()
2987    {
2988     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2989    
2990     # compat
2991     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2992     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2993    
2994     # support both types for the moment
2995     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
2996     then
2997     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2998     else
2999     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
3000     fi
3001    
3002     # return 0 if the list not exist; nothin is masked
3003     [[ ! -f ${EXCLUDED} ]] && return 0
3004    
3005     local MAGEFILE="$1"
3006    
3007     local PCAT="$(magename2pcat ${MAGEFILE})"
3008     local PNAME="$(magename2pname ${MAGEFILE})"
3009     local PVER="$(magename2pver ${MAGEFILE})"
3010     local PBUILD="$(magename2pbuild ${MAGEFILE})"
3011    
3012     local EXPCAT EXPNAME EXPVER EXPBUILD
3013     while read EXPCAT EXPNAME EXPVER EXPBUILD
3014     do
3015     # ignore spaces and comments
3016             case "${EXPCAT}" in
3017                     \#*|"") continue ;;
3018             esac
3019    
3020     # exclude full pver
3021     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3022     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3023     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3024     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3025     then
3026     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3027     fi
3028    
3029     # exclude pcat/pname only
3030     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3031     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3032     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3033     then
3034     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3035     fi
3036     done << EOF
3037    $( cat ${EXCLUDED}; echo)
3038    EOF
3039    
3040     return 0
3041    }
3042    

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