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

mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class revision 2091 by niro, Mon May 13 07:06:33 2013 UTC mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in revision 2811 by niro, Fri Apr 7 07:31:40 2017 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3  # loads client classes from $MCLIBDIR  # loads client classes from $MCORE_LIBDIR
4  load_client_classes()  load_classes()
5  {  {
6   local i   local class
7     local classtype
8    
9     case $1 in
10     client|control) classtype="$1" ;;
11     *) die "Unknown classes type '$1'" ;;
12     esac
13    
14   # client specific   # client specific
15   for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class)   for class in $(find ${MCORE_LIBDIR}/include -type f -name \*.${classtype}.class)
16   do   do
17   source ${i} || eecho "error loading ${i}"   include ${class} || eecho "error loading ${class}"
18   done   done
19  }  }
20    
# Line 28  stop_service() Line 34  stop_service()
34   local pid   local pid
35   for pid in $(pidof sslsvd)   for pid in $(pidof sslsvd)
36   do   do
37   kill -15 ${pid}   kill -SIGTERM ${pid}
  sleep 1  
  kill -9 ${pid}  
38   done   done
39  }  }
40    
 # # import_resource $table $serial $resource $value  
 # import_resource()  
 # {  
 # local table="$1"  
 # local serial="$2"  
 # local resource="$3"  
 # local value="$4"  
 #  
 # if [[ ${DEBUG} = 1 ]]  
 # then  
 # echo "${table}->${resource}=${value}" >> /root/lala.log  
 # echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log  
 # fi  
 #  
 # mysql_insert "${table}",serial="${serial}","${resource}"="${value}"  
 # }  
   
41  # run_class $method $caller $argv1 $argv2 ... $argvN  # run_class $method $caller $argv1 $argv2 ... $argvN
42  run_class()  run_class()
43  {  {
44   local method="$1"   local method="${GLOBAL_ARGV[0]}"
45   local caller="$2"   local caller="${GLOBAL_ARGV[1]}"
46   local class   local class
47   local cmd   local cmd
48   local argv   local i
49     local count
50    
51   if valid_session   if valid_session
52   then   then
53   class="${caller%.*}"   class="${caller%.*}"
54   cmd="${caller#*.}"   cmd="${caller#*.}"
  argv="${@/${caller}/}" # remove caller  
  argv="${argv/${method}/}" # remove method  
55    
56  # echo "method=${method}"   # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class
57  # echo "caller=${caller}"   unset CLASS_ARGV
58  # echo "class=${class}"   count="${#GLOBAL_ARGV[*]}"
59  # echo "cmd=${cmd}"   for (( i=2; i<count; i++ ))
60  # echo "argv=${argv}"   do
61     CLASS_ARGV[${i}-2]="${GLOBAL_ARGV[${i}]}"
62     done
63    
64    # decho "method=${method}"
65    # decho "caller=${caller}"
66    # decho "class=${class}"
67    # decho "cmd=${cmd}"
68    # decho "class argv=$(printf '\"%s\" ' ${CLASS_ARGV[*]}; printf '\n')"
69    
70   # check if class.cmd exist   # check if class.cmd exist
71   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
72   then   then
73   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}"
74   else   else
75   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
76   fi   fi
77   else   else
78   invalid_session   invalid_session
79   fi   fi
80  }  }
81    
82    run_push_config()
83    {
84     local serial="$1"
85     local config
86    
87     if [[ -z ${serial} ]]
88     then
89     eecho "missing serial"
90     return 1
91     fi
92    
93     for config in $(NOCOLORS=1 print_push_config)
94     do
95     if [[ -n $(typeset -f push_config_${config}) ]]
96     then
97     decho "running: 'push_config_${config} ${serial}'"
98     push_config_"${config}" "${serial}"
99     else
100     decho "no function 'push_config_${config}' for '${config}' found."
101     fi
102     done
103    }
104    
105    run_push_firstboot()
106    {
107     local serial="$1"
108     local config
109    
110     if [[ -z ${serial} ]]
111     then
112     eecho "missing serial"
113     return 1
114     fi
115    
116     for config in $(NOCOLORS=1 print_push_firstboot)
117     do
118     if [[ -n $(typeset -f push_firstboot_${config}) ]]
119     then
120     decho "running: 'push_firstboot_${config} ${serial}'"
121     push_firstboot_"${config}" "${serial}"
122     else
123     decho "no function 'push_firstboot_${config}' for '${config}' found."
124     fi
125     done
126    }
127    
128  help_topics()  help_topics()
129  {  {
130   local i   local i
# Line 96  help_topics() Line 136  help_topics()
136   mecho "\tget      - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
137   mecho "\tset      - sets value for a setting"   mecho "\tset      - sets value for a setting"
138   mecho "\tauth     - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
139     mecho "\tcertauth - authenticate to the daemon via fingerprint"
140   mecho "\tprovide  - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
141   mecho "\trequire  - verify plugin requirements"   mecho "\trequire  - verify plugin requirements"
142   mecho "\treload   - reloads all client classes plugins"   mecho "\treload   - reloads all client classes plugins"
# Line 122  help_topics() Line 163  help_topics()
163   mecho "Type 'help [topic]' for more information about every topic."   mecho "Type 'help [topic]' for more information about every topic."
164  }  }
165    
 # on newer xorg-servers root is not allowed to run progs in a user session  
 x11runas()  
 {  
  if [[ -n $(pidof X) ]]  
  then  
  su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"  
  fi  
 }  
   
 addconfig()  
 {  
  local opts  
   
  if [[ -z ${CONFIG} ]]  
  then  
  eecho "You must define \$CONFIG varibale first!"  
  return 1  
  fi  
   
  if [[ ! -d $(dirname ${CONFIG}) ]]  
  then  
  install -d $(dirname ${CONFIG})  
  fi  
   
  # check for opts  
  case $1 in  
  -n) shift; opts=" -n" ;;  
  -e) shift; opts=" -e" ;;  
  esac  
   
  echo ${opts} "$@" >> ${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  
 }  
   
166  require()  require()
167  {  {
168   local requires="$@"   local requires="$@"
# Line 192  require() Line 170  require()
170    
171   for i in ${requires}   for i in ${requires}
172   do   do
173   # check for duplicate provides   # check for duplicate require
174   if no_duplicate "${PROVIDE}" "${i}"   if no_duplicate "${REQUIRE}" "${i}"
175   then   then
176   export REQUIRE="${REQUIRE} ${i}"   export REQUIRE="${REQUIRE} ${i}"
177   else   else
178   decho "duplicate provide '${i}' detected!"   decho "duplicate require '${i}' detected!"
179   fi   fi
180   done   done
181  }  }
# Line 226  verify_requirements() Line 204  verify_requirements()
204   # show missing and set the right retval   # show missing and set the right retval
205   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
206   then   then
207   rvecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
208     rvecho ${sorted}
209   return 0   return 0
210   else   else
211   for req in ${sorted}   for req in ${sorted}
# Line 234  verify_requirements() Line 213  verify_requirements()
213   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
214   then   then
215   # print normal   # print normal
216   rvecho -n " ${req}"   rvecho -n "${req} "
217   else   else
218   # print missing   # print missing
219   eecho -n " ${req}"   eecho -n "${req} "
220   fi   fi
221   done   done
222     # print CRLF
223     echo
224   return 1   return 1
225   fi   fi
226  }  }
# Line 271  print_provide() Line 252  print_provide()
252   rvecho ${sorted}   rvecho ${sorted}
253  }  }
254    
255  # message only echo | disabled in quiet mode  is_provided()
 mecho()  
256  {  {
257   local COLCYAN="\033[1;36m"   local feature="$1"
258   local COLDEFAULT="\033[0m"   local i
259   local opts   local retval
  local webcrlf  
   
  # print nothing if quiet mode was requested  
  [[ ${QUIET} = true ]] && return  
   
  if [[ ${NOCOLORS} = true ]]  
  then  
  COLCYAN=""  
  COLDEFAULT=""  
  fi  
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
260    
261   # respect -n   retval=1
262   case $1 in   for i in $(print_provide)
263   -n) shift; opts="n" ;;   do
264   esac   if [[ ${i} = ${feature} ]]
265     then
266     retval=0
267     break
268     fi
269     done
270    
271   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"   return "${retval}"
272  }  }
273    
274  # prints error messages | enabled even in quiet mode  push_config()
 eecho()  
275  {  {
276   local COLRED="\033[1;31m"   local push_configs="$@"
277   local COLDEFAULT="\033[0m"   local i
  local opts  
  local webcrlf  
   
  if [[ ${NOCOLORS} = true ]]  
  then  
  COLRED=""  
  COLDEFAULT=""  
  fi  
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
278    
279   echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"   for i in ${push_configs}
280     do
281     # check for duplicate provides
282     if no_duplicate "${PUSH_CONFIG}" "${i}"
283     then
284     export PUSH_CONFIG="${PUSH_CONFIG} ${i}"
285     else
286     decho "duplicate push_config '${i}' detected!"
287     fi
288     done
289  }  }
290    
291  # prints return values of get | enabled even in quiet mode  print_push_config()
 rvecho()  
292  {  {
293   local COLPURPLE="\033[1;35m"   local sorted
  local COLDEFAULT="\033[0m"  
  local opts  
  local webcrlf  
   
  if [[ ${NOCOLORS} = true ]]  
  then  
  COLPURPLE=""  
  COLDEFAULT=""  
  fi  
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
294    
295   echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"   # sort them alpabetically
296     sorted=$(for i in ${PUSH_CONFIG}; do echo "${i}"; done | sort)
297     # do not escape, or CRLFS get printed to screen too
298     rvecho ${sorted}
299  }  }
300    
301  # prints debug messages if requested | enabled even in quiet mode  push_firstboot()
 decho()  
302  {  {
303   # print nothing if debug mode was *not* requested   local push_firstboots="$@"
304   [[ ${DEBUG} != 1 ]] && return   local i
305    
306   eecho "DEBUG: ${@}"   for i in ${push_firstboots}
307     do
308     # check for duplicate provides
309     if no_duplicate "${PUSH_FIRSTBOOT}" "${i}"
310     then
311     export PUSH_FIRSTBOOT="${PUSH_FIRSTBOOT} ${i}"
312     else
313     decho "duplicate push_firstboot '${i}' detected!"
314     fi
315     done
316  }  }
317    
318  path_not_empty()  print_push_firstboot()
319  {  {
320   local path="$1"   local sorted
  [[ -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  
321    
322   # every thing went ok, directory not empty   # sort them alpabetically
323   return 0   sorted=$(for i in ${PUSH_FIRSTBOOT}; do echo "${i}"; done | sort)
324     # do not escape, or CRLFS get printed to screen too
325     rvecho ${sorted}
326  }  }
327    
328  help_daemon_mroot()  help_daemon_mroot()
# Line 396  set_daemon_mroot() Line 352  set_daemon_mroot()
352   fi   fi
353  }  }
354    
 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}"  
 }  
   
355  print_version()  print_version()
356  {  {
357   echo "mcored-$(<${MCLIBDIR}/VERSION)"   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
358  }  }
   
 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}  
 }  
   

Legend:
Removed from v.2091  
changed lines
  Added in v.2811