--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/09/11 19:47:08 240 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2006/01/01 22:59:52 310 @@ -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.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 $ mage_setup() { @@ -379,7 +379,7 @@ [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" - mknode -m ${posix} -c "${MROOT}${pathto}" + mknod -m ${posix} -c "${MROOT}${pathto}" done < ${BUILDDIR}/${pkgname}/.char # very important: unsetting the '§' fieldseperator @@ -432,6 +432,7 @@ local magefile local dbrecorddir local provide + local i # very basic getops for i in $* @@ -473,7 +474,6 @@ # create fake file descriptors # used by virtual and source packages - local i for i in .dirs .symlinks .files .pipes .char do touch ${dbrecorddir}/${i} @@ -504,7 +504,10 @@ provide="$(get_value_from_magefile PROVIDE ${magefile})" if [ -n "${provide}" ] then - virtuals_add "${provide}" "${pcat}/${pname}" + for i in ${provide} + do + virtuals_add "${i}" "${pcat}/${pname}" + done fi } @@ -523,6 +526,7 @@ local magefile local dbrecorddir local provide + local i # very basic getops for i in $* @@ -552,11 +556,18 @@ # abort if mage file not exists [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." - # first unregister virtuals - provide="$(get_value_from_magefile PROVIDE ${magefile})" - if [ -n "${provide}" ] + # remove virtuals only if no other exist + if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] then - virtuals_del "${provide}" "${pcat}/${pname}" + # first unregister virtuals + provide="$(get_value_from_magefile PROVIDE ${magefile})" + if [ -n "${provide}" ] + then + for i in ${provide} + do + virtuals_del "${i}" "${pcat}/${pname}" + done + fi fi # removes database entry @@ -566,6 +577,39 @@ fi } +# get the number of installed packages +count_installed_pkgs() +{ + local pcat + local pname + local pkg + local i + + # very basic getops + for i in $* + do + case $1 in + --pcat|-c) shift; pcat="$1" ;; + --pname|-n) shift; pname="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." + [ -z "${pname}" ] && die "pkg_count() \$pname not given." + + declare -i i=0 + for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) + do + (( i++ )) + #echo "$i ${pkg}" + done + + # return the value + echo "${i}" +} + ################################################### # function compare_mtime # @@ -758,10 +802,35 @@ # 1=keep me # case ${retval} in 0) - [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" - rm "${MROOT}${pathto}" - ;; + # check if the file is config_protected + # ${MROOT} will automatically added if set !! + is_config_protected "${pathto}" + retval="$?" + + # 0 - not protected # + # 1 - error # + # 2 - protected # + # 3 - protected but masked # + + case ${retval} in + # file is not protected - delete it + 0|3) + [[ ${VERBOSE} = on ]] && echo -e "\t<<< FILE: ${MROOT}${pathto}" + rm "${MROOT}${pathto}" + ;; + # file is protected, do not delete + 2) + if [[ ${VERBOSE} = on ]] + then + echo -en "${COLRED}" + echo -n "! prot " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + ;; + esac + ;; 1) [[ ${VERBOSE} = on ]] && \ echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" @@ -1087,7 +1156,7 @@ --continue \ --progress bar \ --directory-prefix=${PKGDIR} \ - ${opt} ${mirr}/packages/${pkg} + ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} if [[ $? = 0 ]] then break @@ -1219,7 +1288,7 @@ STATE="$(get_value_from_magefile STATE "$1")" # state testing - if [[ ${USE_TESTING} = true ]] + if [[ ${USE_TESTING} = true ]] || [[ ${MAGE_DISTRIBUTION} = testing ]] then case ${STATE} in testing|stable) return 0 ;; @@ -1228,7 +1297,7 @@ fi # state unstable - if [[ ${USE_UNSTABLE} = true ]] + if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] then case ${STATE} in unstable|testing|stable) return 0 ;; @@ -1490,6 +1559,7 @@ local oldline local line i local installed_file + local OLDIFS if virtuals_read ${virtualname} then @@ -1512,6 +1582,7 @@ # make a backup mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old + OLDIFS="${IFS}" IFS=$'\n' for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) do @@ -1523,10 +1594,10 @@ echo "${line}" >> ${MROOT}${VIRTUALDB_FILE} fi done - - #unset IFS + # unset IFS + IFS="${OLDIFS}" else - echo -ne "${COLBLUE} *** ${COLDEFAULT}" + echo -ne "${COLBLUE} >>> ${COLDEFAULT}" echo "register ${pkgname} as ${virtualname} ..." echo "${virtualname} ${pkgname}" >> ${MROOT}${VIRTUALDB_FILE} fi @@ -1538,61 +1609,68 @@ #$1 virtualname; $2 pkgname virtuals_del() { - local VIRTUAL_NAME PKG_NAME OLD_LINE METHOD line i x PKG_INSTALLED - - VIRTUAL_NAME=$1 - PKG_NAME=$2 - - #first check if exists - if virtuals_read ${VIRTUAL_NAME} + local virtualname="$1" + local pkgname="$2" + local oldline + local method + local line i x + local pkg_installed + local OLDIFS + + # first check if exists + if virtuals_read ${virtualname} then - #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} declare -i x=0 - for i in $(virtuals_read ${VIRTUAL_NAME} showpkgs) + for i in $(virtuals_read ${virtualname} showpkgs) do - if [ "${i}" == "${PKG_NAME}" ] + if [[ ${i} = ${pkgname} ]] then - PKG_INSTALLED=true + pkg_installed=true fi ((x++)) done - - #abort if not installed - if [ "${PKG_INSTALLED}" != "true" ] + + # abort if not installed + if [[ ${pkg_installed} != true ]] then - echo "!!!! ${PKG_NAME} does not exists in ${VIRTUAL_NAME}." + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "${pkgname} does not exists in ${virtualname}." return 0 fi - + if [ ${x} -ge 2 ] then - METHOD=update + method=update else - METHOD=delall + method=delall fi - - #get the complete line - OLD_LINE="$(virtuals_read ${VIRTUAL_NAME} showline)" - - #make a backup + + # get the complete line + oldline="$(virtuals_read ${virtualname} showline)" + + # make a backup of the db mv ${VIRTUALDB_FILE} ${VIRTUALDB_FILE}.old - - #parse virtualdb + + # parse virtualdb + OLDIFS="${IFS}" IFS=$'\n' for line in $(< ${VIRTUALDB_FILE}.old) do - if [ "${line}" == "${OLD_LINE}" ] + if [[ ${line} = ${oldline} ]] then #delall or update? - case ${METHOD} in + case ${method} in update) - echo "<<<< Unlinking ${PKG_NAME} from ${VIRTUAL_NAME} in virtual database ..." - #del PKG_NAME from line - echo "${line/ ${PKG_NAME}/}" >> ${VIRTUALDB_FILE} + echo -ne "${COLBLUE} *** ${COLDEFAULT}" + echo "Unlinking ${pkgname} from ${virtualname} in virtual database ..." + # del PKG_NAME from line + echo "${line/ ${pkgname}/}" >> ${VIRTUALDB_FILE} ;; delall) - echo "<<<< Deleting ${VIRTUAL_NAME} in virtual database ..." - #continue; do not write anything + echo -ne "${COLBLUE} <<< ${COLDEFAULT}" + echo "Deleting ${virtualname} in virtual database ..." + # continue; do not write anything continue ;; esac @@ -1600,9 +1678,11 @@ echo "${line}" >> ${VIRTUALDB_FILE} fi done - unset IFS + # unset IFS + IFS="${OLDIFS}" else - echo "!!!! ${VIRTUAL_NAME} does not exists in virtual database." + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "${virtualname} does not exists in virtual database." fi } @@ -1667,7 +1747,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} ]] @@ -1960,6 +2040,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove # sanity checks [ -f ${magefile} ] && source ${magefile} || \ @@ -1969,6 +2051,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() @@ -1985,6 +2073,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -2146,6 +2236,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() @@ -2304,6 +2400,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -2401,6 +2499,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() { @@ -2499,3 +2603,25 @@ 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 +}