#!/bin/bash DIR=`dirname $0` DIR="$(cd $DIR; pwd)" XCONF=/tmp/proxy-xray.json usage() { echo "proxy-xray -- [options]" echo " --ltx id@host:port" echo " --ltt id@host:port" echo " --lttw id@host:port:/webpath" echo " --lttg id@host:port:/svcpath" echo " --mtt id@host:port" echo " --mttw id@host:port:/webpath" echo " --ttt password@host:port" echo " --tttw password@host:port:/webpath" # echo " --ssa password:method@host:port" # echo " --sst password:method@host:port" echo " -i|--stdin Read XRay config from stdin instead of auto generation" echo " -d|--debug Start Xray in debug mode with verbose output" } TEMP=`getopt -o di --long ltx:,ltt:,lttw:,lttg:,mtt:,mttw:,ttt:,tttw:,ssa:,sst:stdin,debug -n "$0" -- $@` if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" while true ; do case "$1" in --ltx|--ltt|--lttw|--lttg|--mtt|--mttw|--ttt|--tttw|--ssa|--sst) subcmd=`echo "$1"|tr -d "\-\-"` $DIR/proxy-${subcmd}.sh $2 >$XCONF if [ $? != 0 ]; then echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" exit 2 else XRAY=1 fi shift 2 ;; -i|--stdin) STDINCONF=1 shift 1 ;; -d|--debug) DEBUG=1 shift 1 ;; --) shift break ;; *) usage; exit 1 ;; esac done if [ "${STDINCONF}" = "1" ]; then exec /usr/local/bin/xray else if [ "${XRAY}" = "1" ]; then if [ "${DEBUG}" = "1" ]; then cat $XCONF |jq '.log.loglevel |="debug"' |sponge $XCONF echo cat $XCONF echo else /usr/bin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml & fi else usage exit 1 fi fi exec /usr/local/bin/xray -c $XCONF