diff --git a/reality/Dockerfile b/reality/Dockerfile index 673ee3d..75bd9c2 100644 --- a/reality/Dockerfile +++ b/reality/Dockerfile @@ -11,7 +11,7 @@ RUN apk add --no-cache git && git clone https://github.com/XTLS/Xray-core.git . go build -o xray /app/main/ # runner -FROM alpine:3.17 as runner +FROM alpine:latest as runner ENV UUID="" diff --git a/reality/README.MD b/reality/README.MD index 4d16ee1..45d6fb7 100644 --- a/reality/README.MD +++ b/reality/README.MD @@ -12,7 +12,7 @@ curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh ``` -ocker run -d --name xray_reality -p 443:443 wulabing/xray_docker_reality:0.0.1 +docker run -d --name xray_reality --restart=always -p 443:443 wulabing/xray_docker_reality:0.0.1 ``` 查看日志获取配置信息 diff --git a/reality/SERVERNAMES.MD b/reality/SERVERNAMES.MD new file mode 100644 index 0000000..6e17700 --- /dev/null +++ b/reality/SERVERNAMES.MD @@ -0,0 +1 @@ +## 已知可用的 SERVERNAMES 及 DEST 列表 diff --git a/reality/entrypoint.sh b/reality/entrypoint.sh index 51ec85a..5d9e201 100644 --- a/reality/entrypoint.sh +++ b/reality/entrypoint.sh @@ -1,55 +1,58 @@ #!/bin/sh - -if [ -z "$UUID" ]; then +if [ -f /config_info.txt ]; then + echo "config.json exist" + cat /config_info.txt +else + if [ -z "$UUID" ]; then echo "UUID is not set, generate random UUID " UUID="$(uuidgen)" echo "UUID: $UUID" - -fi -if [ -z "$DEST" ]; then + fi + + if [ -z "$DEST" ]; then echo "DEST is not set. default value www.apple.com:443" DEST="www.apple.com:443" -fi + fi -if [ -z "$SERVERNAMES" ]; then + if [ -z "$SERVERNAMES" ]; then echo "SERVERNAMES is not set. use default value [\"www.apple.com\",\"images.apple.com\"]" SERVERNAMES="www.apple.com images.apple.com" -fi + fi -if [ -z "$PRIVATEKEY" ]; then + if [ -z "$PRIVATEKEY" ]; then echo "PRIVATEKEY is not set. generate new key" - /xray x25519 > /key + /xray x25519 >/key PRIVATEKEY=$(cat /key | grep "Private" | awk -F ': ' '{print $2}') - PUBLICKEY=$(cat /key | grep "Public" | awk -F ': ' '{print $2}') + PUBLICKEY=$(cat /key | grep "Public" | awk -F ': ' '{print $2}') echo "Private key: $PRIVATEKEY" echo "Public key: $PUBLICKEY" -fi + fi -if [ -z "$NETWORK" ]; then + if [ -z "$NETWORK" ]; then echo "NETWORK is not set,set default value tcp" NETWORK="tcp" + fi + # change config + jq ".inbounds[0].settings.clients[0].id=\"$UUID\"" /config.json >/config.json_tmp && mv /config.json_tmp /config.json + jq ".inbounds[0].streamSettings.realitySettings.dest=\"$DEST\"" /config.json >/config.json_tmp && mv /config.json_tmp /config.json + + SERVERNAMES_JSON_ARRAY="$(echo "[$(echo $SERVERNAMES | awk '{for(i=1;i<=NF;i++) printf "\"%s\",", $i}' | sed 's/,$//')]")" + jq --argjson serverNames "$SERVERNAMES_JSON_ARRAY" '.inbounds[0].streamSettings.realitySettings.serverNames = $serverNames' /config.json >/config.json_tmp && mv /config.json_tmp /config.json + + jq ".inbounds[0].streamSettings.realitySettings.privateKey=\"$PRIVATEKEY\"" /config.json >/config.json_tmp && mv /config.json_tmp /config.json + jq ".inbounds[0].streamSettings.network=\"$NETWORK\"" /config.json >/config.json_tmp && mv /config.json_tmp /config.json fi -# change config -jq ".inbounds[0].settings.clients[0].id=\"$UUID\"" /config.json > /config.json_tmp && mv /config.json_tmp /config.json -jq ".inbounds[0].streamSettings.realitySettings.dest=\"$DEST\"" /config.json > /config.json_tmp && mv /config.json_tmp /config.json - -SERVERNAMES_JSON_ARRAY="$(echo "[$(echo $SERVERNAMES | awk '{for(i=1;i<=NF;i++) printf "\"%s\",", $i}' | sed 's/,$//')]")" -jq --argjson serverNames "$SERVERNAMES_JSON_ARRAY" '.inbounds[0].streamSettings.realitySettings.serverNames = $serverNames' /config.json > /config.json_tmp && mv /config.json_tmp /config.json - -jq ".inbounds[0].streamSettings.realitySettings.privateKey=\"$PRIVATEKEY\"" /config.json > /config.json_tmp && mv /config.json_tmp /config.json -jq ".inbounds[0].streamSettings.network=\"$NETWORK\"" /config.json > /config.json_tmp && mv /config.json_tmp /config.json - # config info with green color -echo -e "\033[32m" -echo "UUID: $UUID" -echo "DEST: $DEST" -echo "SERVERNAMES: $SERVERNAMES (任选其一)" -echo "PRIVATEKEY: $PRIVATEKEY" -echo "PUBLICKEY: $PUBLICKEY" -echo "NETWORK: $NETWORK" -echo -e "\033[0m" +echo -e "\033[32m" >/config_info.txt +echo "UUID: $UUID" >>/config_info.txt +echo "DEST: $DEST" >>/config_info.txt +echo "SERVERNAMES: $SERVERNAMES (任选其一)" >>/config_info.txt +echo "PRIVATEKEY: $PRIVATEKEY" >>/config_info.txt +echo "PUBLICKEY: $PUBLICKEY" >>/config_info.txt +echo "NETWORK: $NETWORK" >>/config_info.txt +echo -e "\033[0m" >>/config_info.txt # run xray -/xray -config /config.json \ No newline at end of file +exec /xray -config /config.json