| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| set -u |
| |
| REAL="${OUC_REAL_BIN:-$HOME/.opencode/bin/opencode}" |
| |
| if [ ! -x "$REAL" ]; then |
| for c in "$HOME/.local/bin/opencode" /usr/local/bin/opencode /usr/bin/opencode; do |
| [ -x "$c" ] && [ "$c" != "$(readlink -f "$0" 2>/dev/null)" ] && REAL="$c" && break |
| done |
| fi |
| [ -x "$REAL" ] || { echo "opencode binary not found — set OUC_REAL_BIN or reinstall"; exit 1; } |
| |
| |
| |
| |
| AAAA_POOL=$(dig +short AAAA opencode.ai @1.1.1.1 2>/dev/null | grep -E '^[0-9A-Fa-f:]+$' | sort -u) |
| [ -z "$AAAA_POOL" ] && AAAA_POOL=$(python3 -c " |
| import socket |
| print('\n'.join({i[4][0] for i in socket.getaddrinfo('opencode.ai',443,socket.AF_INET6)}))" 2>/dev/null) |
| |
| [ -z "$AAAA_POOL" ] && AAAA_POOL="2606:4700:10::ac42:ad95 |
| 2606:4700:10::ac42:ad96 |
| 2606:4700:10::6814:2011" |
| AAAA=$(echo "$AAAA_POOL" | shuf -n 1) |
| |
| |
| TD=$(mktemp -d /tmp/ouc-lane.XXXXXX 2>/dev/null || { mkdir -p /tmp/opencode-unlimited; mktemp -d /tmp/opencode-unlimited/lane.XXXXXX; }) |
| trap 'rm -rf "$TD"' EXIT |
| |
| |
| |
| printf '%s opencode.ai\n%s www.opencode.ai\n%s api.opencode.ai\n' "$AAAA" "$AAAA" "$AAAA" > "$TD/hosts" |
| |
| |
| tr -dc 'a-f0-9' < /dev/urandom | head -c 32 > "$TD/machine-id" |
| |
| |
| CAN_UNSHARE=0 |
| if unshare -rm true 2>/dev/null; then |
| CAN_UNSHARE=1 |
| fi |
| |
| if [ "$CAN_UNSHARE" = "1" ]; then |
| exec unshare -rm bash -c ' |
| mount --bind "$1/hosts" /etc/hosts |
| mount --bind "$1/machine-id" /etc/machine-id |
| exec "$2" "${@:3}" |
| ' _ "$TD" "$REAL" "$@" |
| else |
| |
| |
| PROXY_TARGET="" |
| if (echo > /dev/tcp/127.0.0.1/41987) 2>/dev/null; then |
| PROXY_TARGET="http://127.0.0.1:41987" |
| elif (echo > /dev/tcp/127.0.0.1/40000) 2>/dev/null; then |
| PROXY_TARGET="socks5h://127.0.0.1:40000" |
| else |
| PROXY_TARGET="http://127.0.0.1:41987" |
| fi |
| export HTTPS_PROXY="${HTTPS_PROXY:-$PROXY_TARGET}" |
| export HTTP_PROXY="${HTTP_PROXY:-$PROXY_TARGET}" |
| export ALL_PROXY="${ALL_PROXY:-$PROXY_TARGET}" |
| export NO_PROXY="127.0.0.1,localhost,::1" |
| exec "$REAL" "$@" |
| fi |