Magellan Linux

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

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

revision 258 by niro, Tue Oct 4 14:35:21 2005 UTC revision 373 by niro, Thu Apr 27 17:15:23 2006 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.7 2005-10-04 14:35:21 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.19 2006-04-27 17:15:23 niro Exp $
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 361  install_characterdevices() Line 361  install_characterdevices()
361   local pkgname="$1"   local pkgname="$1"
362   local pathto   local pathto
363   local posix   local posix
364     local major
365     local minor
366   local IFS   local IFS
367    
368   # sanity checks; abort if not given   # sanity checks; abort if not given
# Line 374  install_characterdevices() Line 376  install_characterdevices()
376   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
377   IFS=§   IFS=§
378    
379   while read pathto posix   while read pathto posix major minor
380   do   do
381   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
382   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
383    
384   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor}
385   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
386    
387   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# Line 432  install_database_entry() Line 434  install_database_entry()
434   local magefile   local magefile
435   local dbrecorddir   local dbrecorddir
436   local provide   local provide
437     local i
438    
439   # very basic getops   # very basic getops
440   for i in $*   for i in $*
# Line 473  install_database_entry() Line 476  install_database_entry()
476    
477   # create fake file descriptors   # create fake file descriptors
478   # used by virtual and source packages   # used by virtual and source packages
  local i  
479   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char
480   do   do
481   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
# Line 504  install_database_entry() Line 506  install_database_entry()
506   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
507   if [ -n "${provide}" ]   if [ -n "${provide}" ]
508   then   then
509   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
510     do
511     virtuals_add "${i}" "${pcat}/${pname}"
512     done
513   fi   fi
514  }  }
515    
# Line 523  remove_database_entry() Line 528  remove_database_entry()
528   local magefile   local magefile
529   local dbrecorddir   local dbrecorddir
530   local provide   local provide
531     local i
532    
533   # very basic getops   # very basic getops
534   for i in $*   for i in $*
# Line 552  remove_database_entry() Line 558  remove_database_entry()
558   # abort if mage file not exists   # abort if mage file not exists
559   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
560    
561   # first unregister virtuals   # remove virtuals only if no other exist
562   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
563   then   then
564   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
565     provide="$(get_value_from_magefile PROVIDE ${magefile})"
566     if [ -n "${provide}" ]
567     then
568     for i in ${provide}
569     do
570     virtuals_del "${i}" "${pcat}/${pname}"
571     done
572     fi
573   fi   fi
574    
575   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 579  remove_database_entry()
579   fi   fi
580  }  }
581    
582    # get the number of installed packages
583    count_installed_pkgs()
584    {
585     local pcat
586     local pname
587     local pkg
588     local i
589    
590     # very basic getops
591     for i in $*
592     do
593     case $1 in
594     --pcat|-c) shift; pcat="$1" ;;
595     --pname|-n) shift; pname="$1" ;;
596     esac
597     shift
598     done
599    
600     # sanity checks; abort if not given
601     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
602     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
603    
604     declare -i i=0
605     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
606     do
607     (( i++ ))
608     #echo "$i ${pkg}"
609     done
610    
611     # return the value
612     echo "${i}"
613    }
614    
615    
616  ###################################################  ###################################################
617  # function compare_mtime                          #  # function compare_mtime                          #
# Line 758  remove_files() Line 804  remove_files()
804   # 1=keep me   #   # 1=keep me   #
805   case ${retval} in   case ${retval} in
806   0)   0)
807   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
808   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
809   ;;   is_config_protected "${pathto}"
810     retval="$?"
811    
812     # 0 - not protected        #
813     # 1 - error                #
814     # 2 - protected            #
815     # 3 - protected but masked #
816    
817     case ${retval} in
818     # file is not protected - delete it
819     0|3)
820     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
821     rm "${MROOT}${pathto}"
822     ;;
823    
824     # file is protected, do not delete
825     2)
826     if [[ ${VERBOSE} = on ]]
827     then
828     echo -en "${COLRED}"
829     echo -n "! prot "
830     echo -en "${COLDEFAULT}"
831     echo " === FILE: ${MROOT}${pathto}"
832     fi
833     ;;
834     esac
835     ;;
836   1)   1)
837   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
838   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 1087  fetch_packages() Line 1158  fetch_packages()
1158   --continue \   --continue \
1159   --progress bar \   --progress bar \
1160   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1161   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1162   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1163   then   then
1164   break   break
# Line 1215  pname2pcat() Line 1286  pname2pcat()
1286  # returns 0=stable 1=unstable  # returns 0=stable 1=unstable
1287  check_stable_package()  check_stable_package()
1288  {  {
1289     # first check if this magefile is not blacklisted
1290     blacklisted "$1" || return 1
1291    
1292   local STATE   local STATE
1293   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1294    
1295   # state testing   # state testing
1296   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1297   then   then
1298   case ${STATE} in   case ${STATE} in
1299   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1302  check_stable_package()
1302   fi   fi
1303    
1304   # state unstable   # state unstable
1305   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1306   then   then
1307   case ${STATE} in   case ${STATE} in
1308   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1266  get_highest_magefile() Line 1340  get_highest_magefile()
1340   fi   fi
1341   done   done
1342    
1343   # stop here if HIGHEST_MAGEFILE is zero  # do not so anything
1344   # this package must be unstable or old  # # stop here if HIGHEST_MAGEFILE is zero
1345   if [ -z "${HIGHEST_MAGEFILE}" ]  # # this package must be unstable or old
1346   then  # if [ -z "${HIGHEST_MAGEFILE}" ]
1347   echo  # then
1348   echo -n "All packages named "  # echo
1349   echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}  # echo -n "All packages named "
1350   echo -n " are marked "  # echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT}
1351   echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}  # echo -n " are marked "
1352   echo "."  # echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT}
1353   echo "You need to declare USE_UNSTABLE=true to install this."  # echo "."
1354   echo  # echo "You need to declare USE_UNSTABLE=true to install this."
1355   echo "Example:"  # echo
1356   echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"  # echo "Example:"
1357   echo  # echo "         USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}"
1358   echo "Be warned that these packages are not stable and may cause serious problems."  # echo
1359   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."
1360   echo  # echo "You should know what you are doing, so don't complain about any damage."
1361   return 1  # echo
1362   fi  # return 1
1363    # fi
1364    
1365   echo "${HIGHEST_MAGEFILE}"   echo "${HIGHEST_MAGEFILE}"
1366   return 0   return 0
# Line 1397  get_uninstall_candidates() Line 1472  get_uninstall_candidates()
1472   shift   shift
1473   done   done
1474    
1475   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1476   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1477    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1478    
1479    
1480   # check needed global vars   # check needed global vars
1481   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1482    
1483   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1484   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1485    
1486   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1487   do   do
# Line 1490  virtuals_add() Line 1566  virtuals_add()
1566   local oldline   local oldline
1567   local line i   local line i
1568   local installed_file   local installed_file
1569     local OLDIFS
1570    
1571   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1572   then   then
1573   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1574   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1575   do   do
1576   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 1589  virtuals_add()
1589   # make a backup   # make a backup
1590   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1591    
1592     OLDIFS="${IFS}"
1593   IFS=$'\n'   IFS=$'\n'
1594   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1595   do   do
# Line 1523  virtuals_add() Line 1601  virtuals_add()
1601   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1602   fi   fi
1603   done   done
1604     # unset IFS
1605   #unset IFS   IFS="${OLDIFS}"
1606   else   else
1607   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1608   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1609   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1610   fi   fi
# Line 1538  virtuals_add() Line 1616  virtuals_add()
1616  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1617  virtuals_del() {  virtuals_del() {
1618    
1619   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1620     local pkgname="$2"
1621   VIRTUAL_NAME=$1   local oldline
1622   PKG_NAME=$2   local method
1623     local line i x
1624   #first check if exists   local pkg_installed
1625   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1626    
1627     # first check if exists
1628     if virtuals_read ${virtualname}
1629   then   then
1630   #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}
1631   declare -i x=0   declare -i x=0
1632   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1633   do   do
1634   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1635   then   then
1636   PKG_INSTALLED=true   pkg_installed=true
1637   fi   fi
1638   ((x++))   ((x++))
1639   done   done
1640    
1641   #abort if not installed   # abort if not installed
1642   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1643   then   then
1644   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1645     echo "${pkgname} does not exists in ${virtualname}."
1646   return 0   return 0
1647   fi   fi
1648    
1649   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1650   then   then
1651   METHOD=update   method=update
1652   else   else
1653   METHOD=delall   method=delall
1654   fi   fi
1655    
1656   #get the complete line   # get the complete line
1657   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1658    
1659   #make a backup   # make a backup of the db
1660   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1661    
1662   #parse virtualdb   # parse virtualdb
1663     OLDIFS="${IFS}"
1664   IFS=$'\n'   IFS=$'\n'
1665   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1666   do   do
1667   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1668   then   then
1669   #delall or update?   #delall or update?
1670   case ${METHOD} in   case ${method} in
1671   update)   update)
1672   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1673   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1674   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1675     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1676   ;;   ;;
1677   delall)   delall)
1678   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1679   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1680     # continue; do not write anything
1681   continue   continue
1682   ;;   ;;
1683   esac   esac
# Line 1600  virtuals_del() { Line 1685  virtuals_del() {
1685   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1686   fi   fi
1687   done   done
1688   unset IFS   # unset IFS
1689     IFS="${OLDIFS}"
1690   else   else
1691   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1692     echo "${virtualname} does not exists in virtual database."
1693   fi   fi
1694  }  }
1695    
# Line 1676  is_newer_mage_version_available() Line 1763  is_newer_mage_version_available()
1763   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}   echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT}
1764   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}   echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT}
1765   echo "It is recommened to install this newer version"   echo "It is recommened to install this newer version"
1766   echo "or your current system installation may brake."   echo "or your current system installation may break."
1767   echo   echo
1768   echo -en "Please update mage by running "   echo -en "Please update mage by running "
1769   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}   echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT}
# Line 1948  get_value_from_magefile() Line 2035  get_value_from_magefile()
2035   local magefile="$2"   local magefile="$2"
2036   local value   local value
2037    
2038     [[ -z ${var} ]] && return 1
2039     [[ -z ${magefile} ]] && return 1
2040    
2041   # local all possible vars of a mage file   # local all possible vars of a mage file
2042   # to prevent bad issues   # to prevent bad issues
2043   local PKGNAME   local PKGNAME
# Line 2459  pkgsearch() Line 2549  pkgsearch()
2549   local ipbuild   local ipbuild
2550    
2551   # only names no versions   # only names no versions
2552   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*')"
2553   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2554    
2555   # nothing found   # nothing found
2556   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2545  export_inherits() Line 2635  export_inherits()
2635   shift   shift
2636   done   done
2637  }  }
2638    
2639    mlibdir()
2640    {
2641     local libdir=lib
2642     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2643    
2644     echo "${libdir}"
2645    }
2646    
2647    ## blacklisted ${magefile}
2648    blacklisted()
2649    {
2650     [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable
2651    
2652     # compat
2653     [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable
2654     [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing
2655    
2656     local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}"
2657    
2658     # return 0 if the list not exist; nothin is masked
2659     [[ ! -f ${EXCLUDED} ]] && return 0
2660    
2661     local MAGEFILE="$1"
2662    
2663     local PCAT="$(magename2pcat ${MAGEFILE})"
2664     local PNAME="$(magename2pname ${MAGEFILE})"
2665     local PVER="$(magename2pver ${MAGEFILE})"
2666     local PBUILD="$(magename2pbuild ${MAGEFILE})"
2667    
2668     local EXPCAT EXPNAME EXPVER EXPBUILD
2669     while read EXPCAT EXPNAME EXPVER EXPBUILD
2670     do
2671     # ignore spaces and comments
2672             case "${EXPCAT}" in
2673                     \#*|"") continue ;;
2674             esac
2675    
2676     # exclude full pver
2677     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2678     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2679     [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] &&
2680     [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]]
2681     then
2682     [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1
2683     fi
2684    
2685     # exclude pcat/pname only
2686     if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] &&
2687     [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] &&
2688     [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]]
2689     then
2690     [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1
2691     fi
2692     done << EOF
2693    $( cat ${EXCLUDED}; echo)
2694    EOF
2695    
2696     return 0
2697    }
2698    

Legend:
Removed from v.258  
changed lines
  Added in v.373