setup_remote_copilot.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # 本地网络代理端口(如果有的话)
  3. LOCAL_PROXY_PORT=7890
  4. REMOTE_FORWARD_PORT=8090
  5. REMOTE_HOST="10.192.72.11"
  6. REMOTE_USER="ubuntu"
  7. echo "Setting up GitHub Copilot connectivity for remote development..."
  8. # 1. 检查本地代理是否可用
  9. if curl -s --proxy http://localhost:$LOCAL_PROXY_PORT --connect-timeout 5 http://www.google.com > /dev/null; then
  10. echo "✓ Local proxy detected on port $LOCAL_PROXY_PORT"
  11. PROXY_TARGET="localhost:$LOCAL_PROXY_PORT"
  12. else
  13. echo "ℹ No local proxy detected, using direct connection"
  14. PROXY_TARGET="0.0.0.0:80"
  15. fi
  16. # 2. 建立 SSH 连接with端口转发
  17. echo "Establishing SSH connection with port forwarding..."
  18. ssh -o "ExitOnForwardFailure=yes" \
  19. -o "ServerAliveInterval=60" \
  20. -o "ServerAliveCountMax=3" \
  21. -L 8111:localhost:8101 \
  22. -R $REMOTE_FORWARD_PORT:$PROXY_TARGET \
  23. $REMOTE_USER@$REMOTE_HOST \
  24. "
  25. # 在远程服务器上执行的命令
  26. echo 'Configuring remote environment...'
  27. # 设置代理环境变量
  28. export http_proxy=http://localhost:$REMOTE_FORWARD_PORT
  29. export https_proxy=http://localhost:$REMOTE_FORWARD_PORT
  30. export HTTP_PROXY=http://localhost:$REMOTE_FORWARD_PORT
  31. export HTTPS_PROXY=http://localhost:$REMOTE_FORWARD_PORT
  32. # 更新 VSCode 服务器配置
  33. # mkdir -p ~/.vscode-server/data/Machine
  34. # cat > ~/.vscode-server/data/Machine/settings.json << EOF
  35. # {
  36. # \"http.proxy\": \"http://localhost:$REMOTE_FORWARD_PORT\",
  37. # \"http.proxySupport\": \"on\",
  38. # \"http.proxyAuthorization\": null,
  39. # \"github.copilot.enable\": {
  40. # \"*\": true,
  41. # \"yaml\": true,
  42. # \"plaintext\": true,
  43. # \"markdown\": true
  44. # },
  45. # \"github.copilot.advanced\": {
  46. # \"debug.overrideEngine\": \"codex\",
  47. # \"debug.useNodeFetcher\": true
  48. # }
  49. # }
  50. # EOF
  51. # 测试网络连接
  52. echo 'Testing internet connectivity...'
  53. if curl -s --proxy http://localhost:$REMOTE_FORWARD_PORT --connect-timeout 10 https://api.github.com > /dev/null; then
  54. echo '✓ GitHub API accessible'
  55. else
  56. echo '✗ GitHub API not accessible'
  57. fi
  58. echo 'Setup complete! You can now use GitHub Copilot in VSCode.'
  59. echo 'Keep this SSH session alive for Copilot to work.'
  60. # 保持会话活跃
  61. exec bash
  62. "