JSON merge support

This commit is contained in:
Samuel Huang
2024-08-30 16:24:20 +10:00
parent 13511f80b5
commit 08788f8269
2 changed files with 14 additions and 13 deletions

View File

@@ -85,6 +85,7 @@ server-xray <server-options>
-r|--request-domain <domain-name> Domain name to request for letsencrypt cert
-c|--cert-home <cert-home-dir> Reading TLS certs from folder <cert-home-dir>/<domain-name>/
-i|--stdin Read config from STDIN instead of auto generation
-j|--json '{"log":{"loglevel":"info"}' Json snippet to merge into the config
-d|--debug Start in debug mode with verbose output
```

26
run.sh
View File

@@ -33,7 +33,7 @@ usage() {
echo " -r|--request-domain <domain-name> Domain name to request for letsencrypt cert"
echo " -c|--cert-home <cert-home-dir> Reading TLS certs from folder <cert-home-dir>/<domain-name>/"
echo " -i|--stdin Read config from STDIN instead of auto generation"
echo " -j|--json Extra json snippet needs to merge into config"
echo " -j|--json '{"log":{"loglevel":"info"}' Json snippet to merge into the config"
echo " -d|--debug Start in debug mode with verbose output"
}
@@ -150,18 +150,6 @@ fi
echo '{"log":{"loglevel":"warning"}, "inbounds":[], "outbounds":[{"protocol":"freedom"}]}' |jq .|sponge $XCONF
if [ -n "${INJECT}" ]; then
for JSON_IN in "${INJECT[@]}"
do
echo "${JSON_IN}"|jq -ec >/tmp/merge.json
if [[ $? -ne 0 ]]; then
echo "Invalid json ${JSON_IN}"
exit 1
fi
jq -s '.[0] * .[1]' $XCONF /tmp/merge.json |sponge $XCONF
done
fi
xopt="xconf=$XCONF"
xopt="$xopt,certhome=$CERTHOME"
for uopt in "${UOPT[@]}"
@@ -208,6 +196,18 @@ if [ -n "${SVCMD}" ]; then
nginx;
fi
if [ -n "${INJECT}" ]; then
for JSON_IN in "${INJECT[@]}"
do
echo "${JSON_IN}"|jq -ec >/tmp/merge.json
if [[ $? -ne 0 ]]; then
echo "Invalid json ${JSON_IN}"
exit 1
fi
jq -s '.[0] * .[1]' $XCONF /tmp/merge.json |sponge $XCONF
done
fi
exec /usr/local/bin/xray -c $XCONF
else