Files
palladum-lightning/plugins/wss-proxy/wss-proxy
Rusty Russell 2c57347033 plugins: wss-proxy should not return invalid JSON if sed does not exist.
We try to do a JSON response if Python is not present, but it assumes sed.  We should cleanly
exit on errors.

Before:

```
$ PATH=/tmp ./plugins/wss-proxy/wss-proxy
Something

./plugins/wss-proxy/wss-proxy: 12: sed: not found
{"jsonrpc":"2.0","id":,"result":{"disable":"No python3 binary found"}}
```

After:

```
$ PATH=/tmp ./plugins/wss-proxy/wss-proxy
something

./plugins/wss-proxy/wss-proxy: 12: sed: not found
```

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-02 13:23:41 -07:00

18 lines
553 B
Bash
Executable File

#! /bin/sh
# wss-proxy.py neatly exits if we don't have dependencies, but what if we don't
# have Python itself?
if ! type python3 > /dev/null 2>&1; then
# No python3 binary.
# Fortunately, CLN gives us JSON in a very standard way, so we can assume:
# Eg. {"jsonrpc":"2.0","id":2,"method":"getmanifest","params":{}}\n\n
set -e
read -r JSON
read -r _
id=$(echo "$JSON" | sed 's/.*"id" *: *\([^,]*\),.*/\1/')
echo '{"jsonrpc":"2.0","id":'"$id"',"result":{"disable":"No python3 binary found"}}'
exit 1
fi
exec "$0".py