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 1264 by niro, Fri Feb 4 20:13:23 2011 UTC
# Line 64  help_topics() Line 64  help_topics()
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 "\thelp    - shows help"   mecho "\thelp    - shows help"
67     mecho "\tquit    - quits the connection to the server"
68   mecho   mecho
69   mecho "Help topics:"   mecho "Help topics:"
70   for i in ${topics}   for i in ${topics}
# Line 75  help_topics() Line 76  help_topics()
76    
77   mecho "\t${i}"   mecho "\t${i}"
78   done   done
79     mecho
80     mecho "Type 'help [topic]' for more information about every topic."
81  }  }
82    
83  # 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
84  x11runas()  x11runas()
85  {  {
86   su - "${MCORE_UNPRIV_USER}" -c "$@"   su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"
87  }  }
88    
89  addconfig()  addconfig()
# Line 113  clearconfig() Line 116  clearconfig()
116   : > ${CONFIG}   : > ${CONFIG}
117  }  }
118    
119    # no_duplicate $list $item
120    no_duplicate()
121    {
122     local i
123     local list="$1"
124     local item="$2"
125    
126     for i in ${list}
127     do
128     [[ ${i} = ${item} ]] && return 1
129     done
130    
131     return 0
132    }
133    
134  require()  require()
135  {  {
136   local requires="$@"   local requires="$@"
# Line 120  require() Line 138  require()
138    
139   for i in ${requires}   for i in ${requires}
140   do   do
141   export REQUIRE="${REQUIRE} ${i}"   # check for duplicate provides
142     if no_duplicate "${PROVIDE}" "${i}"
143     then
144     export REQUIRE="${REQUIRE} ${i}"
145     else
146     [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"
147     fi
148   done   done
149  }  }
150    
151  not_provided()  verify_requirements()
152  {  {
153   local i   local req
154   local item="$1"   local prov
155     local missing
156     local sorted
157    
158   for i in ${PROVIDE}   for req in ${REQUIRE}
159   do   do
160   [[ ${i} = ${item} ]] && return 1   # scan PROVIDE for dupes
161     # if a dupe is found, then requirement is fullfilled
162     # else add to missing
163     if no_duplicate "${PROVIDE}" "${req}"
164     then
165     missing="${missing} ${req}"
166     fi
167   done   done
168    
169   return 0   # sort them alpabetically
170     sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort)
171    
172     # show missing and set the right retval
173     if [[ -z ${missing} ]]
174     then
175     mecho "${sorted}"
176     return 0
177     else
178     for req in ${sorted}
179     do
180     if no_duplicate "${missing}" "$req"
181     then
182     # print normal
183     mecho -n " ${req}"
184     else
185     # print missing
186     eecho -n " ${req}"
187     fi
188     done
189     return 1
190     fi
191  }  }
192    
193  provide()  provide()
# Line 145  provide() Line 198  provide()
198   for i in ${provides}   for i in ${provides}
199   do   do
200   # check for duplicate provides   # check for duplicate provides
201   if not_provided "${i}"   if no_duplicate "${PROVIDE}" "${i}"
202   then   then
203   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
204   else   else
# Line 168  mecho() Line 221  mecho()
221  {  {
222   local COLCYAN="\033[1;36m"   local COLCYAN="\033[1;36m"
223   local COLDEFAULT="\033[0m"   local COLDEFAULT="\033[0m"
224     local opts
225    
226   if [[ ${NOCOLORS} = true ]]   if [[ ${NOCOLORS} = true ]]
227   then   then
228   COLCYAN=""   COLCYAN=""
229   COLDEFAULT=""   COLDEFAULT=""
230   fi   fi
231    
232   echo -e "${COLCYAN}$@${COLDEFAULT}"   # respect -n
233     case $1 in
234     -n) shift; opts="n" ;;
235     esac
236    
237     echo -e${opts} "${COLCYAN}$@${COLDEFAULT}"
238    }
239    
240    eecho()
241    {
242     local COLRED="\033[1;31m"
243     local COLDEFAULT="\033[0m"
244     local opts
245    
246     if [[ ${NOCOLORS} = true ]]
247     then
248     COLRED=""
249     COLDEFAULT=""
250     fi
251    
252     # respect -n
253     case $1 in
254     -n) shift; opts="n" ;;
255     esac
256    
257     echo -e${opts} "${COLRED}$@${COLDEFAULT}"
258    }
259    
260    path_not_empty()
261    {
262     local path="$1"
263     [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1
264    
265     # return ERR if path does not exist
266     [[ ! -d ${path} ]] && return 1
267     # return ERR if path empty
268     [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1
269    
270     # every thing went ok, directory not empty
271     return 0
272  }  }

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