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 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.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.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 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 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 932  remove_directories() Line 964  remove_directories()
964    
965   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"   [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found"
966    
  # uninstall of dirs ## added small hack to fix dirs  
  # must be reverse -> smage2 doesn't sort them  
  # -> using tac  
   
967   # sets fieldseperator to "§" instead of " "   # sets fieldseperator to "§" instead of " "
968   IFS=§   IFS=§
969    
970   while read pathto posix   # reversed order is mandatory !
971     tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix
972   do   do
973   [ -z "${pathto}" ] && continue   [ -z "${pathto}" ] && continue
974    
# Line 954  remove_directories() Line 983  remove_directories()
983   if [ -f "${MROOT}${pathto}/.keep" ]   if [ -f "${MROOT}${pathto}/.keep" ]
984   then   then
985   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
986   echo -e "${COLRED}  .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! .keep${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
987   continue   continue
988   fi   fi
989    
# Line 971  remove_directories() Line 1000  remove_directories()
1000   [[ ${VERBOSE} = on ]] && \   [[ ${VERBOSE} = on ]] && \
1001   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"   echo -e "${COLRED}! empty${COLDEFAULT} === DIR:  ${MROOT}${pathto}"
1002   fi   fi
1003   done < ${MROOT}${INSTALLDB}/${pfull}/.dirs   done
1004    
1005   # very important: unsetting the '§' fieldseperator   # very important: unsetting the '§' fieldseperator
1006   IFS=$'\n'   IFS=$'\n'
# Line 1493  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 1515  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 1526  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 1541  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 1603  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 1670  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 1963  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 1972  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 1988  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 2149  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 2253  uninstall_packages() Line 2309  uninstall_packages()
2309   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2310   echo "following candidate(s) will be removed:"   echo "following candidate(s) will be removed:"
2311   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2312   echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}"   echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}"
2313   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"   echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}"
2314   echo   echo
2315   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ]
2316   echo "( Press [CTRL+C] to abort )"   then
2317   echo -ne "${COLBLUE} --- ${COLDEFAULT}"   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2318   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."   echo "( Press [CTRL+C] to abort )"
2319   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))   echo -ne "${COLBLUE} --- ${COLDEFAULT}"
2320   do   echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..."
2321   echo -ne "${COLRED} ${i}${COLDEFAULT}"   for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--))
2322   sleep 1   do
2323   done   echo -ne "${COLRED} ${i}${COLDEFAULT}"
2324   echo   sleep 1
2325   echo   done
2326     echo
2327     echo
2328     fi
2329    
2330   for pkg in ${list}   for pkg in ${list}
2331   do   do
# 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 2341  mage_uninstall() Line 2402  mage_uninstall()
2402   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"   echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}"
2403   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"   echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}"
2404    
2405   magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage"   magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage"
2406   source ${magefile}   source ${magefile}
2407    
2408   ## preremove scripts   ## preremove scripts
# 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 2415  show_etc_update_mesg() { Line 2482  show_etc_update_mesg() {
2482   echo "Please run 'etc-update' to update your configuration files."   echo "Please run 'etc-update' to update your configuration files."
2483   echo   echo
2484  }  }
2485    
2486    pkgsearch()
2487    {
2488     local string="$1"
2489     local result
2490     local pkg
2491     local pcat
2492     local pname
2493     local magefile
2494     local pver
2495     local pbuild
2496     local state
2497     local descriptiom
2498     local homepage
2499     local i
2500     local all_installed
2501     local ipver
2502     local ipbuild
2503    
2504     # only names no versions
2505     result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)"
2506     #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)"
2507    
2508     # nothing found
2509     [[ -z ${result} ]] && die "No package found containing '${string}' in the name."
2510    
2511     for pkg in ${result}
2512     do
2513     # dirty, but does the job
2514     pcat="$(magename2pcat ${pkg}/foo)"
2515     pname="$(magename2pname ${pkg}-foo-foo)"
2516    
2517     # get highest version available
2518     magefile=$(get_highest_magefile ${pcat} ${pname})
2519    
2520     # now get all needed infos to print a nice output
2521     pver="$(magename2pver ${magefile})"
2522     pbuild="$(magename2pbuild ${magefile})"
2523     state="$(get_value_from_magefile STATE ${magefile})"
2524     description="$(get_value_from_magefile DESCRIPTION ${magefile})"
2525     homepage="$(get_value_from_magefile HOMEPAGE ${magefile})"
2526    
2527     # all installed
2528     for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat})
2529     do
2530     ipver="$(magename2pver ${i})"
2531     ipbuild="$(magename2pbuild ${i})"
2532    
2533     if [[ -z ${all_installed} ]]
2534     then
2535     all_installed="${ipver}-${ipbuild}"
2536     else
2537     all_installed="${all_installed} ${ipver}-${ipbuild}"
2538     fi
2539     done
2540     [[ -z ${all_installed} ]] && all_installed="none"
2541    
2542     case ${state} in
2543     stable) state=${COLGREEN}"[s] ";;
2544     testing) state=${COLYELLOW}"[t] ";;
2545     unstable) state=${COLRED}"[u] ";;
2546     old) state=${COLGRAY}"[o] ";;
2547     esac
2548    
2549     echo -e "${state}${pcat}/${pname}"${COLDEFAULT}
2550     echo "      Latest available:   ${pver}-${pbuild}"
2551     echo "      Installed versions: ${all_installed}"
2552     echo "      Description: ${description}"
2553     echo "      Homepage: ${homepage}"
2554     echo
2555    
2556     unset pcat
2557     unset pname
2558     unset magefile
2559     unset pver
2560     unset pbuild
2561     unset state
2562     unset descriptiom
2563     unset homepage
2564     unset all_installed
2565     unset ipver
2566     unset ipbuild
2567     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.226  
changed lines
  Added in v.280