Contents of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in
Parent Directory | Revision Log
Revision 1252 -
(show annotations)
(download)
Wed Feb 2 21:17:54 2011 UTC (13 years, 3 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class
File size: 3144 byte(s)
Wed Feb 2 21:17:54 2011 UTC (13 years, 3 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class
File size: 3144 byte(s)
-disabled mysql based functions atm -clearconfig: install config dir
1 | # $Id$ |
2 | |
3 | # # import_resource $table $serial $resource $value |
4 | # import_resource() |
5 | # { |
6 | # local table="$1" |
7 | # local serial="$2" |
8 | # local resource="$3" |
9 | # local value="$4" |
10 | # |
11 | # if [[ ${DEBUG} = 1 ]] |
12 | # then |
13 | # echo "${table}->${resource}=${value}" >> /root/lala.log |
14 | # echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log |
15 | # fi |
16 | # |
17 | # mysql_insert "${table}",serial="${serial}","${resource}"="${value}" |
18 | # } |
19 | |
20 | # run_class $method $caller $argv1 $argv2 ... $argvN |
21 | run_class() |
22 | { |
23 | local method="$1" |
24 | local caller="$2" |
25 | local class |
26 | local cmd |
27 | local argv |
28 | |
29 | if validate_session |
30 | then |
31 | class="${caller%.*}" |
32 | cmd="${caller#*.}" |
33 | argv="${@/${caller}/}" # remove caller |
34 | argv="${argv/${method}/}" # remove method |
35 | |
36 | # echo "method=${method}" |
37 | # echo "caller=${caller}" |
38 | # echo "class=${class}" |
39 | # echo "cmd=${cmd}" |
40 | # echo "argv=${argv}" |
41 | |
42 | # check if class.cmd exist |
43 | if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] |
44 | then |
45 | "${method}"_"${class}"_"${cmd}" ${argv} |
46 | else |
47 | echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
48 | fi |
49 | else |
50 | invalid_session |
51 | fi |
52 | } |
53 | |
54 | help_topics() |
55 | { |
56 | local i |
57 | local topics |
58 | |
59 | topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
60 | mecho "Global commands:" |
61 | mecho "\timport - import settings to database" |
62 | mecho "\tget - shows current value for a settings" |
63 | mecho "\tset - sets value for a setting" |
64 | mecho "\tauth - authenticate to the daemon" |
65 | mecho "\tprovide - shows provides of a system" |
66 | mecho "\thelp - shows help" |
67 | mecho |
68 | mecho "Help topics:" |
69 | for i in ${topics} |
70 | do |
71 | # excludes |
72 | case ${i} in |
73 | help_topics|topics) continue ;; |
74 | esac |
75 | |
76 | mecho "\t${i}" |
77 | done |
78 | } |
79 | |
80 | # on newer xorg-servers root is not allowed to run progs in a user session |
81 | x11runas() |
82 | { |
83 | su - "${MCORE_UNPRIV_USER}" -c "$@" |
84 | } |
85 | |
86 | addconfig() |
87 | { |
88 | if [[ -z ${CONFIG} ]] |
89 | then |
90 | echo "You must define \$CONFIG varibale first!" |
91 | return 1 |
92 | fi |
93 | |
94 | if [[ ! -d $(dirname ${CONFIG}) ]] |
95 | then |
96 | install -d $(dirname ${CONFIG}) |
97 | fi |
98 | echo "$@" >> ${CONFIG} |
99 | } |
100 | |
101 | clearconfig() |
102 | { |
103 | if [[ -z ${CONFIG} ]] |
104 | then |
105 | echo "You must define \$CONFIG varibale first!" |
106 | return 1 |
107 | fi |
108 | |
109 | if [[ ! -d $(dirname ${CONFIG}) ]] |
110 | then |
111 | install -d $(dirname ${CONFIG}) |
112 | fi |
113 | : > ${CONFIG} |
114 | } |
115 | |
116 | require() |
117 | { |
118 | local requires="$@" |
119 | local i |
120 | |
121 | for i in ${requires} |
122 | do |
123 | export REQUIRE="${REQUIRE} ${i}" |
124 | done |
125 | } |
126 | |
127 | not_provided() |
128 | { |
129 | local i |
130 | local item="$1" |
131 | |
132 | for i in ${PROVIDE} |
133 | do |
134 | [[ ${i} = ${item} ]] && return 1 |
135 | done |
136 | |
137 | return 0 |
138 | } |
139 | |
140 | provide() |
141 | { |
142 | local provides="$@" |
143 | local i |
144 | |
145 | for i in ${provides} |
146 | do |
147 | # check for duplicate provides |
148 | if not_provided "${i}" |
149 | then |
150 | export PROVIDE="${PROVIDE} ${i}" |
151 | else |
152 | [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" |
153 | fi |
154 | done |
155 | } |
156 | |
157 | print_provide() |
158 | { |
159 | local sorted |
160 | |
161 | # sort them alpabetically |
162 | sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
163 | # do not escape, or CRLFS get printed to screen too |
164 | mecho ${sorted} |
165 | } |
166 | |
167 | mecho() |
168 | { |
169 | local COLCYAN="\033[1;36m" |
170 | local COLDEFAULT="\033[0m" |
171 | if [[ ${NOCOLORS} = true ]] |
172 | then |
173 | COLCYAN="" |
174 | COLDEFAULT="" |
175 | fi |
176 | |
177 | echo -e "${COLCYAN}$@${COLDEFAULT}" |
178 | } |