Skip to content

Commit

Permalink
Extract Lua code into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Jan 18, 2024
1 parent 891650c commit 2fdc688
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

if { set -C; 2>/dev/null >/var/lock/checkuplink.lock; }; then
trap "rm -f /var/lock/checkuplink.lock" EXIT
trap "rm -f /var/lock/checkuplink.lock" EXIT
else
echo "Lock file exists... exiting"
exit
echo "Lock file exists... exiting"
exit
fi

interface_linklocal() {
Expand Down Expand Up @@ -110,18 +110,7 @@ if [ "$(uci get wireguard.mesh_vpn.enabled)" == "true" ] || [ "$(uci get wiregua

logger -t checkuplink "Got data from wgkex broker: $WGKEX_DATA"

rm -f "/tmp/checkuplink-wgkex-parse"
cat >/tmp/checkuplink-wgkex-parse <<EOF
local json = require 'jsonc'
local input = arg[1]
local data = json.parse(input)
print(data.Endpoint.Address)
print(data.Endpoint.Port)
print(data.Endpoint.PublicKey)
print(data.Endpoint.AllowedIPs[1])
EOF

data=$(lua /tmp/checkuplink-wgkex-parse "$WGKEX_DATA")
data=$(lua /lib/gluon/gluon-mesh-wireguard-vxlan/parse-wgkex-response.lua "$WGKEX_DATA")
if [ $? -eq 1 ]; then
logger -t checkuplink "Parsing wgkex broker data failed"
exit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local json = require 'jsonc'

local input = assert(arg[1])
local data = assert(json.parse(input))
if not data.Endpoint or not data.Endpoint.Address or not data.Endpoint.Port
or not data.Endpoint.PublicKey or not data.Endpoint.AllowedIPs or not data.Endpoint.AllowedIPs[1] then
error("Malformed JSON response, missing required value")
end
print(data.Endpoint.Address)
print(data.Endpoint.Port)
print(data.Endpoint.PublicKey)
print(data.Endpoint.AllowedIPs[1])

0 comments on commit 2fdc688

Please sign in to comment.