--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/09/09 16:35:46 226 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2005/10/04 14:35:21 258 @@ -1,6 +1,6 @@ #!/bin/bash # Magellan Linux Installer Functions (mage.functions.sh) -# $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.7 2005-10-04 14:35:21 niro Exp $ mage_setup() { @@ -744,7 +744,7 @@ do [ -z "${pathto}" ] && continue - if [ -e "${MROOT}${pathto}" ] + if [ ! -e "${MROOT}${pathto}" ] then [[ ${VERBOSE} = on ]] && \ echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" @@ -932,14 +932,11 @@ [ ! -f ${MROOT}${INSTALLDB}/${pfull}/.char ] && die "remove_directories() .dirs not found" - # uninstall of dirs ## added small hack to fix dirs - # must be reverse -> smage2 doesn't sort them - # -> using tac - # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + # reversed order is mandatory ! + tac ${MROOT}${INSTALLDB}/${pfull}/.dirs | while read pathto posix do [ -z "${pathto}" ] && continue @@ -954,7 +951,7 @@ if [ -f "${MROOT}${pathto}/.keep" ] then [[ ${VERBOSE} = on ]] && \ - echo -e "${COLRED} .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" + echo -e "${COLRED}! .keep${COLDEFAULT} === DIR: ${MROOT}${pathto}" continue fi @@ -971,7 +968,7 @@ [[ ${VERBOSE} = on ]] && \ echo -e "${COLRED}! empty${COLDEFAULT} === DIR: ${MROOT}${pathto}" fi - done < ${MROOT}${INSTALLDB}/${pfull}/.dirs + done # very important: unsetting the '§' fieldseperator IFS=$'\n' @@ -1670,7 +1667,7 @@ local newest_mage local installed_mage - newest_mage="$( CATEGORIE=app-mage MAGENAME=mage get_highest_magefile;echo $(basename ${MAGEFILE} .mage) )" + newest_mage="$(basename $(get_highest_magefile app-mage mage) .mage)" installed_mage="$(magequery -n mage | cut -d' ' -f5)" if [[ ${newest_mage} > ${installed_mage} ]] @@ -1963,6 +1960,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove # sanity checks [ -f ${magefile} ] && source ${magefile} || \ @@ -1972,6 +1971,12 @@ source ${magefile} eval value=\$$(echo ${var}) echo "${value}" + + # unset these functions + unset -f preinstall + unset -f postinstall + unset -f preremove + unset -f postremove } mage_install() @@ -1988,6 +1993,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -2149,6 +2156,12 @@ # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " echo "successfully installed." + + # unset these functions + unset -f preinstall + unset -f postinstall + unset -f preremove + unset -f postremove } md5sum_packages() @@ -2253,20 +2266,23 @@ echo -ne "${COLBLUE} --- ${COLDEFAULT}" echo "following candidate(s) will be removed:" echo -ne "${COLBLUE} --- ${COLDEFAULT}" - echo -ne "\033[1m${can_pcat}/${can_pname}:${COLDEFAULT}" + echo -ne "${COLBOLD}${can_pcat}/${can_pname}:${COLDEFAULT}" echo -e "${COLRED} ${can_ver_list} ${COLDEFAULT}" echo - echo -ne "${COLBLUE} --- ${COLDEFAULT}" - echo "( Press [CTRL+C] to abort )" - echo -ne "${COLBLUE} --- ${COLDEFAULT}" - echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." - for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) - do - echo -ne "${COLRED} ${i}${COLDEFAULT}" - sleep 1 - done - echo - echo + if [ ${MAGE_UNINSTALL_TIMEOUT} -gt 0 ] + then + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "( Press [CTRL+C] to abort )" + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo -n "Waiting ${MAGE_UNINSTALL_TIMEOUT} seconds ..." + for ((i=MAGE_UNINSTALL_TIMEOUT; i >= 0; i--)) + do + echo -ne "${COLRED} ${i}${COLDEFAULT}" + sleep 1 + done + echo + echo + fi for pkg in ${list} do @@ -2304,6 +2320,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -2341,7 +2359,7 @@ echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" - magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" + magefile="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" source ${magefile} ## preremove scripts @@ -2401,6 +2419,12 @@ # echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" # echo -ne "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT} " echo "successfully removed." + + # unset these functions + unset -f preinstall + unset -f postinstall + unset -f preremove + unset -f postremove } show_etc_update_mesg() { @@ -2415,3 +2439,109 @@ echo "Please run 'etc-update' to update your configuration files." echo } + +pkgsearch() +{ + local string="$1" + local result + local pkg + local pcat + local pname + local magefile + local pver + local pbuild + local state + local descriptiom + local homepage + local i + local all_installed + local ipver + local ipbuild + + # only names no versions + result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name *${string}*)" + #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)" + + # nothing found + [[ -z ${result} ]] && die "No package found containing '${string}' in the name." + + for pkg in ${result} + do + # dirty, but does the job + pcat="$(magename2pcat ${pkg}/foo)" + pname="$(magename2pname ${pkg}-foo-foo)" + + # get highest version available + magefile=$(get_highest_magefile ${pcat} ${pname}) + + # now get all needed infos to print a nice output + pver="$(magename2pver ${magefile})" + pbuild="$(magename2pbuild ${magefile})" + state="$(get_value_from_magefile STATE ${magefile})" + description="$(get_value_from_magefile DESCRIPTION ${magefile})" + homepage="$(get_value_from_magefile HOMEPAGE ${magefile})" + + # all installed + for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) + do + ipver="$(magename2pver ${i})" + ipbuild="$(magename2pbuild ${i})" + + if [[ -z ${all_installed} ]] + then + all_installed="${ipver}-${ipbuild}" + else + all_installed="${all_installed} ${ipver}-${ipbuild}" + fi + done + [[ -z ${all_installed} ]] && all_installed="none" + + case ${state} in + stable) state=${COLGREEN}"[s] ";; + testing) state=${COLYELLOW}"[t] ";; + unstable) state=${COLRED}"[u] ";; + old) state=${COLGRAY}"[o] ";; + esac + + echo -e "${state}${pcat}/${pname}"${COLDEFAULT} + echo " Latest available: ${pver}-${pbuild}" + echo " Installed versions: ${all_installed}" + echo " Description: ${description}" + echo " Homepage: ${homepage}" + echo + + unset pcat + unset pname + unset magefile + unset pver + unset pbuild + unset state + unset descriptiom + unset homepage + unset all_installed + unset ipver + unset ipbuild + done +} + +export_inherits() +{ + local include="$1" + shift + + while [ "$1" ] + do + local functions="$1" + + # sanity checks + [ -z "${include}" ] && die "export_inherits(): \$include not given." + [ -z "${functions}" ] && die "export_inherits(): \$functions not given." + + eval "${functions}() { ${include}_${functions} ; }" + + # debug + [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" + + shift + done +}