141 |
"$@" \ |
"$@" \ |
142 |
&& return 0 || return 1 |
&& return 0 || return 1 |
143 |
} |
} |
144 |
|
|
145 |
|
# read tables and evaluate all variables |
146 |
|
# cmd: evaluate_table cfg_network |
147 |
|
# result: cfg_network_hostname=DUMMY_HOSTNAME |
148 |
|
evaluate_table() |
149 |
|
{ |
150 |
|
local table="$1" |
151 |
|
local where_statement |
152 |
|
|
153 |
|
if [[ -z $2 ]] |
154 |
|
then |
155 |
|
where_statement="where serial='${ALX_SERIAL}'" |
156 |
|
else |
157 |
|
where_statement="$2" |
158 |
|
fi |
159 |
|
|
160 |
|
export eval $(mysql \ |
161 |
|
--user="${SQL_USER}" \ |
162 |
|
--password="${SQL_PASS}" \ |
163 |
|
--host="${SQL_HOST}" \ |
164 |
|
--database="${SQL_DB}" \ |
165 |
|
--xml \ |
166 |
|
--execute="select * from ${table} ${where_statement}" \ |
167 |
|
| xml sel -T -t -m //row/field \ |
168 |
|
-v "concat('${table}_', @name, '=', '\"' ,self::field, '\"')" -n) |
169 |
|
} |
170 |
|
|
171 |
|
# runs a statement and evaluate the resulting columns |
172 |
|
# cmd: evaluate_command "select serial from cfg_serial where serial=10" |
173 |
|
# result: serial=10 |
174 |
|
# or with a prefix given |
175 |
|
# cmd: evaluate_command "select serial from cfg_serial where serial=10" "cfg_serial" |
176 |
|
# result: cfg_serial_serial=10 |
177 |
|
evaluate_statement() |
178 |
|
{ |
179 |
|
local statement="$1" |
180 |
|
local prefix="$2" |
181 |
|
|
182 |
|
if [[ ! -z ${prefix} ]] |
183 |
|
then |
184 |
|
prefix="${prefix}_" |
185 |
|
fi |
186 |
|
|
187 |
|
export eval $(mysql \ |
188 |
|
--user="${SQL_USER}" \ |
189 |
|
--password="${SQL_PASS}" \ |
190 |
|
--host="${SQL_HOST}" \ |
191 |
|
--database="${SQL_DB}" \ |
192 |
|
--xml \ |
193 |
|
--execute="${statement}" \ |
194 |
|
| xml sel -T -t -m //row/field \ |
195 |
|
-v "concat('${prefix}', @name, '=', '\"', self::field, '\"')" -n) |
196 |
|
} |