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 2006 by niro, Mon Aug 13 09:40:07 2012 UTC mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in revision 2228 by niro, Fri Jan 10 23:51:35 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
7    
8   # client specific   # client specific
9   for i in ${MCLIBDIR}/include/*.client.class   for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class)
10   do   do
11   source ${i} || eecho "error loading ${i}"   source ${i} || eecho "error loading ${i}"
12   done   done
# Line 103  help_topics() Line 105  help_topics()
105   mecho "\tcolors   - enable colors"   mecho "\tcolors   - enable colors"
106   mecho "\tquiet    - do not print any unecessary messages"   mecho "\tquiet    - do not print any unecessary messages"
107   mecho "\thelp     - shows help"   mecho "\thelp     - shows help"
108     mecho "\tversion  - prints version of the daemon"
109   mecho "\tquit     - quits the connection to the server"   mecho "\tquit     - quits the connection to the server"
110   mecho   mecho
111   mecho "Help topics:"   mecho "Help topics:"
# Line 119  help_topics() Line 122  help_topics()
122   mecho "Type 'help [topic]' for more information about every topic."   mecho "Type 'help [topic]' for more information about every topic."
123  }  }
124    
 # 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  
 }  
   
125  require()  require()
126  {  {
127   local requires="$@"   local requires="$@"
# Line 223  verify_requirements() Line 163  verify_requirements()
163   # show missing and set the right retval   # show missing and set the right retval
164   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
165   then   then
166   rvecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
167     rvecho ${sorted}
168   return 0   return 0
169   else   else
170   for req in ${sorted}   for req in ${sorted}
# Line 231  verify_requirements() Line 172  verify_requirements()
172   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
173   then   then
174   # print normal   # print normal
175   rvecho -n " ${req}"   rvecho -n "${req} "
176   else   else
177   # print missing   # print missing
178   eecho -n " ${req}"   eecho -n "${req} "
179   fi   fi
180   done   done
181     # print CRLF
182     echo
183   return 1   return 1
184   fi   fi
185  }  }
# Line 268  print_provide() Line 211  print_provide()
211   rvecho ${sorted}   rvecho ${sorted}
212  }  }
213    
214  # message only echo | disabled in quiet mode  help_daemon_mroot()
 mecho()  
215  {  {
216   local COLCYAN="\033[1;36m"   mecho "get daemon.mroot"
217   local COLDEFAULT="\033[0m"   mecho " Prints current MROOT variable."
218   local opts   mecho
219   local webcrlf   mecho "set daemon.mroot [path]"
220     mecho " set MROOT variable to given path."
  # 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}"  
221  }  }
222    
223  # prints error messages | enabled even in quiet mode  get_daemon_mroot()
 eecho()  
224  {  {
225   local COLRED="\033[1;31m"   rvecho "${MROOT}"
  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}"  
226  }  }
227    
228  # prints return values of get | enabled even in quiet mode  set_daemon_mroot()
 rvecho()  
229  {  {
230   local COLPURPLE="\033[1;35m"   local path=$1
  local COLDEFAULT="\033[0m"  
  local opts  
  local webcrlf  
231    
232   if [[ ${NOCOLORS} = true ]]   if [[ -d ${path} ]]
233   then   then
234   COLPURPLE=""   export MROOT="${path}"
235   COLDEFAULT=""   decho "MROOT='${MROOT}' is set."
236     else
237     eecho "Path '${path}' does not exist. MROOT not set."
238   fi   fi
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
   
  echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}"  
239  }  }
240    
241  # prints debug messages if requested | enabled even in quiet mode  print_version()
 decho()  
242  {  {
243   # print nothing if debug mode was *not* requested   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
  [[ ${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  
244  }  }

Legend:
Removed from v.2006  
changed lines
  Added in v.2228