core-lightning/plugins/clnrest/clnrest
Rusty Russell c4edec8e22 plugins/clnrest: simple wrapper to handle missing python3.
Apparently NixOS didn't have Python (sometimes!) so let's not assume.
By reusing the JSON "parsing" code from cowsay, we can self-disable
to handle this case.

Reported-by: Shahana Farooqui <shahana.farooqui@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: `clnrest` now correctly self-disables if Python not present at all.
2024-04-12 10:32:32 +02:00

16 lines
539 B
Bash
Executable file

#! /bin/sh
# clrest.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
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