--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/09/09 16:35:46 226 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2010/02/19 19:59:22 966 @@ -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.38 2008-10-05 10:32:24 niro Exp $ mage_setup() { @@ -198,10 +198,11 @@ is_config_protected "${pathto}" retval="$?" - # 0 - not protected # - # 1 - error # - # 2 - protected # - # 3 - protected but masked # + # 0 - not protected # + # 1 - error # + # 2 - protected # + # 3 - protected but masked # + # 4 - protected but ignored # case ${retval} in # file is not protected - (over)write it @@ -252,6 +253,18 @@ (( MAGE_PROTECT_COUNTER++ )) export MAGE_PROTECT_COUNTER ;; + + # file is protected but ignored, delete the update/do nothing + 4) + if [[ ${VERBOSE} = on ]] + then + echo -en "${COLRED}" + echo -n "! ignr " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + # simply do nothing here + ;; esac done < ${BUILDDIR}/${pkgname}/.files @@ -298,19 +311,19 @@ ln -snf "${link}" "${MROOT}${pathto}" - # fix mtime and db - fix_descriptor ${pkgname}/.symlinks \ - "${pathto}" \ - "${posix}" \ - "${link}" \ - "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ - "${MROOT}${pathto}")" +# # fix mtime and db +# fix_descriptor ${pkgname}/.symlinks \ +# "${pathto}" \ +# "${posix}" \ +# "${link}" \ +# "$(fix_mtime "${BUILDDIR}/${pkgname}"/.mtime \ +# "${MROOT}${pathto}")" done < ${BUILDDIR}/${pkgname}/.symlinks - # now copy the fixed file over the old one - [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ - cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} +# # now copy the fixed file over the old one +# [ -f ${BUILDDIR}/${pkgname}/.symlinks_fixed ] && \ +# cp -f ${BUILDDIR}/${pkgname}/.symlinks{_fixed,} # very important: unsetting the '§' fieldseperator IFS=$'\n' @@ -361,6 +374,8 @@ local pkgname="$1" local pathto local posix + local major + local minor local IFS # sanity checks; abort if not given @@ -374,12 +389,12 @@ # sets fieldseperator to "§" instead of " " IFS=§ - while read pathto posix + while read pathto posix major minor do [ -z "${pathto}" ] && continue [[ ${VERBOSE} = on ]] && echo -e "\t>>> CHAR: ${MROOT}${pathto}" - mknode -m ${posix} -c "${MROOT}${pathto}" + mknod -m ${posix} "${MROOT}${pathto}" c ${major} ${minor} done < ${BUILDDIR}/${pkgname}/.char # very important: unsetting the '§' fieldseperator @@ -432,6 +447,7 @@ local magefile local dbrecorddir local provide + local i # very basic getops for i in $* @@ -473,7 +489,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 +519,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 +541,7 @@ local magefile local dbrecorddir local provide + local i # very basic getops for i in $* @@ -552,11 +571,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 +592,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 # @@ -744,7 +803,7 @@ do [ -z "${pathto}" ] && continue - if [ -e "${MROOT}${pathto}" ] + if [ ! -e "${MROOT}${pathto}" ] then [[ ${VERBOSE} = on ]] && \ echo -e "${COLRED}! exist${COLDEFAULT} === FILE: ${MROOT}${pathto}" @@ -758,10 +817,48 @@ # 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 # + # 4 - protected but ignored # + + 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 + ;; + + # file is protected but ignored, delete the update/do nothing + 4) + if [[ ${VERBOSE} = on ]] + then + echo -en "${COLRED}" + echo -n "! ignr " + echo -en "${COLDEFAULT}" + echo " === FILE: ${MROOT}${pathto}" + fi + # simply do nothing here + ;; + esac + ;; 1) [[ ${VERBOSE} = on ]] && \ echo -e "${COLRED}! mtime${COLDEFAULT} === FILE: ${MROOT}${pathto}" @@ -932,14 +1029,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 +1048,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 +1065,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' @@ -1038,7 +1132,7 @@ local count_current local count_total - [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your /etc/mage.rc." + [ -z "${MIRRORS}" ] && die "You have no mirrors defined. Please edit your ${MAGERC}." # get count of total packages declare -i count_current=0 @@ -1090,7 +1184,7 @@ --continue \ --progress bar \ --directory-prefix=${PKGDIR} \ - ${opt} ${mirr}/packages/${pkg} + ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} if [[ $? = 0 ]] then break @@ -1113,26 +1207,13 @@ { if [ -z "${RSYNC}" ] then - die "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." + die "You have no rsync-mirrors defined. Please edit your ${MAGERC}." fi local i for i in ${RSYNC} do - rsync \ - --recursive \ - --links \ - --perms \ - --times \ - --devices \ - --timeout=600 \ - --verbose \ - --compress \ - --progress \ - --stats \ - --delete \ - --delete-after \ - ${i} ${MAGEDIR} + rsync ${RSYNC_FETCH_OPTIONS} ${i} ${MAGEDIR} if [[ $? = 0 ]] then break @@ -1144,10 +1225,70 @@ # clean up backup files (foo~) find ${MAGEDIR} -name *~ -exec rm '{}' ';' - # check if an newer mage version is available + # check if a newer mage version is available is_newer_mage_version_available } +syncmage_tarball() +{ + local latest_tarball + local temp="$(mktemp -d)" + local mirr mymirr + + # try to get the tarball marked as latest on the server + latest_tarball="mage-latest.tar.bz2" + + for mirr in ${MIRRORS} + do + # path without distribution + mymirr="${mirr%/*}" + + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "fetching latest tarball from ${mymirr} ..." + + wget \ + --passive-ftp \ + --tries 3 \ + --continue \ + --progress bar \ + --directory-prefix=${temp} \ + ${mymirr}/rsync/tarballs/${latest_tarball} + if [[ $? = 0 ]] + then + break + else + continue + fi + done + + if [[ -f ${temp}/${latest_tarball} ]] + then + if [[ -d ${MAGEDIR} ]] + then + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "cleaning old mage-tree ${MAGEDIR}..." + rm -rf ${MAGEDIR} + fi + + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "updating mage-tree from tarball ..." + # unpack in dirname of MAGEDIR, as the tarball has already the mage + tar xjmf ${temp}/${latest_tarball} -C ${MAGEDIR%/*} || die "Unpacking tarball" + + if [[ -d ${temp} ]] + then + echo -ne "${COLBLUE} --- ${COLDEFAULT}" + echo "clenaing temp-files ..." + rm -rf ${temp} + fi + + # check if a newer mage version is available + is_newer_mage_version_available + else + die "Could not fetch the latest tarball ... aborting" + fi +} + cleanpkg() { if [ -d "${PKGDIR}" ] @@ -1185,7 +1326,7 @@ if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] then #cuts ARCH and PBUILD - #ARCH comes from /etc/mage.rc + #ARCH comes from ${MAGERC} MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") #cuts version number @@ -1218,11 +1359,14 @@ # returns 0=stable 1=unstable check_stable_package() { + # first check if this magefile is not blacklisted + blacklisted "$1" || return 1 + local STATE 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 ;; @@ -1231,7 +1375,7 @@ fi # state unstable - if [[ ${USE_UNSTABLE} = true ]] + if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] then case ${STATE} in unstable|testing|stable) return 0 ;; @@ -1257,10 +1401,12 @@ local PNAME="$2" local magefile - for magefile in $(ls --format=single-column -v ${MAGEDIR}/${PCAT}/${PNAME}/*) + # do not list the content of a directory, only the name (-d) + for magefile in $(ls --format=single-column -v -d ${MAGEDIR}/${PCAT}/${PNAME}/*) do + [[ -z ${magefile} ]] && continue # we exclude subdirs (for stuff like a md5sum dir) - [ -d ${magefile} ] && continue + [[ -d ${magefile} ]] && continue if check_stable_package ${magefile} then HIGHEST_MAGEFILE=${magefile} @@ -1269,26 +1415,27 @@ fi done - # stop here if HIGHEST_MAGEFILE is zero - # this package must be unstable or old - if [ -z "${HIGHEST_MAGEFILE}" ] - then - echo - echo -n "All packages named " - echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} - echo -n " are marked " - echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} - echo "." - echo "You need to declare USE_UNSTABLE=true to install this." - echo - echo "Example:" - echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" - echo - echo "Be warned that these packages are not stable and may cause serious problems." - echo "You should know what you are doing, so don't complain about any damage." - echo - return 1 - fi +# do not so anything +# # stop here if HIGHEST_MAGEFILE is zero +# # this package must be unstable or old +# if [ -z "${HIGHEST_MAGEFILE}" ] +# then +# echo +# echo -n "All packages named " +# echo -en ${COLRED}\""${PKGNAME%-*-*-*}\""${COLDEFAULT} +# echo -n " are marked " +# echo -en ${COLRED}"*UNSTABLE*"${COLDEFAULT} +# echo "." +# echo "You need to declare USE_UNSTABLE=true to install this." +# echo +# echo "Example:" +# echo " USE_UNSTABLE=true mage install ${PKGNAME%-*-*-*}" +# echo +# echo "Be warned that these packages are not stable and may cause serious problems." +# echo "You should know what you are doing, so don't complain about any damage." +# echo +# return 1 +# fi echo "${HIGHEST_MAGEFILE}" return 0 @@ -1304,6 +1451,7 @@ # 1 - error # # 2 - protected # # 3 - protected but masked # +# 4 - protected but ignored # # # ################################################### is_config_protected() @@ -1312,34 +1460,46 @@ local TEST local PROTECTED local IFS + local i + local x EXPFILE="${MROOT}$1" # file does not exist; it can be written - [ ! -e ${EXPFILE} ] && return 0 + [[ ! -e ${EXPFILE} ]] && return 0 # to be safe; it may be '§' IFS=' ' - # check ob in config protect + # check if config protected for i in ${CONFIG_PROTECT} do - # ersetzen von $i nur wenn am anfang der variable + # only replace $i in the beginning of the variable TEST="${EXPFILE/#${MROOT}${i}/Protected}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then - # setzen das es protected ist + # file is config proteced PROTECTED=TRUE - # check ob nicht doch maskiert + # check if not masked for x in ${CONFIG_PROTECT_MASK} do TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then PROTECTED=MASKED fi done + + # check if not ignored + for x in ${CONFIG_PROTECT_IGNORE} + do + TEST="${EXPFILE/#${MROOT}${x}/Protect_Ignored}" + if [[ ${TEST} != ${EXPFILE} ]] + then + PROTECTED=IGNORED + fi + done fi done @@ -1354,6 +1514,10 @@ #echo "I'm protected, but masked - delete me" return 3 ;; + IGNORED) + #echo "I'm protected, but ignored - keep me, del update" + return 4 + ;; *) #echo "delete me" return 0 @@ -1371,7 +1535,29 @@ ################################################### count_protected_files() { - ${MLIBDIR}/writeprotected "$1" + local file="$1" + local dirname="${file%/*}" + local filename="${file##*/}" + local count + local output + local i + + declare -i count=0 + + # check if there are already protected files + for oldpretected in $(find ${dirname} -iname "._cfg????_${filename}" | + sed -e "s:\(^.*/\)\(._cfg*_\)\(/.*$\):\1\2\3\%\2\%\3:" | + sort -t'%' -k3 -k2 | cut -f1 -d'%') + do + count=$(echo ${oldpretected} | cut -d_ -f2 | sed -e "s:cfg::") + done + (( count ++ )) + + # fill output up with zeros + for (( i=${#count}; i < 4; i++ )); do output="${output}0"; done + output="${output}${count}" + + echo "${output}" } # call with @@ -1388,6 +1574,7 @@ local list local pcatdir local protected + local i # very basic getops for i in $* @@ -1400,15 +1587,16 @@ shift done - # sanity checks; abort if not given - [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." +# it's not good to complain here about empty pnames; better to continue later anyway +# # sanity checks; abort if not given +# [ -z "${search_pname}" ] && die "get_uninstall_candidates() \$search_pname not given." # check needed global vars [ -z "${INSTALLDB}" ] && die "get_uninstall_candidates() \$INSTALLDB not set." # set pcatdir to '*' if empty - [ -z "${pcatdir}" ] && pcatdir=* + [ -z "${pcatdir}" ] && pcatdir='*' for pkg in ${MROOT}${INSTALLDB}/${pcatdir}/* do @@ -1493,10 +1681,11 @@ local oldline local line i local installed_file + local OLDIFS if virtuals_read ${virtualname} then - # make shure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already + # make sure ${PKG_NAME} is *not* in ${VIRTUAL_NAME} already for i in $(virtuals_read ${virtualname} showpkgs) do if [[ ${i} = ${pkgname} ]] @@ -1515,6 +1704,7 @@ # make a backup mv ${MROOT}${VIRTUALDB_FILE} ${MROOT}${VIRTUALDB_FILE}.old + OLDIFS="${IFS}" IFS=$'\n' for line in $(< ${MROOT}${VIRTUALDB_FILE}.old) do @@ -1526,10 +1716,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 @@ -1541,61 +1731,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 @@ -1603,9 +1800,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 } @@ -1637,9 +1836,9 @@ { local i - if [ -n "$@" ] + if [[ -n $* ]] then - for i in $@ + for i in $* do [[ ${MAGEDEBUG} = on ]] && \ echo "--- Including ${MAGEDIR}/include/${i}.minc" @@ -1653,9 +1852,9 @@ { local i - if [ -n "$@" ] + if [[ -n $* ]] then - for i in $@ + for i in $* do echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" source ${SMAGESCRIPTSDIR}/include/${i}.sminc @@ -1670,7 +1869,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} ]] @@ -1679,7 +1878,7 @@ echo -en ${COLRED}"An update for your packetmanager is available. "${COLDEFAULT} echo -e ${COLBLUE}"[ ${newest_mage} ]"${COLDEFAULT} echo "It is recommened to install this newer version" - echo "or your current system installation may brake." + echo "or your current system installation may break." echo echo -en "Please update mage by running " echo -e ${COLGREEN}"'mage install mage'"${COLDEFAULT} @@ -1951,6 +2150,9 @@ local magefile="$2" local value + [[ -z ${var} ]] && return 1 + [[ -z ${magefile} ]] && return 1 + # local all possible vars of a mage file # to prevent bad issues local PKGNAME @@ -1961,8 +2163,12 @@ local SDEPEND local PROVIDE local PKGTYPE + local MAGE_TARGETS + local SPLIT_PACKAGE_BASE local preinstall local postinstall + local preremove + local postremove # sanity checks [ -f ${magefile} ] && source ${magefile} || \ @@ -1972,6 +2178,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 +2200,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -1997,6 +2211,7 @@ local count_current local magefile local src_install + local i # very basic getops for i in $* @@ -2070,9 +2285,48 @@ echo B:${pbuild} fi - smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 + if [[ -n ${MAGE_TARGETS} ]] + then + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + then + for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${pname/${MAGE_TARGETS}/}/${pname/${MAGE_TARGETS}/}-${pver}-${pbuild}.smage2 + fi + + elif [[ -n ${SPLIT_PACKAGE_BASE} ]] + then + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + then + for i in ${SMAGESCRIPTSDIR}/trunk/*/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${SPLIT_PACKAGE_BASE}/${SPLIT_PACKAGE_BASE}-${pver}-${pbuild}.smage2 + fi + + else + # basic svn compat + if [[ -d ${SMAGESCRIPTSDIR}/trunk ]] + then + for i in ${SMAGESCRIPTSDIR}/trunk/*/${pname}/${pname}-${pver}-${pbuild}.smage2 + do + smage2file="${i}" + done + else + smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 + fi + fi + if [ -f "${smage2file}" ] then + echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " smage2 ${smage2file} || die "compile failed" else echo @@ -2086,14 +2340,7 @@ if [[ ${PKGTYPE} != virtual ]] && \ [[ ${PKGTYPE} != sources ]] then - # show a verbose message on src-install - if [[ ${src_install} = true ]] - then - echo -ne "${COLBLUE} *** ${COLDEFAULT}" - echo -ne "merging files: " - echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" - echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" - fi + echo -e " ${COLBLUE}***${COLDEFAULT} merging files into system ... " build_doinstall ${PKGNAME} fi @@ -2149,6 +2396,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 +2506,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 +2560,8 @@ local PKGTYPE local preinstall local postinstall + local preremove + local postremove local pcat local pname @@ -2339,9 +2597,9 @@ echo -ne "${COLBLUE} <<< ${COLDEFAULT}" echo -n "removing: " echo -ne "${COLBLUE}${pcat}/${COLDEFAULT}" - echo -e "${COLGREEN}${pname}-${pver}-${pbuild}${COLDEFAULT}" + echo -e "${COLRED}${pname}-${pver}-${pbuild}${COLDEFAULT}" - magefile="${MAGEDIR}/${pcat}/${pname}/${pname}-${pver}-${pbuild}.mage" + magefile="${MROOT}${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" source ${magefile} ## preremove scripts @@ -2401,6 +2659,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 +2679,225 @@ 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 + local latest_available + local depsfull + local sdepsfull + local deps + local sdeps + local dep + local sign + + # only names no versions + result="$(find ${MAGEDIR} -mindepth 2 -maxdepth 2 -type d -name '*'${string}'*'| sed '/profiles/d' | sed '/includes/d')" + #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}) + + if [[ ! -z ${magefile} ]] + then + # 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 + + latest_available="${pver}-${pbuild}" + else + # package is masked + state="${COLRED}[m] " + latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" + fi + + depsfull="$(get_value_from_magefile DEPEND ${magefile})" + sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" + + while read sign dep + do + case ${dep} in + "") continue;; + esac + + deps="${deps} $(basename ${dep%-*})" + done << EOF +${depsfull} +EOF + + while read sign dep + do + case ${dep} in + "") continue;; + esac + + sdeps="${sdeps} $(basename ${dep%-*})" + done << EOF +${sdepsfull} +EOF + + echo -e "${state}${pcat}/${pname}"${COLDEFAULT} + echo -e " Latest available: ${latest_available}" + echo " Installed versions: ${all_installed}" + echo " Description: ${description}" + echo " Homepage: ${homepage}" + echo " Depends: ${deps}" + echo " SDepends: ${sdeps}" + echo + + unset pcat + unset pname + unset magefile + unset pver + unset pbuild + unset state + unset descriptiom + unset homepage + unset all_installed + unset ipver + unset ipbuild + unset depsfull + unset sdepsfull + unset deps + unset sdeps + unset dep + unset sign + 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 +} + +mlibdir() +{ + local libdir=lib + [[ ${ARCH} = x86_64 ]] && libdir=lib64 + + echo "${libdir}" +} + +## blacklisted ${magefile} +blacklisted() +{ + [[ -z ${MAGE_DISTRIBUTION} ]] && local MAGE_DISTRIBUTION=stable + + # compat + [[ ${USE_UNSTABLE} = true ]] && local MAGE_DISTRIBUTION=unstable + [[ ${USE_TESTING} = true ]] && local MAGE_DISTRIBUTION=testing + + # support both types for the moment + if [[ -f /etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION} ]] + then + local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" + else + local EXCLUDED="/etc/mage-profile/package.blacklist-${ARCH}" + fi + + # return 0 if the list not exist; nothin is masked + [[ ! -f ${EXCLUDED} ]] && return 0 + + local MAGEFILE="$1" + + local PCAT="$(magename2pcat ${MAGEFILE})" + local PNAME="$(magename2pname ${MAGEFILE})" + local PVER="$(magename2pver ${MAGEFILE})" + local PBUILD="$(magename2pbuild ${MAGEFILE})" + + local EXPCAT EXPNAME EXPVER EXPBUILD + while read EXPCAT EXPNAME EXPVER EXPBUILD + do + # ignore spaces and comments + case "${EXPCAT}" in + \#*|"") continue ;; + esac + + # exclude full pver + if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && + [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && + [[ -n ${PVER} ]] && [[ -n ${PBUILD} ]] && + [[ -n ${EXPVER} ]] && [[ -n ${EXPBUILD} ]] + then + [[ ${EXPCAT}/${EXPNAME}-${EXPVER}-${EXPBUILD} = ${PCAT}/${PNAME}-${PVER}-${PBUILD} ]] && return 1 + fi + + # exclude pcat/pname only + if [[ -n ${PCAT} ]] && [[ -n ${PNAME} ]] && + [[ -n ${EXPCAT} ]] && [[ -n ${EXPNAME} ]] && + [[ -z ${EXPVER} ]] && [[ -z ${EXPBUILD} ]] + then + [[ ${EXPCAT}/${EXPNAME} = ${PCAT}/${PNAME} ]] && return 1 + fi + done << EOF +$( cat ${EXCLUDED}; echo) +EOF + + return 0 +} +