Smail/deploy/install-systemd.sh
smail f60d3b0880
Some checks are pending
Security Checks / security (push) Waiting to run
整理前后端与测试构建目录并完善配置和安全引导
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
2026-09-05 19:19:52 +08:00

30 lines
1.4 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.

#!/usr/bin/env bash
set -eu
if [ "$(id -u)" -ne 0 ]; then
echo "必须使用 root 用户安装 Smail" >&2
exit 1
fi
root_dir="${1:-$(cd "$(dirname "$0")/.." && pwd)}"
install -d -m 0750 /var/lib/smail /run/smail /usr/local/lib/smail
if ! getent group smail >/dev/null; then groupadd --system smail; fi
if ! getent passwd smail >/dev/null; then useradd --system --gid smail --home-dir /var/lib/smail --shell /usr/sbin/nologin smail; fi
chown smail:smail /var/lib/smail
case "$(uname -m)" in
x86_64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*) echo "不支持的系统架构" >&2; exit 1 ;;
esac
install -o root -g root -m 0755 "$root_dir/out/backend/smail_linux_$arch" /usr/local/lib/smail/smail
install -o root -g root -m 0750 "$root_dir/out/backend/smail-admin_linux_$arch" /usr/local/lib/smail/smail-admin
install -o root -g root -m 0644 "$root_dir/deploy/systemd/smail.service" /etc/systemd/system/smail.service
install -o root -g root -m 0644 "$root_dir/deploy/systemd/smail-admin.service" /etc/systemd/system/smail-admin.service
chown smail:smail /run/smail
chmod 0750 /run/smail
systemctl daemon-reload
systemctl enable smail
# 清理旧版本可能留下的开机启动关系。smail-admin 单元没有 [Install],不能再次 enable。
systemctl disable smail-admin >/dev/null 2>&1 || true
echo "Smail 安装完成;smail-admin 仅允许按需执行 start/stop,不支持开机自启动。"