Files
lan-manager/deploy/lan-manager-debian12/install.sh

74 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
set -e
INSTALL_DIR="/opt/lan-manager"
SERVICE_NAME="lan-manager"
USER_NAME="lanmgr"
echo "=== LAN Manager Debian 12 安装脚本 ==="
# 1. 检查 root 权限
if [ "$EUID" -ne 0 ]; then
echo "请使用 root 权限运行sudo bash install.sh"
exit 1
fi
# 2. 创建用户(如果不存在)
if ! id "$USER_NAME" &>/dev/null; then
echo "[1/7] 创建运行用户 $USER_NAME ..."
useradd --system --no-create-home --shell /usr/sbin/nologin "$USER_NAME"
else
echo "[1/7] 用户 $USER_NAME 已存在,跳过"
fi
# 3. 停止服务(如果正在运行)以便覆盖二进制
echo "[2/7] 停止现有服务(如果正在运行)..."
if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then
systemctl stop "$SERVICE_NAME"
sleep 1
fi
# 4. 复制程序文件
echo "[3/7] 复制程序文件到 $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR"
cp lan-manager "$INSTALL_DIR/"
cp lan-manager.env "$INSTALL_DIR/"
# 5. 创建数据目录并授权
echo "[4/7] 创建数据目录 ..."
mkdir -p "$INSTALL_DIR/data"
chown -R "$USER_NAME:$USER_NAME" "$INSTALL_DIR"
chmod +x "$INSTALL_DIR/lan-manager"
# 6. 安装 systemd 服务
echo "[5/7] 安装 systemd 服务 ..."
cp lan-manager.service /etc/systemd/system/
chmod 644 /etc/systemd/system/lan-manager.service
systemctl daemon-reload
# 7. 启动并设置开机自启
echo "[6/7] 启动服务并设置开机自启 ..."
systemctl enable --now lan-manager
# 8. 检查状态
echo "[7/7] 检查服务状态 ..."
sleep 2
if systemctl is-active --quiet lan-manager; then
echo "✅ 服务已正常启动"
else
echo "❌ 服务启动失败请查看日志journalctl -u lan-manager -n 50"
exit 1
fi
echo ""
echo "=== 安装完成 ==="
echo "访问地址: http://$(hostname -I | awk '{print $1}'):8080"
echo ""
echo "⚠️ 重要提示:"
echo " 1. 默认管理员账号: admin / changeme"
echo " 2. 请务必修改 $INSTALL_DIR/lan-manager.env 中的 ADMIN_PASS 和 SESSION_SECRET"
echo " 3. 修改配置后执行: systemctl restart lan-manager"
echo " 4. 查看日志: journalctl -u lan-manager -f"
echo " 5. 如需开放防火墙端口: ufw allow 8080/tcp"
echo ""