Magellan Linux

Diff of /trunk/mage/usr/lib/mage/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 310 by niro, Sun Jan 1 22:59:52 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.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.12 2006-01-01 22:59:52 niro Exp $
4    
5  mage_setup()  mage_setup()
6  {  {
# Line 379  install_characterdevices() Line 379  install_characterdevices()
379   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
380   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"   [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}"
381    
382   mknode -m ${posix} -c "${MROOT}${pathto}"   mknod -m ${posix} -c "${MROOT}${pathto}"
383   done < ${BUILDDIR}/${pkgname}/.char   done < ${BUILDDIR}/${pkgname}/.char
384    
385   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
# 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 552  remove_database_entry() Line 556  remove_database_entry()
556   # abort if mage file not exists   # abort if mage file not exists
557   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."   [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist."
558    
559   # first unregister virtuals   # remove virtuals only if no other exist
560   provide="$(get_value_from_magefile PROVIDE ${magefile})"   if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]]
  if [ -n "${provide}" ]  
561   then   then
562   virtuals_del "${provide}" "${pcat}/${pname}"   # first unregister virtuals
563     provide="$(get_value_from_magefile PROVIDE ${magefile})"
564     if [ -n "${provide}" ]
565     then
566     for i in ${provide}
567     do
568     virtuals_del "${i}" "${pcat}/${pname}"
569     done
570     fi
571   fi   fi
572    
573   # removes database entry   # removes database entry
# Line 566  remove_database_entry() Line 577  remove_database_entry()
577   fi   fi
578  }  }
579    
580    # get the number of installed packages
581    count_installed_pkgs()
582    {
583     local pcat
584     local pname
585     local pkg
586     local i
587    
588     # very basic getops
589     for i in $*
590     do
591     case $1 in
592     --pcat|-c) shift; pcat="$1" ;;
593     --pname|-n) shift; pname="$1" ;;
594     esac
595     shift
596     done
597    
598     # sanity checks; abort if not given
599     [ -z "${pcat}" ] && die "pkg_count() \$pcat not given."
600     [ -z "${pname}" ] && die "pkg_count() \$pname not given."
601    
602     declare -i i=0
603     for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname})
604     do
605     (( i++ ))
606     #echo "$i ${pkg}"
607     done
608    
609     # return the value
610     echo "${i}"
611    }
612    
613    
614  ###################################################  ###################################################
615  # function compare_mtime                          #  # function compare_mtime                          #
# Line 758  remove_files() Line 802  remove_files()
802   # 1=keep me   #   # 1=keep me   #
803   case ${retval} in   case ${retval} in
804   0)   0)
805   [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"   # check if the file is config_protected
806   rm "${MROOT}${pathto}"   # ${MROOT} will automatically added if set !!
807   ;;   is_config_protected "${pathto}"
808     retval="$?"
809    
810     # 0 - not protected        #
811     # 1 - error                #
812     # 2 - protected            #
813     # 3 - protected but masked #
814    
815     case ${retval} in
816     # file is not protected - delete it
817     0|3)
818     [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}"
819     rm "${MROOT}${pathto}"
820     ;;
821    
822     # file is protected, do not delete
823     2)
824     if [[ ${VERBOSE} = on ]]
825     then
826     echo -en "${COLRED}"
827     echo -n "! prot "
828     echo -en "${COLDEFAULT}"
829     echo " === FILE: ${MROOT}${pathto}"
830     fi
831     ;;
832     esac
833     ;;
834   1)   1)
835   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
836   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 1087  fetch_packages() Line 1156  fetch_packages()
1156   --continue \   --continue \
1157   --progress bar \   --progress bar \
1158   --directory-prefix=${PKGDIR} \   --directory-prefix=${PKGDIR} \
1159   ${opt} ${mirr}/packages/${pkg}   ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg}
1160   if [[ $? = 0 ]]   if [[ $? = 0 ]]
1161   then   then
1162   break   break
# Line 1219  check_stable_package() Line 1288  check_stable_package()
1288   STATE="$(get_value_from_magefile STATE "$1")"   STATE="$(get_value_from_magefile STATE "$1")"
1289    
1290   # state testing   # state testing
1291   if [[ ${USE_TESTING} = true ]]   if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]]
1292   then   then
1293   case ${STATE} in   case ${STATE} in
1294   testing|stable) return 0 ;;   testing|stable) return 0 ;;
# Line 1228  check_stable_package() Line 1297  check_stable_package()
1297   fi   fi
1298    
1299   # state unstable   # state unstable
1300   if [[ ${USE_UNSTABLE} = true ]]   if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]]
1301   then   then
1302   case ${STATE} in   case ${STATE} in
1303   unstable|testing|stable) return 0 ;;   unstable|testing|stable) return 0 ;;
# Line 1490  virtuals_add() Line 1559  virtuals_add()
1559   local oldline   local oldline
1560   local line i   local line i
1561   local installed_file   local installed_file
1562     local OLDIFS
1563    
1564   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1565   then   then
# Line 1512  virtuals_add() Line 1582  virtuals_add()
1582   # make a backup   # make a backup
1583   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1584    
1585     OLDIFS="${IFS}"
1586   IFS=$'\n'   IFS=$'\n'
1587   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1588   do   do
# Line 1523  virtuals_add() Line 1594  virtuals_add()
1594   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1595   fi   fi
1596   done   done
1597     # unset IFS
1598   #unset IFS   IFS="${OLDIFS}"
1599   else   else
1600   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1601   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1602   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1603   fi   fi
# Line 1538  virtuals_add() Line 1609  virtuals_add()
1609  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1610  virtuals_del() {  virtuals_del() {
1611    
1612   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1613     local pkgname="$2"
1614   VIRTUAL_NAME=$1   local oldline
1615   PKG_NAME=$2   local method
1616     local line i x
1617   #first check if exists   local pkg_installed
1618   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1619    
1620     # first check if exists
1621     if virtuals_read ${virtualname}
1622   then   then
1623   #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}
1624   declare -i x=0   declare -i x=0
1625   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1626   do   do
1627   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1628   then   then
1629   PKG_INSTALLED=true   pkg_installed=true
1630   fi   fi
1631   ((x++))   ((x++))
1632   done   done
1633    
1634   #abort if not installed   # abort if not installed
1635   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1636   then   then
1637   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1638     echo "${pkgname} does not exists in ${virtualname}."
1639   return 0   return 0
1640   fi   fi
1641    
1642   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1643   then   then
1644   METHOD=update   method=update
1645   else   else
1646   METHOD=delall   method=delall
1647   fi   fi
1648    
1649   #get the complete line   # get the complete line
1650   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1651    
1652   #make a backup   # make a backup of the db
1653   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1654    
1655   #parse virtualdb   # parse virtualdb
1656     OLDIFS="${IFS}"
1657   IFS=$'\n'   IFS=$'\n'
1658   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1659   do   do
1660   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1661   then   then
1662   #delall or update?   #delall or update?
1663   case ${METHOD} in   case ${method} in
1664   update)   update)
1665   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1666   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1667   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1668     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1669   ;;   ;;
1670   delall)   delall)
1671   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1672   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1673     # continue; do not write anything
1674   continue   continue
1675   ;;   ;;
1676   esac   esac
# Line 1600  virtuals_del() { Line 1678  virtuals_del() {
1678   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1679   fi   fi
1680   done   done
1681   unset IFS   # unset IFS
1682     IFS="${OLDIFS}"
1683   else   else
1684   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1685     echo "${virtualname} does not exists in virtual database."
1686   fi   fi
1687  }  }
1688    
# Line 1667  is_newer_mage_version_available() Line 1747  is_newer_mage_version_available()
1747   local newest_mage   local newest_mage
1748   local installed_mage   local installed_mage
1749    
1750   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1751   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1752    
1753   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1960  get_value_from_magefile() Line 2040  get_value_from_magefile()
2040   local PKGTYPE   local PKGTYPE
2041   local preinstall   local preinstall
2042   local postinstall   local postinstall
2043     local preremove
2044     local postremove
2045    
2046   # sanity checks   # sanity checks
2047   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1969  get_value_from_magefile() Line 2051  get_value_from_magefile()
2051   source ${magefile}   source ${magefile}
2052   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2053   echo "${value}"   echo "${value}"
2054    
2055     # unset these functions
2056     unset -f preinstall
2057     unset -f postinstall
2058     unset -f preremove
2059     unset -f postremove
2060  }  }
2061    
2062  mage_install()  mage_install()
# Line 1985  mage_install() Line 2073  mage_install()
2073   local PKGTYPE   local PKGTYPE
2074   local preinstall   local preinstall
2075   local postinstall   local postinstall
2076     local preremove
2077     local postremove
2078    
2079   local pcat   local pcat
2080   local pname   local pname
# Line 2146  mage_install() Line 2236  mage_install()
2236  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2237  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2238   echo "successfully installed."   echo "successfully installed."
2239    
2240     # unset these functions
2241     unset -f preinstall
2242     unset -f postinstall
2243     unset -f preremove
2244     unset -f postremove
2245  }  }
2246    
2247  md5sum_packages()  md5sum_packages()
# Line 2304  mage_uninstall() Line 2400  mage_uninstall()
2400   local PKGTYPE   local PKGTYPE
2401   local preinstall   local preinstall
2402   local postinstall   local postinstall
2403     local preremove
2404     local postremove
2405    
2406   local pcat   local pcat
2407   local pname   local pname
# Line 2401  mage_uninstall() Line 2499  mage_uninstall()
2499  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2500  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2501   echo "successfully removed."   echo "successfully removed."
2502    
2503     # unset these functions
2504     unset -f preinstall
2505     unset -f postinstall
2506     unset -f preremove
2507     unset -f postremove
2508  }  }
2509    
2510  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2499  pkgsearch() Line 2603  pkgsearch()
2603   unset ipbuild   unset ipbuild
2604   done   done
2605  }  }
2606    
2607    export_inherits()
2608    {
2609     local include="$1"
2610     shift
2611    
2612     while [ "$1" ]
2613     do
2614     local functions="$1"
2615    
2616     # sanity checks
2617     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2618     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2619    
2620     eval "${functions}() { ${include}_${functions} ; }"
2621    
2622     # debug
2623     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2624    
2625     shift
2626     done
2627    }

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