Magellan Linux

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

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

revision 314 by niro, Sun Jan 1 23:45:27 2006 UTC revision 675 by niro, Sun Feb 10 12:26:09 2008 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.14 2006-01-01 23:45:27 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.35 2008-02-10 12:26:09 niro Exp $
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 1106  fetch_packages() Line 1106  fetch_packages()
1106   local count_current   local count_current
1107   local count_total   local count_total
1108    
1109   [ -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}."
1110    
1111   # get count of total packages   # get count of total packages
1112   declare -i count_current=0   declare -i count_current=0
# Line 1181  syncmage() Line 1181  syncmage()
1181  {  {
1182   if [ -z "${RSYNC}" ]   if [ -z "${RSYNC}" ]
1183   then   then
1184   die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc."   die "You have no rsync-mirrors defined. Please edit your ${MAGERC}."
1185   fi   fi
1186    
1187   local i   local i
1188   for i in ${RSYNC}   for i in ${RSYNC}
1189   do   do
1190   rsync \   rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR}
  --recursive \  
  --links \  
  --perms \  
  --times \  
  --devices \  
  --timeout=600 \  
  --verbose \  
  --compress \  
  --progress \  
  --stats \  
  --delete \  
  --delete-after \  
  ${i} ${MAGEDIR}  
1191   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1192   then   then
1193   break   break
# Line 1253  choppkgname() Line 1240  choppkgname()
1240   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]   if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ]
1241   then   then
1242   #cuts ARCH and PBUILD   #cuts ARCH and PBUILD
1243   #ARCH comes from /etc/mage.rc   #ARCH comes from ${MAGERC}
1244   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")   MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g")
1245    
1246   #cuts version number   #cuts version number
# Line 1286  pname2pcat() Line 1273  pname2pcat()
1273  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1274  check_stable_package()  check_stable_package()
1275  {  {
1276     # first check if this magefile is not blacklisted
1277     blacklisted "$1" || return 1
1278    
1279   local STATE   local STATE
1280   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1281    
# Line 1337  get_highest_magefile() Line 1327  get_highest_magefile()
1327   fi   fi
1328   done   done
1329    
1330   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1331   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1332   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1333   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1334   echo  # then
1335   echo -n "All packages named "  # echo
1336   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1337   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1338   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1339   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1340   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1341   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1342   echo "Example:"  # echo
1343   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1344   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1345   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1346   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."
1347   echo  # echo "You should know what you are doing, so don't complain about any damage."
1348   return 1  # echo
1349   fi  # return 1
1350    # fi
1351    
1352   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1353   return 0   return 0
# Line 1384  is_config_protected() Line 1375  is_config_protected()
1375   EXPFILE="${MROOT}$1"   EXPFILE="${MROOT}$1"
1376    
1377   # file does not exist; it can be written   # file does not exist; it can be written
1378   [ ! -e ${EXPFILE} ] && return 0   [[ ! -e ${EXPFILE} ]] && return 0
1379    
1380   # to be safe; it may be '§'   # to be safe; it may be '§'
1381   IFS=' '   IFS=' '
# Line 1394  is_config_protected() Line 1385  is_config_protected()
1385   do   do
1386   # ersetzen von $i nur wenn am anfang der variable   # ersetzen von $i nur wenn am anfang der variable
1387   TEST="${EXPFILE/#${MROOT}${i}/Protected}"   TEST="${EXPFILE/#${MROOT}${i}/Protected}"
1388   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1389   then   then
1390   # setzen das es protected ist   # setzen das es protected ist
1391   PROTECTED=TRUE   PROTECTED=TRUE
# Line 1403  is_config_protected() Line 1394  is_config_protected()
1394   for x in ${CONFIG_PROTECT_MASK}   for x in ${CONFIG_PROTECT_MASK}
1395   do   do
1396   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"   TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}"
1397   if [ "${TEST}" != "${EXPFILE}" ]   if [[ ${TEST} != ${EXPFILE} ]]
1398   then   then
1399   PROTECTED=MASKED   PROTECTED=MASKED
1400   fi   fi
# Line 1439  is_config_protected() Line 1430  is_config_protected()
1430  ###################################################  ###################################################
1431  count_protected_files()  count_protected_files()
1432  {  {
1433   ${MLIBDIR}/writeprotected "$1"   local file="$1"
1434     local dirname="${file%/*}"
1435     local filename="${file##*/}"
1436     local count
1437     local output
1438     local i
1439    
1440     declare -i count=0
1441    
1442     # check if there are already protected files
1443     for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" |
1444     sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" |
1445     sort -t'%' -k3 -k2 | cut -f1 -d'%')
1446     do
1447     count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::")
1448     done
1449     (( count ++ ))
1450    
1451     # fill output up with zeros
1452     for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done
1453     output="${output}${count}"
1454    
1455     echo "${output}"
1456  }  }
1457    
1458  # call with  # call with
# Line 1456  get_uninstall_candidates() Line 1469  get_uninstall_candidates()
1469   local list   local list
1470   local pcatdir   local pcatdir
1471   local protected   local protected
1472     local i
1473    
1474   # very basic getops   # very basic getops
1475   for i in $*   for i in $*
# Line 1468  get_uninstall_candidates() Line 1482  get_uninstall_candidates()
1482   shift   shift
1483   done   done
1484    
1485   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1486   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1487    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1488    
1489    
1490   # check needed global vars   # check needed global vars
1491   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1492    
1493   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1494   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1495    
1496   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1497   do   do
# Line 1565  virtuals_add() Line 1580  virtuals_add()
1580    
1581   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1582   then   then
1583   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1584   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1585   do   do
1586   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1716  minclude() Line 1731  minclude()
1731  {  {
1732   local i   local i
1733    
1734   if [ -n "$@" ]   if [[ -n $* ]]
1735   then   then
1736   for i in $@   for i in $*
1737   do   do
1738   [[ ${MAGEDEBUG} = on ]] && \   [[ ${MAGEDEBUG} = on ]] && \
1739   echo "--- Including ${MAGEDIR}/include/${i}.minc"   echo "--- Including ${MAGEDIR}/include/${i}.minc"
# Line 1732  sminclude() Line 1747  sminclude()
1747  {  {
1748   local i   local i
1749    
1750   if [ -n "$@" ]   if [[ -n $* ]]
1751   then   then
1752   for i in $@   for i in $*
1753   do   do
1754   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
1755   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
# Line 1758  is_newer_mage_version_available() Line 1773  is_newer_mage_version_available()
1773   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1774   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1775   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
1776   echo "or your current system installation may brake."   echo "or your current system installation may break."
1777   echo   echo
1778   echo -en "Please update mage by running "   echo -en "Please update mage by running "
1779   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 2030  get_value_from_magefile() Line 2045  get_value_from_magefile()
2045   local magefile="$2"   local magefile="$2"
2046   local value   local value
2047    
2048     [[ -z ${var} ]] && return 1
2049     [[ -z ${magefile} ]] && return 1
2050    
2051   # local all possible vars of a mage file   # local all possible vars of a mage file
2052   # to prevent bad issues   # to prevent bad issues
2053   local PKGNAME   local PKGNAME
# Line 2159  mage_install() Line 2177  mage_install()
2177   echo B:${pbuild}   echo B:${pbuild}
2178   fi   fi
2179    
2180   smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2   if [[ -z ${MAGE_TARGETS} ]]
2181     then
2182     smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2
2183     else
2184     smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2
2185     fi
2186   if [ -f "${smage2file}" ]   if [ -f "${smage2file}" ]
2187   then   then
2188     echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... "
2189   smage2 ${smage2file} || die "compile failed"   smage2 ${smage2file} || die "compile failed"
2190   else   else
2191   echo   echo
# Line 2175  mage_install() Line 2199  mage_install()
2199   if [[ ${PKGTYPE} != virtual ]] && \   if [[ ${PKGTYPE} != virtual ]] && \
2200   [[ ${PKGTYPE} != sources ]]   [[ ${PKGTYPE} != sources ]]
2201   then   then
2202   # 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  
2203   build_doinstall ${PKGNAME}   build_doinstall ${PKGNAME}
2204   fi   fi
2205    
# Line 2439  mage_uninstall() Line 2456  mage_uninstall()
2456   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
2457   echo -n "removing: "   echo -n "removing: "
2458   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2459   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2460    
2461   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"   magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2462   source ${magefile}   source ${magefile}
2463    
2464   ## preremove scripts   ## preremove scripts
# Line 2539  pkgsearch() Line 2556  pkgsearch()
2556   local all_installed   local all_installed
2557   local ipver   local ipver
2558   local ipbuild   local ipbuild
2559     local latest_available
2560     local depsfull
2561     local sdepsfull
2562     local deps
2563     local sdeps
2564     local dep
2565     local sign
2566    
2567   # only names no versions   # only names no versions
2568   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')"
2569   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2570    
2571   # nothing found   # nothing found
2572   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2556  pkgsearch() Line 2580  pkgsearch()
2580   # get highest version available   # get highest version available
2581   magefile=$(get_highest_magefile ${pcat} ${pname})   magefile=$(get_highest_magefile ${pcat} ${pname})
2582    
2583   # now get all needed infos to print a nice output   if [[ ! -z ${magefile} ]]
2584   pver="$(magename2pver ${magefile})"   then
2585   pbuild="$(magename2pbuild ${magefile})"   # now get all needed infos to print a nice output
2586   state="$(get_value_from_magefile STATE ${magefile})"   pver="$(magename2pver ${magefile})"
2587   description="$(get_value_from_magefile DESCRIPTION ${magefile})"   pbuild="$(magename2pbuild ${magefile})"
2588   homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"   state="$(get_value_from_magefile STATE ${magefile})"
2589     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2590     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2591    
2592     # all installed
2593     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2594     do
2595     ipver="$(magename2pver ${i})"
2596     ipbuild="$(magename2pbuild ${i})"
2597    
2598     if [[ -z ${all_installed} ]]
2599     then
2600     all_installed="${ipver}-${ipbuild}"
2601     else
2602     all_installed="${all_installed} ${ipver}-${ipbuild}"
2603     fi
2604     done
2605     [[ -z ${all_installed} ]] && all_installed="none"
2606    
2607     case ${state} in
2608     stable) state=${COLGREEN}"[s] ";;
2609     testing) state=${COLYELLOW}"[t] ";;
2610     unstable) state=${COLRED}"[u] ";;
2611     old) state=${COLGRAY}"[o] ";;
2612     esac
2613    
2614   # all installed   latest_available="${pver}-${pbuild}"
2615   for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})   else
2616   do   # package is masked
2617   ipver="$(magename2pver ${i})"   state="${COLRED}[m] "
2618   ipbuild="$(magename2pbuild ${i})"   latest_available="${COLRED}masked for this distribution.${COLDEFAULT}"
2619     fi
2620    
2621   if [[ -z ${all_installed} ]]   depsfull="$(get_value_from_magefile DEPEND ${magefile})"
2622   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"  
2623    
2624   case ${state} in   while read sign dep
2625   stable) state=${COLGREEN}"[s] ";;   do
2626   testing) state=${COLYELLOW}"[t] ";;   case ${dep} in
2627   unstable) state=${COLRED}"[u] ";;   "") continue;;
2628   old) state=${COLGRAY}"[o] ";;   esac
2629   esac  
2630     deps="${deps} $(basename ${dep%-*})"
2631     done << EOF
2632    ${depsfull}
2633    EOF
2634    
2635     while read sign dep
2636     do
2637     case ${dep} in
2638     "") continue;;
2639     esac
2640    
2641     sdeps="${sdeps} $(basename ${dep%-*})"
2642     done << EOF
2643    ${sdepsfull}
2644    EOF
2645    
2646   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}   echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2647   echo "      Latest available:   ${pver}-${pbuild}"   echo -e "      Latest available:   ${latest_available}"
2648   echo "      Installed versions: ${all_installed}"   echo "      Installed versions: ${all_installed}"
2649   echo "      Description: ${description}"   echo "      Description: ${description}"
2650   echo "      Homepage: ${homepage}"   echo "      Homepage: ${homepage}"
2651     echo "      Depends: ${deps}"
2652     echo "      SDepends: ${sdeps}"
2653   echo   echo
2654    
2655   unset pcat   unset pcat
# Line 2603  pkgsearch() Line 2663  pkgsearch()
2663   unset all_installed   unset all_installed
2664   unset ipver   unset ipver
2665   unset ipbuild   unset ipbuild
2666     unset depsfull
2667     unset sdepsfull
2668     unset deps
2669     unset sdeps
2670     unset dep
2671     unset sign
2672   done   done
2673  }  }
2674    
# Line 2627  export_inherits() Line 2693  export_inherits()
2693   shift   shift
2694   done   done
2695  }  }
2696    
2697    mlibdir()
2698    {
2699     local libdir=lib
2700     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2701    
2702     echo "${libdir}"
2703    }
2704    
2705    ## blacklisted ${magefile}
2706    blacklisted()
2707    {
2708     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2709    
2710     # compat
2711     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2712     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2713    
2714     local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2715    
2716     # return 0 if the list not exist; nothin is masked
2717     [[ ! -f ${EXCLUDED} ]] && return 0
2718    
2719     local MAGEFILE="$1"
2720    
2721     local PCAT="$(magename2pcat ${MAGEFILE})"
2722     local PNAME="$(magename2pname ${MAGEFILE})"
2723     local PVER="$(magename2pver ${MAGEFILE})"
2724     local PBUILD="$(magename2pbuild ${MAGEFILE})"
2725    
2726     local EXPCAT EXPNAME EXPVER EXPBUILD
2727     while read EXPCAT EXPNAME EXPVER EXPBUILD
2728     do
2729     # ignore spaces and comments
2730             case "${EXPCAT}" in
2731                     \#*|"") continue ;;
2732             esac
2733    
2734     # exclude full pver
2735     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2736     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2737     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
2738     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
2739     then
2740     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
2741     fi
2742    
2743     # exclude pcat/pname only
2744     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2745     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2746     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
2747     then
2748     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
2749     fi
2750     done << EOF
2751    $( cat ${EXCLUDED}; echo)
2752    EOF
2753    
2754     return 0
2755    }
2756    

Legend:
Removed from v.314  
changed lines
  Added in v.675