setup_remote_copilot.sh 2.5 KB

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