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 294 by niro, Sun Dec 4 11:54:15 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.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.11 2005-12-04 11:54:15 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 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 1972  get_value_from_magefile() Line 2052  get_value_from_magefile()
2052   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
2053   echo "${value}"   echo "${value}"
2054    
2055   unset preinstall   # unset these functions
2056   unset postinstall   unset -f preinstall
2057   unset preremove   unset -f postinstall
2058   unset postremove   unset -f preremove
2059     unset -f postremove
2060  }  }
2061    
2062  mage_install()  mage_install()
# Line 2156  mage_install() Line 2237  mage_install()
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 preinstall   # unset these functions
2241   unset postinstall   unset -f preinstall
2242   unset preremove   unset -f postinstall
2243   unset postremove   unset -f preremove
2244     unset -f postremove
2245  }  }
2246    
2247  md5sum_packages()  md5sum_packages()
# Line 2418  mage_uninstall() Line 2500  mage_uninstall()
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 preinstall   # unset these functions
2504   unset postinstall   unset -f preinstall
2505   unset preremove   unset -f postinstall
2506   unset postremove   unset -f preremove
2507     unset -f postremove
2508  }  }
2509    
2510  show_etc_update_mesg() {  show_etc_update_mesg() {

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