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 2083 by niro, Fri May 10 13:14:35 2013 UTC mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in revision 2302 by niro, Mon Jan 20 14:02:27 2014 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_client_classes()
5  {  {
6   local i   local i
7    
8   # client specific   # client specific
9   for i in $(find ${MCLIBDIR}/include -type f -name \*.client.class)   for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class)
10   do   do
11   source ${i} || eecho "error loading ${i}"   include ${i} || eecho "error loading ${i}"
12   done   done
13  }  }
14    
# Line 28  stop_service() Line 28  stop_service()
28   local pid   local pid
29   for pid in $(pidof sslsvd)   for pid in $(pidof sslsvd)
30   do   do
31   kill -15 ${pid}   kill -SIGTERM ${pid}
  sleep 1  
  kill -9 ${pid}  
32   done   done
33  }  }
34    
# Line 54  stop_service() Line 52  stop_service()
52  # run_class $method $caller $argv1 $argv2 ... $argvN  # run_class $method $caller $argv1 $argv2 ... $argvN
53  run_class()  run_class()
54  {  {
55   local method="$1"   local method="${GLOBAL_ARGV[0]}"
56   local caller="$2"   local caller="${GLOBAL_ARGV[1]}"
57   local class   local class
58   local cmd   local cmd
59   local argv   local i
60     local count
61    
62   if valid_session   if valid_session
63   then   then
64   class="${caller%.*}"   class="${caller%.*}"
65   cmd="${caller#*.}"   cmd="${caller#*.}"
  argv="${@/${caller}/}" # remove caller  
  argv="${argv/${method}/}" # remove method  
66    
67  # echo "method=${method}"   # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class
68  # echo "caller=${caller}"   unset CLASS_ARGV
69  # echo "class=${class}"   count="${#GLOBAL_ARGV[*]}"
70  # echo "cmd=${cmd}"   for (( i=2; i<count; i++ ))
71  # echo "argv=${argv}"   do
72     CLASS_ARGV[${i}-2]="${GLOBAL_ARGV[${i}]}"
73     done
74    
75    # decho "method=${method}"
76    # decho "caller=${caller}"
77    # decho "class=${class}"
78    # decho "cmd=${cmd}"
79    # decho "class argv=$(printf '\"%s\" ' ${CLASS_ARGV[*]}; printf '\n')"
80    
81   # check if class.cmd exist   # check if class.cmd exist
82   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
83   then   then
84   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}"
85   else   else
86   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
87   fi   fi
88   else   else
89   invalid_session   invalid_session
# Line 122  help_topics() Line 127  help_topics()
127   mecho "Type 'help [topic]' for more information about every topic."   mecho "Type 'help [topic]' for more information about every topic."
128  }  }
129    
 # 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  
 }  
   
130  require()  require()
131  {  {
132   local requires="$@"   local requires="$@"
# Line 226  verify_requirements() Line 168  verify_requirements()
168   # show missing and set the right retval   # show missing and set the right retval
169   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
170   then   then
171   rvecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
172     rvecho ${sorted}
173   return 0   return 0
174   else   else
175   for req in ${sorted}   for req in ${sorted}
# Line 234  verify_requirements() Line 177  verify_requirements()
177   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
178   then   then
179   # print normal   # print normal
180   rvecho -n " ${req}"   rvecho -n "${req} "
181   else   else
182   # print missing   # print missing
183   eecho -n " ${req}"   eecho -n "${req} "
184   fi   fi
185   done   done
186     # print CRLF
187     echo
188   return 1   return 1
189   fi   fi
190  }  }
# Line 271  print_provide() Line 216  print_provide()
216   rvecho ${sorted}   rvecho ${sorted}
217  }  }
218    
 # 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="<br>"  
   
  # 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="<br>"  
   
  # 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="<br>"  
   
  # 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  
 }  
   
219  help_daemon_mroot()  help_daemon_mroot()
220  {  {
221   mecho "get daemon.mroot"   mecho "get daemon.mroot"
# Line 396  set_daemon_mroot() Line 243  set_daemon_mroot()
243   fi   fi
244  }  }
245    
 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}"  
 }  
   
246  print_version()  print_version()
247  {  {
248   echo "mcored-$(<${MCLIBDIR}/VERSION)"   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
249  }  }
   
 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.2083  
changed lines
  Added in v.2302