5e0e1941854053e11a491c15647baa1be5c60cbc
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / functions.sh
1 uci_remove_list_element() {
2 local option="$1"
3 local value="$2"
4 local list="$(uci get $option)"
5 local elem
6
7 uci delete $option
8 for elem in $list; do
9 if [ "$elem" != "$value" ]; then
10 uci add_list $option=$elem
11 fi
12 done
13 }
14
15 set_defaults() {
16 for def in $(env |grep "^$1"); do
17 option=${def/$1/}
18 uci set $2.$option
19 echo " ${option/=/: }"
20 done
21 }
22
23 # 1 argument: section to remove
24 section_cleanup() {
25 uci -q delete $1 && msg_cleanup $1 || msg_cleanup_error $1
26 }
27
28 # 3 arguements: 1=config name 2=oldname 3=newname
29 section_rename() {
30 uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.2 $1.$3
31 }
32
33 msg_start() {
34 echo " Starting configuration of $1"
35 }
36
37 msg_cleanup() {
38 echo " Cleanup: Removed section $1."
39 }
40
41 msg_cleanup_error() {
42 echo -e " \033[1mWarning:\033[0m Cleanup of $1 failed."
43 }
44
45 msg_missing_value() {
46 echo -e " \033[1mWarning:\033[0m Configuration option for $2 is missing in $1."
47 }
48
49 msg_success() {
50 echo " Finished."
51 }
52
53 msg_error() {
54 echo " \033[1mError: \033[0mThere was a problem."
55 }
56
57 msg_rename() {
58 echo " Renamed unnamed section $1 to $2."
59 }
60
61 msg_rename_error() {
62 echo " \033[1mWarning:\033[0m Could not rename $1 to $2."
63 }