Magellan Linux

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

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

revision 248 by niro, Tue Sep 27 14:38:01 2005 UTC revision 286 by niro, Thu Dec 1 12:38:45 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.4 2005-09-27 14:38:01 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.10 2005-12-01 12:38:45 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 1087  fetch_packages() Line 1119  fetch_packages()
1119   --continue \   --continue \
1120   --progress bar \   --progress bar \
1121   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1122   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1123   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1124   then   then
1125   break   break
# Line 1219  check_stable_package() Line 1251  check_stable_package()
1251   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1252    
1253   # state testing   # state testing
1254   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1255   then   then
1256   case ${STATE} in   case ${STATE} in
1257   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1260  check_stable_package()
1260   fi   fi
1261    
1262   # state unstable   # state unstable
1263   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1264   then   then
1265   case ${STATE} in   case ${STATE} in
1266   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# 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 1972  get_value_from_magefile() Line 2015  get_value_from_magefile()
2015   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2016   echo "${value}"   echo "${value}"
2017    
2018   unset preinstall   # unset these functions
2019   unset postinstall   unset -f preinstall
2020   unset preremove   unset -f postinstall
2021   unset postremove   unset -f preremove
2022     unset -f postremove
2023  }  }
2024    
2025  mage_install()  mage_install()
# Line 2156  mage_install() Line 2200  mage_install()
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 preinstall   # unset these functions
2204   unset postinstall   unset -f preinstall
2205   unset preremove   unset -f postinstall
2206   unset postremove   unset -f preremove
2207     unset -f postremove
2208  }  }
2209    
2210  md5sum_packages()  md5sum_packages()
# Line 2418  mage_uninstall() Line 2463  mage_uninstall()
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 preinstall   # unset these functions
2467   unset postinstall   unset -f preinstall
2468   unset preremove   unset -f postinstall
2469   unset postremove   unset -f preremove
2470     unset -f postremove
2471  }  }
2472    
2473  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2520  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.248  
changed lines
  Added in v.286