• R/O
  • HTTP
  • SSH
  • HTTPS

packages: Commit

Community maintained packages for ImmortalWrt.


Commit MetaInfo

Révision0aaa90629c8e72447ca44cde83df9d126811eb5f (tree)
l'heure2022-01-20 21:57:46
AuteurNick Hainke <vincent@syst...>
CommiterNick Hainke

Message de Log

wg-installer: rework code

Use shellcheck to rework the code. Use "export" to return variables from
a function call. Further, fix typos.

Signed-off-by: Nick Hainke <vincent@systemli.org>
(cherry picked from commit 69c81790d1045e064cd9c643a1643a0f919f448d)

Change Summary

Modification

--- a/net/wg-installer/common/wg.sh
+++ b/net/wg-installer/common/wg.sh
@@ -6,9 +6,9 @@ next_port () {
66
77 ports=$(wg show all listen-port | awk '{print $2}')
88
9- for i in $(seq $port_start $port_end); do
10- if ! echo $ports | grep -q "$i"; then
11- echo $i
9+ for i in $(seq "$port_start" "$port_end"); do
10+ if ! echo "$ports" | grep -q "$i"; then
11+ echo "$i"
1212 return
1313 fi
1414 done
@@ -25,15 +25,13 @@ delete_wg_interface() {
2525 }
2626
2727 check_wg_neighbors() {
28- local phy
29-
3028 wg_interfaces=$(ip link | grep wg | awk '{print $2}' | sed 's/://')
3129 for phy in $wg_interfaces; do
32- linklocal=$(ip -6 addr list dev $phy | grep "scope link" | awk '{print $2}' | sed 's/\/64//') 2>/dev/null
33- ips=$(ping ff02::1%$phy -w5 -W5 -c10 | awk '/from/{print($4)}' | sed 's/.$//') 2>/dev/null
30+ linklocal=$(ip -6 addr list dev "$phy" | grep "scope link" | awk '{print $2}' | sed 's/\/64//') 2>/dev/null
31+ ips=$(ping ff02::1%"$phy" -w5 -W5 -c10 | awk '/from/{print($4)}' | sed 's/.$//') 2>/dev/null
3432 delete=1
3533 for ip in $ips; do
36- if [ $ip != $linklocal ] && [ $(owipcalc $ip linklocal) -eq 1 ]; then
34+ if [ "$ip" != "$linklocal" ] && [ "$(owipcalc $ip linklocal)" -eq 1 ]; then
3735 delete=0
3836 break
3937 fi
--- a/net/wg-installer/wg-client/config/wgclient.conf
+++ b/net/wg-installer/wg-client/config/wgclient.conf
@@ -1,7 +1,4 @@
11 config client
2- option wg_key '/root/wg.key'
3- option wg_pub '/root/wg.pub'
4- option base_prefix '2000::/64'
52 option port_start '51820'
63 option port_end '52820'
74 option try_insecure '1'
--- a/net/wg-installer/wg-client/lib/rpcd_ubus.sh
+++ b/net/wg-installer/wg-client/lib/rpcd_ubus.sh
@@ -1,3 +1,5 @@
1+#!/bin/sh
2+
13 . /usr/share/libubox/jshn.sh
24
35 query_gw () {
@@ -5,26 +7,26 @@ query_gw () {
57 local req=$2
68
79 # first try https
8- ret=$(curl https://$ip/ubus -d "$req") 2>/dev/null
10+ ret=$(curl https://"$ip"/ubus -d "$req") 2>/dev/null
911 if [ $? -eq 0 ]; then
10- echo $ret
12+ echo "$ret"
1113 return 0
1214 fi
1315
1416 # try with --insecure
15- if [ $(uci get wgclient.@client[0].try_insecure) == '1' ]; then
16- ret=$(curl --insecure https://$ip/ubus -d "$req") 2>/dev/null
17+ if [ "$(uci get wgclient.@client[0].try_insecure)" -eq '1' ]; then
18+ ret=$(curl --insecure https://"$ip"/ubus -d "$req") 2>/dev/null
1719 if [ $? -eq 0 ]; then
18- echo $ret
20+ echo "$ret"
1921 return 0
2022 fi
2123 fi
2224
2325 # try with http
24- if [ $(uci get wgclient.@client[0].try_http) == '1' ]; then
25- ret=$(curl http://$ip/ubus -d "$req") 2>/dev/null
26+ if [ "$(uci get wgclient.@client[0].try_http)" -eq '1' ]; then
27+ ret=$(curl http://"$ip"/ubus -d "$req") 2>/dev/null
2628 if [ $? -eq 0 ]; then
27- echo $ret
29+ echo "$ret"
2830 return 0
2931 fi
3032 fi
@@ -46,13 +48,13 @@ request_token () {
4648 json_add_string "" "session"
4749 json_add_string "" "login"
4850 json_add_object
49- json_add_string "username" $user
50- json_add_string "password" $password
51+ json_add_string "username" "$user"
52+ json_add_string "password" "$password"
5153 json_close_object
5254 json_close_array
5355 req=$(json_dump)
54- ret=$(query_gw $ip "$req") 2>/dev/null
55- if [ $? != 0 ]; then
56+ ret=$(query_gw "$ip" "$req") 2>/dev/null
57+ if [ $? -ne 0 ]; then
5658 return 1
5759 fi
5860 json_load "$ret"
@@ -60,7 +62,7 @@ request_token () {
6062 json_select result
6163 json_select 2
6264 json_get_var ubus_rpc_session ubus_rpc_session
63- echo $ubus_rpc_session
65+ echo "$ubus_rpc_session"
6466 }
6567
6668 wg_rpcd_get_usage () {
@@ -73,18 +75,17 @@ wg_rpcd_get_usage () {
7375 json_add_int "id" "1"
7476 json_add_string "method" "call"
7577 json_add_array "params"
76- json_add_string "" $token
78+ json_add_string "" "$token"
7779 json_add_string "" "wginstaller"
7880 json_add_string "" "get_usage"
7981 json_add_object
8082 json_close_object
8183 json_close_array
8284 req=$(json_dump)
83- ret=$(query_gw $ip "$req") 2>/dev/null
84- if [ $? != 0 ]; then
85+ ret=$(query_gw "$ip" "$req") 2>/dev/null
86+ if [ $? -ne 0 ]; then
8587 return 1
8688 fi
87-
8889 # return values
8990 json_load "$ret"
9091 json_get_vars result result
@@ -95,40 +96,39 @@ wg_rpcd_get_usage () {
9596 }
9697
9798 wg_rpcd_register () {
98- local token=$1
99- local ip=$2
100- local uplink_bw=$3
101- local mtu=$4
102- local public_key=$5
99+ local token=$5
100+ local ip=$6
101+ local mtu=$7
102+ local public_key=$8
103103
104104 json_init
105105 json_add_string "jsonrpc" "2.0"
106106 json_add_int "id" "1"
107107 json_add_string "method" "call"
108108 json_add_array "params"
109- json_add_string "" $token
109+ json_add_string "" "$token"
110110 json_add_string "" "wginstaller"
111111 json_add_string "" "register"
112112 json_add_object
113- json_add_int "uplink_bw" $uplink_bw
114- json_add_int "mtu" $mtu
115- json_add_string "public_key" $public_key
113+ json_add_int "mtu" "$mtu"
114+ json_add_string "public_key" "$public_key"
116115 json_close_object
117116 json_close_array
118117 req=$(json_dump)
119- ret=$(query_gw $ip "$req") 2>/dev/null
120- if [ $? != 0 ]; then
118+ ret=$(query_gw "$ip" "$req") 2>/dev/null
119+ if [ $? -ne 0 ]; then
121120 return 1
122121 fi
123-
124122 json_load "$ret"
125123 json_get_vars result result
126124 json_select result
127125 json_select 2
128- json_get_var pubkey pubkey
129- json_get_var gw_ip gw_ip
130- json_get_var port port
131- echo "pubkey: ${pubkey}"
132- echo "gw_ip: ${gw_ip}"
133- echo "port: ${port}"
126+ json_get_var gw_pubkey gw_pubkey
127+ json_get_var gw_ipv4 gw_ipv4
128+ json_get_var gw_ipv6 gw_ipv6
129+ json_get_var gw_port gw_port
130+ export "$1=$gw_pubkey"
131+ export "$2=$gw_ipv4"
132+ export "$3=$gw_ipv6"
133+ export "$4=$gw_port"
134134 }
--- a/net/wg-installer/wg-client/wg-client-installer.sh
+++ b/net/wg-installer/wg-client/wg-client-installer.sh
@@ -12,8 +12,8 @@ while true; do
1212 echo "help"
1313 shift 1
1414 ;;
15- -i | --ip)
16- IP=$2
15+ --endpoint)
16+ ENDPOINT=$2
1717 shift 2
1818 ;;
1919 --user)
@@ -24,10 +24,6 @@ while true; do
2424 PASSWORD=$2
2525 shift 2
2626 ;;
27- --bandwidth)
28- BANDWIDTH=$2
29- shift 2
30- ;;
3127 --mtu)
3228 WG_MTU=$2
3329 shift 2
@@ -45,86 +41,56 @@ while true; do
4541 esac
4642 done
4743
48-escape_ip () {
49- local gw_ip=$1
50-
51- # ipv4 processing
52- ret_ip=$(echo $gw_ip | tr '.' '_')
53-
54- # ipv6 processing
55- ret_ip=$(echo $ret_ip | tr ':' '_')
56- ret_ip=$(echo $ret_ip | cut -d '[' -f 2)
57- ret_ip=$(echo $ret_ip | cut -d ']' -f 1)
58-
59- echo $ret_ip
60-}
61-
6244 register_client_interface () {
63- local privkey=$1
64- local pubkey=$2
65- local gw_ip=$3
66- local gw_port=$4
67- local endpoint=$5
68- local mtu_client=$6
45+ local endpoint=$2
46+ local mtu_client=$3
47+ local privkey=$4
48+ local pubkey=$5
49+ local gw_port=$6
6950
7051 port_start=$(uci get wgclient.@client[0].port_start)
7152 port_end=$(uci get wgclient.@client[0].port_end)
72- base_prefix=$(uci get wgclient.@client[0].base_prefix)
7353
74- port=$(next_port $port_start $port_end)
54+ port=$(next_port "$port_start" "$port_end")
7555 ifname="wg_$port"
7656
77- offset=$(($port - $port_start))
78- client_ip=$(owipcalc $base_prefix add $offset next 128)
79- client_ip_assign="${client_ip}/128"
80-
81- echo "Installing Interface With:"
82- echo "Endpoint ${endpoint}"
83- echo "Client IP ${client_ip}"
84- echo "Port ${port}"
85- echo "Pubkey ${pubkey}"
57+ ip link add dev "$ifname" type wireguard
58+ ip -6 addr add dev "$ifname" fe80::2/64
59+ wg set "$ifname" listen-port "$port" private-key "$privkey" peer "$pubkey" allowed-ips 0.0.0.0/0,::0/0 endpoint "${endpoint}:${gw_port}"
60+ ip link set up dev "$ifname"
61+ ip link set mtu "$mtu_client" dev "$ifname"
8662
87- ip link add dev $ifname type wireguard
88-
89- ip -6 addr add dev $ifname $client_ip
90- ip -6 addr add dev $ifname fe80::2/64
91- wg set $ifname listen-port $port private-key $privkey peer $pubkey allowed-ips 0.0.0.0/0,::0/0 endpoint "${endpoint}:${gw_port}"
92- ip link set up dev $ifname
93- ip link set mtu $mtu_client dev $ifname # configure mtu here!
63+ export "$1=$ifname"
9464 }
9565
9666 # rpc login
97-token="$(request_token $IP $USER $PASSWORD)"
98-if [ $? != 0 ]; then
99- echo "failed to register token"
67+token="$(request_token "$ENDPOINT" "$USER" "$PASSWORD")"
68+if [ $? -ne 0 ]; then
69+ logger -t "wg-client-installer" "Failed to register token!"
10070 exit 1
10171 fi
10272
10373 # now call procedure
10474 case $CMD in
10575 "get_usage")
106- wg_rpcd_get_usage $token $IP
76+ wg_rpcd_get_usage "$token" "$ENDPOINT"
10777 ;;
10878 "register")
10979
110- if [ ! -z "$WG_KEY_FILE" ]; then
111- wg_priv_key_file=$WG_KEY_FILE
112- wg_pub_key=$(wg pubkey < $WG_KEY_FILE)
113- else
114- wg_priv_key_file=$(uci get wgclient.@client[0].wg_key)
115- wg_pub_key=$(cat $(uci get wgclient.@client[0].wg_pub))
80+ if [ -n "$WG_KEY_FILE" ]; then
81+ wg_priv_key_file="$WG_KEY_FILE"
82+ wg_pub_key=$(wg pubkey < "$WG_KEY_FILE")
11683 fi
11784
118- register_output=$(wg_rpcd_register $token $IP $BANDWIDTH $WG_MTU $wg_pub_key)
119- if [ $? != 0 ]; then
120- echo "Failed to Register!"
85+ wg_rpcd_register __gw_pubkey __gw_ipv4 __gw_ipv6 __gw_port "$token" "$ENDPOINT" "$WG_MTU" "$wg_pub_key"
86+ if [ $? -ne 0 ]; then
87+ logger -t "wg-client-installer" "Failed to Register!"
12188 exit 1
12289 fi
123- pubkey=$(echo $register_output | awk '{print $2}')
124- ip_addr=$(echo $register_output | awk '{print $4}')
125- port=$(echo $register_output | awk '{print $6}')
126- client_ip=$(echo $register_output | awk '{print $8}')
127- register_client_interface $wg_priv_key_file $pubkey $ip_addr $port $IP $WG_MTU
90+
91+ register_client_interface __interface "$ENDPOINT" "$WG_MTU" "$wg_priv_key_file" "$__gw_pubkey" "$__gw_port"
92+ logger -t "wg-client-installer" "Registered: $__interface"
93+ echo $__interface
12894 ;;
129-*) echo "Usage: wg-client-installer [cmd] --ip [2001::1] --user wginstaller --password wginstaller" ;;
95+*) echo "Usage: wg-client-installer [cmd] --endpoint [2001::1] --mtu 1500 --user wginstaller --password wginstaller" ;;
13096 esac
--- a/net/wg-installer/wg-server/config/wgserver.conf
+++ b/net/wg-installer/wg-server/config/wgserver.conf
@@ -1,8 +1,8 @@
11 config server
22 option port_start '51820'
33 option port_end '52820'
4- option base_prefix '2002::/64'
5- option base_v4prefix '10.0.0.1/24'
4+ option base_prefix_ipv4 '10.0.0.1/24'
5+ option base_prefix_ipv6 '2002::/64'
66 option wg_key '/root/wg.key'
77 option wg_pub '/root/wg.pub'
88 option wg_tmp_key '1'
--- a/net/wg-installer/wg-server/hotplug.d/99-mesh-babeld
+++ b/net/wg-installer/wg-server/hotplug.d/99-mesh-babeld
@@ -6,31 +6,31 @@ if [ "${DEVTYPE}" != "wireguard" ]; then
66 fi
77
88 # check if correct naming
9-slicedint=$(echo $INTERFACE | cut -c1-3)
9+slicedint=$(echo "$INTERFACE" | cut -c1-3)
1010 if [ "${slicedint}" != "wg_" ]; then
1111 exit 0
1212 fi
1313
14-if [ "${ACTION}" == "add" ]; then
14+if [ "${ACTION}" = "add" ]; then
1515 uci add babeld interface
1616 uci set babeld.@interface[-1].ifname="${INTERFACE}"
1717 uci get wgserver.@babeld_hotplug[0].rxcost
18- if [ $? ]; then
18+ if [ $? -eq 0 ]; then
1919 babeld_rxcost="$(uci get wgserver.@babeld_hotplug[0].rxcost)"
2020 uci set babeld.@interface[-1].rxcost="$babeld_rxcost"
2121 fi
22- uci -c "$(dirname $(realpath /etc/config/babeld))" commit babeld
22+ uci -c "$(dirname "$(realpath /etc/config/babeld)")" commit babeld
2323 /etc/init.d/babeld reload
2424 fi
2525
26-if [ "${ACTION}" == "remove" ]; then
26+if [ "${ACTION}" = "remove" ]; then
2727 i=0
2828 while uci get babeld.@interface[$i] &> /dev/null ; do
29- if [ "$(uci get babeld.@interface[$i].ifname)" == "${INTERFACE}" ]; then
29+ if [ "$(uci get babeld.@interface[$i].ifname)" = "${INTERFACE}" ]; then
3030 uci delete babeld.@interface[$i]
3131 fi
3232 i=$((i+1));
3333 done
34- uci -c "$(dirname $(realpath /etc/config/babeld))" commit babeld
34+ uci -c "$(dirname "$(realpath /etc/config/babeld)")" commit babeld
3535 /etc/init.d/babeld reload
3636 fi
--- a/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd
+++ b/net/wg-installer/wg-server/hotplug.d/99-mesh-olsrd
@@ -6,15 +6,15 @@ if [ "${DEVTYPE}" != "wireguard" ]; then
66 fi
77
88 # check if correct naming
9-slicedint=$(echo $INTERFACE | cut -c1-3)
9+slicedint=$(echo "$INTERFACE" | cut -c1-3)
1010 if [ "${slicedint}" != "wg_" ]; then
1111 exit 0
1212 fi
1313
14-if [ "${ACTION}" == "add" ]; then
15- ubus call olsrd add_interface '{"ifname":'\"$INTERFACE\"'}'
14+if [ "${ACTION}" = "add" ]; then
15+ ubus call olsrd add_interface '{"ifname":'\""$INTERFACE"\"'}'
1616 fi
1717
18-if [ "${ACTION}" == "remove" ]; then
19- ubus call olsrd del_interface '{"ifname":'\"$INTERFACE\"'}'
18+if [ "${ACTION}" = "remove" ]; then
19+ ubus call olsrd del_interface '{"ifname":'\""$INTERFACE"\"'}'
2020 fi
--- a/net/wg-installer/wg-server/lib/install_wginstaller_user.sh
+++ b/net/wg-installer/wg-server/lib/install_wginstaller_user.sh
@@ -1,7 +1,7 @@
11 #!/bin/sh
22
33 # do not override already existing user!!!
4-[ "$(uci show rpcd | grep wginstaller)" ] && exit 0
4+uci show rpcd | grep -q wginstaller && exit 0
55
66 # install wginstaller user with standard credentials
77 # user: wginstaller
@@ -10,7 +10,7 @@ uci add rpcd login
1010 uci set rpcd.@login[-1].username='wginstaller'
1111
1212 password=$(uhttpd -m wginstaller)
13-uci set rpcd.@login[-1].password=$password
13+uci set rpcd.@login[-1].password="$password"
1414 uci add_list rpcd.@login[-1].read='wginstaller'
1515 uci add_list rpcd.@login[-1].write='wginstaller'
1616 uci commit rpcd
--- a/net/wg-installer/wg-server/lib/wg_functions.sh
+++ b/net/wg-installer/wg-server/lib/wg_functions.sh
@@ -1,13 +1,15 @@
1+#!/bin/sh
2+
13 . /usr/share/libubox/jshn.sh
24 . /usr/share/wginstaller/wg.sh
35
46 wg_timeout () {
57 local int=$1
68
7- handshake=$(wg show $int latest-handshakes | awk '{print $2}')
9+ handshake=$(wg show "$int" latest-handshakes | awk '{print $2}')
810 timeout=$(uci get wgserver.@server[0].timeout_handshake)
911
10- if [ $handshake -ge $timeout ]; then
12+ if [ "$handshake" -ge "$timeout" ]; then
1113 echo "1"
1214 else
1315 echo "0"
@@ -16,23 +18,23 @@ wg_timeout () {
1618
1719 wg_check_interface () {
1820 local int=$1
19- if [ $(wg_timeout $int) -eq "1" ]; then
20- ip link del dev $int
21+ if [ "$(wg_timeout "$int")" -eq "1" ]; then
22+ ip link del dev "$int"
2123 fi
2224 }
2325
2426 wg_check_interfaces () {
2527 wg_interfaces=$(wg show interfaces)
2628 for interface in $wg_interfaces; do
27- wg_check_interface $interface
29+ wg_check_interface "$interface"
2830 done
2931 }
3032
3133 wg_get_usage () {
3234 num_interfaces=$(wg show interfaces | wc -w)
3335 json_init
34- json_add_int "num_interfaces" $num_interfaces
35- echo $(json_dump)
36+ json_add_int "num_interfaces" "$num_interfaces"
37+ json_dump
3638 }
3739
3840 wg_register () {
@@ -40,52 +42,52 @@ wg_register () {
4042 local mtu=$2
4143 local public_key=$3
4244
43- base_prefix=$(uci get wgserver.@server[0].base_prefix)
45+ base_prefix_ipv6=$(uci get wgserver.@server[0].base_prefix_ipv6)
4446 port_start=$(uci get wgserver.@server[0].port_start)
4547 port_end=$(uci get wgserver.@server[0].port_end)
4648
47- port=$(next_port $port_start $port_end)
49+ port=$(next_port "$port_start" "$port_end")
4850 ifname="wg_$port"
4951
50- offset=$(($port - $port_start))
51- gw_ip=$(owipcalc $base_prefix add $offset next 128) # gateway ip
52- gw_ip_assign="${gw_ip}/128"
52+ offset=$((port - port_start))
53+ gw_ipv6=$(owipcalc "$base_prefix_ipv6" add "$offset" next 128) # gateway ip
54+ gw_ipv6_assign="${gw_ipv6}/128"
5355
5456 gw_key=$(uci get wgserver.@server[0].wg_key)
5557 gw_pub=$(uci get wgserver.@server[0].wg_pub)
5658
57- if [ $(uci get wgserver.@server[0].wg_tmp_key) -eq 1 ]; then
59+ if [ "$(uci get wgserver.@server[0].wg_tmp_key)" -eq 1 ]; then
5860 [ -d "/tmp/run/wgserver" ] || mkdir -p /tmp/run/wgserver
5961 gw_key="/tmp/run/wgserver/${ifname}.key"
6062 gw_pub="/tmp/run/wgserver/${ifname}.pub"
61- wg genkey | tee $gw_key | wg pubkey > $gw_pub
63+ wg genkey | tee "$gw_key" | wg pubkey > "$gw_pub"
6264 fi
63- wg_server_pubkey=$(cat $gw_pub)
65+ wg_server_pubkey=$(cat "$gw_pub")
6466
6567 # create wg tunnel
66- ip link add dev $ifname type wireguard
67- wg set $ifname listen-port $port private-key $gw_key peer $public_key allowed-ips 0.0.0.0/0,::0/0
68- ip -6 addr add $gw_ip_assign dev $ifname
69- ip -6 addr add fe80::1/64 dev $ifname
68+ ip link add dev "$ifname" type wireguard
69+ wg set "$ifname" listen-port "$port" private-key "$gw_key" peer "$public_key" allowed-ips 0.0.0.0/0,::0/0
70+ ip -6 addr add "$gw_ipv6_assign" dev "$ifname"
71+ ip -6 addr add fe80::1/64 dev "$ifname"
7072
71- v4prefix=$(uci get wgserver.@server[0].base_v4prefix)
73+ base_prefix_ipv4=$(uci get wgserver.@server[0].base_prefix_ipv4)
7274 if [ $? -eq 0 ]; then
73- gw_ipv4=$(owipcalc $v4prefix add $offset next 32) # gateway ip
75+ gw_ipv4=$(owipcalc "$base_prefix_ipv4" add "$offset" next 32) # gateway ip
7476 gw_ipv4_assign="${gw_ipv4}/32"
75- ip addr add $gw_ipv4_assign broadcast 255.255.255.255 dev $ifname
77+ ip addr add "$gw_ipv4_assign" broadcast 255.255.255.255 dev "$ifname"
7678 fi
7779
78- ip link set up dev $ifname
79- ip link set mtu $mtu dev $ifname
80+ ip link set up dev "$ifname"
81+ ip link set mtu "$mtu" dev "$ifname"
8082
8183 # craft return address
8284 json_init
83- json_add_string "pubkey" $wg_server_pubkey
84- json_add_string "gw_ip" $gw_ip_assign
85+ json_add_string "gw_pubkey" "$wg_server_pubkey"
8586 if test -n "${gw_ipv4_assign-}"; then
86- json_add_string "gw_ipv4" $gw_ipv4_assign
87+ json_add_string "gw_ipv4" "$gw_ipv4_assign"
8788 fi
88- json_add_int "port" $port
89+ json_add_string "gw_ipv6" "$gw_ipv6_assign"
90+ json_add_int "gw_port" "$port"
8991
90- echo $(json_dump)
92+ json_dump
9193 }
--- a/net/wg-installer/wg-server/wginstaller.sh
+++ b/net/wg-installer/wg-server/wginstaller.sh
@@ -6,26 +6,25 @@
66 case "$1" in
77 list)
88 cmd='{ "get_usage": {},'
9- cmd=$(echo $cmd ' "register": {"uplink_bw":"10", "mtu":"1400", "public_key": "xyz"} }')
10- echo $cmd
9+ cmd=$(echo "$cmd" ' "register": {"mtu":"1400", "public_key": "xyz"} }')
10+ echo "$cmd"
1111 ;;
1212 call)
1313 case "$2" in
1414 get_usage)
15- read input
15+ read -r input
1616 logger -t "wginstaller" "call" "$2" "$input"
1717 wg_get_usage
1818 ;;
1919 register)
20- read input
20+ read -r input
2121 logger -t "wginstaller" "call" "$2" "$input"
2222
2323 json_load "$input"
24- json_get_var uplink_bw uplink_bw
2524 json_get_var mtu mtu
2625 json_get_var public_key public_key
2726
28- wg_register $uplink_bw $mtu $public_key
27+ wg_register "$uplink_bw" "$mtu" "$public_key"
2928 ;;
3029 esac
3130 ;;
Afficher sur ancien navigateur de dépôt.