From 9c197d44c517843311c5a4a144bd40a90c76e5fe Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Fri, 30 Aug 2024 16:24:44 +1000 Subject: [PATCH] JSON merge support --- README.md | 1 + run.sh | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47e360d..9b84427 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ proxy-xray --tpw password@host:port:/wspath -d|--debug Start in debug mode with verbose output -i|--stdin Read config from stdin instead of auto generation + -j|--json '{"log":{"loglevel":"info"}' Json snippet to merge into the config --dns Designated upstream DNS server IP, 1.1.1.1 will be applied by default --dns-local-cn Enable China-accessible domains to be resolved in China --domain-direct Add a domain rule for direct routing, likegeosite:geosite:geolocation-cn diff --git a/run.sh b/run.sh index 62b0ec6..9b51fa8 100755 --- a/run.sh +++ b/run.sh @@ -22,6 +22,7 @@ usage() { echo " --tpw password@host:port:/wspath" echo " -d|--debug Start in debug mode with verbose output" echo " -i|--stdin Read config from stdin instead of auto generation" + echo " -j|--json '{"log":{"loglevel":"info"}' Json snippet to merge into the config" echo " --dns Designated upstream DNS server IP, 1.1.1.1 will be applied by default" # echo " --dns-local Enable designated domain conf file. Like apple.china.conf" echo " --dns-local-cn Enable China-accessible domains to be resolved in China" @@ -38,7 +39,7 @@ usage() { Jrules='{"rules":[]}' -TEMP=`getopt -o di --long lx:,ls:,ms:,ts:,lsg:,lss:,lsw:,msw:,tsw:,lpg:,lps:,lpw:,mpw:,tpw:,stdin,debug,dns:,dns-local:,dns-local-cn,domain-direct:,domain-proxy:,domain-block:,ip-direct:,ip-proxy:,ip-block:,cn-direct,rules-path: -n "$0" -- $@` +TEMP=`getopt -o j:di --long json:lx:,ls:,ms:,ts:,lsg:,lss:,lsw:,msw:,tsw:,lpg:,lps:,lpw:,mpw:,tpw:,stdin,debug,dns:,dns-local:,dns-local-cn,domain-direct:,domain-proxy:,domain-block:,ip-direct:,ip-proxy:,ip-block:,cn-direct,rules-path: -n "$0" -- $@` if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" while true ; do @@ -116,6 +117,10 @@ while true ; do export XRAY_LOCATION_ASSET=$2 shift 2 ;; + -j|--json) + INJECT+=("$2") + shift 2 + ;; -i|--stdin) STDINCONF=1 XRAYCFG=1 @@ -177,5 +182,17 @@ if [ "${DEBUG}" = "1" ]; then cat $XCONF 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