Magellan Linux

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

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

revision 1252 by niro, Wed Feb 2 21:17:54 2011 UTC revision 1915 by niro, Wed Nov 9 13:24:00 2011 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  # # import_resource $table $serial $resource $value  # # import_resource $table $serial $resource $value
24  # import_resource()  # import_resource()
25  # {  # {
# Line 26  run_class() Line 46  run_class()
46   local cmd   local cmd
47   local argv   local argv
48    
49   if validate_session   if valid_session
50   then   then
51   class="${caller%.*}"   class="${caller%.*}"
52   cmd="${caller#*.}"   cmd="${caller#*.}"
# Line 44  run_class() Line 64  run_class()
64   then   then
65   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}" ${argv}
66   else   else
67   echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"
68   fi   fi
69   else   else
70   invalid_session   invalid_session
# Line 58  help_topics() Line 78  help_topics()
78    
79   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
80   mecho "Global commands:"   mecho "Global commands:"
81   mecho "\timport  - import settings to database"   mecho "\timport   - import settings to database"
82   mecho "\tget     - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
83   mecho "\tset     - sets value for a setting"   mecho "\tset      - sets value for a setting"
84   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
85   mecho "\tprovide - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
86   mecho "\thelp    - shows help"   mecho "\trequire  - verify plugin requirements"
87     mecho "\tnocolors - disable colors, useful for the webclient"
88     mecho "\tquiet    - do not print any unecessary messages"
89     mecho "\thelp     - shows help"
90     mecho "\tquit     - quits the connection to the server"
91   mecho   mecho
92   mecho "Help topics:"   mecho "Help topics:"
93   for i in ${topics}   for i in ${topics}
# Line 75  help_topics() Line 99  help_topics()
99    
100   mecho "\t${i}"   mecho "\t${i}"
101   done   done
102     mecho
103     mecho "Type 'help [topic]' for more information about every topic."
104  }  }
105    
106  # 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
107  x11runas()  x11runas()
108  {  {
109   su - "${MCORE_UNPRIV_USER}" -c "$@"   if [[ -n $(pidof X) ]]
110     then
111     su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
112     fi
113  }  }
114    
115  addconfig()  addconfig()
116  {  {
117     local opts
118    
119   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
120   then   then
121   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
122   return 1   return 1
123   fi   fi
124    
# Line 95  addconfig() Line 126  addconfig()
126   then   then
127   install -d $(dirname ${CONFIG})   install -d $(dirname ${CONFIG})
128   fi   fi
129   echo "$@" >> ${CONFIG}  
130     # check for opts
131     case $1 in
132     -n) shift; opts=" -n" ;;
133     -e) shift; opts=" -e" ;;
134     esac
135    
136     echo ${opts} "$@" >> ${CONFIG}
137  }  }
138    
139  clearconfig()  clearconfig()
140  {  {
141   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
142   then   then
143   echo "You must define \$CONFIG varibale first!"   eecho "You must define \$CONFIG varibale first!"
144   return 1   return 1
145   fi   fi
146    
# Line 113  clearconfig() Line 151  clearconfig()
151   : > ${CONFIG}   : > ${CONFIG}
152  }  }
153    
154    # no_duplicate $list $item
155    no_duplicate()
156    {
157     local i
158     local list="$1"
159     local item="$2"
160    
161     for i in ${list}
162     do
163     [[ ${i} = ${item} ]] && return 1
164     done
165    
166     return 0
167    }
168    
169  require()  require()
170  {  {
171   local requires="$@"   local requires="$@"
# Line 120  require() Line 173  require()
173    
174   for i in ${requires}   for i in ${requires}
175   do   do
176   export REQUIRE="${REQUIRE} ${i}"   # check for duplicate provides
177     if no_duplicate "${PROVIDE}" "${i}"
178     then
179     export REQUIRE="${REQUIRE} ${i}"
180     else
181     decho "duplicate provide '${i}' detected!"
182     fi
183   done   done
184  }  }
185    
186  not_provided()  verify_requirements()
187  {  {
188   local i   local req
189   local item="$1"   local prov
190     local missing
191     local sorted
192    
193   for i in ${PROVIDE}   for req in ${REQUIRE}
194   do   do
195   [[ ${i} = ${item} ]] && return 1   # scan PROVIDE for dupes
196     # if a dupe is found, then requirement is fullfilled
197     # else add to missing
198     if no_duplicate "${PROVIDE}" "${req}"
199     then
200     missing="${missing} ${req}"
201     fi
202   done   done
203    
204   return 0   # sort them alpabetically
205     sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort)
206    
207     # show missing and set the right retval
208     if [[ -z ${missing} ]]
209     then
210     rvecho "${sorted}"
211     return 0
212     else
213     for req in ${sorted}
214     do
215     if no_duplicate "${missing}" "$req"
216     then
217     # print normal
218     rvecho -n " ${req}"
219     else
220     # print missing
221     eecho -n " ${req}"
222     fi
223     done
224     return 1
225     fi
226  }  }
227    
228  provide()  provide()
# Line 145  provide() Line 233  provide()
233   for i in ${provides}   for i in ${provides}
234   do   do
235   # check for duplicate provides   # check for duplicate provides
236   if not_provided "${i}"   if no_duplicate "${PROVIDE}" "${i}"
237   then   then
238   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
239   else   else
240   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
241   fi   fi
242   done   done
243  }  }
# Line 161  print_provide() Line 249  print_provide()
249   # sort them alpabetically   # sort them alpabetically
250   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
251   # do not escape, or CRLFS get printed to screen too   # do not escape, or CRLFS get printed to screen too
252   mecho ${sorted}   rvecho ${sorted}
253  }  }
254    
255    # message only echo | disabled in quiet mode
256  mecho()  mecho()
257  {  {
258   local COLCYAN="\033[1;36m"   local COLCYAN="\033[1;36m"
259   local COLDEFAULT="\033[0m"   local COLDEFAULT="\033[0m"
260     local opts
261     local webcrlf
262    
263     # print nothing if quiet mode was requested
264     [[ ${QUIET} = true ]] && return
265    
266   if [[ ${NOCOLORS} = true ]]   if [[ ${NOCOLORS} = true ]]
267   then   then
268   COLCYAN=""   COLCYAN=""
269   COLDEFAULT=""   COLDEFAULT=""
270   fi   fi
271    
272   echo -e "${COLCYAN}$@${COLDEFAULT}"   [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
273    
274     # respect -n
275     case $1 in
276     -n) shift; opts="n" ;;
277     esac
278    
279     echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"
280    }
281    
282    # prints error messages | enabled even in quiet mode
283    eecho()
284    {
285     local COLRED="\033[1;31m"
286     local COLDEFAULT="\033[0m"
287     local opts
288     local webcrlf
289    
290     if [[ ${NOCOLORS} = true ]]
291     then
292     COLRED=""
293     COLDEFAULT=""
294     fi
295    
296     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
297    
298     # respect -n
299     case $1 in
300     -n) shift; opts="n" ;;
301     esac
302    
303     echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"
304    }
305    
306    # prints return values of get | enabled even in quiet mode
307    rvecho()
308    {
309     local COLPURPLE="\033[1;35m"
310     local COLDEFAULT="\033[0m"
311     local opts
312     local webcrlf
313    
314     if [[ ${NOCOLORS} = true ]]
315     then
316     COLPURPLE=""
317     COLDEFAULT=""
318     fi
319    
320     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
321    
322     # respect -n
323     case $1 in
324     -n) shift; opts="n" ;;
325     esac
326    
327     echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"
328    }
329    
330    # prints debug messages if requested | enabled even in quiet mode
331    decho()
332    {
333     # print nothing if debug mode was *not* requested
334     [[ ${DEBUG} != 1 ]] && return
335    
336     eecho "DEBUG: ${@}"
337    }
338    
339    path_not_empty()
340    {
341     local path="$1"
342     [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1
343    
344     # return ERR if path does not exist
345     [[ ! -d ${path} ]] && return 1
346     # return ERR if path empty
347     [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1
348    
349     # every thing went ok, directory not empty
350     return 0
351  }  }

Legend:
Removed from v.1252  
changed lines
  Added in v.1915