--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/04 20:13:23 1264 +++ mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2013/05/08 11:04:43 2044 @@ -1,5 +1,39 @@ # $Id$ +# loads client classes from $MCLIBDIR +load_client_classes() +{ + local i + + # client specific + for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class) + do + source ${i} || eecho "error loading ${i}" + done +} + +# restarts the whole service via remote cmd +restart_service() +{ + local pid + for pid in $(pidof sslsvd) + do + kill -SIGHUP ${pid} + done +} + +# stops the whole service via remote cmd +stop_service() +{ + local pid + for pid in $(pidof sslsvd) + do + kill -15 ${pid} + sleep 1 + kill -9 ${pid} + done +} + # # import_resource $table $serial $resource $value # import_resource() # { @@ -26,7 +60,7 @@ local cmd local argv - if validate_session + if valid_session then class="${caller%.*}" cmd="${caller#*.}" @@ -44,7 +78,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 @@ -58,13 +92,21 @@ topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) mecho "Global commands:" - mecho "\timport - import settings to database" - mecho "\tget - shows current value for a settings" - mecho "\tset - sets value for a setting" - 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 "\timport - import settings to database" + mecho "\tget - shows current value for a settings" + mecho "\tset - sets value for a setting" + mecho "\tauth - authenticate to the daemon" + mecho "\tprovide - shows provides of a system" + mecho "\trequire - verify plugin requirements" + mecho "\treload - reloads all client classes plugins" + mecho "\trestart - restarts the daemon" + mecho "\tstop - stops the daemon" + mecho "\tnocolors - disable colors, useful for the webclient" + mecho "\tcolors - enable colors" + mecho "\tquiet - do not print any unecessary messages" + mecho "\thelp - shows help" + mecho "\tversion - prints version of the daemon" + mecho "\tquit - quits the connection to the server" mecho mecho "Help topics:" for i in ${topics} @@ -83,14 +125,19 @@ # 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 [[ -n $(pidof X) ]] + then + su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" + fi } addconfig() { + local opts + if [[ -z ${CONFIG} ]] then - echo "You must define \$CONFIG varibale first!" + eecho "You must define \$CONFIG varibale first!" return 1 fi @@ -98,14 +145,21 @@ then install -d $(dirname ${CONFIG}) fi - echo "$@" >> ${CONFIG} + + # check for opts + case $1 in + -n) shift; opts=" -n" ;; + -e) shift; opts=" -e" ;; + esac + + echo ${opts} "$@" >> ${CONFIG} } clearconfig() { if [[ -z ${CONFIG} ]] then - echo "You must define \$CONFIG varibale first!" + eecho "You must define \$CONFIG varibale first!" return 1 fi @@ -143,7 +197,7 @@ then export REQUIRE="${REQUIRE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -172,7 +226,7 @@ # show missing and set the right retval if [[ -z ${missing} ]] then - mecho "${sorted}" + rvecho "${sorted}" return 0 else for req in ${sorted} @@ -180,7 +234,7 @@ if no_duplicate "${missing}" "$req" then # print normal - mecho -n " ${req}" + rvecho -n " ${req}" else # print missing eecho -n " ${req}" @@ -202,7 +256,7 @@ then export PROVIDE="${PROVIDE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -214,14 +268,19 @@ # 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" local COLDEFAULT="\033[0m" local opts + local webcrlf + + # print nothing if quiet mode was requested + [[ ${QUIET} = true ]] && return if [[ ${NOCOLORS} = true ]] then @@ -229,19 +288,23 @@ COLDEFAULT="" fi + [[ ${WEBCRLF} = true ]] && webcrlf="
" + # respect -n case $1 in -n) shift; opts="n" ;; esac - echo -e${opts} "${COLCYAN}$@${COLDEFAULT}" + echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" } +# prints error messages | enabled even in quiet mode eecho() { local COLRED="\033[1;31m" local COLDEFAULT="\033[0m" local opts + local webcrlf if [[ ${NOCOLORS} = true ]] then @@ -249,18 +312,53 @@ COLDEFAULT="" fi + [[ ${WEBCRLF} = true ]] && webcrlf="
" + + # respect -n + case $1 in + -n) shift; opts="n" ;; + esac + + 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} "${COLRED}$@${COLDEFAULT}" + 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 @@ -270,3 +368,79 @@ # every thing went ok, directory not empty return 0 } + +help_daemon_mroot() +{ + mecho "get daemon.mroot" + mecho " Prints current MROOT variable." + mecho + mecho "set daemon.mroot [path]" + mecho " set MROOT variable to given path." +} + +get_daemon_mroot() +{ + rvecho "${MROOT}" +} + +set_daemon_mroot() +{ + local path=$1 + + if [[ -d ${path} ]] + then + export MROOT="${path}" + decho "MROOT='${MROOT}' is set." + else + eecho "Path '${path}' does not exist. MROOT not set." + fi +} + +list_files_in_directory() +{ + local i + local retval + local path + local opts + local type + + # basic getops + for i in $* + do + case $1 in + -mindepth) shift; opts+=" -mindepth $1" ;; + -maxdepth) shift; opts+=" -maxdepth $1" ;; + -type) shift; type="$1" ;; + '') continue ;; + *) path="$1" ;; + esac + shift + done + + if [[ -z ${path} ]] + then + eecho "No path given." + return 1 + fi + + if [[ ! -d ${path} ]] + then + eecho "Directory '${path}' does not exist." + return 1 + fi + + # default to files + [[ -z ${type} ]] && type=f + + for i in $(find ${path} ${opts} -type ${type} | sort) + do + if [[ -z ${retval} ]] + then + retval="$(basename ${i})" + else + retval="${retval} $(basename ${i})" + fi + done + + rvecho "${retval}" +}