Magellan Linux

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

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

revision 226 by niro, Fri Sep 9 16:35:46 2005 UTC revision 273 by niro, Fri Oct 21 14:50:13 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.1 2005-09-09 16:35:38 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.8 2005-10-21 14:50:13 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 744  remove_files() Line 751  remove_files()
751   do   do
752   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
753    
754   if [ -e "${MROOT}${pathto}" ]   if [ ! -e "${MROOT}${pathto}" ]
755   then   then
756   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
757   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"   echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}"
# Line 932  remove_directories() Line 939  remove_directories()
939    
940   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
941    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
942   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
943   IFS=§   IFS=§
944    
945   while read pathto posix   # reversed order is mandatory !
946     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
947   do   do
948   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
949    
# Line 954  remove_directories() Line 958  remove_directories()
958   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
959   then   then
960   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
961   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
962   continue   continue
963   fi   fi
964    
# Line 971  remove_directories() Line 975  remove_directories()
975   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
976   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
977   fi   fi
978   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
979    
980   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
981   IFS=$'\n'   IFS=$'\n'
# Line 1493  virtuals_add() Line 1497  virtuals_add()
1497   local oldline   local oldline
1498   local line i   local line i
1499   local installed_file   local installed_file
1500     local OLDIFS
1501    
1502   if virtuals_read ${virtualname}   if virtuals_read ${virtualname}
1503   then   then
# Line 1515  virtuals_add() Line 1520  virtuals_add()
1520   # make a backup   # make a backup
1521   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old   mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old
1522    
1523     OLDIFS="${IFS}"
1524   IFS=$'\n'   IFS=$'\n'
1525   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)   for line in $(< ${MROOT}${VIRTUALDB_FILE}.old)
1526   do   do
# Line 1526  virtuals_add() Line 1532  virtuals_add()
1532   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${line}" >> ${MROOT}${VIRTUALDB_FILE}
1533   fi   fi
1534   done   done
1535     # unset IFS
1536   #unset IFS   IFS="${OLDIFS}"
1537   else   else
1538   echo -ne "${COLBLUE} *** ${COLDEFAULT}"   echo -ne "${COLBLUE} >>> ${COLDEFAULT}"
1539   echo "register ${pkgname} as ${virtualname} ..."   echo "register ${pkgname} as ${virtualname} ..."
1540   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}   echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE}
1541   fi   fi
# Line 1541  virtuals_add() Line 1547  virtuals_add()
1547  #$1 virtualname; $2 pkgname  #$1 virtualname; $2 pkgname
1548  virtuals_del() {  virtuals_del() {
1549    
1550   local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED   local virtualname="$1"
1551     local pkgname="$2"
1552   VIRTUAL_NAME=$1   local oldline
1553   PKG_NAME=$2   local method
1554     local line i x
1555   #first check if exists   local pkg_installed
1556   if virtuals_read ${VIRTUAL_NAME}   local OLDIFS
1557    
1558     # first check if exists
1559     if virtuals_read ${virtualname}
1560   then   then
1561   #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}
1562   declare -i x=0   declare -i x=0
1563   for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs)   for i in $(virtuals_read ${virtualname} showpkgs)
1564   do   do
1565   if [ "${i}" == "${PKG_NAME}" ]   if [[ ${i} = ${pkgname} ]]
1566   then   then
1567   PKG_INSTALLED=true   pkg_installed=true
1568   fi   fi
1569   ((x++))   ((x++))
1570   done   done
1571    
1572   #abort if not installed   # abort if not installed
1573   if [ "${PKG_INSTALLED}" != "true" ]   if [[ ${pkg_installed} != true ]]
1574   then   then
1575   echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1576     echo "${pkgname} does not exists in ${virtualname}."
1577   return 0   return 0
1578   fi   fi
1579    
1580   if [ ${x} -ge 2 ]   if [ ${x} -ge 2 ]
1581   then   then
1582   METHOD=update   method=update
1583   else   else
1584   METHOD=delall   method=delall
1585   fi   fi
1586    
1587   #get the complete line   # get the complete line
1588   OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)"   oldline="$(virtuals_read ${virtualname} showline)"
1589    
1590   #make a backup   # make a backup of the db
1591   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old   mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old
1592    
1593   #parse virtualdb   # parse virtualdb
1594     OLDIFS="${IFS}"
1595   IFS=$'\n'   IFS=$'\n'
1596   for line in $(< ${VIRTUALDB_FILE}.old)   for line in $(< ${VIRTUALDB_FILE}.old)
1597   do   do
1598   if [ "${line}" == "${OLD_LINE}" ]   if [[ ${line} = ${oldline} ]]
1599   then   then
1600   #delall or update?   #delall or update?
1601   case ${METHOD} in   case ${method} in
1602   update)   update)
1603   echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} *** ${COLDEFAULT}"
1604   #del PKG_NAME from line   echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..."
1605   echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE}   # del PKG_NAME from line
1606     echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE}
1607   ;;   ;;
1608   delall)   delall)
1609   echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..."   echo -ne "${COLBLUE} <<< ${COLDEFAULT}"
1610   #continue; do not write anything   echo "Deleting ${virtualname} in virtual database ..."
1611     # continue; do not write anything
1612   continue   continue
1613   ;;   ;;
1614   esac   esac
# Line 1603  virtuals_del() { Line 1616  virtuals_del() {
1616   echo "${line}" >> ${VIRTUALDB_FILE}   echo "${line}" >> ${VIRTUALDB_FILE}
1617   fi   fi
1618   done   done
1619   unset IFS   # unset IFS
1620     IFS="${OLDIFS}"
1621   else   else
1622   echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database."   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
1623     echo "${virtualname} does not exists in virtual database."
1624   fi   fi
1625  }  }
1626    
# Line 1670  is_newer_mage_version_available() Line 1685  is_newer_mage_version_available()
1685   local newest_mage   local newest_mage
1686   local installed_mage   local installed_mage
1687    
1688   newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )"   newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)"
1689   installed_mage="$(magequery -n mage | cut -d' ' -f5)"   installed_mage="$(magequery -n mage | cut -d' ' -f5)"
1690    
1691   if [[ ${newest_mage} > ${installed_mage} ]]   if [[ ${newest_mage} > ${installed_mage} ]]
# Line 1963  get_value_from_magefile() Line 1978  get_value_from_magefile()
1978   local PKGTYPE   local PKGTYPE
1979   local preinstall   local preinstall
1980   local postinstall   local postinstall
1981     local preremove
1982     local postremove
1983    
1984   # sanity checks   # sanity checks
1985   [ -f ${magefile} ] && source ${magefile} || \   [ -f ${magefile} ] && source ${magefile} || \
# Line 1972  get_value_from_magefile() Line 1989  get_value_from_magefile()
1989   source ${magefile}   source ${magefile}
1990   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
1991   echo "${value}"   echo "${value}"
1992    
1993     # unset these functions
1994     unset -f preinstall
1995     unset -f postinstall
1996     unset -f preremove
1997     unset -f postremove
1998  }  }
1999    
2000  mage_install()  mage_install()
# Line 1988  mage_install() Line 2011  mage_install()
2011   local PKGTYPE   local PKGTYPE
2012   local preinstall   local preinstall
2013   local postinstall   local postinstall
2014     local preremove
2015     local postremove
2016    
2017   local pcat   local pcat
2018   local pname   local pname
# Line 2149  mage_install() Line 2174  mage_install()
2174  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2175  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2176   echo "successfully installed."   echo "successfully installed."
2177    
2178     # unset these functions
2179     unset -f preinstall
2180     unset -f postinstall
2181     unset -f preremove
2182     unset -f postremove
2183  }  }
2184    
2185  md5sum_packages()  md5sum_packages()
# Line 2253  uninstall_packages() Line 2284  uninstall_packages()
2284   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2285   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2286   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2287   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2288   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2289   echo   echo
2290   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2291   echo "( Press [CTRL+C] to abort )"   then
2292   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2293   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2294   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2295   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2296   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2297   sleep 1   do
2298   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2299   echo   sleep 1
2300   echo   done
2301     echo
2302     echo
2303     fi
2304    
2305   for pkg in ${list}   for pkg in ${list}
2306   do   do
# Line 2304  mage_uninstall() Line 2338  mage_uninstall()
2338   local PKGTYPE   local PKGTYPE
2339   local preinstall   local preinstall
2340   local postinstall   local postinstall
2341     local preremove
2342     local postremove
2343    
2344   local pcat   local pcat
2345   local pname   local pname
# Line 2341  mage_uninstall() Line 2377  mage_uninstall()
2377   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2378   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2379    
2380   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2381   source ${magefile}   source ${magefile}
2382    
2383   ## preremove scripts   ## preremove scripts
# Line 2401  mage_uninstall() Line 2437  mage_uninstall()
2437  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"  # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2438  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "  # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} "
2439   echo "successfully removed."   echo "successfully removed."
2440    
2441     # unset these functions
2442     unset -f preinstall
2443     unset -f postinstall
2444     unset -f preremove
2445     unset -f postremove
2446  }  }
2447    
2448  show_etc_update_mesg() {  show_etc_update_mesg() {
# Line 2415  show_etc_update_mesg() { Line 2457  show_etc_update_mesg() {
2457   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
2458   echo   echo
2459  }  }
2460    
2461    pkgsearch()
2462    {
2463     local string="$1"
2464     local result
2465     local pkg
2466     local pcat
2467     local pname
2468     local magefile
2469     local pver
2470     local pbuild
2471     local state
2472     local descriptiom
2473     local homepage
2474     local i
2475     local all_installed
2476     local ipver
2477     local ipbuild
2478    
2479     # only names no versions
2480     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"
2481     #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"
2482    
2483     # nothing found
2484     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2485    
2486     for pkg in ${result}
2487     do
2488     # dirty, but does the job
2489     pcat="$(magename2pcat ${pkg}/foo)"
2490     pname="$(magename2pname ${pkg}-foo-foo)"
2491    
2492     # get highest version available
2493     magefile=$(get_highest_magefile ${pcat} ${pname})
2494    
2495     # now get all needed infos to print a nice output
2496     pver="$(magename2pver ${magefile})"
2497     pbuild="$(magename2pbuild ${magefile})"
2498     state="$(get_value_from_magefile STATE ${magefile})"
2499     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2500     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2501    
2502     # all installed
2503     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2504     do
2505     ipver="$(magename2pver ${i})"
2506     ipbuild="$(magename2pbuild ${i})"
2507    
2508     if [[ -z ${all_installed} ]]
2509     then
2510     all_installed="${ipver}-${ipbuild}"
2511     else
2512     all_installed="${all_installed} ${ipver}-${ipbuild}"
2513     fi
2514     done
2515     [[ -z ${all_installed} ]] && all_installed="none"
2516    
2517     case ${state} in
2518     stable) state=${COLGREEN}"[s] ";;
2519     testing) state=${COLYELLOW}"[t] ";;
2520     unstable) state=${COLRED}"[u] ";;
2521     old) state=${COLGRAY}"[o] ";;
2522     esac
2523    
2524     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2525     echo "      Latest available:   ${pver}-${pbuild}"
2526     echo "      Installed versions: ${all_installed}"
2527     echo "      Description: ${description}"
2528     echo "      Homepage: ${homepage}"
2529     echo
2530    
2531     unset pcat
2532     unset pname
2533     unset magefile
2534     unset pver
2535     unset pbuild
2536     unset state
2537     unset descriptiom
2538     unset homepage
2539     unset all_installed
2540     unset ipver
2541     unset ipbuild
2542     done
2543    }
2544    
2545    export_inherits()
2546    {
2547     local include="$1"
2548     shift
2549    
2550     while [ "$1" ]
2551     do
2552     local functions="$1"
2553    
2554     # sanity checks
2555     [ -z "${include}" ] && die "export_inherits(): \$include not given."
2556     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
2557    
2558     eval "${functions}() { ${include}_${functions} ; }"
2559    
2560     # debug
2561     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
2562    
2563     shift
2564     done
2565    }

Legend:
Removed from v.226  
changed lines
  Added in v.273