Magellan Linux

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

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

revision 252 by niro, Sun Oct 2 14:09:41 2005 UTC revision 350 by niro, Wed Mar 22 17:43:59 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.6 2005-10-02 14:09:41 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.17 2006-03-22 17:43:59 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 1219  check_stable_package() Line 1290  check_stable_package()
1290   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1291    
1292   # state testing   # state testing
1293   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1294   then   then
1295   case ${STATE} in   case ${STATE} in
1296   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1299  check_stable_package()
1299   fi   fi
1300    
1301   # state unstable   # state unstable
1302   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1303   then   then
1304   case ${STATE} in   case ${STATE} in
1305   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1397  get_uninstall_candidates() Line 1468  get_uninstall_candidates()
1468   shift   shift
1469   done   done
1470    
1471   # sanity checks; abort if not given  # it's not good to complain here about empty pnames; better to continue later anyway
1472   [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."  # # sanity checks; abort if not given
1473    # [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given."
1474    
1475    
1476   # check needed global vars   # check needed global vars
1477   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."   [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set."
1478    
1479   # set pcatdir to '*' if empty   # set pcatdir to '*' if empty
1480   [ -z "${pcatdir}" ] && pcatdir=*   [ -z "${pcatdir}" ] && pcatdir='*'
1481    
1482   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*   for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/*
1483   do   do
# Line 1490  virtuals_add() Line 1562  virtuals_add()
1562   local oldline   local oldline
1563   local line i   local line i
1564   local installed_file   local installed_file
1565     local OLDIFS
1566    
1567   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1568   then   then
1569   # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already   # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already
1570   for i in $(virtuals_read ${virtualname} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1571   do   do
1572   if [[ ${i} = ${pkgname} ]]   if [[ ${i} = ${pkgname} ]]
# Line 1512  virtuals_add() Line 1585  virtuals_add()
1585   # make a backup   # make a backup
1586   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1587    
1588     OLDIFS="${IFS}"
1589   IFS=$'\n'   IFS=$'\n'
1590   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1591   do   do
# Line 1523  virtuals_add() Line 1597  virtuals_add()
1597   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1598   fi   fi
1599   done   done
1600     # unset IFS
1601   #unset IFS   IFS="${OLDIFS}"
1602   else   else
1603   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1604   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1605   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1606   fi   fi
# Line 1538  virtuals_add() Line 1612  virtuals_add()
1612  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1613  virtuals_del() {  virtuals_del() {
1614    
1615   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1616     local pkgname="$2"
1617   VIRTUAL_NAME=$1   local oldline
1618   PKG_NAME=$2   local method
1619     local line i x
1620   #first check if exists   local pkg_installed
1621   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1622    
1623     # first check if exists
1624     if virtuals_read ${virtualname}
1625   then   then
1626   #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}
1627   declare -i x=0   declare -i x=0
1628   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1629   do   do
1630   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1631   then   then
1632   PKG_INSTALLED=true   pkg_installed=true
1633   fi   fi
1634   ((x++))   ((x++))
1635   done   done
1636    
1637   #abort if not installed   # abort if not installed
1638   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1639   then   then
1640   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1641     echo "${pkgname} does not exists in ${virtualname}."
1642   return 0   return 0
1643   fi   fi
1644    
1645   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1646   then   then
1647   METHOD=update   method=update
1648   else   else
1649   METHOD=delall   method=delall
1650   fi   fi
1651    
1652   #get the complete line   # get the complete line
1653   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1654    
1655   #make a backup   # make a backup of the db
1656   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1657    
1658   #parse virtualdb   # parse virtualdb
1659     OLDIFS="${IFS}"
1660   IFS=$'\n'   IFS=$'\n'
1661   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1662   do   do
1663   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1664   then   then
1665   #delall or update?   #delall or update?
1666   case ${METHOD} in   case ${method} in
1667   update)   update)
1668   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1669   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1670   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1671     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1672   ;;   ;;
1673   delall)   delall)
1674   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1675   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1676     # continue; do not write anything
1677   continue   continue
1678   ;;   ;;
1679   esac   esac
# Line 1600  virtuals_del() { Line 1681  virtuals_del() {
1681   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1682   fi   fi
1683   done   done
1684   unset IFS   # unset IFS
1685     IFS="${OLDIFS}"
1686   else   else
1687   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1688     echo "${virtualname} does not exists in virtual database."
1689   fi   fi
1690  }  }
1691    
# Line 1972  get_value_from_magefile() Line 2055  get_value_from_magefile()
2055   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2056   echo "${value}"   echo "${value}"
2057    
2058   unset preinstall   # unset these functions
2059   unset postinstall   unset -f preinstall
2060   unset preremove   unset -f postinstall
2061   unset postremove   unset -f preremove
2062     unset -f postremove
2063  }  }
2064    
2065  mage_install()  mage_install()
# Line 2156  mage_install() Line 2240  mage_install()
2240  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2241   echo "successfully installed."   echo "successfully installed."
2242    
2243   unset preinstall   # unset these functions
2244   unset postinstall   unset -f preinstall
2245   unset preremove   unset -f postinstall
2246   unset postremove   unset -f preremove
2247     unset -f postremove
2248  }  }
2249    
2250  md5sum_packages()  md5sum_packages()
# Line 2418  mage_uninstall() Line 2503  mage_uninstall()
2503  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2504   echo "successfully removed."   echo "successfully removed."
2505    
2506   unset preinstall   # unset these functions
2507   unset postinstall   unset -f preinstall
2508   unset preremove   unset -f postinstall
2509   unset postremove   unset -f preremove
2510     unset -f postremove
2511  }  }
2512    
2513  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2456  pkgsearch() Line 2542  pkgsearch()
2542   local ipbuild   local ipbuild
2543    
2544   # only names no versions   # only names no versions
2545   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"   result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*')"
2546   #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"   #result="$(find ${MAGEDIR} -type f -name '*'${string}'*'.mage | sort)"
2547    
2548   # nothing found   # nothing found
2549   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."   [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
# Line 2542  export_inherits() Line 2628  export_inherits()
2628   shift   shift
2629   done   done
2630  }  }
2631    
2632    mlibdir()
2633    {
2634     local libdir=lib
2635     [[ ${ARCH} = x86_64 ]] && libdir=lib64
2636    
2637     echo "${libdir}"
2638    }

Legend:
Removed from v.252  
changed lines
  Added in v.350