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 2139 by niro, Fri Jan 10 10:23:50 2014 UTC revision 2140 by niro, Fri Jan 10 12:02:07 2014 UTC
# Line 122  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 274  print_provide() Line 211  print_provide()
211   rvecho ${sorted}   rvecho ${sorted}
212  }  }
213    
 # 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  
 }  
   
214  help_daemon_mroot()  help_daemon_mroot()
215  {  {
216   mecho "get daemon.mroot"   mecho "get daemon.mroot"
# Line 399  set_daemon_mroot() Line 238  set_daemon_mroot()
238   fi   fi
239  }  }
240    
 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}"  
 }  
   
241  print_version()  print_version()
242  {  {
243   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
244  }  }
   
 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.2139  
changed lines
  Added in v.2140