--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/17 21:42:57 1350 +++ mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/03/10 18:08:47 1639 @@ -44,7 +44,7 @@ then "${method}"_"${class}"_"${cmd}" ${argv} else - echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" + eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" fi else invalid_session @@ -65,6 +65,7 @@ mecho "\tprovide - shows provides of a system" mecho "\trequire - verify plugin requirements" mecho "\tnocolors - disable colors, useful for the webclient" + mecho "\tquiet - do not print any unecessary messages" mecho "\thelp - shows help" mecho "\tquit - quits the connection to the server" mecho @@ -85,7 +86,10 @@ # on newer xorg-servers root is not allowed to run progs in a user session x11runas() { - su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" + if pidof X + then + su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" + fi } addconfig() @@ -94,7 +98,7 @@ if [[ -z ${CONFIG} ]] then - echo "You must define \$CONFIG varibale first!" + eecho "You must define \$CONFIG varibale first!" return 1 fi @@ -116,7 +120,7 @@ { if [[ -z ${CONFIG} ]] then - echo "You must define \$CONFIG varibale first!" + eecho "You must define \$CONFIG varibale first!" return 1 fi @@ -154,7 +158,7 @@ then export REQUIRE="${REQUIRE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -183,7 +187,7 @@ # show missing and set the right retval if [[ -z ${missing} ]] then - mecho "${sorted}" + rvecho "${sorted}" return 0 else for req in ${sorted} @@ -191,7 +195,7 @@ if no_duplicate "${missing}" "$req" then # print normal - mecho -n " ${req}" + rvecho -n " ${req}" else # print missing eecho -n " ${req}" @@ -213,7 +217,7 @@ then export PROVIDE="${PROVIDE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -225,9 +229,10 @@ # sort them alpabetically sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) # do not escape, or CRLFS get printed to screen too - mecho ${sorted} + rvecho ${sorted} } +# message only echo | disabled in quiet mode mecho() { local COLCYAN="\033[1;36m" @@ -235,6 +240,9 @@ local opts local webcrlf + # print nothing if quiet mode was requested + [[ ${QUIET} = true ]] && return + if [[ ${NOCOLORS} = true ]] then COLCYAN="" @@ -251,6 +259,7 @@ echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" } +# prints error messages | enabled even in quiet mode eecho() { local COLRED="\033[1;31m" @@ -274,10 +283,43 @@ echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" } +# prints return values of get | enabled even in quiet mode +rvecho() +{ + local COLPURPLE="\033[1;35m" + local COLDEFAULT="\033[0m" + local opts + local webcrlf + + if [[ ${NOCOLORS} = true ]] + then + COLPURPLE="" + COLDEFAULT="" + fi + + [[ ${WEBCRLF} = true ]] && webcrlf="
" + + # respect -n + case $1 in + -n) shift; opts="n" ;; + esac + + echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" +} + +# prints debug messages if requested | enabled even in quiet mode +decho() +{ + # print nothing if debug mode was *not* requested + [[ ${DEBUG} != 1 ]] && return + + eecho "DEBUG: ${@}" +} + path_not_empty() { local path="$1" - [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1 + [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 # return ERR if path does not exist [[ ! -d ${path} ]] && return 1