Files
gerrit/configure_permissions.sh
2025-12-22 17:12:39 +08:00

78 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 配置 Gerrit 项目权限的脚本
PROJECT_NAME="zhini-im"
GERRIT_DIR="/home/renjianbo/gerrit_install/review_site"
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-2.el7_9.x86_64"
echo "=========================================="
echo "配置 Gerrit 项目权限"
echo "=========================================="
echo ""
cd "$GERRIT_DIR" || exit 1
# 方法 1: 尝试使用 SSH如果密钥配置正确
echo "方法 1: 尝试使用 SSH 配置..."
ssh -p 29418 renjianbo@localhost gerrit set-access "$PROJECT_NAME" -a refs/for/* -g Administrators Label-Code-Review+2 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ 通过 SSH 配置成功"
exit 0
fi
echo "SSH 配置失败,尝试其他方法..."
echo ""
# 方法 2: 直接编辑配置文件
echo "方法 2: 编辑配置文件..."
PROJECT_CONFIG_DIR="$GERRIT_DIR/git/$PROJECT_NAME.git"
PROJECT_CONFIG="$PROJECT_CONFIG_DIR/config"
if [ ! -d "$PROJECT_CONFIG_DIR" ]; then
echo "❌ 项目目录不存在: $PROJECT_CONFIG_DIR"
exit 1
fi
# 备份配置文件
if [ -f "$PROJECT_CONFIG" ]; then
cp "$PROJECT_CONFIG" "$PROJECT_CONFIG.bak.$(date +%Y%m%d_%H%M%S)"
echo "✅ 已备份配置文件"
fi
# 检查是否已有权限配置
if grep -q "refs/for/\*" "$PROJECT_CONFIG" 2>/dev/null; then
echo "⚠️ 检测到已有 refs/for/* 权限配置"
echo "请手动编辑文件: $PROJECT_CONFIG"
echo ""
echo "添加以下内容:"
echo " [access \"refs/for/*\"]"
echo " label-Code-Review = +2 group Administrators"
else
# 添加权限配置
cat >> "$PROJECT_CONFIG" << 'EOF'
[access "refs/for/*"]
label-Code-Review = +2 group Administrators
EOF
echo "✅ 已添加权限配置到配置文件"
fi
echo ""
echo "配置文件位置: $PROJECT_CONFIG"
echo ""
echo "下一步:"
echo "1. 检查配置文件内容是否正确"
echo "2. 重启 Gerrit 服务使配置生效:"
echo " cd $GERRIT_DIR"
echo " JAVA_HOME=$JAVA_HOME bin/gerrit.sh restart"
echo ""
# 显示配置文件内容
echo "当前配置文件内容(最后 20 行):"
tail -20 "$PROJECT_CONFIG"