--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/02 21:17:54 1252 +++ mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/04 20:13:23 1264 @@ -64,6 +64,7 @@ mecho "\tauth - authenticate to the daemon" mecho "\tprovide - shows provides of a system" mecho "\thelp - shows help" + mecho "\tquit - quits the connection to the server" mecho mecho "Help topics:" for i in ${topics} @@ -75,12 +76,14 @@ mecho "\t${i}" done + mecho + mecho "Type 'help [topic]' for more information about every topic." } # on newer xorg-servers root is not allowed to run progs in a user session x11runas() { - su - "${MCORE_UNPRIV_USER}" -c "$@" + su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" } addconfig() @@ -113,6 +116,21 @@ : > ${CONFIG} } +# no_duplicate $list $item +no_duplicate() +{ + local i + local list="$1" + local item="$2" + + for i in ${list} + do + [[ ${i} = ${item} ]] && return 1 + done + + return 0 +} + require() { local requires="$@" @@ -120,21 +138,56 @@ for i in ${requires} do - export REQUIRE="${REQUIRE} ${i}" + # check for duplicate provides + if no_duplicate "${PROVIDE}" "${i}" + then + export REQUIRE="${REQUIRE} ${i}" + else + [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + fi done } -not_provided() +verify_requirements() { - local i - local item="$1" + local req + local prov + local missing + local sorted - for i in ${PROVIDE} + for req in ${REQUIRE} do - [[ ${i} = ${item} ]] && return 1 + # scan PROVIDE for dupes + # if a dupe is found, then requirement is fullfilled + # else add to missing + if no_duplicate "${PROVIDE}" "${req}" + then + missing="${missing} ${req}" + fi done - return 0 + # sort them alpabetically + sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) + + # show missing and set the right retval + if [[ -z ${missing} ]] + then + mecho "${sorted}" + return 0 + else + for req in ${sorted} + do + if no_duplicate "${missing}" "$req" + then + # print normal + mecho -n " ${req}" + else + # print missing + eecho -n " ${req}" + fi + done + return 1 + fi } provide() @@ -145,7 +198,7 @@ for i in ${provides} do # check for duplicate provides - if not_provided "${i}" + if no_duplicate "${PROVIDE}" "${i}" then export PROVIDE="${PROVIDE} ${i}" else @@ -168,11 +221,52 @@ { local COLCYAN="\033[1;36m" local COLDEFAULT="\033[0m" + local opts + if [[ ${NOCOLORS} = true ]] then COLCYAN="" COLDEFAULT="" fi - echo -e "${COLCYAN}$@${COLDEFAULT}" + # respect -n + case $1 in + -n) shift; opts="n" ;; + esac + + echo -e${opts} "${COLCYAN}$@${COLDEFAULT}" +} + +eecho() +{ + local COLRED="\033[1;31m" + local COLDEFAULT="\033[0m" + local opts + + if [[ ${NOCOLORS} = true ]] + then + COLRED="" + COLDEFAULT="" + fi + + # respect -n + case $1 in + -n) shift; opts="n" ;; + esac + + echo -e${opts} "${COLRED}$@${COLDEFAULT}" +} + +path_not_empty() +{ + local path="$1" + [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1 + + # return ERR if path does not exist + [[ ! -d ${path} ]] && return 1 + # return ERR if path empty + [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1 + + # every thing went ok, directory not empty + return 0 }