Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 1087 by niro, Mon Jun 28 18:46:57 2010 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 361  install_characterdevices() Line 374  install_characterdevices()
374   local pkgname="$1"   local pkgname="$1"
375   local pathto   local pathto
376   local posix   local posix
377     local major
378     local minor
379   local IFS   local IFS
380    
381   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 389  install_characterdevices()
389   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
390   IFS=§   IFS=§
391    
392   while read pathto posix   while read pathto posix major minor
393   do   do
394   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
395   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
396    
397   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}
398   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
399    
400   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 432  install_database_entry() Line 447  install_database_entry()
447   local magefile   local magefile
448   local dbrecorddir   local dbrecorddir
449   local provide   local provide
450     local i
451    
452   # very basic getops   # very basic getops
453   for i in $*   for i in $*
# Line 473  install_database_entry() Line 489  install_database_entry()
489    
490   # create fake file descriptors   # create fake file descriptors
491   # used by virtual and source packages   # used by virtual and source packages
  local i  
492   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char
493   do   do
494   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
# Line 504  install_database_entry() Line 519  install_database_entry()
519   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
520   if [ -n "${provide}" ]   if [ -n "${provide}" ]
521   then   then
522   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
523     do
524     virtuals_add "${i}" "${pcat}/${pname}"
525     done
526   fi   fi
527  }  }
528    
# Line 523  remove_database_entry() Line 541  remove_database_entry()
541   local magefile   local magefile
542   local dbrecorddir   local dbrecorddir
543   local provide   local provide
544     local i
545    
546   # very basic getops   # very basic getops
547   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 571  remove_database_entry()
571   # abort if mage file not exists   # abort if mage file not exists
572   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
573    
574   # first unregister virtuals   # remove virtuals only if no other exist
575   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
576   then   then
577   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
578     provide="$(get_value_from_magefile PROVIDE ${magefile})"
579     if [ -n "${provide}" ]
580     then
581     for i in ${provide}
582     do
583     virtuals_del "${i}" "${pcat}/${pname}"
584     done
585     fi
586   fi   fi
587    
588   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 592  remove_database_entry()
592   fi   fi
593  }  }
594    
595    # get the number of installed packages
596    count_installed_pkgs()
597    {
598     local pcat
599     local pname
600     local pkg
601     local i
602    
603     # very basic getops
604     for i in $*
605     do
606     case $1 in
607     --pcat|-c) shift; pcat="$1" ;;
608     --pname|-n) shift; pname="$1" ;;
609     esac
610     shift
611     done
612    
613     # sanity checks; abort if not given
614     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
615     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
616    
617     declare -i i=0
618     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
619     do
620     (( i++ ))
621     #echo "$i ${pkg}"
622     done
623    
624     # return the value
625     echo "${i}"
626    }
627    
628    
629  ###################################################  ###################################################
630  # function compare_mtime                          #  # function compare_mtime                          #
# Line 744  remove_files() Line 803  remove_files()
803   do   do
804   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
805    
806   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
807   then   then
808   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
809   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 758  remove_files() Line 817  remove_files()
817   # 1=keep me   #   # 1=keep me   #
818   case ${retval} in   case ${retval} in
819   0)   0)
820   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
821   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
822   ;;   is_config_protected "${pathto}"
823     retval="$?"
824    
825     # 0 - not protected         #
826     # 1 - error                 #
827     # 2 - protected             #
828     # 3 - protected but masked  #
829     # 4 - protected but ignored #
830    
831     case ${retval} in
832     # file is not protected - delete it
833     0|3)
834     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
835     rm "${MROOT}${pathto}"
836     ;;
837    
838     # file is protected, do not delete
839     2)
840     if [[ ${VERBOSE} = on ]]
841     then
842     echo -en "${COLRED}"
843     echo -n "! prot "
844     echo -en "${COLDEFAULT}"
845     echo " === FILE: ${MROOT}${pathto}"
846     fi
847     ;;
848    
849     # file is protected but ignored, delete the update/do nothing
850     4)
851     if [[ ${VERBOSE} = on ]]
852     then
853     echo -en "${COLRED}"
854     echo -n "! ignr "
855     echo -en "${COLDEFAULT}"
856     echo " === FILE: ${MROOT}${pathto}"
857     fi
858     # simply do nothing here
859     ;;
860     esac
861     ;;
862   1)   1)
863   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
864   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 932  remove_directories() Line 1029  remove_directories()
1029    
1030   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
1031    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
1032   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
1033   IFS=§   IFS=§
1034    
1035   while read pathto posix   # reversed order is mandatory !
1036     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
1037   do   do
1038   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
1039    
# Line 954  remove_directories() Line 1048  remove_directories()
1048   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
1049   then   then
1050   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1051   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1052   continue   continue
1053   fi   fi
1054    
# Line 971  remove_directories() Line 1065  remove_directories()
1065   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1066   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1067   fi   fi
1068   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1069    
1070   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1071   IFS=$'\n'   IFS=$'\n'
# Line 1038  fetch_packages() Line 1132  fetch_packages()
1132   local count_current   local count_current
1133   local count_total   local count_total
1134    
1135   [ -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}."
1136    
1137   # get count of total packages   # get count of total packages
1138   declare -i count_current=0   declare -i count_current=0
# Line 1085  fetch_packages() Line 1179  fetch_packages()
1179   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "   echo -e " fetching (${count_current}/${count_total}): ${pkg} ... "
1180   [[ ${VERBOSE} = off ]] && opt="--quiet"   [[ ${VERBOSE} = off ]] && opt="--quiet"
1181   wget \   wget \
1182   --passive-ftp \   ${WGET_FETCH_OPTIONS} \
  --tries 3 \  
  --continue \  
  --progress bar \  
1183   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1184   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1185   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1186   then   then
1187   break   break
# Line 1113  syncmage() Line 1204  syncmage()
1204  {  {
1205   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1206   then   then
1207   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1208   fi   fi
1209    
1210   local i   local i
1211   for i in ${RSYNC}   for i in ${RSYNC}
1212   do   do
1213   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1214   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1215   then   then
1216   break   break
# Line 1144  syncmage() Line 1222  syncmage()
1222   # clean up backup files (foo~)   # clean up backup files (foo~)
1223   find ${MAGEDIR} -name *~ -exec rm '{}' ';'   find ${MAGEDIR} -name *~ -exec rm '{}' ';'
1224    
1225   # check if an newer mage version is available   # check if a newer mage version is available
1226   is_newer_mage_version_available   is_newer_mage_version_available
1227  }  }
1228    
1229    syncmage_tarball()
1230    {
1231     local latest_tarball
1232     local latest_md5
1233     local temp="$(mktemp -d)"
1234     local mirr mymirr
1235     local opt
1236    
1237     # try to get the md5 marked as latest on the server
1238     latest_md5="mage-latest.md5"
1239    
1240     # try to get the tarball marked as latest on the server
1241     latest_tarball="mage-latest.tar.bz2"
1242    
1243     for mirr in ${MIRRORS}
1244     do
1245     # path without distribution
1246     mymirr="${mirr%/*}"
1247    
1248     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1249     echo "fetching latest md5 from ${mymirr} ..."
1250     [[ ${VERBOSE} = off ]] && opt="--quiet"
1251     wget \
1252     ${WGET_FETCH_OPTIONS} \
1253     --directory-prefix=${temp} \
1254     ${opt} ${mymirr}/rsync/tarballs/${latest_md5}
1255    
1256     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1257     echo "fetching latest tarball from ${mymirr} ..."
1258     wget \
1259     ${WGET_FETCH_OPTIONS} \
1260     --directory-prefix=${temp} \
1261     ${opt} ${mymirr}/rsync/tarballs/${latest_tarball}
1262     if [[ $? = 0 ]]
1263     then
1264     break
1265     else
1266     continue
1267     fi
1268     done
1269    
1270     if [[ -f ${temp}/${latest_tarball} ]]
1271     then
1272     # check md5
1273     if [[ ! -f ${temp}/${latest_md5} ]]
1274     then
1275     die "md5 is missing ... aborting"
1276     else
1277     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1278     echo -n "checking md5sum... "
1279     ( cd ${temp}; md5sum --check ${latest_md5} ) || die "md5 for ${latest_tarball} failed"
1280     fi
1281    
1282     if [[ -d ${MAGEDIR} ]]
1283     then
1284     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1285     echo "cleaning old mage-tree ${MAGEDIR}..."
1286     rm -rf ${MAGEDIR}
1287     fi
1288    
1289     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1290     echo "updating mage-tree from tarball ..."
1291     # unpack in dirname of MAGEDIR, as the tarball has already the mage
1292     tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball"
1293    
1294     if [[ -d ${temp} ]]
1295     then
1296     echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1297     echo "cleaning temp-files ..."
1298     rm -rf ${temp}
1299     fi
1300    
1301     # check if a newer mage version is available
1302     is_newer_mage_version_available
1303     else
1304     die "Could not fetch the latest tarball ... aborting"
1305     fi
1306    }
1307    
1308  cleanpkg()  cleanpkg()
1309  {  {
1310   if [ -d "${PKGDIR}" ]   if [ -d "${PKGDIR}" ]
# Line 1185  choppkgname() Line 1342  choppkgname()
1342   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1343   then   then
1344   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1345   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1346   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1347    
1348   #cuts version number   #cuts version number
# Line 1218  pname2pcat() Line 1375  pname2pcat()
1375  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1376  check_stable_package()  check_stable_package()
1377  {  {
1378     # first check if this magefile is not blacklisted
1379     blacklisted "$1" || return 1
1380    
1381   local STATE   local STATE
1382   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1383    
1384   # state testing   # state testing
1385   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1386   then   then
1387   case ${STATE} in   case ${STATE} in
1388   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1231  check_stable_package() Line 1391  check_stable_package()
1391   fi   fi
1392    
1393   # state unstable   # state unstable
1394   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1395   then   then
1396   case ${STATE} in   case ${STATE} in
1397   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1257  get_highest_magefile() Line 1417  get_highest_magefile()
1417   local PNAME="$2"   local PNAME="$2"
1418   local magefile   local magefile
1419    
1420   for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*)   # do not list the content of a directory, only the name (-d)
1421     for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*)
1422   do   do
1423     [[ -z ${magefile} ]] && continue
1424   # we exclude subdirs (for stuff like a md5sum dir)   # we exclude subdirs (for stuff like a md5sum dir)
1425   [ -d ${magefile} ] && continue   [[ -d ${magefile} ]] && continue
1426   if check_stable_package ${magefile}   if check_stable_package ${magefile}
1427   then   then
1428   HIGHEST_MAGEFILE=${magefile}   HIGHEST_MAGEFILE=${magefile}
# Line 1269  get_highest_magefile() Line 1431  get_highest_magefile()
1431   fi   fi
1432   done   done
1433    
1434   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1435   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1436   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1437   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1438   echo  # then
1439   echo -n "All packages named "  # echo
1440   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1441   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1442   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1443   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1444   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1445   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1446   echo "Example:"  # echo
1447   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1448   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1449   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1450   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."
1451   echo  # echo "You should know what you are doing, so don't complain about any damage."
1452   return 1  # echo
1453   fi  # return 1
1454    # fi
1455    
1456   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1457   return 0   return 0
# Line 1304  get_highest_magefile() Line 1467  get_highest_magefile()
1467  #        1 - error                                #  #        1 - error                                #
1468  #        2 - protected                            #  #        2 - protected                            #
1469  #        3 - protected but masked                 #  #        3 - protected but masked                 #
1470    #        4 - protected but ignored                #
1471  #                                                 #  #                                                 #
1472  ###################################################  ###################################################
1473  is_config_protected()  is_config_protected()
# Line 1312  is_config_protected() Line 1476  is_config_protected()
1476   local TEST   local TEST
1477   local PROTECTED   local PROTECTED
1478   local IFS   local IFS
1479     local i
1480     local x
1481    
1482   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1483    
1484   # file does not exist; it can be written   # file does not exist; it can be written
1485   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1486    
1487   # to be safe; it may be '§'   # to be safe; it may be '§'
1488   IFS=' '   IFS=' '
1489    
1490   # check ob in config protect   # check if config protected
1491   for i in ${CONFIG_PROTECT}   for i in ${CONFIG_PROTECT}
1492   do   do
1493   # ersetzen von $i nur wenn am anfang der variable   # only replace $i in the beginning of the variable
1494   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1495   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1496   then   then
1497   # setzen das es protected ist   # file is config proteced
1498   PROTECTED=TRUE   PROTECTED=TRUE
1499    
1500   # check ob nicht doch maskiert   # check if not masked
1501   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1502   do   do
1503   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1504   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1505   then   then
1506   PROTECTED=MASKED   PROTECTED=MASKED
1507   fi   fi
1508   done   done
1509    
1510     # check if not ignored
1511     for x in ${CONFIG_PROTECT_IGNORE}
1512     do
1513     TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}"
1514     if [[ ${TEST} != ${EXPFILE} ]]
1515     then
1516     PROTECTED=IGNORED
1517     fi
1518     done
1519   fi   fi
1520   done   done
1521    
# Line 1354  is_config_protected() Line 1530  is_config_protected()
1530   #echo "I'm protected, but masked - delete me"   #echo "I'm protected, but masked - delete me"
1531   return 3   return 3
1532   ;;   ;;
1533     IGNORED)
1534     #echo "I'm protected, but ignored - keep me, del update"
1535     return 4
1536     ;;
1537   *)   *)
1538   #echo "delete me"   #echo "delete me"
1539   return 0   return 0
# Line 1371  is_config_protected() Line 1551  is_config_protected()
1551  ###################################################  ###################################################
1552  count_protected_files()  count_protected_files()
1553  {  {
1554   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1555     local dirname="${file%/*}"
1556     local filename="${file##*/}"
1557     local count
1558     local output
1559     local i
1560    
1561     declare -i count=0
1562    
1563     # check if there are already protected files
1564     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1565     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1566     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1567     do
1568     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1569     done
1570     (( count ++ ))
1571    
1572     # fill output up with zeros
1573     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1574     output="${output}${count}"
1575    
1576     echo "${output}"
1577  }  }
1578    
1579  # call with  # call with
# Line 1388  get_uninstall_candidates() Line 1590  get_uninstall_candidates()
1590   local list   local list
1591   local pcatdir   local pcatdir
1592   local protected   local protected
1593     local i
1594    
1595   # very basic getops   # very basic getops
1596   for i in $*   for i in $*
# Line 1400  get_uninstall_candidates() Line 1603  get_uninstall_candidates()
1603   shift   shift
1604   done   done
1605    
1606   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1607   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1608    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1609    
1610    
1611   # check needed global vars   # check needed global vars
1612   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1613    
1614   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1615   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1616    
1617   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1618   do   do
# Line 1493  virtuals_add() Line 1697  virtuals_add()
1697   local oldline   local oldline
1698   local line i   local line i
1699   local installed_file   local installed_file
1700     local OLDIFS
1701    
1702   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1703   then   then
1704   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1705   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1706   do   do
1707   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1515  virtuals_add() Line 1720  virtuals_add()
1720   # make a backup   # make a backup
1721   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1722    
1723     OLDIFS="${IFS}"
1724   IFS=$'\n'   IFS=$'\n'
1725   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1726   do   do
# Line 1526  virtuals_add() Line 1732  virtuals_add()
1732   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1733   fi   fi
1734   done   done
1735     # unset IFS
1736   #unset IFS   IFS="${OLDIFS}"
1737   else   else
1738   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1739   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1740   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1741   fi   fi
# Line 1541  virtuals_add() Line 1747  virtuals_add()
1747  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1748  virtuals_del() {  virtuals_del() {
1749    
1750   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1751     local pkgname="$2"
1752   VIRTUAL_NAME=$1   local oldline
1753   PKG_NAME=$2   local method
1754     local line i x
1755   #first check if exists   local pkg_installed
1756   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1757    
1758     # first check if exists
1759     if virtuals_read ${virtualname}
1760   then   then
1761   #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}
1762   declare -i x=0   declare -i x=0
1763   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1764   do   do
1765   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1766   then   then
1767   PKG_INSTALLED=true   pkg_installed=true
1768   fi   fi
1769   ((x++))   ((x++))
1770   done   done
1771    
1772   #abort if not installed   # abort if not installed
1773   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1774   then   then
1775   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1776     echo "${pkgname} does not exists in ${virtualname}."
1777   return 0   return 0
1778   fi   fi
1779    
1780   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1781   then   then
1782   METHOD=update   method=update
1783   else   else
1784   METHOD=delall   method=delall
1785   fi   fi
1786    
1787   #get the complete line   # get the complete line
1788   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1789    
1790   #make a backup   # make a backup of the db
1791   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1792    
1793   #parse virtualdb   # parse virtualdb
1794     OLDIFS="${IFS}"
1795   IFS=$'\n'   IFS=$'\n'
1796   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1797   do   do
1798   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1799   then   then
1800   #delall or update?   #delall or update?
1801   case ${METHOD} in   case ${method} in
1802   update)   update)
1803   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1804   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1805   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1806     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1807   ;;   ;;
1808   delall)   delall)
1809   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1810   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1811     # continue; do not write anything
1812   continue   continue
1813   ;;   ;;
1814   esac   esac
# Line 1603  virtuals_del() { Line 1816  virtuals_del() {
1816   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1817   fi   fi
1818   done   done
1819   unset IFS   # unset IFS
1820     IFS="${OLDIFS}"
1821   else   else
1822   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1823     echo "${virtualname} does not exists in virtual database."
1824   fi   fi
1825  }  }
1826    
# Line 1637  minclude() Line 1852  minclude()
1852  {  {
1853   local i   local i
1854    
1855   if [ -n "$@" ]   if [[ -n $* ]]
1856   then   then
1857   for i in $@   for i in $*
1858   do   do
1859   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
1860   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1653  sminclude() Line 1868  sminclude()
1868  {  {
1869   local i   local i
1870    
1871   if [ -n "$@" ]   if [[ -n $* ]]
1872   then   then
1873   for i in $@   for i in $*
1874   do   do
1875   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1876   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1670  is_newer_mage_version_available() Line 1885  is_newer_mage_version_available()
1885   local newest_mage   local newest_mage
1886   local installed_mage   local installed_mage
1887    
1888   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1889   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1890    
1891   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1679  is_newer_mage_version_available() Line 1894  is_newer_mage_version_available()
1894   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1895   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1896   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
1897   echo "or your current system installation may brake."   echo "or your current system installation may break."
1898   echo   echo
1899   echo -en "Please update mage by running "   echo -en "Please update mage by running "
1900   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1951  get_value_from_magefile() Line 2166  get_value_from_magefile()
2166   local magefile="$2"   local magefile="$2"
2167   local value   local value
2168    
2169     [[ -z ${var} ]] && return 1
2170     [[ -z ${magefile} ]] && return 1
2171    
2172   # local all possible vars of a mage file   # local all possible vars of a mage file
2173   # to prevent bad issues   # to prevent bad issues
2174   local PKGNAME   local PKGNAME
# Line 1961  get_value_from_magefile() Line 2179  get_value_from_magefile()
2179   local SDEPEND   local SDEPEND
2180   local PROVIDE   local PROVIDE
2181   local PKGTYPE   local PKGTYPE
2182     local MAGE_TARGETS
2183     local SPLIT_PACKAGE_BASE
2184   local preinstall   local preinstall
2185   local postinstall   local postinstall
2186     local preremove
2187     local postremove
2188    
2189   # sanity checks   # sanity checks
2190   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 2194  get_value_from_magefile()
2194   source ${magefile}   source ${magefile}
2195   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2196   echo "${value}"   echo "${value}"
2197    
2198     # unset these functions
2199     unset -f preinstall
2200     unset -f postinstall
2201     unset -f preremove
2202     unset -f postremove
2203  }  }
2204    
2205  mage_install()  mage_install()
# Line 1988  mage_install() Line 2216  mage_install()
2216   local PKGTYPE   local PKGTYPE
2217   local preinstall   local preinstall
2218   local postinstall   local postinstall
2219     local preremove
2220     local postremove
2221    
2222   local pcat   local pcat
2223   local pname   local pname
# Line 1997  mage_install() Line 2227  mage_install()
2227   local count_current   local count_current
2228   local magefile   local magefile
2229   local src_install   local src_install
2230     local i
2231    
2232   # very basic getops   # very basic getops
2233   for i in $*   for i in $*
# Line 2070  mage_install() Line 2301  mage_install()
2301   echo B:${pbuild}   echo B:${pbuild}
2302   fi   fi
2303    
2304   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -n ${MAGE_TARGETS} ]]
2305     then
2306     # basic svn compat
2307     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2308     then
2309     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2310     do
2311     smage2file="${i}"
2312     done
2313     else
2314     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2315     fi
2316    
2317     elif [[ -n ${SPLIT_PACKAGE_BASE} ]]
2318     then
2319     # basic svn compat
2320     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2321     then
2322     for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2323     do
2324     smage2file="${i}"
2325     done
2326     else
2327     smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2
2328     fi
2329    
2330     else
2331     # basic svn compat
2332     if [[ -d ${SMAGESCRIPTSDIR}/trunk ]]
2333     then
2334     for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2
2335     do
2336     smage2file="${i}"
2337     done
2338     else
2339     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2340     fi
2341     fi
2342    
2343   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2344   then   then
2345     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2346   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2347   else   else
2348   echo   echo
# Line 2086  mage_install() Line 2356  mage_install()
2356   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2357   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2358   then   then
2359   # 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  
2360   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2361   fi   fi
2362    
# Line 2149  mage_install() Line 2412  mage_install()
2412  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2413  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2414   echo "successfully installed."   echo "successfully installed."
2415    
2416     # unset these functions
2417     unset -f preinstall
2418     unset -f postinstall
2419     unset -f preremove
2420     unset -f postremove
2421  }  }
2422    
2423  md5sum_packages()  md5sum_packages()
# Line 2253  uninstall_packages() Line 2522  uninstall_packages()
2522   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2523   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2524   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2525   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2526   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2527   echo   echo
2528   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2529   echo "( Press [CTRL+C] to abort )"   then
2530   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2531   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2532   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2533   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2534   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2535   sleep 1   do
2536   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2537   echo   sleep 1
2538   echo   done
2539     echo
2540     echo
2541     fi
2542    
2543   for pkg in ${list}   for pkg in ${list}
2544   do   do
# Line 2304  mage_uninstall() Line 2576  mage_uninstall()
2576   local PKGTYPE   local PKGTYPE
2577   local preinstall   local preinstall
2578   local postinstall   local postinstall
2579     local preremove
2580     local postremove
2581    
2582   local pcat   local pcat
2583   local pname   local pname
# Line 2339  mage_uninstall() Line 2613  mage_uninstall()
2613   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2614   echo -n "removing: "   echo -n "removing: "
2615   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2616   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2617    
2618   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2619   source ${magefile}   source ${magefile}
2620    
2621   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2675  mage_uninstall()
2675  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2676  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2677   echo "successfully removed."   echo "successfully removed."
2678    
2679     # unset these functions
2680     unset -f preinstall
2681     unset -f postinstall
2682     unset -f preremove
2683     unset -f postremove
2684  }  }
2685    
2686  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2415  show_etc_update_mesg() { Line 2695  show_etc_update_mesg() {
2695   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
2696   echo   echo
2697  }  }
2698    
2699    pkgsearch()
2700    {
2701     local string="$1"
2702     local result
2703     local pkg
2704     local pcat
2705     local pname
2706     local magefile
2707     local pver
2708     local pbuild
2709     local state
2710     local descriptiom
2711     local homepage
2712     local i
2713     local all_installed
2714     local ipver
2715     local ipbuild
2716     local latest_available
2717     local depsfull
2718     local sdepsfull
2719     local deps
2720     local sdeps
2721     local dep
2722     local sign
2723    
2724     # only names no versions
2725     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')"
2726     #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2727    
2728     # nothing found
2729     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2730    
2731     for pkg in ${result}
2732     do
2733     # dirty, but does the job
2734     pcat="$(magename2pcat ${pkg}/foo)"
2735     pname="$(magename2pname ${pkg}-foo-foo)"
2736    
2737     # get highest version available
2738     magefile=$(get_highest_magefile ${pcat} ${pname})
2739    
2740     if [[ ! -z ${magefile} ]]
2741     then
2742     # now get all needed infos to print a nice output
2743     pver="$(magename2pver ${magefile})"
2744     pbuild="$(magename2pbuild ${magefile})"
2745     state="$(get_value_from_magefile STATE ${magefile})"
2746     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2747     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2748    
2749     # all installed
2750     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2751     do
2752     ipver="$(magename2pver ${i})"
2753     ipbuild="$(magename2pbuild ${i})"
2754    
2755     if [[ -z ${all_installed} ]]
2756     then
2757     all_installed="${ipver}-${ipbuild}"
2758     else
2759     all_installed="${all_installed} ${ipver}-${ipbuild}"
2760     fi
2761     done
2762     [[ -z ${all_installed} ]] && all_installed="none"
2763    
2764     case ${state} in
2765     stable) state=${COLGREEN}"[s] ";;
2766     testing) state=${COLYELLOW}"[t] ";;
2767     unstable) state=${COLRED}"[u] ";;
2768     old) state=${COLGRAY}"[o] ";;
2769     esac
2770    
2771     latest_available="${pver}-${pbuild}"
2772     else
2773     # package is masked
2774     state="${COLRED}[m] "
2775     latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2776     fi
2777    
2778     depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2779     sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})"
2780    
2781     while read sign dep
2782     do
2783     case ${dep} in
2784     "") continue;;
2785     esac
2786    
2787     deps="${deps} $(basename ${dep%-*})"
2788     done << EOF
2789    ${depsfull}
2790    EOF
2791    
2792     while read sign dep
2793     do
2794     case ${dep} in
2795     "") continue;;
2796     esac
2797    
2798     sdeps="${sdeps} $(basename ${dep%-*})"
2799     done << EOF
2800    ${sdepsfull}
2801    EOF
2802    
2803     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2804     echo -e "      Latest available:   ${latest_available}"
2805     echo "      Installed versions: ${all_installed}"
2806     echo "      Description: ${description}"
2807     echo "      Homepage: ${homepage}"
2808     echo "      Depends: ${deps}"
2809     echo "      SDepends: ${sdeps}"
2810     echo
2811    
2812     unset pcat
2813     unset pname
2814     unset magefile
2815     unset pver
2816     unset pbuild
2817     unset state
2818     unset descriptiom
2819     unset homepage
2820     unset all_installed
2821     unset ipver
2822     unset ipbuild
2823     unset depsfull
2824     unset sdepsfull
2825     unset deps
2826     unset sdeps
2827     unset dep
2828     unset sign
2829     done
2830    }
2831    
2832    export_inherits()
2833    {
2834     local include="$1"
2835     shift
2836    
2837     while [ "$1" ]
2838     do
2839     local functions="$1"
2840    
2841     # sanity checks
2842     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2843     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2844    
2845     eval "${functions}() { ${include}_${functions} ; }"
2846    
2847     # debug
2848     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2849    
2850     shift
2851     done
2852    }
2853    
2854    mlibdir()
2855    {
2856     local libdir=lib
2857     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2858    
2859     echo "${libdir}"
2860    }
2861    
2862    ## blacklisted ${magefile}
2863    blacklisted()
2864    {
2865     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2866    
2867     # compat
2868     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2869     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2870    
2871     # support both types for the moment
2872     if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]]
2873     then
2874     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2875     else
2876     local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}"
2877     fi
2878    
2879     # return 0 if the list not exist; nothin is masked
2880     [[ ! -f ${EXCLUDED} ]] && return 0
2881    
2882     local MAGEFILE="$1"
2883    
2884     local PCAT="$(magename2pcat ${MAGEFILE})"
2885     local PNAME="$(magename2pname ${MAGEFILE})"
2886     local PVER="$(magename2pver ${MAGEFILE})"
2887     local PBUILD="$(magename2pbuild ${MAGEFILE})"
2888    
2889     local EXPCAT EXPNAME EXPVER EXPBUILD
2890     while read EXPCAT EXPNAME EXPVER EXPBUILD
2891     do
2892     # ignore spaces and comments
2893             case "${EXPCAT}" in
2894                     \#*|"") continue ;;
2895             esac
2896    
2897     # exclude full pver
2898     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2899     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2900     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
2901     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
2902     then
2903     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
2904     fi
2905    
2906     # exclude pcat/pname only
2907     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2908     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2909     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
2910     then
2911     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
2912     fi
2913     done << EOF
2914    $( cat ${EXCLUDED}; echo)
2915    EOF
2916    
2917     return 0
2918    }
2919    

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