From ae8a1a469ae976c663de1a1fbf1374c83e29e110 Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Mon, 30 Sep 2024 19:49:06 +1000 Subject: [PATCH] Codacy compliant --- run.sh | 42 ++++++++++---------- server-lgp.sh | 22 +++++------ server-lgr.sh | 36 ++++++++--------- server-lgt.sh | 26 ++++++------ server-lsp.sh | 22 +++++------ server-lst.sh | 26 ++++++------ server-ltr.sh | 36 ++++++++--------- server-ltt.sh | 26 ++++++------ server-lwp.sh | 22 +++++------ server-lwt.sh | 26 ++++++------ server-mtt.sh | 26 ++++++------ server-mwp.sh | 22 +++++------ server-mwt.sh | 26 ++++++------ server-nginx.sh | 22 +++++------ server-ttt.sh | 26 ++++++------ server-twp.sh | 102 ++++++------------------------------------------ server-twt.sh | 26 ++++++------ 17 files changed, 227 insertions(+), 307 deletions(-) diff --git a/run.sh b/run.sh index 464125e..5889474 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) DIR="$(cd $DIR; pwd)" CERTHOME="/opt/cert" XCONF=/tmp/server-xray.json @@ -42,7 +42,7 @@ usage() { Jrules='{"rules":[]}' -TEMP=`getopt -o u:k:r:c:j:di --long lgp:,lgr:,lgt:,lsp:,lst:,ltr:,ltrx:,ltt:,lttx:,lwp:,lwt:,mtt:,mwp:,mwt:,ttt:,twp:,twt:,user:,hook:,request-domain:,cert-home:,ip-block:,domain-block:,cn-block,ng-server:,ng-proxy:,st-server:,st-map:,json:,stdin,debug -n "$0" -- $@` +TEMP=$(getopt -o u:k:r:c:j:di --long lgp:,lgr:,lgt:,lsp:,lst:,ltr:,ltrx:,ltt:,lttx:,lwp:,lwt:,mtt:,mwp:,mwt:,ttt:,twp:,twt:,user:,hook:,request-domain:,cert-home:,ip-block:,domain-block:,cn-block,ng-server:,ng-proxy:,st-server:,st-map:,json:,stdin,debug -n "$0" -- $@) if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" @@ -79,33 +79,33 @@ while true ; do ;; --lgp|--lgr|--lgt|--lsp|--lst|--ltr|--ltt|--lwp|--lwt|--mtt|--mwp|--mwt|--ttt|--twp|--twt) # Alias options - SVC=`echo $1|tr -d '\-\-'` + SVC=$(echo $1|tr -d '\-\-') SVCMD+=("${DIR}/server-${SVC}.sh $2") shift 2 ;; --ltrx|--lttx) # Alias options - SVC=`echo $1|tr -d '\-\-'|tr -d x` + SVC=$(echo $1|tr -d '\-\-'|tr -d x) SVCMD+=("${DIR}/server-${SVC}.sh $2,xtls") shift 2 ;; --domain-block) - Jrules=`echo "${Jrules}" | jq --arg blkdomain "$2" \ - '.rules += [{"type":"field","outboundTag":"blocked","domain":[$blkdomain]}]'` + Jrules=$(echo "${Jrules}" | jq --arg blkdomain "$2" \ + '.rules += [{"type":"field","outboundTag":"blocked","domain":[$blkdomain]}]') shift 2 ;; --ip-block) - Jrules=`echo "${Jrules}" | jq --arg blkip "$2" \ - '.rules += [{"type":"field","outboundTag":"blocked","ip":[$blkip]}]'` + Jrules=$(echo "${Jrules}" | jq --arg blkip "$2" \ + '.rules += [{"type":"field","outboundTag":"blocked","ip":[$blkip]}]') shift 2 ;; --cn-block) - Jrules=`echo "${Jrules}" | jq --arg igndomain "geosite:geolocation-cn" \ - '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]'` - Jrules=`echo "${Jrules}" | jq --arg igndomain "geosite:cn" \ - '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]'` - Jrules=`echo "${Jrules}" | jq --arg ignip "geoip:cn" \ - '.rules += [{"type":"field","outboundTag":"blocked","ip":[$ignip]}]'` + Jrules=$(echo "${Jrules}" | jq --arg igndomain "geosite:geolocation-cn" \ + '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]') + Jrules=$(echo "${Jrules}" | jq --arg igndomain "geosite:cn" \ + '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]') + Jrules=$(echo "${Jrules}" | jq --arg ignip "geoip:cn" \ + '.rules += [{"type":"field","outboundTag":"blocked","ip":[$ignip]}]') shift 1 ;; --ng-server) @@ -214,30 +214,30 @@ Jroot='{"outbounds":[{"tag":"direct","protocol":"freedom"},{"tag":"blocked","pro # Add routing config Jrouting='{"routing":{"domainStrategy":"AsIs"}}' -Jrouting=`echo $Jrouting |jq --argjson jrules "${Jrules}" '.routing += $jrules'` +Jrouting=$(echo $Jrouting |jq --argjson jrules "${Jrules}" '.routing += $jrules') -Jroot=`echo $Jroot| jq --argjson jrouting "${Jrouting}" '. += $jrouting'` +Jroot=$(echo $Jroot| jq --argjson jrouting "${Jrouting}" '. += $jrouting') # Xray service config generation for svcmd in "${SVCMD[@]}" do - Jsvc=`$svcmd,$xopt` + Jsvc=$($svcmd,$xopt) if [[ $? -ne 0 ]]; then echo "Service creation command failed: $svcmd,$xopt" exit 1 fi - Jroot=`echo $Jroot| jq --argjson Jsvc "${Jsvc}" '.inbounds += [$Jsvc]'` + Jroot=$(echo $Jroot| jq --argjson Jsvc "${Jsvc}" '.inbounds += [$Jsvc]') done if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi -Jroot=`echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel'` +Jroot=$(echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel') if [ -n "${INJECT}" ]; then for JSON_IN in "${INJECT[@]}" do - Jmerge=`jq -nc "${JSON_IN}"` + Jmerge=$(jq -nc "${JSON_IN}") if [[ $? -ne 0 ]]; then echo "Invalid json ${JSON_IN}"; exit 1; fi - Jroot=`jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge'` + Jroot=$(jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge') done fi diff --git a/server-lgp.sh b/server-lgp.sh index c161290..4127a35 100755 --- a/server-lgp.sh +++ b/server-lgp.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-GRPC-PLAIN server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) domain="${kv[1]}" @@ -58,7 +58,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -69,20 +69,20 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgp.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` +inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}') # Fallback settings for fb in "${fallback[@]}" @@ -93,8 +93,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lgr.sh b/server-lgr.sh index cf64967..57c3212 100755 --- a/server-lgr.sh +++ b/server-lgr.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-GRPC-REALITY server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|dest) dest="${kv[1]}" @@ -65,7 +65,7 @@ fi if [ -z "${prvkey}" ]; then >&2 echo "Warning: PrivateKey undefined, Generated new..." - kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`) + kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' ')) prvkey="${kv[0]}" pubkey="${kv[1]}" >&2 echo "PublicKey: $pubkey" @@ -84,7 +84,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -95,34 +95,34 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgr.$dest"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` +inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"reality"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"reality"}') # Reality settings -inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ -'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'` +inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ +'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}') # serverNames settings if [ -n "${serverNames}" ]; then - JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc` - inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames'` + JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc) + inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames') fi # shortIds settings -JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc` -inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds'` +JshortIds=$(printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc) +inbound=$(echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds') # Fallback settings for fb in "${fallback[@]}" @@ -133,8 +133,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lgt.sh b/server-lgt.sh index 55594a7..e63cd8f 100755 --- a/server-lgt.sh +++ b/server-lgt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-GRPC-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -88,22 +88,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` +inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -114,8 +114,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lsp.sh b/server-lsp.sh index ff51635..68f11a6 100755 --- a/server-lsp.sh +++ b/server-lsp.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-SPLT-PLAIN server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) domain="${kv[1]}" @@ -58,7 +58,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -69,20 +69,20 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lsp.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'` +inbound=$(echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}') # Fallback settings for fb in "${fallback[@]}" @@ -93,8 +93,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lst.sh b/server-lst.sh index 9bc8773..baed18e 100755 --- a/server-lst.sh +++ b/server-lst.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-SPLT-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -88,22 +88,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lst.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'` +inbound=$(echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -114,8 +114,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-ltr.sh b/server-ltr.sh index 158ce59..b05f9b9 100755 --- a/server-ltr.sh +++ b/server-ltr.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-TCP-REALITY server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|dest) dest="${kv[1]}" @@ -62,7 +62,7 @@ fi if [ -z "${prvkey}" ]; then >&2 echo "Warning: PrivateKey undefined, Generated new..." - kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`) + kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' ')) prvkey="${kv[0]}" pubkey="${kv[1]}" >&2 echo "PublicKey: $pubkey" @@ -76,7 +76,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -87,34 +87,34 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ltr.$dest"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"reality"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"reality"}') # Reality settings -inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ -'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'` +inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ +'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}') # serverNames settings if [ -n "${serverNames}" ]; then - JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc` - inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames'` + JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc) + inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames') fi # shortIds settings -JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc` -inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds'` +JshortIds=$(printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc) +inbound=$(echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds') # Fallback settings for fb in "${fallback[@]}" @@ -125,8 +125,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-ltt.sh b/server-ltt.sh index d2285b6..0610c63 100755 --- a/server-ltt.sh +++ b/server-ltt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-TCP-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -80,22 +80,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ltt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -106,8 +106,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lwp.sh b/server-lwp.sh index 3a0ecd8..57287d8 100755 --- a/server-lwp.sh +++ b/server-lwp.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-WS-PLAIN server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) domain="${kv[1]}" @@ -58,7 +58,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -69,20 +69,20 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lwp.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}') # Fallback settings for fb in "${fallback[@]}" @@ -93,8 +93,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-lwt.sh b/server-lwt.sh index 5161112..439e0ef 100755 --- a/server-lwt.sh +++ b/server-lwt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VLESS-WS-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -88,22 +88,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lwt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -114,8 +114,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-mtt.sh b/server-mtt.sh index c5fcc3c..52d1d6c 100755 --- a/server-mtt.sh +++ b/server-mtt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VMESS-TCP-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -80,22 +80,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mtt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -106,8 +106,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-mwp.sh b/server-mwp.sh index f89f802..10f1760 100755 --- a/server-mwp.sh +++ b/server-mwp.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VMESS-WS-PLAIN server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) domain="${kv[1]}" @@ -58,7 +58,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -69,20 +69,20 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mwp.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}') # Fallback settings for fb in "${fallback[@]}" @@ -96,8 +96,8 @@ do fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-mwt.sh b/server-mwt.sh index 9b3f9cd..43aa0b6 100755 --- a/server-mwt.sh +++ b/server-mwt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "VMESS-WS-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -88,22 +88,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mwt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -117,8 +117,8 @@ do fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-nginx.sh b/server-nginx.sh index 379c49e..f48aff1 100755 --- a/server-nginx.sh +++ b/server-nginx.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) DIR="$(cd $DIR; pwd)" SITE_TPL="nginx-site.tpl" STREAM_TPL="nginx-stream.tpl" @@ -14,7 +14,7 @@ usage() { >&2 echo " --st-server [p=443],[proxy_pass]" } -TEMP=`getopt -o m:n:p:s:x: --long ng-server:,ng-proxy:,st-server:,st-map: -n "$0" -- $@` +TEMP=$(getopt -o m:n:p:s:x: --long ng-server:,ng-proxy:,st-server:,st-map: -n "$0" -- $@) if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" @@ -71,10 +71,10 @@ sed -i '/\#STREAM_TAG/d' /etc/nginx/nginx.conf # Generate Nginx Stream server configuration. if [ -n "${STSVR}" ]; then -options=(`echo $STSVR |tr ',' ' '`) +options=($(echo $STSVR |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in p|port) STPORT="${kv[1]}" @@ -92,10 +92,10 @@ options=(`echo $STSVR |tr ',' ' '`) cat ${STREAM_TPL} >> /etc/nginx/nginx.conf for stmap in "${STMAP[@]}" do - options=(`echo $stmap |tr ',' ' '`) + options=($(echo $stmap |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in sni) sni="${kv[1]}" @@ -106,7 +106,7 @@ options=(`echo $STSVR |tr ',' ' '`) esac done # Naming the upstream as yahoo_com_jp for SNI yahoo.com.jp - upsname=`echo $sni|sed 's/\./_/g'` + upsname=$(echo $sni|sed 's/\./_/g') echo " $sni $upsname;" >>/tmp/stmap.conf echo " upstream $upsname {" >>/tmp/stups.conf echo " server $upstream;" >>/tmp/stups.conf @@ -134,10 +134,10 @@ do unset certhome NGPROTOCOL # removing site default config file if any. rm -rf /etc/nginx/conf.d/00_default_*.conf - options=(`echo $ngsvr |tr ',' ' '`) + options=($(echo $ngsvr |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -200,10 +200,10 @@ done for ngproxy in "${NGPROXY[@]}" do unset XDOMAINS xhost xport xlocation xnetwork - options=(`echo $ngproxy |tr ',' ' '`) + options=($(echo $ngproxy |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) XDOMAINS+=("${kv[1]}") diff --git a/server-ttt.sh b/server-ttt.sh index 186c583..4b6a1af 100755 --- a/server-ttt.sh +++ b/server-ttt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "TROJAN-TCP-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user|u=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -80,22 +80,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ttt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -106,8 +106,8 @@ do if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound diff --git a/server-twp.sh b/server-twp.sh index 2cf0112..3095f8e 100755 --- a/server-twp.sh +++ b/server-twp.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "TROJAN-WS-PLAIN server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in d|domain) domain="${kv[1]}" @@ -58,7 +58,7 @@ fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -69,20 +69,20 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@twp.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}') # Fallback settings for fb in "${fallback[@]}" @@ -96,89 +96,9 @@ do fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound exit 0 - - - - - - -} - -options=(`echo $1 |tr ',' ' '`) -for option in "${options[@]}" -do - kv=(`echo $option |tr '=' ' '`) - case "${kv[0]}" in - d|domain) - domain="${kv[1]}" - ;; - p|port) - port="${kv[1]}" - ;; - u|user) - xuser+=("${kv[1]}") - ;; - w|wpath) - wspath="${kv[1]}" - ;; - x|xconf) - xconf="${kv[1]}" - ;; - esac -done - -if [ -z "${port}" ]; then - echo "Error: port undefined." - usage - exit 1 ; -fi - -if [ -z "${wspath}" ]; then - echo "Error: wspath undefined." - usage - exit 1 -fi - -if [ -z "${xuser}" ]; then - echo "Error: user undefined." - usage - exit 1 -fi - -if [ -z "${xconf}" ]; then - echo "Error: xconf undefined." - usage - exit 1 -fi - -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi - -XCONF=$xconf -# Remove existing port number if existing. -cat $XCONF |jq --arg port "${port}" 'del( .inbounds[] | select(.port == ($port|tonumber)) )' |sponge $XCONF - -# Add inbound element -cat $XCONF |jq --arg port "${port}" '.inbounds +=[{"port":($port|tonumber),"protocol":"trojan","settings":{"clients":[]}}]' |sponge $XCONF -cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF - -# User settings -for xu in "${xuser[@]}" -do - cat $XCONF | ${DIR}/addusertj.sh -p $port -u ${xu} -c twp.$domain $flowopt | sponge $XCONF -done - -# Network settings -cat $XCONF |jq --arg port "${port}" --arg wspath "${wspath}" \ -'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"ws","wsSettings":{"path":$wspath}} ' \ -|sponge $XCONF - -# Plain settings -cat $XCONF |jq --arg port "${port}" \ -'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \ -|sponge $XCONF diff --git a/server-twt.sh b/server-twt.sh index 4d01f25..4c57eaf 100755 --- a/server-twt.sh +++ b/server-twt.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR=`dirname $0` +DIR=$(dirname $0) usage() { >&2 echo "TROJAN-WS-TLS server builder" @@ -9,10 +9,10 @@ usage() { >&2 echo "User format: user=[:level:email]" } -options=(`echo $1 |tr ',' ' '`) +options=($(echo $1 |tr ',' ' ')) for option in "${options[@]}" do - kv=(`echo $option |tr '=' ' '`) + kv=($(echo $option |tr '=' ' ')) case "${kv[0]}" in c|certhome) certhome="${kv[1]}" @@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi # inbound frame -inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` +inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}') # User settings for user in "${xuser[@]}" @@ -88,22 +88,22 @@ do if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@twt.$domain"; fi - inbound=`echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ - '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` + inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ + '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]') done # StreamSettings if [ -n "${acceptProxyProtocol}" ]; then - inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` + inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}') fi # Network settings -inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` +inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}') # Security settings -inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` -inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ -'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` +inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}') +inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ +'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}') # Fallback settings for fb in "${fallback[@]}" @@ -117,8 +117,8 @@ do fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" - Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` - inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` + Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') + inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]') done echo $inbound