|
|
@@ -0,0 +1,72 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+# 本地网络代理端口(如果有的话)
|
|
|
+LOCAL_PROXY_PORT=7890
|
|
|
+REMOTE_FORWARD_PORT=8090
|
|
|
+REMOTE_HOST="10.192.72.11"
|
|
|
+REMOTE_USER="ubuntu"
|
|
|
+
|
|
|
+echo "Setting up GitHub Copilot connectivity for remote development..."
|
|
|
+
|
|
|
+# 1. 检查本地代理是否可用
|
|
|
+if curl -s --proxy http://localhost:$LOCAL_PROXY_PORT --connect-timeout 5 http://www.google.com > /dev/null; then
|
|
|
+ echo "✓ Local proxy detected on port $LOCAL_PROXY_PORT"
|
|
|
+ PROXY_TARGET="localhost:$LOCAL_PROXY_PORT"
|
|
|
+else
|
|
|
+ echo "ℹ No local proxy detected, using direct connection"
|
|
|
+ PROXY_TARGET="0.0.0.0:80"
|
|
|
+fi
|
|
|
+
|
|
|
+# 2. 建立 SSH 连接with端口转发
|
|
|
+echo "Establishing SSH connection with port forwarding..."
|
|
|
+
|
|
|
+ssh -o "ExitOnForwardFailure=yes" \
|
|
|
+ -o "ServerAliveInterval=60" \
|
|
|
+ -o "ServerAliveCountMax=3" \
|
|
|
+ -L 8111:localhost:8101 \
|
|
|
+ -R $REMOTE_FORWARD_PORT:$PROXY_TARGET \
|
|
|
+ $REMOTE_USER@$REMOTE_HOST \
|
|
|
+ "
|
|
|
+ # 在远程服务器上执行的命令
|
|
|
+ echo 'Configuring remote environment...'
|
|
|
+
|
|
|
+ # 设置代理环境变量
|
|
|
+ export http_proxy=http://localhost:$REMOTE_FORWARD_PORT
|
|
|
+ export https_proxy=http://localhost:$REMOTE_FORWARD_PORT
|
|
|
+ export HTTP_PROXY=http://localhost:$REMOTE_FORWARD_PORT
|
|
|
+ export HTTPS_PROXY=http://localhost:$REMOTE_FORWARD_PORT
|
|
|
+
|
|
|
+ # 更新 VSCode 服务器配置
|
|
|
+# mkdir -p ~/.vscode-server/data/Machine
|
|
|
+# cat > ~/.vscode-server/data/Machine/settings.json << EOF
|
|
|
+# {
|
|
|
+# \"http.proxy\": \"http://localhost:$REMOTE_FORWARD_PORT\",
|
|
|
+# \"http.proxySupport\": \"on\",
|
|
|
+# \"http.proxyAuthorization\": null,
|
|
|
+# \"github.copilot.enable\": {
|
|
|
+# \"*\": true,
|
|
|
+# \"yaml\": true,
|
|
|
+# \"plaintext\": true,
|
|
|
+# \"markdown\": true
|
|
|
+# },
|
|
|
+# \"github.copilot.advanced\": {
|
|
|
+# \"debug.overrideEngine\": \"codex\",
|
|
|
+# \"debug.useNodeFetcher\": true
|
|
|
+# }
|
|
|
+# }
|
|
|
+# EOF
|
|
|
+
|
|
|
+ # 测试网络连接
|
|
|
+ echo 'Testing internet connectivity...'
|
|
|
+ if curl -s --proxy http://localhost:$REMOTE_FORWARD_PORT --connect-timeout 10 https://api.github.com > /dev/null; then
|
|
|
+ echo '✓ GitHub API accessible'
|
|
|
+ else
|
|
|
+ echo '✗ GitHub API not accessible'
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo 'Setup complete! You can now use GitHub Copilot in VSCode.'
|
|
|
+ echo 'Keep this SSH session alive for Copilot to work.'
|
|
|
+
|
|
|
+ # 保持会话活跃
|
|
|
+ exec bash
|
|
|
+ "
|