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 1330 by niro, Wed Feb 16 18:24:35 2011 UTC revision 2005 by niro, Mon Aug 13 09:38:21 2012 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3    # loads client classes from $MCLIBDIR
4    load_client_classes()
5    {
6     # client specific
7     for i in ${MCLIBDIR}/include/*.client.class
8     do
9     source ${i} || eecho "error loading ${i}"
10     done
11    }
12    
13    # restarts the whole service via remote cmd
14    restart_service()
15    {
16     local pid
17     for pid in $(pidof sslsvd)
18     do
19     kill -SIGHUP ${pid}
20     done
21    }
22    
23    # stops the whole service via remote cmd
24    stop_service()
25    {
26     local pid
27     for pid in $(pidof sslsvd)
28     do
29     kill -15 ${pid}
30     sleep 1
31     kill -9 ${pid}
32     done
33    }
34    
35  # # import_resource $table $serial $resource $value  # # import_resource $table $serial $resource $value
36  # import_resource()  # import_resource()
37  # {  # {
# Line 44  run_class() Line 76  run_class()
76   then   then
77   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}" ${argv}
78   else   else
79   echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"
80   fi   fi
81   else   else
82   invalid_session   invalid_session
# Line 58  help_topics() Line 90  help_topics()
90    
91   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
92   mecho "Global commands:"   mecho "Global commands:"
93   mecho "\timport  - import settings to database"   mecho "\timport   - import settings to database"
94   mecho "\tget     - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
95   mecho "\tset     - sets value for a setting"   mecho "\tset      - sets value for a setting"
96   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
97   mecho "\tprovide - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
98   mecho "\trequire - verify plugin requirements"   mecho "\trequire  - verify plugin requirements"
99     mecho "\treload   - reloads all client classes plugins"
100     mecho "\trestart  - restarts the daemon"
101     mecho "\tstop     - stops the daemon"
102   mecho "\tnocolors - disable colors, useful for the webclient"   mecho "\tnocolors - disable colors, useful for the webclient"
103   mecho "\thelp    - shows help"   mecho "\tquiet    - do not print any unecessary messages"
104   mecho "\tquit    - quits the connection to the server"   mecho "\thelp     - shows help"
105     mecho "\tquit     - quits the connection to the server"
106   mecho   mecho
107   mecho "Help topics:"   mecho "Help topics:"
108   for i in ${topics}   for i in ${topics}
# Line 85  help_topics() Line 121  help_topics()
121  # 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
122  x11runas()  x11runas()
123  {  {
124   su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"   if [[ -n $(pidof X) ]]
125     then
126     su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
127     fi
128  }  }
129    
130  addconfig()  addconfig()
# Line 94  addconfig() Line 133  addconfig()
133    
134   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
135   then   then
136   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
137   return 1   return 1
138   fi   fi
139    
# Line 116  clearconfig() Line 155  clearconfig()
155  {  {
156   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
157   then   then
158   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
159   return 1   return 1
160   fi   fi
161    
# Line 154  require() Line 193  require()
193   then   then
194   export REQUIRE="${REQUIRE} ${i}"   export REQUIRE="${REQUIRE} ${i}"
195   else   else
196   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
197   fi   fi
198   done   done
199  }  }
# Line 183  verify_requirements() Line 222  verify_requirements()
222   # show missing and set the right retval   # show missing and set the right retval
223   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
224   then   then
225   mecho "${sorted}"   rvecho "${sorted}"
226   return 0   return 0
227   else   else
228   for req in ${sorted}   for req in ${sorted}
# Line 191  verify_requirements() Line 230  verify_requirements()
230   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
231   then   then
232   # print normal   # print normal
233   mecho -n " ${req}"   rvecho -n " ${req}"
234   else   else
235   # print missing   # print missing
236   eecho -n " ${req}"   eecho -n " ${req}"
# Line 213  provide() Line 252  provide()
252   then   then
253   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
254   else   else
255   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
256   fi   fi
257   done   done
258  }  }
# Line 225  print_provide() Line 264  print_provide()
264   # sort them alpabetically   # sort them alpabetically
265   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
266   # do not escape, or CRLFS get printed to screen too   # do not escape, or CRLFS get printed to screen too
267   mecho ${sorted}   rvecho ${sorted}
268  }  }
269    
270    # message only echo | disabled in quiet mode
271  mecho()  mecho()
272  {  {
273   local COLCYAN="\033[1;36m"   local COLCYAN="\033[1;36m"
# Line 235  mecho() Line 275  mecho()
275   local opts   local opts
276   local webcrlf   local webcrlf
277    
278     # print nothing if quiet mode was requested
279     [[ ${QUIET} = true ]] && return
280    
281   if [[ ${NOCOLORS} = true ]]   if [[ ${NOCOLORS} = true ]]
282   then   then
283   COLCYAN=""   COLCYAN=""
# Line 251  mecho() Line 294  mecho()
294   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"
295  }  }
296    
297    # prints error messages | enabled even in quiet mode
298  eecho()  eecho()
299  {  {
300   local COLRED="\033[1;31m"   local COLRED="\033[1;31m"
# Line 274  eecho() Line 318  eecho()
318   echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"   echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"
319  }  }
320    
321    # prints return values of get | enabled even in quiet mode
322    rvecho()
323    {
324     local COLPURPLE="\033[1;35m"
325     local COLDEFAULT="\033[0m"
326     local opts
327     local webcrlf
328    
329     if [[ ${NOCOLORS} = true ]]
330     then
331     COLPURPLE=""
332     COLDEFAULT=""
333     fi
334    
335     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
336    
337     # respect -n
338     case $1 in
339     -n) shift; opts="n" ;;
340     esac
341    
342     echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"
343    }
344    
345    # prints debug messages if requested | enabled even in quiet mode
346    decho()
347    {
348     # print nothing if debug mode was *not* requested
349     [[ ${DEBUG} != 1 ]] && return
350    
351     eecho "DEBUG: ${@}"
352    }
353    
354  path_not_empty()  path_not_empty()
355  {  {
356   local path="$1"   local path="$1"
357   [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1   [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1
358    
359   # return ERR if path does not exist   # return ERR if path does not exist
360   [[ ! -d ${path} ]] && return 1   [[ ! -d ${path} ]] && return 1

Legend:
Removed from v.1330  
changed lines
  Added in v.2005