--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/10/21 14:50:13 273 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2007/04/10 09:21:55 458 @@ -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.8 2005-10-21 14:50:13 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.31 2007-04-10 09:21:55 niro Exp $ mage_setup() { @@ -361,6 +361,8 @@ local pkgname="$1" local pathto local posix + local major + local minor local IFS # sanity checks; abort if not given @@ -374,12 +376,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 @@ -556,14 +558,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 - for i in ${provide} - do - virtuals_del "${i}" "${pcat}/${pname}" - done + # 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 @@ -573,6 +579,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 # @@ -765,10 +804,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}" @@ -1042,7 +1106,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 @@ -1094,7 +1158,7 @@ --continue \ --progress bar \ --directory-prefix=${PKGDIR} \ - ${opt} ${mirr}/packages/${pkg} + ${opt} ${mirr}/${PACKAGES_SERVER_PATH}/${pkg} if [[ $? = 0 ]] then break @@ -1117,26 +1181,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 @@ -1189,7 +1240,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 @@ -1222,11 +1273,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 ;; @@ -1235,7 +1289,7 @@ fi # state unstable - if [[ ${USE_UNSTABLE} = true ]] + if [[ ${USE_UNSTABLE} = true ]] || [[ ${MAGE_DISTRIBUTION} = unstable ]] then case ${STATE} in unstable|testing|stable) return 0 ;; @@ -1273,26 +1327,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 @@ -1320,7 +1375,7 @@ 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=' ' @@ -1330,7 +1385,7 @@ do # ersetzen von $i nur wenn am anfang der variable TEST="${EXPFILE/#${MROOT}${i}/Protected}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then # setzen das es protected ist PROTECTED=TRUE @@ -1339,7 +1394,7 @@ for x in ${CONFIG_PROTECT_MASK} do TEST="${EXPFILE/#${MROOT}${x}/Protect_Masked}" - if [ "${TEST}" != "${EXPFILE}" ] + if [[ ${TEST} != ${EXPFILE} ]] then PROTECTED=MASKED fi @@ -1392,6 +1447,7 @@ local list local pcatdir local protected + local i # very basic getops for i in $* @@ -1404,15 +1460,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 @@ -1501,7 +1558,7 @@ 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} ]] @@ -1652,9 +1709,9 @@ { local i - if [ -n "$@" ] + if [[ -n $* ]] then - for i in $@ + for i in $* do [[ ${MAGEDEBUG} = on ]] && \ echo "--- Including ${MAGEDIR}/include/${i}.minc" @@ -1668,9 +1725,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 @@ -1694,7 +1751,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} @@ -1966,6 +2023,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 @@ -2098,6 +2158,7 @@ smage2file=${SMAGESCRIPTSDIR}/${pname}/${pname}-${pver}-${pbuild}.smage2 if [ -f "${smage2file}" ] then + echo -e " ${COLBLUE}***${COLDEFAULT} building package from source ... " smage2 ${smage2file} || die "compile failed" else echo @@ -2111,14 +2172,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 @@ -2375,7 +2429,7 @@ 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="${INSTALLDB}/${pcat}/${pname}-${pver}-${pbuild}/${pname}-${pver}-${pbuild}.mage" source ${magefile} @@ -2475,10 +2529,17 @@ 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}*)" - #result="$(find ${MAGEDIR} -type f -name *${string}*.mage | sort)" + 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." @@ -2492,40 +2553,76 @@ # 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})" + 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 - # all installed - for i in $(get_uninstall_candidates --pname ${pname} --pcat ${pcat}) - do - ipver="$(magename2pver ${i})" - ipbuild="$(magename2pbuild ${i})" + latest_available="${pver}-${pbuild}" + else + # package is masked + state="${COLRED}[m] " + latest_available="${COLRED}masked for this distribution.${COLDEFAULT}" + fi - if [[ -z ${all_installed} ]] - then - all_installed="${ipver}-${ipbuild}" - else - all_installed="${all_installed} ${ipver}-${ipbuild}" - fi - done - [[ -z ${all_installed} ]] && all_installed="none" + depsfull="$(get_value_from_magefile DEPEND ${magefile})" + sdepsfull="$(get_value_from_magefile SDEPEND ${magefile})" - case ${state} in - stable) state=${COLGREEN}"[s] ";; - testing) state=${COLYELLOW}"[t] ";; - unstable) state=${COLRED}"[u] ";; - old) state=${COLGRAY}"[o] ";; - esac + 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 " Latest available: ${pver}-${pbuild}" + 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 @@ -2539,6 +2636,12 @@ unset all_installed unset ipver unset ipbuild + unset depsfull + unset sdepsfull + unset deps + unset sdeps + unset dep + unset sign done } @@ -2563,3 +2666,64 @@ 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 + + local EXCLUDED="${MROOT}/etc/mage-profile/package.blacklist-${ARCH}-${MAGE_DISTRIBUTION}" + + # 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 +} +