From 3a7de9479e3817d3121a900cedf028e7f2874334 Mon Sep 17 00:00:00 2001 From: smail Date: Sat, 17 Oct 2026 00:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=89=E8=A3=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=9A=E6=94=AF=E6=8C=81=E5=9C=A8=E8=A7=A3=E5=8E=8B?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=9B=AE=E5=BD=95=E5=B0=B1=E5=9C=B0=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/install-systemd.sh | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/deploy/install-systemd.sh b/deploy/install-systemd.sh index d88f98bd..4d5e95d0 100644 --- a/deploy/install-systemd.sh +++ b/deploy/install-systemd.sh @@ -43,7 +43,7 @@ is_packaged=false if [ -f "$root_dir/smail" ] && [ -f "$root_dir/smail-admin" ] && [ -f "$root_dir/smail-config" ]; then is_packaged=true fi -runtime_dir=/opt/smail +runtime_dir="${root_dir}" fresh_confirmation="确认全新部署 Smail" printf '这是不可逆的 Smail 专属数据清理操作。请输入“%s”继续: ' "$fresh_confirmation" if ! IFS= read -r confirmation || [ "$confirmation" != "$fresh_confirmation" ]; then @@ -87,7 +87,7 @@ for process in /proc/[0-9]*/exe; do exit 1 ;; esac done -if [ -L /opt ] || [ -L "$runtime_dir" ] || { [ -e "$runtime_dir" ] && [ ! -d "$runtime_dir" ]; }; then +if [ -L "$runtime_dir" ] || { [ -e "$runtime_dir" ] && [ ! -d "$runtime_dir" ]; }; then echo "部署路径不能是链接或普通文件。" >&2 exit 1 fi @@ -135,7 +135,15 @@ if [ "$fresh" = true ]; then fi if [ -d "$runtime_dir" ]; then - find "$runtime_dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + + if [ "$is_packaged" = true ]; then + for directory in config data ssl log; do + if [ -d "$runtime_dir/$directory" ]; then + find "$runtime_dir/$directory" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + + fi + done + else + find "$runtime_dir" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + + fi fi if [ -d /etc/smail ]; then find /etc/smail -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + @@ -159,7 +167,7 @@ install -d -o root -g root -m 0750 /etc/smail if [ ! -e /etc/smail/smail.env ]; then # 每次部署都重新创建服务环境文件,不继承旧的凭据或代理配置。 umask 0077 - printf '%s\n' 'SMAIL_ROOT=/opt/smail' 'GOMEMLIMIT=256MiB' > /etc/smail/smail.env + printf '%s\n' "SMAIL_ROOT=$runtime_dir" 'GOMEMLIMIT=256MiB' > /etc/smail/smail.env fi if ! grep -q '^SMAIL_PLUGIN_UID=' /etc/smail/smail.env; then printf 'SMAIL_PLUGIN_UID=%s\n' "$(id -u smail-plugin)" >> /etc/smail/smail.env @@ -186,8 +194,22 @@ install -d -o root -g root -m 0755 /run/systemd/ask-password install -o root -g root -m 0755 "$backend_smail" "$runtime_dir/smail" install -o root -g root -m 0700 "$backend_smail_admin" "$runtime_dir/smail-admin" install -o root -g root -m 0700 "$backend_smail_config" "$runtime_dir/smail-config" -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 +sed -e "s|WorkingDirectory=/opt/smail|WorkingDirectory=$runtime_dir|g" \ + -e "s|ExecStart=/opt/smail/smail|ExecStart=$runtime_dir/smail|g" \ + -e "s|/opt/smail/config|$runtime_dir/config|g" \ + -e "s|/opt/smail/data|$runtime_dir/data|g" \ + -e "s|/opt/smail/ssl|$runtime_dir/ssl|g" \ + -e "s|/opt/smail/log|$runtime_dir/log|g" \ + -e "s|/opt/smail/plugins|$runtime_dir/plugins|g" \ + "$root_dir/deploy/systemd/smail.service" > /etc/systemd/system/smail.service +chmod 0644 /etc/systemd/system/smail.service +chown root:root /etc/systemd/system/smail.service + +sed -e "s|WorkingDirectory=/opt/smail|WorkingDirectory=$runtime_dir|g" \ + -e "s|ExecStart=/opt/smail/smail-admin|ExecStart=$runtime_dir/smail-admin|g" \ + "$root_dir/deploy/systemd/smail-admin.service" > /etc/systemd/system/smail-admin.service +chmod 0644 /etc/systemd/system/smail-admin.service +chown root:root /etc/systemd/system/smail-admin.service systemctl daemon-reload systemctl enable smail # 清理旧版本可能留下的开机启动关系。smail-admin 单元没有 [Install],不能再次 enable。