Magellan Linux

Diff of /branches/mage-next/src/mage4.functions.sh

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

revision 240 by niro, Sun Sep 11 19:47:08 2005 UTC revision 280 by niro, Fri Oct 21 16:01:40 2005 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Magellan Linux Installer Functions (mage.functions.sh)  # Magellan Linux Installer Functions (mage.functions.sh)
3  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.3 2005-09-11 19:47:08 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.9 2005-10-21 16:01:40 niro Exp $
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 432  install_database_entry() Line 432  install_database_entry()
432   local magefile   local magefile
433   local dbrecorddir   local dbrecorddir
434   local provide   local provide
435     local i
436    
437   # very basic getops   # very basic getops
438   for i in $*   for i in $*
# Line 473  install_database_entry() Line 474  install_database_entry()
474    
475   # create fake file descriptors   # create fake file descriptors
476   # used by virtual and source packages   # used by virtual and source packages
  local i  
477   for i in .dirs .symlinks .files .pipes .char   for i in .dirs .symlinks .files .pipes .char
478   do   do
479   touch ${dbrecorddir}/${i}   touch ${dbrecorddir}/${i}
# Line 504  install_database_entry() Line 504  install_database_entry()
504   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
505   if [ -n "${provide}" ]   if [ -n "${provide}" ]
506   then   then
507   virtuals_add "${provide}" "${pcat}/${pname}"   for i in ${provide}
508     do
509     virtuals_add "${i}" "${pcat}/${pname}"
510     done
511   fi   fi
512  }  }
513    
# Line 523  remove_database_entry() Line 526  remove_database_entry()
526   local magefile   local magefile
527   local dbrecorddir   local dbrecorddir
528   local provide   local provide
529     local i
530    
531   # very basic getops   # very basic getops
532   for i in $*   for i in $*
# Line 556  remove_database_entry() Line 560  remove_database_entry()
560   provide="$(get_value_from_magefile PROVIDE ${magefile})"   provide="$(get_value_from_magefile PROVIDE ${magefile})"
561   if [ -n "${provide}" ]   if [ -n "${provide}" ]
562   then   then
563   virtuals_del "${provide}" "${pcat}/${pname}"   for i in ${provide}
564     do
565     virtuals_del "${i}" "${pcat}/${pname}"
566     done
567   fi   fi
568    
569   # removes database entry   # removes database entry
# Line 758  remove_files() Line 765  remove_files()
765   # 1=keep me   #   # 1=keep me   #
766   case ${retval} in   case ${retval} in
767   0)   0)
768   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
769   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
770   ;;   is_config_protected "${pathto}"
771     retval="$?"
772    
773     # 0 - not protected        #
774     # 1 - error                #
775     # 2 - protected            #
776     # 3 - protected but masked #
777    
778     case ${retval} in
779     # file is not protected - delete it
780     0|3)
781     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
782     rm "${MROOT}${pathto}"
783     ;;
784    
785     # file is protected, do not delete
786     2)
787     if [[ ${VERBOSE} = on ]]
788     then
789     echo -en "${COLRED}"
790     echo -n "! prot "
791     echo -en "${COLDEFAULT}"
792     echo " === FILE: ${MROOT}${pathto}"
793     fi
794     ;;
795     esac
796     ;;
797   1)   1)
798   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
799   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 1490  virtuals_add() Line 1522  virtuals_add()
1522   local oldline   local oldline
1523   local line i   local line i
1524   local installed_file   local installed_file
1525     local OLDIFS
1526    
1527   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1528   then   then
# Line 1512  virtuals_add() Line 1545  virtuals_add()
1545   # make a backup   # make a backup
1546   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1547    
1548     OLDIFS="${IFS}"
1549   IFS=$'\n'   IFS=$'\n'
1550   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1551   do   do
# Line 1523  virtuals_add() Line 1557  virtuals_add()
1557   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1558   fi   fi
1559   done   done
1560     # unset IFS
1561   #unset IFS   IFS="${OLDIFS}"
1562   else   else
1563   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1564   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1565   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1566   fi   fi
# Line 1538  virtuals_add() Line 1572  virtuals_add()
1572  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1573  virtuals_del() {  virtuals_del() {
1574    
1575   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1576     local pkgname="$2"
1577   VIRTUAL_NAME=$1   local oldline
1578   PKG_NAME=$2   local method
1579     local line i x
1580   #first check if exists   local pkg_installed
1581   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1582    
1583     # first check if exists
1584     if virtuals_read ${virtualname}
1585   then   then
1586   #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}
1587   declare -i x=0   declare -i x=0
1588   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1589   do   do
1590   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1591   then   then
1592   PKG_INSTALLED=true   pkg_installed=true
1593   fi   fi
1594   ((x++))   ((x++))
1595   done   done
1596    
1597   #abort if not installed   # abort if not installed
1598   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1599   then   then
1600   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1601     echo "${pkgname} does not exists in ${virtualname}."
1602   return 0   return 0
1603   fi   fi
1604    
1605   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1606   then   then
1607   METHOD=update   method=update
1608   else   else
1609   METHOD=delall   method=delall
1610   fi   fi
1611    
1612   #get the complete line   # get the complete line
1613   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1614    
1615   #make a backup   # make a backup of the db
1616   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1617    
1618   #parse virtualdb   # parse virtualdb
1619     OLDIFS="${IFS}"
1620   IFS=$'\n'   IFS=$'\n'
1621   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1622   do   do
1623   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1624   then   then
1625   #delall or update?   #delall or update?
1626   case ${METHOD} in   case ${method} in
1627   update)   update)
1628   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1629   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1630   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1631     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1632   ;;   ;;
1633   delall)   delall)
1634   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1635   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1636     # continue; do not write anything
1637   continue   continue
1638   ;;   ;;
1639   esac   esac
# Line 1600  virtuals_del() { Line 1641  virtuals_del() {
1641   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1642   fi   fi
1643   done   done
1644   unset IFS   # unset IFS
1645     IFS="${OLDIFS}"
1646   else   else
1647   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1648     echo "${virtualname} does not exists in virtual database."
1649   fi   fi
1650  }  }
1651    
# Line 1667  is_newer_mage_version_available() Line 1710  is_newer_mage_version_available()
1710   local newest_mage   local newest_mage
1711   local installed_mage   local installed_mage
1712    
1713   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1714   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1715    
1716   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1960  get_value_from_magefile() Line 2003  get_value_from_magefile()
2003   local PKGTYPE   local PKGTYPE
2004   local preinstall   local preinstall
2005   local postinstall   local postinstall
2006     local preremove
2007     local postremove
2008    
2009   # sanity checks   # sanity checks
2010   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1969  get_value_from_magefile() Line 2014  get_value_from_magefile()
2014   source ${magefile}   source ${magefile}
2015   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2016   echo "${value}"   echo "${value}"
2017    
2018     # unset these functions
2019     unset -f preinstall
2020     unset -f postinstall
2021     unset -f preremove
2022     unset -f postremove
2023  }  }
2024    
2025  mage_install()  mage_install()
# Line 1985  mage_install() Line 2036  mage_install()
2036   local PKGTYPE   local PKGTYPE
2037   local preinstall   local preinstall
2038   local postinstall   local postinstall
2039     local preremove
2040     local postremove
2041    
2042   local pcat   local pcat
2043   local pname   local pname
# Line 2146  mage_install() Line 2199  mage_install()
2199  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2200  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2201   echo "successfully installed."   echo "successfully installed."
2202    
2203     # unset these functions
2204     unset -f preinstall
2205     unset -f postinstall
2206     unset -f preremove
2207     unset -f postremove
2208  }  }
2209    
2210  md5sum_packages()  md5sum_packages()
# Line 2304  mage_uninstall() Line 2363  mage_uninstall()
2363   local PKGTYPE   local PKGTYPE
2364   local preinstall   local preinstall
2365   local postinstall   local postinstall
2366     local preremove
2367     local postremove
2368    
2369   local pcat   local pcat
2370   local pname   local pname
# Line 2401  mage_uninstall() Line 2462  mage_uninstall()
2462  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2463  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2464   echo "successfully removed."   echo "successfully removed."
2465    
2466     # unset these functions
2467     unset -f preinstall
2468     unset -f postinstall
2469     unset -f preremove
2470     unset -f postremove
2471  }  }
2472    
2473  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2499  pkgsearch() Line 2566  pkgsearch()
2566   unset ipbuild   unset ipbuild
2567   done   done
2568  }  }
2569    
2570    export_inherits()
2571    {
2572     local include="$1"
2573     shift
2574    
2575     while [ "$1" ]
2576     do
2577     local functions="$1"
2578    
2579     # sanity checks
2580     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2581     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2582    
2583     eval "${functions}() { ${include}_${functions} ; }"
2584    
2585     # debug
2586     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2587    
2588     shift
2589     done
2590    }

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