223 lines
6.5 KiB
Bash
Executable File
223 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# BEVFusion Git服务配置脚本
|
||
# 提供多种Git访问方式配置选项
|
||
|
||
set -e
|
||
|
||
# 颜色输出
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m'
|
||
|
||
print_header() {
|
||
echo -e "${BLUE}================================================${NC}"
|
||
echo -e "${BLUE} BEVFusion Git服务配置工具${NC}"
|
||
echo -e "${BLUE}================================================${NC}"
|
||
echo
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
# 检查网络连通性
|
||
check_connectivity() {
|
||
echo
|
||
print_info "检查网络连通性..."
|
||
|
||
if ping -c 1 github.com &>/dev/null; then
|
||
print_success "GitHub网络连接正常"
|
||
else
|
||
print_warning "GitHub网络连接失败,请检查网络设置"
|
||
fi
|
||
}
|
||
|
||
# HTTPS配置选项
|
||
setup_https() {
|
||
echo
|
||
print_info "配置HTTPS访问GitHub..."
|
||
echo "当前远程仓库: $(git remote get-url origin 2>/dev/null || echo '未配置')"
|
||
echo
|
||
echo "HTTPS访问说明:"
|
||
echo "1. 克隆: git clone https://github.com/mit-han-lab/bevfusion.git"
|
||
echo "2. 推送需要认证:"
|
||
echo " - 使用Personal Access Token替代密码"
|
||
echo " - 或使用GitHub CLI: gh auth login"
|
||
echo
|
||
read -p "是否要测试HTTPS连接? (y/n): " test_https
|
||
if [[ $test_https =~ ^[Yy]$ ]]; then
|
||
echo "测试HTTPS克隆..."
|
||
timeout 30 git ls-remote https://github.com/mit-han-lab/bevfusion.git HEAD &>/dev/null && \
|
||
print_success "HTTPS连接测试成功" || print_warning "HTTPS连接测试失败"
|
||
fi
|
||
}
|
||
|
||
# SSH配置选项
|
||
setup_ssh() {
|
||
echo
|
||
print_info "配置SSH访问GitHub..."
|
||
|
||
# 检查是否已有SSH密钥
|
||
if [[ -f ~/.ssh/id_ed25519.pub || -f ~/.ssh/id_rsa.pub ]]; then
|
||
print_info "发现现有的SSH密钥"
|
||
ls -la ~/.ssh/id_* 2>/dev/null
|
||
else
|
||
echo "未发现SSH密钥,是否要生成新的密钥对?"
|
||
read -p "生成SSH密钥? (y/n): " generate_key
|
||
if [[ $generate_key =~ ^[Yy]$ ]]; then
|
||
echo "生成Ed25519 SSH密钥..."
|
||
ssh-keygen -t ed25519 -C "$(git config user.email)" -f ~/.ssh/id_ed25519_bevfusion
|
||
print_success "SSH密钥已生成"
|
||
echo
|
||
print_info "请手动将以下公钥添加到GitHub:"
|
||
print_info "GitHub -> Settings -> SSH and GPG keys -> New SSH key"
|
||
echo
|
||
cat ~/.ssh/id_ed25519_bevfusion.pub
|
||
echo
|
||
fi
|
||
fi
|
||
|
||
echo "SSH配置说明:"
|
||
echo "1. 将公钥添加到GitHub SSH keys"
|
||
echo "2. 测试连接: ssh -T git@github.com"
|
||
echo "3. 更改远程URL: git remote set-url origin git@github.com:mit-han-lab/bevfusion.git"
|
||
echo
|
||
read -p "是否要测试SSH连接? (y/n): " test_ssh
|
||
if [[ $test_ssh =~ ^[Yy]$ ]]; then
|
||
echo "测试SSH连接..."
|
||
if ssh -T git@github.com -o ConnectTimeout=10 2>&1 | grep -q "successfully authenticated"; then
|
||
print_success "SSH连接测试成功"
|
||
else
|
||
print_warning "SSH连接测试失败,请检查密钥配置"
|
||
fi
|
||
fi
|
||
}
|
||
|
||
# 本地Git服务配置
|
||
setup_local_git() {
|
||
echo
|
||
print_info "配置本地Git服务..."
|
||
|
||
echo "本地Git服务选项:"
|
||
echo "1. SSH + Git (推荐)"
|
||
echo "2. Git Daemon (只读)"
|
||
echo "3. HTTP服务"
|
||
echo
|
||
|
||
read -p "选择服务类型 (1-3): " service_type
|
||
|
||
case $service_type in
|
||
1)
|
||
print_info "SSH + Git服务配置"
|
||
echo "1. 安装SSH服务: sudo apt install openssh-server"
|
||
echo "2. 启动服务: sudo systemctl start ssh"
|
||
echo "3. 创建仓库: mkdir /srv/git && git init --bare /srv/git/bevfusion.git"
|
||
echo "4. 推送: git remote add local ssh://user@host/srv/git/bevfusion.git"
|
||
;;
|
||
2)
|
||
print_info "Git Daemon配置 (只读)"
|
||
echo "启动服务: git daemon --reuseaddr --base-path=/path/to/repos --export-all"
|
||
echo "访问地址: git://host:9418/repo.git"
|
||
;;
|
||
3)
|
||
print_info "HTTP服务配置"
|
||
echo "需要Web服务器 + git-http-backend"
|
||
echo "访问地址: https://host/git/repo.git"
|
||
;;
|
||
*)
|
||
print_warning "无效选择"
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# 私有Git服务配置
|
||
setup_private_git() {
|
||
echo
|
||
print_info "私有Git服务部署选项..."
|
||
|
||
echo "推荐的私有Git服务:"
|
||
echo "1. Gitea (轻量级,Go语言)"
|
||
echo "2. GitLab (功能丰富,企业级)"
|
||
echo "3. Gogs (轻量级,类似GitHub)"
|
||
echo
|
||
|
||
read -p "选择服务 (1-3): " git_service
|
||
|
||
case $git_service in
|
||
1)
|
||
print_info "Gitea部署指南"
|
||
echo "1. 下载: wget https://dl.gitea.io/gitea/main/gitea-main-linux-amd64"
|
||
echo "2. 运行: chmod +x gitea-main-linux-amd64 && ./gitea-main-linux-amd64 web"
|
||
echo "3. 访问: http://localhost:3000"
|
||
echo "4. 初始化并创建BEVFusion仓库"
|
||
;;
|
||
2)
|
||
print_info "GitLab部署 (较复杂)"
|
||
echo "推荐使用Docker: docker run -d --name gitlab -p 80:80 gitlab/gitlab-ce"
|
||
;;
|
||
3)
|
||
print_info "Gogs部署"
|
||
echo "类似Gitea,更轻量"
|
||
;;
|
||
*)
|
||
print_warning "无效选择"
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# 主菜单
|
||
main_menu() {
|
||
while true; do
|
||
echo
|
||
echo "选择Git访问配置方案:"
|
||
echo "1. HTTPS访问GitHub (最简单)"
|
||
echo "2. SSH访问GitHub (推荐)"
|
||
echo "3. 本地网络Git服务"
|
||
echo "4. 私有Git服务部署"
|
||
echo "5. 网络连通性检查"
|
||
echo "6. 退出"
|
||
echo
|
||
|
||
read -p "请选择 (1-6): " choice
|
||
|
||
case $choice in
|
||
1) setup_https ;;
|
||
2) setup_ssh ;;
|
||
3) setup_local_git ;;
|
||
4) setup_private_git ;;
|
||
5) check_connectivity ;;
|
||
6)
|
||
print_success "配置完成!"
|
||
exit 0
|
||
;;
|
||
*) print_error "无效选择,请重新输入" ;;
|
||
esac
|
||
done
|
||
}
|
||
|
||
# 主程序
|
||
print_header
|
||
echo "当前Git配置状态:"
|
||
echo "- 用户: $(git config user.name) <$(git config user.email)>"
|
||
echo "- 远程: $(git remote get-url origin 2>/dev/null || echo '未配置')"
|
||
echo "- 分支: $(git branch --show-current)"
|
||
echo "- 状态: $(git status --porcelain | wc -l) 个未提交文件"
|
||
echo
|
||
|
||
main_menu
|