|
@@ -0,0 +1,930 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+## zraid-maker
|
|
3
|
+## (c) author's idea and realization: Kleemov A. & Koshuba V.
|
|
4
|
+## script author: Koshuba V - stvixfree@gmail.com
|
|
5
|
+## all parameters
|
|
6
|
+option=$1;
|
|
7
|
+params=$2;
|
|
8
|
+PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zraid";
|
|
9
|
+version="10.03.18";
|
|
10
|
+## msg [53]
|
|
11
|
+set_msg=( '"0" "1"' '"1" "1"' '"2" "1"' '"3" "1"' '"4" "1"' '"5" "1"' '"6" "1"' '"7" "1"' '"8" "1"'
|
|
12
|
+ '"9" "1"' '"10" "1"' '"11" "1"' '"12" "1"' '"13" "1"' '"14" "1"' '"15" "1"' '"16" "1"'
|
|
13
|
+ '"17" "1"' '"18" "1"' '"19" "1"' '"20" "1"' '"21" "1"' '"22" "1"' '"23" "1"' '"24" "1"'
|
|
14
|
+ '"25" "1"' '"26" "1"' '"27" "1"' '"28" "1"' '"29" "1"' '"30" "1"' '"31" "1"' '"32" "1"'
|
|
15
|
+ '"33" "1"' '"34" "0"' '"35" "0"' '"36" "0"' '"37" "0"' '"38" "0"' '"39" "0"' '"40" "0"'
|
|
16
|
+ '"41" "0"' '"42" "1"' '"43" "1"' '"44" "1"' '"45" "0"' '"46" "1"' '"47" "1"' '"48" "1"'
|
|
17
|
+ '"49" "1"' '"50" "1"' '"51" "1"' '"52" "1"' '"53" "1"' );
|
|
18
|
+msg=();
|
|
19
|
+
|
|
20
|
+##
|
|
21
|
+lang=$(locale|grep LANG=|sed 's/\LANG=//g');
|
|
22
|
+rdate=$(date +%c);
|
|
23
|
+eval kernel_version="(" $(uname -r|sed 's/\./ /g'|awk '{print$1" "$2}') ")";
|
|
24
|
+test_module=$(find /lib/modules/$(uname -r) -name '*.ko'|grep zram|wc -m);
|
|
25
|
+##
|
|
26
|
+total_mem=$(cat /proc/meminfo |awk '/^MemTotal:/{print $2}');
|
|
27
|
+free_mem=$(cat /proc/meminfo |awk '/^MemAvailable:/{print $2}');
|
|
28
|
+limit_mem=0;
|
|
29
|
+info_limit_mem=0;
|
|
30
|
+zpath="/etc/zraid";
|
|
31
|
+zconfig="/etc/zraid/zraid.conf";
|
|
32
|
+zmsg="/etc/zraid/messages.dat";
|
|
33
|
+log="/var/log/zraid.log";
|
|
34
|
+##
|
|
35
|
+reports=();
|
|
36
|
+id_zmd=();
|
|
37
|
+image_zmd=();
|
|
38
|
+size_zmd=();
|
|
39
|
+json_key=( "id" "image" );
|
|
40
|
+zdm_vars=( "id_zmd" "image_zmd" );
|
|
41
|
+input_unit=();
|
|
42
|
+math_unit=0;
|
|
43
|
+total_size_images=0;
|
|
44
|
+test_status=0;
|
|
45
|
+kernel_status=(); # [0]-kernel3x,[1]-kernel4x
|
|
46
|
+##
|
|
47
|
+set_md_id="";
|
|
48
|
+set_zram_id="";
|
|
49
|
+set_md_status=(); # [0]-on\off,[1]-load zram,[2]-in config
|
|
50
|
+set_prepare=""; # 0 - new md, 1 - md assemble
|
|
51
|
+##
|
|
52
|
+zr_blkid=$(whereis -b blkid|awk '/^blkid:/{print $2}');
|
|
53
|
+zr_jq=$(whereis -b jq|awk '/^jq:/{print $2}');
|
|
54
|
+zr_mdadm=$(whereis -b mdadm|awk '/^mdadm:/{print $2}');
|
|
55
|
+
|
|
56
|
+## functions & operations
|
|
57
|
+operation_test=( "clear" "checkDep" "loadMsg" "testId" "checkModule" "confRead" "testMd" "testImage" "reportConf" "printInfo" );
|
|
58
|
+operation_on=( "checkDep" "loadMsg" "testId" "confRead" "checkModule" "testMd" "testImage" "statusZraid" "createZraid" );
|
|
59
|
+operation_sign_on=( "checkDep" "loadMsg" "testId" "confRead" "checkModule" "testImage" "inParams" "singleTestMd" "singleStart" );
|
|
60
|
+operation_sign_off=( "checkDep" "loadMsg" "testId" "confRead" "checkModule" "testImage" "inParams" "singleTestMd" "singleStop" );
|
|
61
|
+operation_off=( "checkDep" "loadMsg" "testId" "confRead" "checkModule" "offZraid" );
|
|
62
|
+operation_status=( "checkDep" "loadMsg" "testId" "confRead" "statusZraid" );
|
|
63
|
+operation_help=( "clear" "checkDep" "loadMsg" "printInfo" );
|
|
64
|
+execute_func=();
|
|
65
|
+
|
|
66
|
+## logic executor values
|
|
67
|
+iFs=();
|
|
68
|
+logic=();
|
|
69
|
+value_in="";
|
|
70
|
+lEnd=1;
|
|
71
|
+
|
|
72
|
+##--@F math functions
|
|
73
|
+## Byte <> Kb
|
|
74
|
+function Byte(){ if [ ! ${input_unit[2]} ]
|
|
75
|
+ then eval ${input_unit[1]}=$(echo "scale=0; ${input_unit[0]}/1024"|bc -lq);
|
|
76
|
+ else eval ${input_unit[1]}=$(echo ${input_unit[0]}*1024|bc -lq);
|
|
77
|
+ fi }
|
|
78
|
+## Kb <> Byte
|
|
79
|
+function Kb() { if [ ! ${input_unit[2]} ]
|
|
80
|
+ then eval ${input_unit[1]}=$(echo ${input_unit[0]}*1024|bc -lq);
|
|
81
|
+ else eval ${input_unit[1]}=$(echo "scale=0; ${input_unit[0]}/1024"|bc -lq);
|
|
82
|
+ fi }
|
|
83
|
+## Mb <> Byte
|
|
84
|
+function Mb() { if [ ! ${input_unit[2]} ]
|
|
85
|
+ then eval ${input_unit[1]}=$(echo ${input_unit[0]}*1024^2|bc -lq);
|
|
86
|
+ else eval ${input_unit[1]}=$(echo "scale=0; ${input_unit[0]}/1024^2"|bc -lq);
|
|
87
|
+ fi }
|
|
88
|
+## Gb <> Byte
|
|
89
|
+function Gb() { if [ ! ${input_unit[2]} ]
|
|
90
|
+ then eval ${input_unit[1]}=$(echo ${input_unit[0]}*1024^3|bc -lq);
|
|
91
|
+ else eval ${input_unit[1]}=$(echo "scale=0; ${input_unit[0]}/1024^3"|bc -lq);
|
|
92
|
+ fi }
|
|
93
|
+## Tb <> Byte
|
|
94
|
+function Tb() { if [ ! ${input_unit[2]} ]
|
|
95
|
+ then eval ${input_unit[1]}=$(echo ${input_unit[0]}*1024^4|bc -lq);
|
|
96
|
+ else eval ${input_unit[1]}=$(echo "scale=0; ${input_unit[0]}/1024^4"|bc -lq);
|
|
97
|
+ fi }
|
|
98
|
+
|
|
99
|
+## -@F logic executor
|
|
100
|
+function eXlogic() {
|
|
101
|
+lEnd=1;
|
|
102
|
+if [[ ${#iFs[@]} -eq 0 ]]||[[ ${#iFs[@]} != ${#logic[@]} ]]
|
|
103
|
+ then echo "exit";
|
|
104
|
+ exit 0;
|
|
105
|
+fi
|
|
106
|
+
|
|
107
|
+local exfunc=();
|
|
108
|
+for ((lg_index=0; lg_index != ${#iFs[@]}; lg_index++))
|
|
109
|
+ do
|
|
110
|
+ ## !! debug operation...
|
|
111
|
+ ##echo "eXlogic = execution: function ${iFs[$lg_index]} : index=$lg_index";
|
|
112
|
+ local lg=$(echo $((${iFs[$lg_index]})) );
|
|
113
|
+ local exfunc=( ${logic[$lg_index]} );
|
|
114
|
+ local runfunc=$(echo ${exfunc[$lg]}| sed 's/\"//g');
|
|
115
|
+ $runfunc;
|
|
116
|
+ if [[ $lEnd == 0 ]]
|
|
117
|
+ then lg_index=$((${#iFs[@]}-1));
|
|
118
|
+ fi
|
|
119
|
+done
|
|
120
|
+iFs=();
|
|
121
|
+logic=();
|
|
122
|
+value_in="";
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+##--@F write log events
|
|
126
|
+function writeToLog() {
|
|
127
|
+for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++))
|
|
128
|
+do
|
|
129
|
+ echo "$rdate zraid message: ${reports[$rpt_index]}">>$log;
|
|
130
|
+done
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+##--@F make all errors
|
|
134
|
+function makeErr() {
|
|
135
|
+if [[ "$option" == "--on" ]]
|
|
136
|
+ then
|
|
137
|
+ if [ ! "$params" ]
|
|
138
|
+ then
|
|
139
|
+ reports[${#reports[@]}]="${msg[0]}";
|
|
140
|
+ else
|
|
141
|
+ reports[${#reports[@]}]=${msg[42]};
|
|
142
|
+ fi
|
|
143
|
+ else
|
|
144
|
+ reports[${#reports[@]}]=${msg[42]};
|
|
145
|
+fi
|
|
146
|
+
|
|
147
|
+ printInfo;
|
|
148
|
+ writeToLog;
|
|
149
|
+ exit 0;
|
|
150
|
+}
|
|
151
|
+
|
|
152
|
+function printInfo() {
|
|
153
|
+value_in="$option";
|
|
154
|
+iFs=( "$(echo -n $value_in|wc -m) == 0"
|
|
155
|
+ "$(echo -n $value_in|sed 's/--help//g'|wc -m) == 0"
|
|
156
|
+ "$(echo -n $value_in|sed 's/--test//g'|wc -m) == 0"
|
|
157
|
+ "$(echo -n ${#reports[@]}) == 0" );
|
|
158
|
+
|
|
159
|
+logic=( '"" "pInone"'
|
|
160
|
+ '"" "pIhelp"'
|
|
161
|
+ '"" "pItest"'
|
|
162
|
+ '"pIdf" "pInone"' );
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+function pInone() {
|
|
166
|
+ lEnd=0;
|
|
167
|
+ ##clear
|
|
168
|
+ echo
|
|
169
|
+ echo -e ${msg[1]}"\n"${msg[2]}"\n"${msg[3]}"\n"${msg[4]}"\n"${msg[5]};
|
|
170
|
+ echo -e ${msg[52]}"\n"${msg[53]};
|
|
171
|
+ echo -e ${msg[31]}"\n"${msg[48]} $version;
|
|
172
|
+ exit 0;
|
|
173
|
+}
|
|
174
|
+
|
|
175
|
+function pIhelp() {
|
|
176
|
+ lEnd=0;
|
|
177
|
+ ##clear
|
|
178
|
+ echo
|
|
179
|
+ echo -e ${msg[2]}"\n"${msg[3]}"\n"${msg[4]}"\n"${msg[5]};
|
|
180
|
+ echo -e ${msg[51]}"\n"${msg[52]}
|
|
181
|
+ echo -e ${msg[31]}"\n"${msg[48]} $version;
|
|
182
|
+ exit 0;
|
|
183
|
+}
|
|
184
|
+
|
|
185
|
+function pItest() {
|
|
186
|
+ lEnd=0;
|
|
187
|
+ info_free_mem=0;
|
|
188
|
+ info_total_mem=0;
|
|
189
|
+ input_unit=( "$free_mem" "info_free_mem" "1" );
|
|
190
|
+ Kb;
|
|
191
|
+ input_unit=( "$total_mem" "info_total_mem" "1" );
|
|
192
|
+ Kb;
|
|
193
|
+ echo "==============================================================...";
|
|
194
|
+ echo "${msg[32]} $info_total_mem""Mb ${msg[33]} $info_free_mem""Mb";
|
|
195
|
+ echo "==============================================================...";
|
|
196
|
+ for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++))
|
|
197
|
+ do
|
|
198
|
+ echo "${reports[$rpt_index]}";
|
|
199
|
+ done
|
|
200
|
+ echo "--------------------------------------------------------------...";
|
|
201
|
+ exit 0;
|
|
202
|
+}
|
|
203
|
+
|
|
204
|
+## default function last eXlogic..
|
|
205
|
+function pIdf() {
|
|
206
|
+ for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++))
|
|
207
|
+ do
|
|
208
|
+ echo "${reports[$rpt_index]}";
|
|
209
|
+ done
|
|
210
|
+ }
|
|
211
|
+eXlogic;
|
|
212
|
+}
|
|
213
|
+
|
|
214
|
+##--@F Check the program dependency
|
|
215
|
+function checkDep() {
|
|
216
|
+# This installation check $zr_jq
|
|
217
|
+if [ $(echo $zr_jq|grep jq|wc -m) = 0 ]
|
|
218
|
+ then
|
|
219
|
+ ## lang messages if yes then lang else us...
|
|
220
|
+ reports[${#reports[@]}]=${msg[6]};
|
|
221
|
+ makeErr
|
|
222
|
+fi
|
|
223
|
+# This installation check mdadm
|
|
224
|
+if [ $(echo $zr_mdadm|grep mdadm|wc -m) = 0 ]
|
|
225
|
+ then
|
|
226
|
+ reports[${#reports[@]}]=${msg[8]};
|
|
227
|
+ makeErr
|
|
228
|
+fi
|
|
229
|
+
|
|
230
|
+if [ ! "$lang" ]
|
|
231
|
+ then
|
|
232
|
+ lang="C.UTF-8";
|
|
233
|
+fi
|
|
234
|
+
|
|
235
|
+}
|
|
236
|
+
|
|
237
|
+##--@F read locale messages
|
|
238
|
+function loadMsg() {
|
|
239
|
+ # test enable file messages
|
|
240
|
+if [ ! -f $zmsg ]
|
|
241
|
+ then
|
|
242
|
+ reports=();
|
|
243
|
+ reports[${#reports[@]}]="$zmsg - file not found!";
|
|
244
|
+ makeErr;
|
|
245
|
+fi
|
|
246
|
+
|
|
247
|
+# read msg
|
|
248
|
+if [[ ! $(cat $zmsg|grep "$lang"|wc -m) == 0 ]]
|
|
249
|
+ then
|
|
250
|
+ index_msg="$(cat $zmsg | jq '."'$lang'".msg[]'|wc -l)";
|
|
251
|
+ if [[ ! "$index_msg" == "0" ]]||[[ "$index_msg" == "${#set_msg[@]}" ]]
|
|
252
|
+ then
|
|
253
|
+ for (( m_index=0; m_index != $index_msg; m_index++))
|
|
254
|
+ do
|
|
255
|
+ eval st_in_msg="(" ${set_msg[$m_index]} ")";
|
|
256
|
+ if [ "${st_in_msg[1]}" != "0" ]
|
|
257
|
+ then
|
|
258
|
+ read_msg=$(cat $zmsg | jq '."'$lang'".msg['$m_index']'| sed 's/\"//g');
|
|
259
|
+ msg[$m_index]="$read_msg";
|
|
260
|
+ else
|
|
261
|
+ msg[$m_index]="";
|
|
262
|
+ fi
|
|
263
|
+ done
|
|
264
|
+ else
|
|
265
|
+ reports=();
|
|
266
|
+ reports[${#reports[@]}]="$zmsg - Incorrect file format or empty!";
|
|
267
|
+ makeErr;
|
|
268
|
+ fi
|
|
269
|
+ fi
|
|
270
|
+}
|
|
271
|
+
|
|
272
|
+##--@F check module zram & kernel version
|
|
273
|
+function checkModule() {
|
|
274
|
+# test kernel version
|
|
275
|
+iFs=( "${kernel_version[0]} < 3"
|
|
276
|
+ "${kernel_version[0]} == 3"
|
|
277
|
+ "${kernel_version[0]} == 4"
|
|
278
|
+ "$test_module == 0" );
|
|
279
|
+logic=( '"" "notVersion"'
|
|
280
|
+ '"" "kernel3"'
|
|
281
|
+ '"" "kernel4"'
|
|
282
|
+ '"" "zramFalse"' );
|
|
283
|
+
|
|
284
|
+function notVersion() {
|
|
285
|
+ lEnd=0;
|
|
286
|
+ reports[${#reports[@]}]="${msg[28]}";
|
|
287
|
+ makeErr;
|
|
288
|
+}
|
|
289
|
+
|
|
290
|
+function kernel3() {
|
|
291
|
+kernel_status[${#kernel_status[@]}]="1";
|
|
292
|
+ if (( "${kernel_version[1]}" < "14" ))
|
|
293
|
+ then
|
|
294
|
+ lEnd=0;
|
|
295
|
+ reports[${#reports[@]}]="${msg[28]}";
|
|
296
|
+ makeErr;
|
|
297
|
+ fi
|
|
298
|
+}
|
|
299
|
+
|
|
300
|
+function kernel4() {
|
|
301
|
+kernel_status[${#kernel_status[@]}]="1";
|
|
302
|
+ if (( "${kernel_version[1]}" > "2" ))
|
|
303
|
+ then
|
|
304
|
+ kernel_status[${#kernel_status[@]}]=1;
|
|
305
|
+ fi
|
|
306
|
+}
|
|
307
|
+
|
|
308
|
+# test module zram
|
|
309
|
+function zramFalse() {
|
|
310
|
+ lEnd=0;
|
|
311
|
+ reports[${#reports[@]}]=${msg[27]};
|
|
312
|
+ makeErr;
|
|
313
|
+}
|
|
314
|
+
|
|
315
|
+eXlogic;
|
|
316
|
+}
|
|
317
|
+
|
|
318
|
+##--@F step operation
|
|
319
|
+function confRead() {
|
|
320
|
+# test enable file zraid.conf
|
|
321
|
+if [ ! -f $zconfig ]
|
|
322
|
+ then
|
|
323
|
+ reports=();
|
|
324
|
+ reports[${#reports[@]}]=${msg[7]};
|
|
325
|
+ makeErr;
|
|
326
|
+fi
|
|
327
|
+# read config
|
|
328
|
+for (( rd_index=0; rd_index !=${#zdm_vars[@]}; rd_index++))
|
|
329
|
+ do
|
|
330
|
+ read_key=$(cat $zconfig | jq '.md[].'${json_key[$rd_index]}| sed 's/\"//g');
|
|
331
|
+ eval ${zdm_vars[$rd_index]}="(" $read_key ")";
|
|
332
|
+done
|
|
333
|
+log=$(cat $zconfig | jq '.log'| sed 's/\"//g');
|
|
334
|
+
|
|
335
|
+## test free memory
|
|
336
|
+value_mem=$(cat $zconfig | jq '.limit_free_mem.value_size'| sed 's/\"//g');
|
|
337
|
+
|
|
338
|
+value_in="$value_mem";
|
|
339
|
+iFs=( "$(echo -n $value_in|wc -m) == 0"
|
|
340
|
+ "$(echo -n $value_in|sed 's/%//g'|wc -m) == 0"
|
|
341
|
+ "$(echo -n $value_in|sed 's/Kb//g'|wc -m) == 0" );
|
|
342
|
+logic=( '"" "lmem_Err"'
|
|
343
|
+ '"" "lmem_Per"'
|
|
344
|
+ '"lmem_Err" "lmem_Kb"' );
|
|
345
|
+
|
|
346
|
+lmem_Err() {
|
|
347
|
+reports=();
|
|
348
|
+reports[${#reports[@]}]="${msg[29]} $value_mem /or null - ${msg[10]}(${msg[30]}:Kb,%)";
|
|
349
|
+makeErr;
|
|
350
|
+ }
|
|
351
|
+
|
|
352
|
+lmem_Per() {
|
|
353
|
+lEnd=0;
|
|
354
|
+test_read_mem=0;
|
|
355
|
+input_unit=( "$free_mem" "test_read_mem" );
|
|
356
|
+Kb;
|
|
357
|
+math_unit=$(echo "scale=2; $(echo "scale=2; $test_read_mem/100"|bc -lq)*$(cat $zconfig | jq '.limit_free_mem.size'| sed 's/\"//g')"|bc -lq|sed 's/\./ /g'|awk '{print$1}');
|
|
358
|
+## -"
|
|
359
|
+
|
|
360
|
+if (( "$math_unit" < 0 ))||[[ "$math_unit" == "" ]]||[[ ! "$math_unit" =~ ^([0-9]+)$ ]]
|
|
361
|
+ then
|
|
362
|
+ reports=();
|
|
363
|
+ reports[${#reports[@]}]="${msg[29]} $value_mem /or null - ${msg[10]}(${msg[30]}:Kb,%)";
|
|
364
|
+ makeErr;
|
|
365
|
+ else
|
|
366
|
+ limit_mem=$math_unit;
|
|
367
|
+ input_unit=( "$math_unit" "info_limit_mem" );
|
|
368
|
+ Byte;
|
|
369
|
+ math_unit=$info_limit_mem;
|
|
370
|
+ input_unit=( "$math_unit" "info_limit_mem" "1" );
|
|
371
|
+ Kb;
|
|
372
|
+fi
|
|
373
|
+ }
|
|
374
|
+
|
|
375
|
+lmem_Kb() {
|
|
376
|
+lEnd=0;
|
|
377
|
+input_unit=( "$(cat $zconfig | jq '.limit_free_mem.size'| sed 's/\"//g')" "math_unit" );
|
|
378
|
+Kb;
|
|
379
|
+limit_mem=$math_unit;
|
|
380
|
+input_unit=( "$math_unit" "info_limit_mem");
|
|
381
|
+Mb;
|
|
382
|
+ }
|
|
383
|
+eXlogic;
|
|
384
|
+}
|
|
385
|
+
|
|
386
|
+##--@F step operation
|
|
387
|
+function testMd() {
|
|
388
|
+# test the md number parameters for errors and busy in system
|
|
389
|
+if [ ${#id_zmd[@]} -eq 0 ]
|
|
390
|
+ then reports[${#reports[@]}]="${msg[21]}${id_zmd[$md_index]} - ${msg[9]}";
|
|
391
|
+ makeErr;
|
|
392
|
+fi
|
|
393
|
+
|
|
394
|
+for (( md_index=0; md_index != ${#id_zmd[@]}; md_index++))
|
|
395
|
+ do
|
|
396
|
+ if (( "${id_zmd[$md_index]}" < 0 ))||[[ "${id_zmd[$md_index]}" == "" ]]||[[ ! "${id_zmd[$md_index]}" =~ ^([0-9]+)$ ]]
|
|
397
|
+ then reports[${#reports[@]}]="${msg[21]}${id_zmd[$md_index]} - ${msg[10]}";
|
|
398
|
+ makeErr;
|
|
399
|
+ fi
|
|
400
|
+###
|
|
401
|
+ if [ "$($zr_blkid /dev/md${id_zmd[$md_index]}|grep ${id_zmd[$md_index]})" ]
|
|
402
|
+ then reports[${#reports[@]}]="${msg[21]}${id_zmd[$md_index]} - ${msg[11]}";
|
|
403
|
+ makeErr;
|
|
404
|
+ fi
|
|
405
|
+done
|
|
406
|
+# test the duble number md
|
|
407
|
+test_dub=( $(echo -e ${id_zmd[@]}|tr " " "\n"|sort|tr "\n" " ") );
|
|
408
|
+for (( dub_index=0; dub_index != ${#id_zmd[@]}; dub_index++ ))
|
|
409
|
+ do
|
|
410
|
+ dubtest_index=$(($dub_index+1));
|
|
411
|
+ if [[ ! $dubtest_index > $((${#id_zmd[@]}-1)) ]]
|
|
412
|
+ then
|
|
413
|
+ if [[ $((${test_dub[dubtest_index]}-${test_dub[dub_index]})) == 0 ]];
|
|
414
|
+ then reports[${#reports[@]}]="${msg[21]}${id_zmd[$dub_index]} - ${msg[12]}";
|
|
415
|
+ makeErr;
|
|
416
|
+ fi
|
|
417
|
+ fi
|
|
418
|
+done
|
|
419
|
+## ok test md*
|
|
420
|
+if [ "$option" == "--test" ]
|
|
421
|
+ then
|
|
422
|
+ reports[${#reports[@]}]=${msg[25]};
|
|
423
|
+fi
|
|
424
|
+}
|
|
425
|
+
|
|
426
|
+##--@F step operation
|
|
427
|
+function testImage() {
|
|
428
|
+
|
|
429
|
+function test_true() {
|
|
430
|
+if [ "$option" == "--test" ]
|
|
431
|
+ then
|
|
432
|
+ reports[${#reports[@]}]=${msg[26]};
|
|
433
|
+fi
|
|
434
|
+}
|
|
435
|
+
|
|
436
|
+function test_null() {
|
|
437
|
+if [ "$option" == "--test" ]
|
|
438
|
+ then
|
|
439
|
+reports[${#reports[@]}]=${msg[46]};
|
|
440
|
+fi
|
|
441
|
+}
|
|
442
|
+
|
|
443
|
+function sum_img() {
|
|
444
|
+## the sum size images
|
|
445
|
+for (( image_index=0; image_index != ${#image_zmd[@]}; image_index++ ))
|
|
446
|
+ do
|
|
447
|
+ if [ ! -f ${image_zmd[$image_index]} ]
|
|
448
|
+ then reports[${#reports[@]}]="${msg[22]}${image_zmd[$image_index]} - ${msg[13]}";
|
|
449
|
+ makeErr
|
|
450
|
+ fi
|
|
451
|
+ size_zmd[$image_index]=$(stat -c%s ${image_zmd[$image_index]});
|
|
452
|
+ done
|
|
453
|
+# test size image end size zram ...
|
|
454
|
+for (( im_index=0; im_index != ${#image_zmd[@]}; im_index++ ))
|
|
455
|
+ do
|
|
456
|
+ total_size_images=$(($total_size_images+${size_zmd[$im_index]}));
|
|
457
|
+ done
|
|
458
|
+}
|
|
459
|
+
|
|
460
|
+function test_false() {
|
|
461
|
+ reports=();
|
|
462
|
+ reports[${#reports[@]}]="${msg[22]}$set_image - ${msg[14]}";
|
|
463
|
+ makeErr;
|
|
464
|
+}
|
|
465
|
+iFs=( "$(echo -n ${#image_zmd[@]}) > 0" );
|
|
466
|
+logic=( '"test_null" "sum_img"' );
|
|
467
|
+eXlogic;
|
|
468
|
+
|
|
469
|
+iFs=( "$(echo -n $total_size_images) <= $limit_mem" );
|
|
470
|
+logic=( '"test_false" "test_true"' );
|
|
471
|
+eXlogic;
|
|
472
|
+
|
|
473
|
+}
|
|
474
|
+
|
|
475
|
+##--@F step operation
|
|
476
|
+function reportConf() {
|
|
477
|
+ if (( $total_size_images > 1024 ))
|
|
478
|
+ then
|
|
479
|
+ input_unit=( "$total_size_images" "math_unit" "1" );
|
|
480
|
+ Kb;
|
|
481
|
+ rep_size="$math_unit""Kb";
|
|
482
|
+ else
|
|
483
|
+ rep_size="$total_size_images""b";
|
|
484
|
+ fi
|
|
485
|
+ reports[${#reports[@]}]="size images: $rep_size";
|
|
486
|
+ reports[${#reports[@]}]="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
|
|
487
|
+ reports[${#reports[@]}]="${msg[20]} $info_limit_mem Mb";
|
|
488
|
+}
|
|
489
|
+
|
|
490
|
+##--@F step operation
|
|
491
|
+function createZraid(){
|
|
492
|
+local check_start="0"
|
|
493
|
+if [ "$(lsmod |grep zram|wc -m)" == 0 ]
|
|
494
|
+ then
|
|
495
|
+ modprobe zram num_devices=${#id_zmd[@]};
|
|
496
|
+ fi
|
|
497
|
+
|
|
498
|
+for ((crt_index=0; crt_index != ${#id_zmd[@]}; crt_index++))
|
|
499
|
+ do
|
|
500
|
+set_md_id=${id_zmd[$crt_index]};
|
|
501
|
+singleTestMd;
|
|
502
|
+
|
|
503
|
+local tstart_md=$(echo ${set_md_status[@]}|tr -d ' '|sed 's/\"//g');
|
|
504
|
+if [[ "$tstart_md" == "" ]] || [[ ! "$tstart_md" =~ ^([0-9]+)$ ]] || (( "$tstart_md" < "0" ))
|
|
505
|
+ then
|
|
506
|
+ reports=();
|
|
507
|
+ reports[${#reports[@]}]=${msg[10]};
|
|
508
|
+ makeErr;
|
|
509
|
+fi
|
|
510
|
+if [[ "$tstart_md" == "001" ]]
|
|
511
|
+ then
|
|
512
|
+ check_start=$(echo $(($check_start+1)));
|
|
513
|
+ zblock_dev=$((${size_zmd[$crt_index]}));
|
|
514
|
+ echo $zblock_dev > /sys/block/zram$crt_index/disksize;
|
|
515
|
+ on_loop=$(losetup -f "${image_zmd[$crt_index]}" && losetup -a |grep "${image_zmd[$crt_index]}"|awk '{print$1}'|sed 's/\://g');
|
|
516
|
+#
|
|
517
|
+set_image_name=${image_zmd[$crt_index]};
|
|
518
|
+prepareMd;
|
|
519
|
+#
|
|
520
|
+if [[ $set_prepare == "0" ]]
|
|
521
|
+ then
|
|
522
|
+ echo -e "y"|mdadm --create /dev/md${id_zmd[$crt_index]} --auto=yes --metadata=1.2 --level=raid1 --raid-devices=2 missing $on_loop;
|
|
523
|
+ echo -e "y"|mdadm --add /dev/md${id_zmd[$crt_index]} /dev/zram$crt_index;
|
|
524
|
+ else
|
|
525
|
+ echo -e "y"|mdadm --create /dev/md${id_zmd[$crt_index]} --assume-clean --auto=yes --metadata=1.2 --level=raid1 --raid-devices=2 missing $on_loop;
|
|
526
|
+ echo -e "y"|mdadm --add /dev/md${id_zmd[$crt_index]} /dev/zram$crt_index;
|
|
527
|
+ fi
|
|
528
|
+fi
|
|
529
|
+done
|
|
530
|
+
|
|
531
|
+if (( "$check_start" >"0" ))
|
|
532
|
+ then
|
|
533
|
+ reports[${#reports[@]}]=${msg[16]};
|
|
534
|
+ writeToLog;
|
|
535
|
+ printInfo;
|
|
536
|
+ else
|
|
537
|
+ reports[${#reports[@]}]=${msg[50]};
|
|
538
|
+ writeToLog;
|
|
539
|
+ printInfo;
|
|
540
|
+fi
|
|
541
|
+}
|
|
542
|
+
|
|
543
|
+##--@F step operation --------
|
|
544
|
+function offZraid(){
|
|
545
|
+local check_stop="0";
|
|
546
|
+for ((off_index=0; off_index != ${#id_zmd[@]}; off_index++))
|
|
547
|
+ do
|
|
548
|
+set_md_id=${id_zmd[$off_index]};
|
|
549
|
+singleTestMd;
|
|
550
|
+local tstop_md=$(echo ${set_md_status[@]}|tr -d ' '|sed 's/\"//g');
|
|
551
|
+
|
|
552
|
+if [[ "$tstop_md" == "" ]] || [[ ! "$tstop_md" =~ ^([0-9]+)$ ]] || (( "$tstop_md" < "0" ))
|
|
553
|
+ then
|
|
554
|
+ reports=();
|
|
555
|
+ reports[${#reports[@]}]=${msg[10]};
|
|
556
|
+ makeErr;
|
|
557
|
+fi
|
|
558
|
+
|
|
559
|
+if [[ "$tstop_md" == "111" ]]||[[ "$tstop_md" == "101" ]]
|
|
560
|
+ then
|
|
561
|
+check_stop=$(echo $(($check_stop+1)));
|
|
562
|
+local off_set_loop=$(losetup -a |grep "${image_zmd[$off_index]}"|awk '{print$1}'|sed 's/\://g');
|
|
563
|
+local off_set_zraid=$(cat /proc/mdstat |grep "md$set_md_id"|tail -n1|awk '{print$5}'|sed 's/\[2]//g');
|
|
564
|
+mdadm -S /dev/md$set_md_id;
|
|
565
|
+ if [[ "$off_set_loop" ]]
|
|
566
|
+ then
|
|
567
|
+ losetup -d $off_set_loop;
|
|
568
|
+ fi
|
|
569
|
+
|
|
570
|
+local kernel_type=$(echo ${kernel_status[@]}|tr -d ' '|sed 's/\:\"//g');
|
|
571
|
+ if [ "$kernel_type" == "11" ]
|
|
572
|
+ then
|
|
573
|
+ if [ "$(lsmod|grep zram|wc -m)" != "0" ]
|
|
574
|
+ then
|
|
575
|
+ echo $(echo $off_set_zraid|sed 's/\dev//g'|sed 's/\zram//g'|sed 's/\///g') > /sys/class/zram-control/hot_remove ;
|
|
576
|
+ fi
|
|
577
|
+ fi
|
|
578
|
+fi
|
|
579
|
+done
|
|
580
|
+
|
|
581
|
+if [ $(lsmod|grep zram|wc -m) ]
|
|
582
|
+ then modprobe -r zram;
|
|
583
|
+fi
|
|
584
|
+if (( "$check_stop" >"0" ))
|
|
585
|
+ then
|
|
586
|
+ reports[${#reports[@]}]=${msg[17]};
|
|
587
|
+ writeToLog;
|
|
588
|
+ printInfo;
|
|
589
|
+ else
|
|
590
|
+ reports[${#reports[@]}]=${msg[19]};
|
|
591
|
+ writeToLog;
|
|
592
|
+ printInfo;
|
|
593
|
+fi
|
|
594
|
+}
|
|
595
|
+
|
|
596
|
+##--@F step operation
|
|
597
|
+function statusZraid(){
|
|
598
|
+status=();
|
|
599
|
+for ((st_index=0; st_index != ${#id_zmd[@]}; st_index++))
|
|
600
|
+ do
|
|
601
|
+ test_loop="$(cat /proc/mdstat |grep md${id_zmd[$st_index]}|awk '{print$6}'|cut -d'[' -f1)";
|
|
602
|
+ if [ "$test_loop" ]
|
|
603
|
+ then
|
|
604
|
+ test_zmd="$(sudo losetup -a |grep $test_loop|awk '{print$3}'|grep ${image_zmd[$st_index]}|wc -m)";
|
|
605
|
+ if [ "$test_zmd" ]
|
|
606
|
+ then status[${#status[@]}]="md${id_zmd[$st_index]}";
|
|
607
|
+ fi
|
|
608
|
+ fi
|
|
609
|
+done
|
|
610
|
+if [ $test_status != 0 ]
|
|
611
|
+ then
|
|
612
|
+ test_status=0;
|
|
613
|
+ if [ ! ${#status[@]} == 0 ]
|
|
614
|
+ then
|
|
615
|
+ reports[${#reports[@]}]="${msg[18]} ${status[@]}";
|
|
616
|
+ writeToLog;
|
|
617
|
+ printInfo;
|
|
618
|
+ exit 0;
|
|
619
|
+ else
|
|
620
|
+ reports[${#reports[@]}]=${msg[19]};
|
|
621
|
+ writeToLog;
|
|
622
|
+ printInfo;
|
|
623
|
+ exit 0;
|
|
624
|
+ fi
|
|
625
|
+fi
|
|
626
|
+}
|
|
627
|
+
|
|
628
|
+##--@F step operation
|
|
629
|
+function testId() {
|
|
630
|
+if (( ! $(id|grep "root"|wc -m) ))
|
|
631
|
+ then
|
|
632
|
+ reports=();
|
|
633
|
+ reports[${#reports[@]}]="${msg[47]}";
|
|
634
|
+ makeErr;
|
|
635
|
+fi
|
|
636
|
+}
|
|
637
|
+
|
|
638
|
+##............................................................................................
|
|
639
|
+function singleStart() {
|
|
640
|
+
|
|
641
|
+local tset_md=$(echo ${set_md_status[@]}|tr -d ' '|sed 's/\"//g');
|
|
642
|
+if [[ "$tset_md" == "" ]] || [[ ! "$tset_md" =~ ^([0-9]+)$ ]] || (( "$tset_md" < "0" ))
|
|
643
|
+ then
|
|
644
|
+ reports=();
|
|
645
|
+ reports[${#reports[@]}]=${msg[10]};
|
|
646
|
+ makeErr;
|
|
647
|
+fi
|
|
648
|
+iFs=( "$tset_md == 001"
|
|
649
|
+ "$tset_md == 111"
|
|
650
|
+ "$tset_md == 100"
|
|
651
|
+ "$tset_md == 000" );
|
|
652
|
+logic=( '"" "startSmd"'
|
|
653
|
+ '"" "noStartSmd"'
|
|
654
|
+ '"" "busSmd"'
|
|
655
|
+ '"" "noConfSmd"' );
|
|
656
|
+
|
|
657
|
+function noStartSmd() {
|
|
658
|
+ lEnd=0;
|
|
659
|
+ reports=();
|
|
660
|
+ reports[${#reports[@]}]="md$set_md_id${msg[50]}";
|
|
661
|
+ printInfo;
|
|
662
|
+ exit 0;
|
|
663
|
+}
|
|
664
|
+
|
|
665
|
+function busSmd() {
|
|
666
|
+ lEnd=0;
|
|
667
|
+ reports=();
|
|
668
|
+ reports[${#reports[@]}]="md$set_md_id${msg[15]}";
|
|
669
|
+ printInfo;
|
|
670
|
+ exit 0;
|
|
671
|
+}
|
|
672
|
+
|
|
673
|
+function noConfSmd() {
|
|
674
|
+ lEnd=0;
|
|
675
|
+ reports=();
|
|
676
|
+ reports[${#reports[@]}]="md$set_md_id : ${msg[9]}";
|
|
677
|
+ printInfo;
|
|
678
|
+ exit 0;
|
|
679
|
+}
|
|
680
|
+
|
|
681
|
+function startSmd () {
|
|
682
|
+lEnd=0;
|
|
683
|
+local on_set_image="$(cat $zconfig|jq -c '.md[]|select(.id == "'$set_md_id'")|.image'|sed 's/\"//g' )";
|
|
684
|
+local on_set_loop="$(losetup -f)";
|
|
685
|
+losetup "$on_set_loop" "$on_set_image";
|
|
686
|
+if (( $(lsmod|grep zram|wc -m) != 0 ))
|
|
687
|
+ then
|
|
688
|
+ cat /sys/class/zram-control/hot_add >/dev/nill ; ## add zram dev!
|
|
689
|
+ else
|
|
690
|
+ modprobe zram num_devices=1;
|
|
691
|
+fi
|
|
692
|
+local set_zram_id="$(echo $(($(ls /dev/zram*|sed 's/\dev//g'|sed 's/\zram//g'|sed 's/\///g'|tr -d '\r\n'|wc -c)-1)))";
|
|
693
|
+local zset_block_dev=$(stat -c%s "$on_set_image");
|
|
694
|
+echo $zset_block_dev > /sys/block/zram$set_zram_id/disksize;
|
|
695
|
+#
|
|
696
|
+set_image_name=$on_set_image;
|
|
697
|
+prepareMd;
|
|
698
|
+#
|
|
699
|
+if [[ $set_prepare == "0" ]]
|
|
700
|
+ then
|
|
701
|
+ echo -e "y"|mdadm --create /dev/md$set_md_id --auto=yes --metadata=1.2 --level=raid1 --raid-devices=2 missing $on_set_loop;
|
|
702
|
+ echo -e "y"|mdadm --add /dev/md$set_md_id /dev/zram$set_zram_id;
|
|
703
|
+ else
|
|
704
|
+ echo -e "y"|mdadm --create /dev/md$set_md_id --assume-clean --auto=yes --metadata=1.2 --level=raid1 --raid-devices=2 missing $on_set_loop;
|
|
705
|
+ echo -e "y"|mdadm --add /dev/md$set_md_id /dev/zram$set_zram_id;
|
|
706
|
+ fi
|
|
707
|
+}
|
|
708
|
+eXlogic;
|
|
709
|
+reports[${#reports[@]}]="${msg[43]} : start - /dev/md$set_md_id";
|
|
710
|
+writeToLog;
|
|
711
|
+echo -e "${reports[@]}";
|
|
712
|
+}
|
|
713
|
+
|
|
714
|
+##............................................................................................
|
|
715
|
+function singleStop() {
|
|
716
|
+local tset_md=$(echo ${set_md_status[@]}|tr -d ' '|sed 's/\"//g');
|
|
717
|
+if [[ "$tset_md" == "" ]] || [[ ! "$tset_md" =~ ^([0-9]+)$ ]] || (( "$tset_md" < "0" ))
|
|
718
|
+ then
|
|
719
|
+ reports=();
|
|
720
|
+ reports[${#reports[@]}]=${msg[10]};
|
|
721
|
+ makeErr;
|
|
722
|
+fi
|
|
723
|
+iFs=( "$tset_md == 001"
|
|
724
|
+ "$tset_md == 111"
|
|
725
|
+ "$tset_md == 101"
|
|
726
|
+ "$tset_md == 100"
|
|
727
|
+ "$tset_md == 000" );
|
|
728
|
+logic=( '"" "noStopSmd"'
|
|
729
|
+ '"" "stopSmd"'
|
|
730
|
+ '"" "stopSmd"'
|
|
731
|
+ '"" "sBusSmd"'
|
|
732
|
+ '"" "noConfSmd"' );
|
|
733
|
+
|
|
734
|
+function noStopSmd() {
|
|
735
|
+ lEnd=0;
|
|
736
|
+ reports=();
|
|
737
|
+ reports[${#reports[@]}]="${msg[44]}md$set_md_id";
|
|
738
|
+ reports[${#reports[@]}]="${msg[42]}";
|
|
739
|
+ printInfo;
|
|
740
|
+ exit 0;
|
|
741
|
+}
|
|
742
|
+
|
|
743
|
+function sBusSmd() {
|
|
744
|
+ lEnd=0;
|
|
745
|
+ reports=();
|
|
746
|
+ reports[${#reports[@]}]="md$set_md_id${msg[15]}";
|
|
747
|
+ printInfo;
|
|
748
|
+ exit 0;
|
|
749
|
+}
|
|
750
|
+
|
|
751
|
+function noConfSmd() {
|
|
752
|
+ lEnd=0;
|
|
753
|
+ reports=();
|
|
754
|
+ reports[${#reports[@]}]="md$set_md_id : ${msg[9]}";
|
|
755
|
+ printInfo;
|
|
756
|
+ exit 0;
|
|
757
|
+}
|
|
758
|
+
|
|
759
|
+function stopSmd () {
|
|
760
|
+lEnd=0;
|
|
761
|
+local off_set_loop="/dev/$(ls /sys/block/"md$set_md_id"/md/|grep loop|sed 's/dev-//g')";
|
|
762
|
+local off_set_zraid=$(cat /proc/mdstat |grep "md$set_md_id"|tail -n1|awk '{print$5}'|sed 's/\[2]//g');
|
|
763
|
+mdadm -S /dev/md$set_md_id;
|
|
764
|
+
|
|
765
|
+echo $(echo $off_set_zraid|sed 's/\dev//g'|sed 's/\zram//g'|sed 's/\///g') > /sys/class/zram-control/hot_remove;
|
|
766
|
+if [[ $off_set_loop ]]
|
|
767
|
+ then
|
|
768
|
+ losetup -d $off_set_loop;
|
|
769
|
+fi
|
|
770
|
+}
|
|
771
|
+eXlogic;
|
|
772
|
+reports[${#reports[@]}]="${msg[43]} : stop - /dev/md$set_md_id";
|
|
773
|
+writeToLog;
|
|
774
|
+echo -e "${reports[@]}";
|
|
775
|
+}
|
|
776
|
+
|
|
777
|
+##...........................................................................................
|
|
778
|
+function singleTestMd() {
|
|
779
|
+local check_md=$(cat /proc/mdstat |grep "md$set_md_id"|tail -n 1|awk '{print$1}'|wc -m);
|
|
780
|
+local check_zram=$(cat /proc/mdstat |grep "md$set_md_id"|grep zram|wc -m);
|
|
781
|
+local check_conf=$(cat $zconfig|jq -c '.md[]."id"'|grep -e "$set_md_id"|sed 's/\"//g'|sed 's/^[ \t]*//;s/[ \t]*$//'|wc -m);
|
|
782
|
+
|
|
783
|
+iFs=( "$check_md == 0"
|
|
784
|
+ "$check_conf == 0"
|
|
785
|
+ "$check_zram == 0" );
|
|
786
|
+
|
|
787
|
+logic=( '"statusOn" "statusOff"' # test on MD
|
|
788
|
+ '"mDconfOn" "mDconfOff"' # test MD in conf
|
|
789
|
+ '"mDzramOn" "mDzramOff"' # test zram in MD
|
|
790
|
+ );
|
|
791
|
+
|
|
792
|
+ function statusOn() {
|
|
793
|
+ set_md_status[0]="1";
|
|
794
|
+ }
|
|
795
|
+
|
|
796
|
+ function statusOff() {
|
|
797
|
+ set_md_status[0]="0";
|
|
798
|
+ }
|
|
799
|
+
|
|
800
|
+ function mDzramOn() {
|
|
801
|
+ set_md_status[1]="1";
|
|
802
|
+ }
|
|
803
|
+
|
|
804
|
+ function mDzramOff() {
|
|
805
|
+ set_md_status[1]="0";
|
|
806
|
+ }
|
|
807
|
+
|
|
808
|
+ function mDconfOn() {
|
|
809
|
+ set_md_status[2]="1";
|
|
810
|
+ }
|
|
811
|
+
|
|
812
|
+ function mDconfOff() {
|
|
813
|
+ set_md_status[2]="0";
|
|
814
|
+ }
|
|
815
|
+eXlogic;
|
|
816
|
+}
|
|
817
|
+
|
|
818
|
+##..........................................................................................
|
|
819
|
+function prepareMd() {
|
|
820
|
+local check_loop=$(losetup -a |grep "$set_image_name"|awk '{print$1}'|sed 's/\/dev\/\|s//g;s/\://g');
|
|
821
|
+if (( $(cat /proc/mdstat |grep "$check_loop"|awk '{print$1}'|wc -m) != "0" ))
|
|
822
|
+ then
|
|
823
|
+ mdadm -S /dev/$(cat /proc/mdstat |grep "$check_loop"|awk '{print$1}');
|
|
824
|
+ set_prepare="1";
|
|
825
|
+ else
|
|
826
|
+ set_prepare="0";
|
|
827
|
+fi
|
|
828
|
+}
|
|
829
|
+
|
|
830
|
+##...........................................................................................
|
|
831
|
+function inParams() {
|
|
832
|
+local kernel_type=$(echo ${kernel_status[@]}|tr -d ' ');
|
|
833
|
+if (( "$kernel_type" != "11" ))
|
|
834
|
+ then
|
|
835
|
+ reports=();
|
|
836
|
+ reports[${#reports[@]}]="${msg[49]}";
|
|
837
|
+ makeErr;
|
|
838
|
+fi
|
|
839
|
+eval set_params="(" $(echo -e $params|sed 's/\md//g') ")";
|
|
840
|
+if (( "${#set_params[@]}" >= "1" ))
|
|
841
|
+ then
|
|
842
|
+ set_md_id="${set_params[0]}";
|
|
843
|
+ if [[ "$set_md_id" == "" ]]||[[ ! "$set_md_id" =~ ^([0-9]+)$ ]]||(( "$set_md_id" <= "0" ))
|
|
844
|
+ then
|
|
845
|
+ reports=();
|
|
846
|
+ reports[${#reports[@]}]="${msg[10]}";
|
|
847
|
+ makeErr;
|
|
848
|
+ fi
|
|
849
|
+ else
|
|
850
|
+ reports=();
|
|
851
|
+ reports[${#reports[@]}]="${msg[10]}";
|
|
852
|
+ makeErr;
|
|
853
|
+fi
|
|
854
|
+
|
|
855
|
+}
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+##--@F executor
|
|
859
|
+function executor() {
|
|
860
|
+if [[ ${#execute_func[@]} -eq 0 ]]
|
|
861
|
+ then echo "exit";
|
|
862
|
+ exit 0;
|
|
863
|
+fi
|
|
864
|
+for ((ex_index=0; ex_index != ${#execute_func[@]}; ex_index++))
|
|
865
|
+ do
|
|
866
|
+ ## !! debug operation...
|
|
867
|
+ ##echo "execution: function ${execute_func[ex_index]}"
|
|
868
|
+ ${execute_func[ex_index]};
|
|
869
|
+done
|
|
870
|
+}
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+##- Begin ZRAID
|
|
874
|
+case "$option" in
|
|
875
|
+
|
|
876
|
+## on zraid
|
|
877
|
+"--on" | "--on" )
|
|
878
|
+if [ ! "$params" ]
|
|
879
|
+ then
|
|
880
|
+ execute_func=( ${operation_on[@]} );
|
|
881
|
+ executor;
|
|
882
|
+ else
|
|
883
|
+ execute_func=( ${operation_sign_on[@]} );
|
|
884
|
+ executor;
|
|
885
|
+fi
|
|
886
|
+exit 0;
|
|
887
|
+;;
|
|
888
|
+
|
|
889
|
+## off zraid
|
|
890
|
+"--off" | "--off" )
|
|
891
|
+if [ ! "$params" ]
|
|
892
|
+ then
|
|
893
|
+ execute_func=( ${operation_off[@]} );
|
|
894
|
+ executor;
|
|
895
|
+ else
|
|
896
|
+ execute_func=( ${operation_sign_off[@]} );
|
|
897
|
+ executor;
|
|
898
|
+fi
|
|
899
|
+exit 0;
|
|
900
|
+;;
|
|
901
|
+
|
|
902
|
+## status zraid
|
|
903
|
+"--status" | "--status" )
|
|
904
|
+test_status=1;
|
|
905
|
+execute_func=( ${operation_status[@]} );
|
|
906
|
+executor;
|
|
907
|
+exit 0;
|
|
908
|
+;;
|
|
909
|
+
|
|
910
|
+## test config
|
|
911
|
+"--test" | "--test" )
|
|
912
|
+execute_func=( ${operation_test[@]} );
|
|
913
|
+executor;
|
|
914
|
+exit 0;
|
|
915
|
+;;
|
|
916
|
+
|
|
917
|
+## help
|
|
918
|
+"--help" | "--help" )
|
|
919
|
+execute_func=( ${operation_help[@]} );
|
|
920
|
+executor;
|
|
921
|
+exit 0;
|
|
922
|
+;;
|
|
923
|
+
|
|
924
|
+* )
|
|
925
|
+# selecting defaults.
|
|
926
|
+execute_func=( ${operation_help[@]} );
|
|
927
|
+executor;
|
|
928
|
+exit 1;
|
|
929
|
+;;
|
|
930
|
+esac
|