Download entrypoint.sh from Cwhd2/grok2: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/Cwhd2/grok2/resolve/main/entrypoint.sh
- Command line
-
hf download hf://spaces/Cwhd2/grok2/entrypoint.sh
-
curl -L -o entrypoint.sh https://huggingface.co/spaces/Cwhd2/grok2/resolve/main/entrypoint.sh
2.07 kB
| set -e | |
| # 确保脚本内部的所有操作都在 /app 目录下进行 | |
| cd /app | |
| echo "=== 正在检测本地 WARP 环境 ===" | |
| # 1. 自动注册并生成 Cloudflare WARP 配置文件 (如果容器内不存在手动拷贝的文件) | |
| if [ ! -f "wgcf-profile.conf" ]; then | |
| echo "[1/3] 正在向 Cloudflare 注册 WARP 账号..." | |
| wgcf register --accept-tos || { echo "注册失败,请确保已手动上传 wgcf-profile.conf。"; exit 1; } | |
| echo "[2/3] 正在生成 WireGuard 配置文件..." | |
| wgcf generate | |
| else | |
| echo "=== 检测到已手动上传的 wgcf-profile.conf,跳过注册步骤 ===" | |
| fi | |
| # 2. 将 wgcf 配置文件转换为 wireproxy 配置文件 | |
| # 【核心修正】清理旧的单栈配置,直接复制原始配置,保留完整的 IPv4 + IPv6 双栈通道,防止 dns 路由时因 ipv6 缺失导致 host unreachable | |
| echo "[3/3] 正在将 WARP 配置转换为本地用户态代理配置..." | |
| rm -f wireproxy.conf | |
| cp wgcf-profile.conf wireproxy.conf | |
| # 追加 Socks5 本地代理端点配置 | |
| cat <<EOF >> wireproxy.conf | |
| [Socks5] | |
| BindAddress = 127.0.0.1:1080 | |
| EOF | |
| # 3. 异步启动 wireproxy (在本地 127.0.0.1:1080 开启 SOCKS5 隧道) | |
| echo "=== 正在启动本地用户态 WARP (wireproxy) 代理服务 ===" | |
| wireproxy -c wireproxy.conf & | |
| # 等待本地代理完全初始化 | |
| sleep 3 | |
| # 4. 注入环境变量,强制 grok2api 主程序走本地挂载的 SOCKS5 WARP 代理 | |
| export GROK_PROXY_EGRESS_MODE="single_proxy" | |
| export GROK_PROXY_EGRESS_PROXY_URL="socks5://127.0.0.1:1080" | |
| echo "=== 代理已就绪,正在启动 grok2api 主程序 ===" | |
| # 5. 启动主程序 | |
| if [ $# -gt 0 ]; then | |
| if [ -f "/app/scripts/entrypoint.sh" ]; then | |
| exec /app/scripts/entrypoint.sh "$@" | |
| else | |
| exec "$@" | |
| fi | |
| else | |
| if [ -f "/app/scripts/entrypoint.sh" ]; then | |
| exec /app/scripts/entrypoint.sh granian --interface asgi --host 0.0.0.0 --port ${SERVER_PORT:-7860} --workers 1 app.main:app | |
| else | |
| exec granian --interface asgi --host 0.0.0.0 --port ${SERVER_PORT:-7860} --workers 1 app.main:app | |
| fi | |
| fi |