Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1308 by niro, Sun Feb 6 23:48:20 2011 UTC revision 2115 by niro, Thu Jan 2 16:28:46 2014 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3    # loads client classes from $MCLIBDIR
4    load_client_classes()
5    {
6     local i
7    
8     # client specific
9     for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class)
10     do
11     source ${i} || eecho "error loading ${i}"
12     done
13    }
14    
15    # restarts the whole service via remote cmd
16    restart_service()
17    {
18     local pid
19     for pid in $(pidof sslsvd)
20     do
21     kill -SIGHUP ${pid}
22     done
23    }
24    
25    # stops the whole service via remote cmd
26    stop_service()
27    {
28     local pid
29     for pid in $(pidof sslsvd)
30     do
31     kill -15 ${pid}
32     sleep 1
33     kill -9 ${pid}
34     done
35    }
36    
37  # # import_resource $table $serial $resource $value  # # import_resource $table $serial $resource $value
38  # import_resource()  # import_resource()
39  # {  # {
# Line 44  run_class() Line 78  run_class()
78   then   then
79   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}" ${argv}
80   else   else
81   echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"
82   fi   fi
83   else   else
84   invalid_session   invalid_session
# Line 58  help_topics() Line 92  help_topics()
92    
93   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
94   mecho "Global commands:"   mecho "Global commands:"
95   mecho "\timport  - import settings to database"   mecho "\timport   - import settings to database"
96   mecho "\tget     - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
97   mecho "\tset     - sets value for a setting"   mecho "\tset      - sets value for a setting"
98   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
99   mecho "\tprovide - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
100   mecho "\trequire - verify plugin requirements"   mecho "\trequire  - verify plugin requirements"
101   mecho "\nocolors - disable colors, useful for the webclient"   mecho "\treload   - reloads all client classes plugins"
102   mecho "\thelp    - shows help"   mecho "\trestart  - restarts the daemon"
103   mecho "\tquit    - quits the connection to the server"   mecho "\tstop     - stops the daemon"
104     mecho "\tnocolors - disable colors, useful for the webclient"
105     mecho "\tcolors   - enable colors"
106     mecho "\tquiet    - do not print any unecessary messages"
107     mecho "\thelp     - shows help"
108     mecho "\tversion  - prints version of the daemon"
109     mecho "\tquit     - quits the connection to the server"
110   mecho   mecho
111   mecho "Help topics:"   mecho "Help topics:"
112   for i in ${topics}   for i in ${topics}
# Line 85  help_topics() Line 125  help_topics()
125  # on newer xorg-servers root is not allowed to run progs in a user session  # on newer xorg-servers root is not allowed to run progs in a user session
126  x11runas()  x11runas()
127  {  {
128   su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"   if [[ -n $(pidof X) ]]
129     then
130     su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
131     fi
132  }  }
133    
134  addconfig()  addconfig()
# Line 94  addconfig() Line 137  addconfig()
137    
138   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
139   then   then
140   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
141   return 1   return 1
142   fi   fi
143    
# Line 116  clearconfig() Line 159  clearconfig()
159  {  {
160   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
161   then   then
162   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
163   return 1   return 1
164   fi   fi
165    
# Line 154  require() Line 197  require()
197   then   then
198   export REQUIRE="${REQUIRE} ${i}"   export REQUIRE="${REQUIRE} ${i}"
199   else   else
200   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
201   fi   fi
202   done   done
203  }  }
# Line 183  verify_requirements() Line 226  verify_requirements()
226   # show missing and set the right retval   # show missing and set the right retval
227   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
228   then   then
229   mecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
230     rvecho ${sorted}
231   return 0   return 0
232   else   else
233   for req in ${sorted}   for req in ${sorted}
# Line 191  verify_requirements() Line 235  verify_requirements()
235   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
236   then   then
237   # print normal   # print normal
238   mecho -n " ${req}"   rvecho -n "${req} "
239   else   else
240   # print missing   # print missing
241   eecho -n " ${req}"   eecho -n "${req} "
242   fi   fi
243   done   done
244     # print CRLF
245     echo
246   return 1   return 1
247   fi   fi
248  }  }
# Line 213  provide() Line 259  provide()
259   then   then
260   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
261   else   else
262   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
263   fi   fi
264   done   done
265  }  }
# Line 225  print_provide() Line 271  print_provide()
271   # sort them alpabetically   # sort them alpabetically
272   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
273   # do not escape, or CRLFS get printed to screen too   # do not escape, or CRLFS get printed to screen too
274   mecho ${sorted}   rvecho ${sorted}
275  }  }
276    
277    # message only echo | disabled in quiet mode
278  mecho()  mecho()
279  {  {
280   local COLCYAN="\033[1;36m"   local COLCYAN="\033[1;36m"
# Line 235  mecho() Line 282  mecho()
282   local opts   local opts
283   local webcrlf   local webcrlf
284    
285     # print nothing if quiet mode was requested
286     [[ ${QUIET} = true ]] && return
287    
288   if [[ ${NOCOLORS} = true ]]   if [[ ${NOCOLORS} = true ]]
289   then   then
290   COLCYAN=""   COLCYAN=""
# Line 251  mecho() Line 301  mecho()
301   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"
302  }  }
303    
304    # prints error messages | enabled even in quiet mode
305  eecho()  eecho()
306  {  {
307   local COLRED="\033[1;31m"   local COLRED="\033[1;31m"
# Line 274  eecho() Line 325  eecho()
325   echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"   echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"
326  }  }
327    
328    # prints return values of get | enabled even in quiet mode
329    rvecho()
330    {
331     local COLPURPLE="\033[1;35m"
332     local COLDEFAULT="\033[0m"
333     local opts
334     local webcrlf
335    
336     if [[ ${NOCOLORS} = true ]]
337     then
338     COLPURPLE=""
339     COLDEFAULT=""
340     fi
341    
342     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
343    
344     # respect -n
345     case $1 in
346     -n) shift; opts="n" ;;
347     esac
348    
349     echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"
350    }
351    
352    # prints debug messages if requested | enabled even in quiet mode
353    decho()
354    {
355     # print nothing if debug mode was *not* requested
356     [[ ${DEBUG} != 1 ]] && return
357    
358     eecho "DEBUG: ${@}"
359    }
360    
361  path_not_empty()  path_not_empty()
362  {  {
363   local path="$1"   local path="$1"
364   [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1   [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1
365    
366   # return ERR if path does not exist   # return ERR if path does not exist
367   [[ ! -d ${path} ]] && return 1   [[ ! -d ${path} ]] && return 1
# Line 287  path_not_empty() Line 371  path_not_empty()
371   # every thing went ok, directory not empty   # every thing went ok, directory not empty
372   return 0   return 0
373  }  }
374    
375    help_daemon_mroot()
376    {
377     mecho "get daemon.mroot"
378     mecho " Prints current MROOT variable."
379     mecho
380     mecho "set daemon.mroot [path]"
381     mecho " set MROOT variable to given path."
382    }
383    
384    get_daemon_mroot()
385    {
386     rvecho "${MROOT}"
387    }
388    
389    set_daemon_mroot()
390    {
391     local path=$1
392    
393     if [[ -d ${path} ]]
394     then
395     export MROOT="${path}"
396     decho "MROOT='${MROOT}' is set."
397     else
398     eecho "Path '${path}' does not exist. MROOT not set."
399     fi
400    }
401    
402    list_files_in_directory()
403    {
404     local i
405     local retval
406     local path
407     local opts
408     local type
409    
410     # basic getops
411     for i in $*
412     do
413     case $1 in
414     -mindepth) shift; opts+=" -mindepth $1" ;;
415     -maxdepth) shift; opts+=" -maxdepth $1" ;;
416     -type) shift; type="$1" ;;
417     -name) shift; opts+=" -name $1" ;;
418     '') continue ;;
419     *) path="$1" ;;
420     esac
421     shift
422     done
423    
424     if [[ -z ${path} ]]
425     then
426     eecho "No path given."
427     return 1
428     fi
429    
430     if [[ ! -d ${path} ]]
431     then
432     eecho "Directory '${path}' does not exist."
433     return 1
434     fi
435    
436     # default to files
437     [[ -z ${type} ]] && type=f
438    
439     for i in $(find ${path} ${opts} -type ${type} -printf '%f\n' | sort)
440     do
441     if [[ -z ${retval} ]]
442     then
443     retval="${i}"
444     else
445     retval+=" ${i}"
446     fi
447     done
448    
449     rvecho "${retval}"
450    }
451    
452    print_version()
453    {
454     echo "mcored-$(<${MCLIBDIR}/VERSION)"
455    }
456    
457    system_chroot()
458    {
459     local cmd="$@"
460     if [[ -z ${MROOT} ]]
461     then
462     echo "system_chroot(): \$MROOT was not set, doing nothing!"
463     return 1
464     fi
465     if [ ! -d ${MROOT} ]
466     then
467     eecho "system_chroot(): MROOT='${MROOT}' does not exist."
468     return 1
469     fi
470    
471     chroot ${MROOT} ${cmd}
472    }
473    

Legend:
Removed from v.1308  
changed lines
  Added in v.2115