[packages]: net/freeswitch: Added initial uci configuration capability.
[openwrt/svn-archive/archive.git] / net / freeswitch / files / uci / line_mod.sh
1 #!/bin/sh
2 # Copyright (C) 2010 Vertical Communications
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5
6 # Uncomment commented out XML line
7 fs_uncomment_xml_line() {
8 local file="$1"
9 local tag="$2"
10 local attribute1="$3"
11 local value1="$4"
12 local attribute2="$5"
13 local value2="$6"
14 if [ -n "$attribute2" ]; then
15 if [ -n "$value2" ]; then
16 sed -i -e "/<${tag} ${attribute1}=\"""${value1}""\".*${attribute2}=\"""${value2}""\".*\/>/ s|^\(.*\)<!--.*<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)${attribute2}\=\"""${value2}""\"\(.*\)/>.*-->\(.*\)\$|\1<${tag}\2${attribute1}=\"${value1}\"\3${attribute2}=\"${value2}\"\4/>\5|" $file
17 else
18 sed -i -e "/<${tag} ${attribute1}=\"""${value1}""\".*${attribute2}=.*\/>/ s|^\(.*\)<!--.*<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)${attribute2}\=\(.*\)/>.*-->\(.*\)\$|\1<${tag}\2${attribute1}=\"""${value1}""\"\3${attribute2}=\4/>\5|" $file
19 fi
20 elif [ -n "$attribute1" ]; then
21 sed -i -e "/<${tag} ${attribute1}=\"""${value1}""\".*\/>/ s|^\(.*\)<!--.*<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)\/>.*-->\(.*\)\$|\1<${tag}\2${attribute1}=\"""${value1}""\"\3\/>\4|" $file
22 else
23 logger -t freeswitch "Error uncommenting tag $tag in file $1; no attributes defined"
24 fi
25 }
26
27 # Comment previously uncommented XML line
28 fs_comment_xml_line() {
29 local file="$1"
30 local tag="$2"
31 local attribute1="$3"
32 local value1="$4"
33 local attribute2="$5"
34 local value2="$6"
35 if [ -n "$attribute2" ]; then
36 sed -i -e "/<[^!]${tag} ${attribute1}=\"""${value1}""\".*${attribute2}=\"""${value2}""\"\/>/ s|\(.*\)<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)${attribute2}=\"""${value2}""\"\(.*\)/>(.*\)\$|<!-- \1<${tag}\2${attribute1}=\"${value1}\"\3${attribute2}=\"""${value2}""\"\4/>\5 -->|" $file
37 elif [ -n "$attribute1" ]; then
38 sed -i -e "/<[^!]${tag} ${attribute1}=\"""${value1}""\".*\/>/ s|\(.*\)<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)/>\(.*\)\$|\1<!-- <${tag}\2${attribute1}=\"""${value1}""\"\3/>\4 -->|" $file
39 else
40 logger -t freeswitch "Error uncommenting tag $tag in file $1; no attributes defined"
41 fi
42 }
43
44 # Modify second attribute in tag with two attributes (tag and one attribute
45 # specified) if tag exists and is comments modifies, if commented,
46 # uncomments and and modifies it.
47 fs_mod_attribute2() {
48 local file="$1"
49 local tag="$2"
50 local attribute1="$3"
51 local value1="$4"
52 local attribute2="$5"
53 local newvalue="$6"
54 fs_uncomment_xml_line "$file" "$tag" "$attribute1" "$value1" "$attribute2"
55 sed -i -e "/[^<!-]*<${tag} ${attribute1}=\"""${value1}""\".*${attribute2}=\""".*""\"\/>/ s|\(.*\)<${tag}\(.*\)${attribute1}=\"""${value1}""\"\(.*\)${attribute2}=\""".*""\"\(.*\)/>\(.*\)\$|\1<${tag}\2${attribute1}=\"""${value1}""\"\3${attribute2}=\"""${newvalue}""\"\4/>\5|" $file
56 }
57
58 fs_set_param() {
59 local file="$1"
60 local param="$2"
61 local newvalue="$3"
62
63 if [ -n "$newvalue" ]; then
64 fs_mod_attribute2 "$file" param name "$param" value "$newvalue"
65 else
66 fs_comment_xml_line "$file" param name "$param"
67 fi
68 }
69
70 fs_set_param_bool() {
71 local file="$1"
72 local param="$2"
73 local boolvalue="$3"
74
75 if [ "$boolvalue" = "0" ]; then
76 fs_set_param "$file" "$param" "false"
77 else
78 fs_set_param "$file" "$param" "true"
79 fi
80 }
81