Magellan Linux

Diff of /trunk/mage/usr/lib/mage/mage4.functions.sh

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

revision 240 by niro, Sun Sep 11 19:47:08 2005 UTC revision 1209 by niro, Fri Jan 28 20:37:27 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.3 2005-09-11 19:47:08 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     chown "${user}:${group}" "${MROOT}${pathto}"
364   done < ${BUILDDIR}/${pkgname}/.pipes   done < ${BUILDDIR}/${pkgname}/.pipes
365    
366   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 361  install_characterdevices() Line 377  install_characterdevices()
377   local pkgname="$1"   local pkgname="$1"
378   local pathto   local pathto
379   local posix   local posix
380     local major
381     local minor
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 374  install_characterdevices() Line 394  install_characterdevices()
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>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
401    
402   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}
403     chown "${user}:${group}" "${MROOT}${pathto}"
404   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
405    
406   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
407   IFS=$'\n'   IFS=$'\n'
408  }  }
409    
410    ###################################################
411    # function install_fifos                          #
412    # install_fifos $PKGNAME                    #
413    ###################################################
414    install_fifos()
415    {
416     local pkgname="$1"
417     local pathto
418     local posix
419     local user
420     local group
421     local IFS
422    
423     # sanity checks; abort if not given
424     [ -z "${pkgname}" ] && die "install_fifos() \$pkgname not given."
425    
426     # check needed global vars
427     [ -z "${BUILDDIR}" ] && die "install_fifos() \$BUILDDIR not set."
428    
429     [ ! -f ${BUILDDIR}/${pkgname}/.fifo ] && die "install_fifos() .fifo not found"
430    
431     # sets fieldseperator to "§" instead of " "
432     IFS=§
433    
434     while read pathto posix user group
435     do
436     [ -z "${pathto}" ] && continue
437     [[ ${VERBOSE} = on ]] && echo -e "\t>>> FIFO: ${MROOT}${pathto}"
438    
439     mkfifo -m "${posix}" "${MROOT}${pathto}"
440     chown "${user}:${group}" "${MROOT}${pathto}"
441     done < ${BUILDDIR}/${pkgname}/.fifo
442    
443     # very important: unsetting the '§' fieldseperator
444     IFS=$'\n'
445    }
446    
447    
448  ###################################################  ###################################################
449  # function build_doinstall                        #  # function build_doinstall                        #
450  # build_doinstall $PKGNAME                  #  # build_doinstall $PKGNAME                  #
451  # NOTE: this is an wrapper do install packages    #  # NOTE: this is an wrapper to install packages    #
452  ###################################################  ###################################################
453  build_doinstall()  build_doinstall()
454  {  {
# Line 413  build_doinstall() Line 471  build_doinstall()
471   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"   install_symlinks ${pkgname} || die "install symlinks ${pkgname}"
472   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"   install_blockdevices ${pkgname} || die "install blockdevices ${pkgname}"
473   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"   install_characterdevices ${pkgname} || die "install chardevices ${pkgname}"
474     install_fifos ${pkgname} || die "install fifos ${pkgname}"
475  }  }
476    
477    
# Line 432  install_database_entry() Line 491  install_database_entry()
491   local magefile   local magefile
492   local dbrecorddir   local dbrecorddir
493   local provide   local provide
494     local i
495    
496   # very basic getops   # very basic getops
497   for i in $*   for i in $*
# Line 473  install_database_entry() Line 533  install_database_entry()
533    
534   # create fake file descriptors   # create fake file descriptors
535   # used by virtual and source packages   # used by virtual and source packages
536   local i   for i in .dirs .symlinks .files .pipes .char .fifo
  for i in .dirs .symlinks .files .pipes .char  
537   do   do
538   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
539   done   done
# Line 492  install_database_entry() Line 551  install_database_entry()
551    
552   # normal packages needs these files   # normal packages needs these files
553   local i   local i
554   for i in .char .dirs .files .pipes .symlinks   for i in .char .dirs .files .pipes .symlinks .fifo
555   do   do
556   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \   install -m 0644 ${BUILDDIR}/${pkgname}/${i} \
557   ${dbrecorddir}/${i}   ${dbrecorddir}/${i}
# Line 504  install_database_entry() Line 563  install_database_entry()
563   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
564   if [ -n "${provide}" ]   if [ -n "${provide}" ]
565   then   then
566   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
567     do
568     virtuals_add "${i}" "${pcat}/${pname}"
569     done
570   fi   fi
571  }  }
572    
# Line 523  remove_database_entry() Line 585  remove_database_entry()
585   local magefile   local magefile
586   local dbrecorddir   local dbrecorddir
587   local provide   local provide
588     local i
589    
590   # very basic getops   # very basic getops
591   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 615  remove_database_entry()
615   # abort if mage file not exists   # abort if mage file not exists
616   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
617    
618   # first unregister virtuals   # remove virtuals only if no other exist
619   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
620   then   then
621   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
622     provide="$(get_value_from_magefile PROVIDE ${magefile})"
623     if [ -n "${provide}" ]
624     then
625     for i in ${provide}
626     do
627     virtuals_del "${i}" "${pcat}/${pname}"
628     done
629     fi
630   fi   fi
631    
632   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 636  remove_database_entry()
636   fi   fi
637  }  }
638    
639    # get the number of installed packages
640    count_installed_pkgs()
641    {
642     local pcat
643     local pname
644     local pkg
645     local i
646    
647     # very basic getops
648     for i in $*
649     do
650     case $1 in
651     --pcat|-c) shift; pcat="$1" ;;
652     --pname|-n) shift; pname="$1" ;;
653     esac
654     shift
655     done
656    
657     # sanity checks; abort if not given
658     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
659     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
660    
661     declare -i i=0
662     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
663     do
664     (( i++ ))
665     #echo "$i ${pkg}"
666     done
667    
668     # return the value
669     echo "${i}"
670    }
671    
672    
673  ###################################################  ###################################################
674  # function compare_mtime                          #  # function compare_mtime                          #
# Line 726  remove_files() Line 829  remove_files()
829   done   done
830    
831   # sanity checks; abort if not given   # sanity checks; abort if not given
832   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_files() \$pcat not given."
833   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_files() \$pname not given."
834   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_files() \$pver not given."
835   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_files() \$pbuild not given."
836   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
837    
838   # check needed global vars   # check needed global vars
# Line 758  remove_files() Line 861  remove_files()
861   # 1=keep me   #   # 1=keep me   #
862   case ${retval} in   case ${retval} in
863   0)   0)
864   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
865   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
866   ;;   is_config_protected "${pathto}"
867     retval="$?"
868    
869     # 0 - not protected         #
870     # 1 - error                 #
871     # 2 - protected             #
872     # 3 - protected but masked  #
873     # 4 - protected but ignored #
874    
875     case ${retval} in
876     # file is not protected - delete it
877     0|3)
878     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
879     rm "${MROOT}${pathto}"
880     ;;
881    
882     # file is protected, do not delete
883     2)
884     if [[ ${VERBOSE} = on ]]
885     then
886     echo -en "${COLRED}"
887     echo -n "! prot "
888     echo -en "${COLDEFAULT}"
889     echo " === FILE: ${MROOT}${pathto}"
890     fi
891     ;;
892    
893     # file is protected but ignored, delete the update/do nothing
894     4)
895     if [[ ${VERBOSE} = on ]]
896     then
897     echo -en "${COLRED}"
898     echo -n "! ignr "
899     echo -en "${COLDEFAULT}"
900     echo " === FILE: ${MROOT}${pathto}"
901     fi
902     # simply do nothing here
903     ;;
904     esac
905     ;;
906   1)   1)
907   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
908   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 782  remove_blockdevices() Line 923  remove_blockdevices()
923  {  {
924   local pathto   local pathto
925   local posix   local posix
926     local user
927     local group
928   local IFS   local IFS
929   local pcat   local pcat
930   local pname   local pname
# Line 805  remove_blockdevices() Line 948  remove_blockdevices()
948   done   done
949    
950   # sanity checks; abort if not given   # sanity checks; abort if not given
951   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_blockdevices() \$pcat not given."
952   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_blockdevices() \$pname not given."
953   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_blockdevices() \$pver not given."
954   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_blockdevices() \$pbuild not given."
955   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
956    
957   # check needed global vars   # check needed global vars
# Line 819  remove_blockdevices() Line 962  remove_blockdevices()
962   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
963   IFS=§   IFS=§
964    
965   while read pathto posix   while read pathto posix user group
966   do   do
967   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
968    
# Line 840  remove_characterdevices() Line 983  remove_characterdevices()
983  {  {
984   local pathto   local pathto
985   local posix   local posix
986     local user
987     local group
988   local IFS   local IFS
989   local pcat   local pcat
990   local pname   local pname
# Line 863  remove_characterdevices() Line 1008  remove_characterdevices()
1008   done   done
1009    
1010   # sanity checks; abort if not given   # sanity checks; abort if not given
1011   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_characterdevices() \$pcat not given."
1012   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_characterdevices() \$pname not given."
1013   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_characterdevices() \$pver not given."
1014   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_characterdevices() \$pbuild not given."
1015   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1016    
1017   # check needed global vars   # check needed global vars
# Line 877  remove_characterdevices() Line 1022  remove_characterdevices()
1022   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1023   IFS=§   IFS=§
1024    
1025   while read pathto posix   while read pathto posix user group
1026   do   do
1027   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1028    
# Line 891  remove_characterdevices() Line 1036  remove_characterdevices()
1036    
1037    
1038  ###################################################  ###################################################
1039    # function remove_fifos                           #
1040    # remove_fifos $PKGNAME                     #
1041    ###################################################
1042    remove_fifos()
1043    {
1044     local pathto
1045     local posix
1046     local user
1047     local group
1048     local IFS
1049     local pcat
1050     local pname
1051     local pver
1052     local pbuild
1053     local i
1054     local pfull
1055    
1056     IFS=$'\n'
1057    
1058     # very basic getops
1059     for i in $*
1060     do
1061     case $1 in
1062     --pcat|-c) shift; pcat="$1" ;;
1063     --pname|-n) shift; pname="$1" ;;
1064     --pver|-v) shift; pver="$1" ;;
1065     --pbuild|-b) shift; pbuild="$1" ;;
1066     esac
1067     shift
1068     done
1069    
1070     # sanity checks; abort if not given
1071     [ -z "${pcat}" ] && die "remove_fifos() \$pcat not given."
1072     [ -z "${pname}" ] && die "remove_fifos() \$pname not given."
1073     [ -z "${pver}" ] && die "remove_fifos() \$pver not given."
1074     [ -z "${pbuild}" ] && die "remove_fifos() \$pbuild not given."
1075     pfull="${pcat}/${pname}-${pver}-${pbuild}"
1076    
1077     # check needed global vars
1078     [ -z "${BUILDDIR}" ] && die "remove_fifos() \$BUILDDIR not set."
1079    
1080     [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.fifo ] && die "remove_fifos() .fifo not found"
1081    
1082     # sets fieldseperator to "§" instead of " "
1083     IFS=§
1084    
1085     while read pathto posix user group
1086     do
1087     [ -z "${pathto}" ] && continue
1088    
1089     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FIFO: ${MROOT}${pathto}"
1090     rm "${MROOT}${pathto}"
1091     done < ${MROOT}${INSTALLDB}/${pfull}/.fifo
1092    
1093     # very important: unsetting the '§' fieldseperator
1094     IFS=$'\n'
1095    }
1096    
1097    
1098    ###################################################
1099  # function remove_direcories                      #  # function remove_direcories                      #
1100  # remove_direcories $PKGNAME                #  # remove_direcories $PKGNAME                #
1101  ###################################################  ###################################################
# Line 921  remove_directories() Line 1126  remove_directories()
1126   done   done
1127    
1128   # sanity checks; abort if not given   # sanity checks; abort if not given
1129   [ -z "${pcat}" ] && die "remove_symlinks() \$pcat not given."   [ -z "${pcat}" ] && die "remove_directories() \$pcat not given."
1130   [ -z "${pname}" ] && die "remove_symlinks() \$pname not given."   [ -z "${pname}" ] && die "remove_directories() \$pname not given."
1131   [ -z "${pver}" ] && die "remove_symlinks() \$pver not given."   [ -z "${pver}" ] && die "remove_directories() \$pver not given."
1132   [ -z "${pbuild}" ] && die "remove_symlinks() \$pbuild not given."   [ -z "${pbuild}" ] && die "remove_directories() \$pbuild not given."
1133   pfull="${pcat}/${pname}-${pver}-${pbuild}"   pfull="${pcat}/${pname}-${pver}-${pbuild}"
1134    
1135   # check needed global vars   # check needed global vars
# Line 978  remove_directories() Line 1183  remove_directories()
1183  ###################################################  ###################################################
1184  # function build_douninstall                      #  # function build_douninstall                      #
1185  # build_douninstall $PKGNAME                #  # build_douninstall $PKGNAME                #
1186  # NOTE: this is an wrapper do remove packages     #  # NOTE: this is an wrapper to remove packages     #
1187  ###################################################  ###################################################
1188  build_douninstall()  build_douninstall()
1189  {  {
# Line 1012  build_douninstall() Line 1217  build_douninstall()
1217   # !! we use § as field seperator !!   # !! we use § as field seperator !!
1218   # doing so prevent us to get errors by filenames with spaces   # doing so prevent us to get errors by filenames with spaces
1219    
1220   for i in symlinks files blockdevices characterdevices directories   for i in symlinks files blockdevices characterdevices directories fifos
1221   do   do
1222   remove_${i} \   remove_${i} \
1223   --pcat "${pcat}" \   --pcat "${pcat}" \
# Line 1035  fetch_packages() Line 1240  fetch_packages()
1240   local count_current   local count_current
1241   local count_total   local count_total
1242    
1243   [ -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}."
1244    
1245   # get count of total packages   # get count of total packages
1246   declare -i count_current=0   declare -i count_current=0
# Line 1082  fetch_packages() Line 1287  fetch_packages()
1287   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1288   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1289   wget \   wget \
1290   --passive-ftp \   ${WGET_FETCH_OPTIONS} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1291   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1292   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1293   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1294   then   then
1295   break   break
# Line 1110  syncmage() Line 1312  syncmage()
1312  {  {
1313   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1314   then   then
1315   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1316   fi   fi
1317    
1318   local i   local i
1319   for i in ${RSYNC}   for i in ${RSYNC}
1320   do   do
1321   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1322   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1323   then   then
1324   break   break
# Line 1141  syncmage() Line 1330  syncmage()
1330   # clean up backup files (foo~)   # clean up backup files (foo~)
1331   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name *~ -exec rm '{}' ';'
1332    
1333   # check if an newer mage version is available   # check if a newer mage version is available
1334   is_newer_mage_version_available   is_newer_mage_version_available
1335  }  }
1336    
1337    syncmage_tarball()
1338    {
1339     local latest_tarball
1340     local latest_md5
1341     local temp="$(mktemp -d)"
1342     local mirr mymirr
1343     local opt
1344    
1345     # try to get the md5 marked as latest on the server
1346     latest_md5="mage-latest.md5"
1347    
1348     # try to get the tarball marked as latest on the server
1349     latest_tarball="mage-latest.tar.bz2"
1350    
1351     for mirr in ${MIRRORS}
1352     do
1353     # path without distribution
1354     mymirr="${mirr%/*}"
1355    
1356     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1357     echo "fetching latest md5 from ${mymirr} ..."
1358     [[ ${VERBOSE} = off ]] && opt="--quiet"
1359     wget \
1360     ${WGET_FETCH_OPTIONS} \
1361     --directory-prefix=${temp} \
1362     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1363    
1364     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1365     echo "fetching latest tarball from ${mymirr} ..."
1366     wget \
1367     ${WGET_FETCH_OPTIONS} \
1368     --directory-prefix=${temp} \
1369     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1370     if [[ $? = 0 ]]
1371     then
1372     break
1373     else
1374     continue
1375     fi
1376     done
1377    
1378     if [[ -f ${temp}/${latest_tarball} ]]
1379     then
1380     # check md5
1381     if [[ ! -f ${temp}/${latest_md5} ]]
1382     then
1383     die "md5 is missing ... aborting"
1384     else
1385     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1386     echo -n "checking md5sum... "
1387     ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1388     fi
1389    
1390     if [[ -d ${MAGEDIR} ]]
1391     then
1392     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1393     echo "cleaning old mage-tree ${MAGEDIR}..."
1394     rm -rf ${MAGEDIR}
1395     fi
1396    
1397     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1398     echo "updating mage-tree from tarball ..."
1399     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1400     tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1401    
1402     if [[ -d ${temp} ]]
1403     then
1404     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1405     echo "cleaning temp-files ..."
1406     rm -rf ${temp}
1407     fi
1408    
1409     # check if a newer mage version is available
1410     is_newer_mage_version_available
1411     else
1412     die "Could not fetch the latest tarball ... aborting"
1413     fi
1414    }
1415    
1416  cleanpkg()  cleanpkg()
1417  {  {
1418   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1182  choppkgname() Line 1450  choppkgname()
1450   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1451   then   then
1452   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1453   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1454   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1455    
1456   #cuts version number   #cuts version number
# Line 1215  pname2pcat() Line 1483  pname2pcat()
1483  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1484  check_stable_package()  check_stable_package()
1485  {  {
1486     # first check if this magefile is not blacklisted
1487     blacklisted "$1" || return 1
1488    
1489   local STATE   local STATE
1490   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1491    
1492   # state testing   # state testing
1493   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1494   then   then
1495   case ${STATE} in   case ${STATE} in
1496   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1499  check_stable_package()
1499   fi   fi
1500    
1501   # state unstable   # state unstable
1502   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1503   then   then
1504   case ${STATE} in   case ${STATE} in
1505   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1254  get_highest_magefile() Line 1525  get_highest_magefile()
1525   local PNAME="$2"   local PNAME="$2"
1526   local magefile   local magefile
1527    
1528   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1529     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)
1530   do   do
1531     [[ -z ${magefile} ]] && continue
1532   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1533   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1534   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1535   then   then
1536   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1266  get_highest_magefile() Line 1539  get_highest_magefile()
1539   fi   fi
1540   done   done
1541    
1542   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1543   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1544   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1545   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1546   echo  # then
1547   echo -n "All packages named "  # echo
1548   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1549   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1550   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1551   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1552   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1553   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1554   echo "Example:"  # echo
1555   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1556   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1557   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1558   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."
1559   echo  # echo "You should know what you are doing, so don't complain about any damage."
1560   return 1  # echo
1561   fi  # return 1
1562    # fi
1563    
1564   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1565   return 0   return 0
# Line 1301  get_highest_magefile() Line 1575  get_highest_magefile()
1575  #        1 - error                                #  #        1 - error                                #
1576  #        2 - protected                            #  #        2 - protected                            #
1577  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1578    #        4 - protected but ignored                #
1579  #                                                 #  #                                                 #
1580  ###################################################  ###################################################
1581  is_config_protected()  is_config_protected()
# Line 1309  is_config_protected() Line 1584  is_config_protected()
1584   local TEST   local TEST
1585   local PROTECTED   local PROTECTED
1586   local IFS   local IFS
1587     local i
1588     local x
1589    
1590   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1591    
1592   # file does not exist; it can be written   # file does not exist; it can be written
1593   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1594    
1595   # to be safe; it may be '§'   # to be safe; it may be '§'
1596   IFS=' '   IFS=' '
1597    
1598   # check ob in config protect   # check if config protected
1599   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1600   do   do
1601   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1602   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1603   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1604   then   then
1605   # setzen das es protected ist   # file is config proteced
1606   PROTECTED=TRUE   PROTECTED=TRUE
1607    
1608   # check ob nicht doch maskiert   # check if not masked
1609   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1610   do   do
1611   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1612   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1613   then   then
1614   PROTECTED=MASKED   PROTECTED=MASKED
1615   fi   fi
1616   done   done
1617    
1618     # check if not ignored
1619     for x in ${CONFIG_PROTECT_IGNORE}
1620     do
1621     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1622     if [[ ${TEST} != ${EXPFILE} ]]
1623     then
1624     PROTECTED=IGNORED
1625     fi
1626     done
1627   fi   fi
1628   done   done
1629    
# Line 1351  is_config_protected() Line 1638  is_config_protected()
1638   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1639   return 3   return 3
1640   ;;   ;;
1641     IGNORED)
1642     #echo "I'm protected, but ignored - keep me, del update"
1643     return 4
1644     ;;
1645   *)   *)
1646   #echo "delete me"   #echo "delete me"
1647   return 0   return 0
# Line 1368  is_config_protected() Line 1659  is_config_protected()
1659  ###################################################  ###################################################
1660  count_protected_files()  count_protected_files()
1661  {  {
1662   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1663     local dirname="${file%/*}"
1664     local filename="${file##*/}"
1665     local count
1666     local output
1667     local i
1668    
1669     declare -i count=0
1670    
1671     # check if there are already protected files
1672     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1673     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1674     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1675     do
1676     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1677     done
1678     (( count ++ ))
1679    
1680     # fill output up with zeros
1681     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1682     output="${output}${count}"
1683    
1684     echo "${output}"
1685  }  }
1686    
1687  # call with  # call with
# Line 1385  get_uninstall_candidates() Line 1698  get_uninstall_candidates()
1698   local list   local list
1699   local pcatdir   local pcatdir
1700   local protected   local protected
1701     local i
1702    
1703   # very basic getops   # very basic getops
1704   for i in $*   for i in $*
# Line 1397  get_uninstall_candidates() Line 1711  get_uninstall_candidates()
1711   shift   shift
1712   done   done
1713    
1714   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1715   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1716    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1717    
1718    
1719   # check needed global vars   # check needed global vars
1720   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1721    
1722   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1723   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1724    
1725   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1726   do   do
# Line 1490  virtuals_add() Line 1805  virtuals_add()
1805   local oldline   local oldline
1806   local line i   local line i
1807   local installed_file   local installed_file
1808     local OLDIFS
1809    
1810   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1811   then   then
1812   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1813   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1814   do   do
1815   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 1828  virtuals_add()
1828   # make a backup   # make a backup
1829   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1830    
1831     OLDIFS="${IFS}"
1832   IFS=$'\n'   IFS=$'\n'
1833   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1834   do   do
# Line 1523  virtuals_add() Line 1840  virtuals_add()
1840   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1841   fi   fi
1842   done   done
1843     # unset IFS
1844   #unset IFS   IFS="${OLDIFS}"
1845   else   else
1846   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1847   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1848   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1849   fi   fi
# Line 1536  virtuals_add() Line 1853  virtuals_add()
1853    
1854  #deletes pakages from virtual database  #deletes pakages from virtual database
1855  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1856  virtuals_del() {  virtuals_del()
1857    {
1858    
1859   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1860     local pkgname="$2"
1861   VIRTUAL_NAME=$1   local oldline
1862   PKG_NAME=$2   local method
1863     local line i x
1864   #first check if exists   local pkg_installed
1865   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1866    
1867     # first check if exists
1868     if virtuals_read ${virtualname}
1869   then   then
1870   #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}
1871   declare -i x=0   declare -i x=0
1872   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1873   do   do
1874   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1875   then   then
1876   PKG_INSTALLED=true   pkg_installed=true
1877   fi   fi
1878   ((x++))   ((x++))
1879   done   done
1880    
1881   #abort if not installed   # abort if not installed
1882   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1883   then   then
1884   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1885     echo "${pkgname} does not exists in ${virtualname}."
1886   return 0   return 0
1887   fi   fi
1888    
1889   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1890   then   then
1891   METHOD=update   method=update
1892   else   else
1893   METHOD=delall   method=delall
1894   fi   fi
1895    
1896   #get the complete line   # get the complete line
1897   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1898    
1899   #make a backup   # make a backup of the db
1900   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1901    
1902   #parse virtualdb   # parse virtualdb
1903     OLDIFS="${IFS}"
1904   IFS=$'\n'   IFS=$'\n'
1905   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1906   do   do
1907   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1908   then   then
1909   #delall or update?   #delall or update?
1910   case ${METHOD} in   case ${method} in
1911   update)   update)
1912   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1913   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1914   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1915     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1916   ;;   ;;
1917   delall)   delall)
1918   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1919   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1920     # continue; do not write anything
1921   continue   continue
1922   ;;   ;;
1923   esac   esac
# Line 1600  virtuals_del() { Line 1925  virtuals_del() {
1925   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1926   fi   fi
1927   done   done
1928   unset IFS   # unset IFS
1929     IFS="${OLDIFS}"
1930   else   else
1931   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1932     echo "${virtualname} does not exists in virtual database."
1933   fi   fi
1934  }  }
1935    
# Line 1634  minclude() Line 1961  minclude()
1961  {  {
1962   local i   local i
1963    
1964   if [ -n "$@" ]   if [[ -n $* ]]
1965   then   then
1966   for i in $@   for i in $*
1967   do   do
1968   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
1969   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1650  sminclude() Line 1977  sminclude()
1977  {  {
1978   local i   local i
1979    
1980   if [ -n "$@" ]   if [[ -n $* ]]
1981   then   then
1982   for i in $@   for i in $*
1983   do   do
1984   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1985   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1667  is_newer_mage_version_available() Line 1994  is_newer_mage_version_available()
1994   local newest_mage   local newest_mage
1995   local installed_mage   local installed_mage
1996    
1997   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1998   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1999    
2000   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1676  is_newer_mage_version_available() Line 2003  is_newer_mage_version_available()
2003   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
2004   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
2005   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
2006   echo "or your current system installation may brake."   echo "or your current system installation may break."
2007   echo   echo
2008   echo -en "Please update mage by running "   echo -en "Please update mage by running "
2009   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1948  get_value_from_magefile() Line 2275  get_value_from_magefile()
2275   local magefile="$2"   local magefile="$2"
2276   local value   local value
2277    
2278     [[ -z ${var} ]] && return 1
2279     [[ -z ${magefile} ]] && return 1
2280    
2281   # local all possible vars of a mage file   # local all possible vars of a mage file
2282   # to prevent bad issues   # to prevent bad issues
2283   local PKGNAME   local PKGNAME
# Line 1958  get_value_from_magefile() Line 2288  get_value_from_magefile()
2288   local SDEPEND   local SDEPEND
2289   local PROVIDE   local PROVIDE
2290   local PKGTYPE   local PKGTYPE
2291     local MAGE_TARGETS
2292     local SPLIT_PACKAGE_BASE
2293   local preinstall   local preinstall
2294   local postinstall   local postinstall
2295     local preremove
2296     local postremove
2297    
2298   # sanity checks   # sanity checks
2299   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1969  get_value_from_magefile() Line 2303  get_value_from_magefile()
2303   source ${magefile}   source ${magefile}
2304   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2305   echo "${value}"   echo "${value}"
2306    
2307     # unset these functions
2308     unset -f preinstall
2309     unset -f postinstall
2310     unset -f preremove
2311     unset -f postremove
2312  }  }
2313    
2314  mage_install()  mage_install()
# Line 1985  mage_install() Line 2325  mage_install()
2325   local PKGTYPE   local PKGTYPE
2326   local preinstall   local preinstall
2327   local postinstall   local postinstall
2328     local preremove
2329     local postremove
2330    
2331   local pcat   local pcat
2332   local pname   local pname
# Line 1994  mage_install() Line 2336  mage_install()
2336   local count_current   local count_current
2337   local magefile   local magefile
2338   local src_install   local src_install
2339     local i
2340    
2341   # very basic getops   # very basic getops
2342   for i in $*   for i in $*
# Line 2067  mage_install() Line 2410  mage_install()
2410   echo B:${pbuild}   echo B:${pbuild}
2411   fi   fi
2412    
2413   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2414     then
2415     # basic svn compat
2416     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2417     then
2418     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2419     do
2420     smage2file="${i}"
2421     done
2422     else
2423     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2424     fi
2425    
2426     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2427     then
2428     # basic svn compat
2429     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2430     then
2431     for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2432     do
2433     smage2file="${i}"
2434     done
2435     else
2436     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2437     fi
2438    
2439     else
2440     # basic svn compat
2441     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2442     then
2443     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2444     do
2445     smage2file="${i}"
2446     done
2447     else
2448     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2449     fi
2450     fi
2451    
2452   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2453   then   then
2454     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2455   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2456   else   else
2457   echo   echo
# Line 2083  mage_install() Line 2465  mage_install()
2465   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2466   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2467   then   then
2468   # 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  
2469   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2470   fi   fi
2471    
# Line 2146  mage_install() Line 2521  mage_install()
2521  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2522  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2523   echo "successfully installed."   echo "successfully installed."
2524    
2525     # unset these functions
2526     unset -f preinstall
2527     unset -f postinstall
2528     unset -f preremove
2529     unset -f postremove
2530  }  }
2531    
2532  md5sum_packages()  md5sum_packages()
# Line 2304  mage_uninstall() Line 2685  mage_uninstall()
2685   local PKGTYPE   local PKGTYPE
2686   local preinstall   local preinstall
2687   local postinstall   local postinstall
2688     local preremove
2689     local postremove
2690    
2691   local pcat   local pcat
2692   local pname   local pname
# Line 2339  mage_uninstall() Line 2722  mage_uninstall()
2722   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2723   echo -n "removing: "   echo -n "removing: "
2724   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2725   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2726    
2727   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2728   source ${magefile}   source ${magefile}
2729    
2730   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2784  mage_uninstall()
2784  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2785  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2786   echo "successfully removed."   echo "successfully removed."
2787    
2788     # unset these functions
2789     unset -f preinstall
2790     unset -f postinstall
2791     unset -f preremove
2792     unset -f postremove
2793  }  }
2794    
2795  show_etc_update_mesg() {  show_etc_update_mesg()
2796    {
2797   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0   [ ${MAGE_PROTECT_COUNTER} -eq 0 ] && return 0
2798    
2799   echo   echo
# Line 2433  pkgsearch() Line 2823  pkgsearch()
2823   local all_installed   local all_installed
2824   local ipver   local ipver
2825   local ipbuild   local ipbuild
2826     local latest_available
2827     local depsfull
2828     local sdepsfull
2829     local deps
2830     local sdeps
2831     local dep
2832     local sign
2833    
2834   # only names no versions   # only names no versions
2835   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')"
2836   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2837    
2838   # nothing found   # nothing found
2839   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2450  pkgsearch() Line 2847  pkgsearch()
2847   # get highest version available   # get highest version available
2848   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
2849    
2850   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
2851   pver="$(magename2pver ${magefile})"   then
2852   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
2853   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
2854   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
2855   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
2856     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2857     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2858    
2859     # all installed
2860     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2861     do
2862     ipver="$(magename2pver ${i})"
2863     ipbuild="$(magename2pbuild ${i})"
2864    
2865     if [[ -z ${all_installed} ]]
2866     then
2867     all_installed="${ipver}-${ipbuild}"
2868     else
2869     all_installed="${all_installed} ${ipver}-${ipbuild}"
2870     fi
2871     done
2872     [[ -z ${all_installed} ]] && all_installed="none"
2873    
2874     case ${state} in
2875     stable) state=${COLGREEN}"[s] ";;
2876     testing) state=${COLYELLOW}"[t] ";;
2877     unstable) state=${COLRED}"[u] ";;
2878     old) state=${COLGRAY}"[o] ";;
2879     esac
2880    
2881   # all installed   latest_available="${pver}-${pbuild}"
2882   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   else
2883   do   # package is masked
2884   ipver="$(magename2pver ${i})"   state="${COLRED}[m] "
2885   ipbuild="$(magename2pbuild ${i})"   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2886     fi
2887    
2888   if [[ -z ${all_installed} ]]   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2889   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"  
2890    
2891   case ${state} in   while read sign dep
2892   stable) state=${COLGREEN}"[s] ";;   do
2893   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
2894   unstable) state=${COLRED}"[u] ";;   "") continue;;
2895   old) state=${COLGRAY}"[o] ";;   esac
2896   esac  
2897     deps="${deps} $(basename ${dep%-*})"
2898     done << EOF
2899    ${depsfull}
2900    EOF
2901    
2902     while read sign dep
2903     do
2904     case ${dep} in
2905     "") continue;;
2906     esac
2907    
2908     sdeps="${sdeps} $(basename ${dep%-*})"
2909     done << EOF
2910    ${sdepsfull}
2911    EOF
2912    
2913   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2914   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
2915   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
2916   echo "      Description: ${description}"   echo "      Description: ${description}"
2917   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
2918     echo "      Depends: ${deps}"
2919     echo "      SDepends: ${sdeps}"
2920   echo   echo
2921    
2922   unset pcat   unset pcat
# Line 2497  pkgsearch() Line 2930  pkgsearch()
2930   unset all_installed   unset all_installed
2931   unset ipver   unset ipver
2932   unset ipbuild   unset ipbuild
2933     unset depsfull
2934     unset sdepsfull
2935     unset deps
2936     unset sdeps
2937     unset dep
2938     unset sign
2939   done   done
2940  }  }
2941    
2942    export_inherits()
2943    {
2944     local include="$1"
2945     shift
2946    
2947     while [ "$1" ]
2948     do
2949     local functions="$1"
2950    
2951     # sanity checks
2952     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2953     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2954    
2955     eval "${functions}() { ${include}_${functions} ; }"
2956    
2957     # debug
2958     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2959    
2960     shift
2961     done
2962    }
2963    
2964    mlibdir()
2965    {
2966     local libdir=lib
2967     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2968    
2969     echo "${libdir}"
2970    }
2971    
2972    ## blacklisted ${magefile}
2973    blacklisted()
2974    {
2975     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2976    
2977     # compat
2978     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2979     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2980    
2981     # support both types for the moment
2982     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
2983     then
2984     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2985     else
2986     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
2987     fi
2988    
2989     # return 0 if the list not exist; nothin is masked
2990     [[ ! -f ${EXCLUDED} ]] && return 0
2991    
2992     local MAGEFILE="$1"
2993    
2994     local PCAT="$(magename2pcat ${MAGEFILE})"
2995     local PNAME="$(magename2pname ${MAGEFILE})"
2996     local PVER="$(magename2pver ${MAGEFILE})"
2997     local PBUILD="$(magename2pbuild ${MAGEFILE})"
2998    
2999     local EXPCAT EXPNAME EXPVER EXPBUILD
3000     while read EXPCAT EXPNAME EXPVER EXPBUILD
3001     do
3002     # ignore spaces and comments
3003             case "${EXPCAT}" in
3004                     \#*|"") continue ;;
3005             esac
3006    
3007     # exclude full pver
3008     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3009     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3010     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
3011     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
3012     then
3013     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
3014     fi
3015    
3016     # exclude pcat/pname only
3017     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
3018     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
3019     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
3020     then
3021     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
3022     fi
3023     done << EOF
3024    $( cat ${EXCLUDED}; echo)
3025    EOF
3026    
3027     return 0
3028    }
3029    

Legend:
Removed from v.240  
changed lines
  Added in v.1209