Files
gerrit/继续安装.sh

120 lines
2.8 KiB
Bash
Raw Normal View History

2025-12-22 17:12:39 +08:00
#!/bin/bash
# 继续完成 Gerrit 安装从第4步开始
GERRIT_HOME="/home/renjianbo/gerrit_install"
GERRIT_VERSION="3.9.0"
SERVER_IP="101.43.95.130"
GERRIT_PORT="8080"
GERRIT_SSH_PORT="29418"
JAVA_HOME="/usr/local/java/jdk-17.0.12+7"
export JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
echo "=========================================="
echo "继续完成 Gerrit 安装"
echo "=========================================="
echo ""
# 4. 初始化 Gerrit修复后的命令
echo "[4/7] 初始化 Gerrit这可能需要几分钟..."
cd ${GERRIT_HOME}
java -Dgerrit.canonicalWebUrl=http://${SERVER_IP}:${GERRIT_PORT}/ \
-jar gerrit-${GERRIT_VERSION}.war init \
-d review_site \
--batch \
--no-auto-start \
--install-plugin=download-commands \
--install-plugin=replication \
--install-plugin=reviewnotes
if [ $? -eq 0 ]; then
echo "✓ 初始化完成"
else
echo "⚠ 初始化完成(可能有警告)"
fi
echo ""
# 5. 配置 Gerrit
echo "[5/7] 配置 Gerrit..."
cd ${GERRIT_HOME}/review_site
# 创建配置文件
cat > etc/gerrit.config << EOF
[gerrit]
basePath = git
canonicalWebUrl = http://${SERVER_IP}:${GERRIT_PORT}/
serverId = $(date +%s)
[database]
type = h2
database = db/ReviewDB
[auth]
type = DEVELOPMENT_BECOME_ANY_ACCOUNT
gitBasicAuth = true
[sshd]
listenAddress = *:${GERRIT_SSH_PORT}
[httpd]
listenUrl = http://*:${GERRIT_PORT}/
cookieSecure = false
cookieSameSite = LAX
cookiePath = /
[cache]
directory = cache
[index]
type = LUCENE
[receive]
enableSignedPush = false
EOF
echo "✓ 配置完成"
echo ""
# 6. 配置启动脚本
echo "[6/7] 配置启动脚本..."
cd ${GERRIT_HOME}/review_site
# 备份原脚本
cp bin/gerrit.sh bin/gerrit.sh.bak
# 在脚本开头添加 Java 环境变量
if ! grep -q "JAVA_HOME.*jdk-17" bin/gerrit.sh; then
sed -i "2i export JAVA_HOME=${JAVA_HOME}\nexport PATH=\$JAVA_HOME/bin:\$PATH" bin/gerrit.sh
fi
echo "✓ 启动脚本已配置"
echo ""
# 7. 启动服务
echo "[7/7] 启动 Gerrit 服务..."
cd ${GERRIT_HOME}/review_site
bin/gerrit.sh start
echo "等待服务启动..."
sleep 8
# 检查服务状态
if bin/gerrit.sh status 2>&1 | grep -q "Gerrit running\|Running"; then
echo "✓ 服务启动成功"
else
echo "检查服务状态..."
bin/gerrit.sh status 2>&1 | head -10
fi
echo ""
echo "=========================================="
echo "安装完成!"
echo "=========================================="
echo ""
echo "访问地址: http://${SERVER_IP}:${GERRIT_PORT}"
echo ""
echo "重要提示:"
echo "1. 清除浏览器 Cookie 和缓存"
echo "2. 访问上述地址"
echo "3. 点击 'Sign In'输入用户名例如admin"
echo "4. 第一个登录的用户将自动成为管理员"
echo "5. 登录后应该能看到 'CREATE NEW' 按钮"
echo ""