--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/03/10 18:08:47 1639 +++ mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2014/01/10 10:23:50 2139 @@ -1,5 +1,39 @@ # $Id$ +# loads client classes from $MCORE_LIBDIR +load_client_classes() +{ + local i + + # client specific + for i in $(find ${MCORE_LIBDIR}/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() # { @@ -64,9 +98,14 @@ 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:" @@ -86,7 +125,7 @@ # on newer xorg-servers root is not allowed to run progs in a user session x11runas() { - if pidof X + if [[ -n $(pidof X) ]] then su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" fi @@ -187,7 +226,8 @@ # show missing and set the right retval if [[ -z ${missing} ]] then - rvecho "${sorted}" + # do not escape, or CRLFS get printed to screen too + rvecho ${sorted} return 0 else for req in ${sorted} @@ -195,12 +235,14 @@ if no_duplicate "${missing}" "$req" then # print normal - rvecho -n " ${req}" + rvecho -n "${req} " else # print missing - eecho -n " ${req}" + eecho -n "${req} " fi done + # print CRLF + echo return 1 fi } @@ -229,7 +271,7 @@ # sort them alpabetically sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) # do not escape, or CRLFS get printed to screen too - rvecho ${sorted} + rvecho ${sorted} } # message only echo | disabled in quiet mode @@ -329,3 +371,103 @@ # 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" ;; + -name) shift; opts+=" -name $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} -printf '%f\n' | sort) + do + if [[ -z ${retval} ]] + then + retval="${i}" + else + retval+=" ${i}" + fi + done + + rvecho "${retval}" +} + +print_version() +{ + echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" +} + +system_chroot() +{ + local cmd="$@" + if [[ -z ${MROOT} ]] + then + echo "system_chroot(): \$MROOT was not set, doing nothing!" + return 1 + fi + if [ ! -d ${MROOT} ] + then + eecho "system_chroot(): MROOT='${MROOT}' does not exist." + return 1 + fi + + chroot ${MROOT} ${cmd} +} +