burrow/deploy/railway-sing-box/entrypoint.sh
2026-06-05 10:33:41 -07:00

47 lines
1.1 KiB
Bash

#!/bin/sh
set -eu
: "${SS_PASSWORD:?Set SS_PASSWORD to a strong test password in Railway variables}"
SS_METHOD="${SS_METHOD:-chacha20-ietf-poly1305}"
SS_LISTEN_HOST="${SS_LISTEN_HOST:-0.0.0.0}"
SS_LISTEN_PORT="${SS_LISTEN_PORT:-8388}"
LOG_LEVEL="${LOG_LEVEL:-info}"
json_escape() {
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}
SS_METHOD_JSON="$(json_escape "$SS_METHOD")"
SS_PASSWORD_JSON="$(json_escape "$SS_PASSWORD")"
LOG_LEVEL_JSON="$(json_escape "$LOG_LEVEL")"
SS_LISTEN_HOST_JSON="$(json_escape "$SS_LISTEN_HOST")"
mkdir -p /etc/sing-box
cat >/etc/sing-box/config.json <<EOF
{
"log": {
"level": "$LOG_LEVEL_JSON",
"timestamp": true
},
"inbounds": [
{
"type": "shadowsocks",
"tag": "ss-test",
"listen": "$SS_LISTEN_HOST_JSON",
"listen_port": $SS_LISTEN_PORT,
"method": "$SS_METHOD_JSON",
"password": "$SS_PASSWORD_JSON"
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}
EOF
echo "starting sing-box Shadowsocks test server on $SS_LISTEN_HOST:$SS_LISTEN_PORT"
exec sing-box run -c /etc/sing-box/config.json