--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2013/05/10 13:14:35 2083 +++ mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in 2014/01/20 14:04:52 2303 @@ -1,14 +1,20 @@ # $Id$ -# loads client classes from $MCLIBDIR -load_client_classes() +# loads client classes from $MCORE_LIBDIR +load_classes() { - local i + local class + local classtype + + case $1 in + client|control) classtype="$1" ;; + *) die "Unknown classes type '$1'" ;; + esac # client specific - for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class) + for class in $(find ${MCORE_LIBDIR}/include -type f -name \*.${classtype}.class) do - source ${i} || eecho "error loading ${i}" + include ${class} || eecho "error loading ${class}" done } @@ -28,9 +34,7 @@ local pid for pid in $(pidof sslsvd) do - kill -15 ${pid} - sleep 1 - kill -9 ${pid} + kill -SIGTERM ${pid} done } @@ -54,31 +58,38 @@ # run_class $method $caller $argv1 $argv2 ... $argvN run_class() { - local method="$1" - local caller="$2" + local method="${GLOBAL_ARGV[0]}" + local caller="${GLOBAL_ARGV[1]}" local class local cmd - local argv + local i + local count if valid_session then class="${caller%.*}" cmd="${caller#*.}" - argv="${@/${caller}/}" # remove caller - argv="${argv/${method}/}" # remove method -# echo "method=${method}" -# echo "caller=${caller}" -# echo "class=${class}" -# echo "cmd=${cmd}" -# echo "argv=${argv}" + # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class + unset CLASS_ARGV + count="${#GLOBAL_ARGV[*]}" + for (( i=2; i> ${CONFIG} -} - -clearconfig() -{ - if [[ -z ${CONFIG} ]] - then - eecho "You must define \$CONFIG varibale first!" - return 1 - fi - - if [[ ! -d $(dirname ${CONFIG}) ]] - then - install -d $(dirname ${CONFIG}) - fi - : > ${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="$@" @@ -226,7 +174,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} @@ -234,12 +183,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 } @@ -271,104 +222,6 @@ 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 - COLCYAN="" - COLDEFAULT="" - fi - - [[ ${WEBCRLF} = true ]] && webcrlf="
" - - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac - - 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 - COLRED="" - 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} "${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} ]] && eecho "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 -} - help_daemon_mroot() { mecho "get daemon.mroot" @@ -396,75 +249,7 @@ 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} -print '%f\n' | sort) - do - if [[ -z ${retval} ]] - then - retval="${i}" - else - retval+=" ${i}" - fi - done - - rvecho "${retval}" -} - print_version() { - echo "mcored-$(<${MCLIBDIR}/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} -} -