[fix] 更正 README.MD 错误
[update]  Dockerfile alpine 版本调整
[fix]  entrypoint.sh 逻辑修正
This commit is contained in:
wulabing 2023-03-17 12:47:50 +08:00
parent 1812cba147
commit a4602771cb
No known key found for this signature in database
GPG Key ID: 213391AFDF73AE00
4 changed files with 38 additions and 34 deletions

View File

@ -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=""

View File

@ -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
```
查看日志获取配置信息

1
reality/SERVERNAMES.MD Normal file
View File

@ -0,0 +1 @@
## 已知可用的 SERVERNAMES 及 DEST 列表

View File

@ -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
fi
if [ -z "$DEST" ]; then
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}')
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
exec /xray -config /config.json