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 1252 by niro, Wed Feb 2 21:17:54 2011 UTC revision 1330 by niro, Wed Feb 16 18:24:35 2011 UTC
# Line 26  run_class() Line 26  run_class()
26   local cmd   local cmd
27   local argv   local argv
28    
29   if validate_session   if valid_session
30   then   then
31   class="${caller%.*}"   class="${caller%.*}"
32   cmd="${caller#*.}"   cmd="${caller#*.}"
# Line 63  help_topics() Line 63  help_topics()
63   mecho "\tset     - sets value for a setting"   mecho "\tset     - sets value for a setting"
64   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth    - authenticate to the daemon"
65   mecho "\tprovide - shows provides of a system"   mecho "\tprovide - shows provides of a system"
66     mecho "\trequire - verify plugin requirements"
67     mecho "\tnocolors - disable colors, useful for the webclient"
68   mecho "\thelp    - shows help"   mecho "\thelp    - shows help"
69     mecho "\tquit    - quits the connection to the server"
70   mecho   mecho
71   mecho "Help topics:"   mecho "Help topics:"
72   for i in ${topics}   for i in ${topics}
# Line 75  help_topics() Line 78  help_topics()
78    
79   mecho "\t${i}"   mecho "\t${i}"
80   done   done
81     mecho
82     mecho "Type 'help [topic]' for more information about every topic."
83  }  }
84    
85  # 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
86  x11runas()  x11runas()
87  {  {
88   su - "${MCORE_UNPRIV_USER}" -c "$@"   su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
89  }  }
90    
91  addconfig()  addconfig()
92  {  {
93     local opts
94    
95   if [[ -z ${CONFIG} ]]   if [[ -z ${CONFIG} ]]
96   then   then
97   echo "You must define \$CONFIG varibale first!"   echo "You must define \$CONFIG varibale first!"
# Line 95  addconfig() Line 102  addconfig()
102   then   then
103   install -d $(dirname ${CONFIG})   install -d $(dirname ${CONFIG})
104   fi   fi
105   echo "$@" >> ${CONFIG}  
106     # check for opts
107     case $1 in
108     -n) shift; opts=" -n" ;;
109     -e) shift; opts=" -e" ;;
110     esac
111    
112     echo ${opts} "$@" >> ${CONFIG}
113  }  }
114    
115  clearconfig()  clearconfig()
# Line 113  clearconfig() Line 127  clearconfig()
127   : > ${CONFIG}   : > ${CONFIG}
128  }  }
129    
130    # no_duplicate $list $item
131    no_duplicate()
132    {
133     local i
134     local list="$1"
135     local item="$2"
136    
137     for i in ${list}
138     do
139     [[ ${i} = ${item} ]] && return 1
140     done
141    
142     return 0
143    }
144    
145  require()  require()
146  {  {
147   local requires="$@"   local requires="$@"
# Line 120  require() Line 149  require()
149    
150   for i in ${requires}   for i in ${requires}
151   do   do
152   export REQUIRE="${REQUIRE} ${i}"   # check for duplicate provides
153     if no_duplicate "${PROVIDE}" "${i}"
154     then
155     export REQUIRE="${REQUIRE} ${i}"
156     else
157     [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"
158     fi
159   done   done
160  }  }
161    
162  not_provided()  verify_requirements()
163  {  {
164   local i   local req
165   local item="$1"   local prov
166     local missing
167     local sorted
168    
169   for i in ${PROVIDE}   for req in ${REQUIRE}
170   do   do
171   [[ ${i} = ${item} ]] && return 1   # scan PROVIDE for dupes
172     # if a dupe is found, then requirement is fullfilled
173     # else add to missing
174     if no_duplicate "${PROVIDE}" "${req}"
175     then
176     missing="${missing} ${req}"
177     fi
178   done   done
179    
180   return 0   # sort them alpabetically
181     sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort)
182    
183     # show missing and set the right retval
184     if [[ -z ${missing} ]]
185     then
186     mecho "${sorted}"
187     return 0
188     else
189     for req in ${sorted}
190     do
191     if no_duplicate "${missing}" "$req"
192     then
193     # print normal
194     mecho -n " ${req}"
195     else
196     # print missing
197     eecho -n " ${req}"
198     fi
199     done
200     return 1
201     fi
202  }  }
203    
204  provide()  provide()
# Line 145  provide() Line 209  provide()
209   for i in ${provides}   for i in ${provides}
210   do   do
211   # check for duplicate provides   # check for duplicate provides
212   if not_provided "${i}"   if no_duplicate "${PROVIDE}" "${i}"
213   then   then
214   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
215   else   else
# Line 168  mecho() Line 232  mecho()
232  {  {
233   local COLCYAN="\033[1;36m"   local COLCYAN="\033[1;36m"
234   local COLDEFAULT="\033[0m"   local COLDEFAULT="\033[0m"
235     local opts
236     local webcrlf
237    
238   if [[ ${NOCOLORS} = true ]]   if [[ ${NOCOLORS} = true ]]
239   then   then
240   COLCYAN=""   COLCYAN=""
241   COLDEFAULT=""   COLDEFAULT=""
242   fi   fi
243    
244   echo -e "${COLCYAN}$@${COLDEFAULT}"   [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
245    
246     # respect -n
247     case $1 in
248     -n) shift; opts="n" ;;
249     esac
250    
251     echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"
252    }
253    
254    eecho()
255    {
256     local COLRED="\033[1;31m"
257     local COLDEFAULT="\033[0m"
258     local opts
259     local webcrlf
260    
261     if [[ ${NOCOLORS} = true ]]
262     then
263     COLRED=""
264     COLDEFAULT=""
265     fi
266    
267     [[ ${WEBCRLF} = true ]] && webcrlf="<br>"
268    
269     # respect -n
270     case $1 in
271     -n) shift; opts="n" ;;
272     esac
273    
274     echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"
275    }
276    
277    path_not_empty()
278    {
279     local path="$1"
280     [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1
281    
282     # return ERR if path does not exist
283     [[ ! -d ${path} ]] && return 1
284     # return ERR if path empty
285     [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1
286    
287     # every thing went ok, directory not empty
288     return 0
289  }  }

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