feat: Update database setup and download handling

- Set a fixed database password and ensure old data is overwritten during setup.
- Enhance the download functionality with improved error handling for missing files, providing user-friendly HTML responses.
- Add instructions for placing client builds in the downloads directory in the admin panel.
This commit is contained in:
2026-02-26 21:05:41 +08:00
parent a376a9e0f3
commit 89948f76b7
3 changed files with 39 additions and 11 deletions

View File

@@ -99,19 +99,23 @@ install_nodejs() {
fi
}
# 配置数据库
# 配置数据库(固定密码 12345678安装时覆盖旧数据
setup_database() {
echo -e "${YELLOW}[4/7] 配置数据库...${NC}"
systemctl enable postgresql
systemctl start postgresql
# 生成随机密码
DB_PASSWORD=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 24)
# 固定数据库密码,安装时覆盖旧库与用户
DB_PASSWORD="12345678"
# 创建数据库和用户
sudo -u postgres psql -c "CREATE USER funmc WITH PASSWORD '$DB_PASSWORD';" 2>/dev/null || true
sudo -u postgres psql -c "CREATE DATABASE funmc OWNER funmc;" 2>/dev/null || true
# 先删除旧数据库和用户(覆盖旧数据)
sudo -u postgres psql -c "DROP DATABASE IF EXISTS funmc;" 2>/dev/null || true
sudo -u postgres psql -c "DROP USER IF EXISTS funmc;" 2>/dev/null || true
# 创建用户和数据库
sudo -u postgres psql -c "CREATE USER funmc WITH PASSWORD '$DB_PASSWORD';"
sudo -u postgres psql -c "CREATE DATABASE funmc OWNER funmc;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE funmc TO funmc;"
# 配置 pg_hba.conf
@@ -122,7 +126,7 @@ setup_database() {
systemctl reload postgresql
fi
echo -e "${GREEN}✓ 数据库配置完成${NC}"
echo -e "${GREEN}✓ 数据库配置完成(密码已设为 12345678已覆盖旧数据${NC}"
echo "$DB_PASSWORD" > /tmp/funmc_db_password
}
@@ -130,8 +134,8 @@ setup_database() {
build_funmc() {
echo -e "${YELLOW}[5/7] 编译 FunMC...${NC}"
# 创建目录
mkdir -p $INSTALL_DIR $CONFIG_DIR $DATA_DIR $LOG_DIR
# 创建目录(含客户端下载目录)
mkdir -p $INSTALL_DIR $INSTALL_DIR/downloads $CONFIG_DIR $DATA_DIR $LOG_DIR
# 克隆或更新代码
if [ -d "$INSTALL_DIR/src" ]; then
@@ -192,6 +196,7 @@ ADMIN_PASSWORD=${ADMIN_PASSWORD}
# 客户端下载
CLIENT_DOWNLOAD_ENABLED=true
CLIENT_VERSION=${FUNMC_VERSION}
DOWNLOADS_DIR=$INSTALL_DIR/downloads
EOF
# 创建中继配置