From e07235ca9827c8fac904d4c04647acfcb17d1be8 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 19 Oct 2025 17:38:55 +1100 Subject: [PATCH] feat: add Stalwart Mail Server and FoundationDB library packages - add stalwart: main mail server with systemd integration and user management - add stalwart-cli: command line interface tool for server administration - add stalwart-foundationdb: FoundationDB-enabled version with proper dependencies - add libfoundationdb: FoundationDB client library (libfdb_c.so) package All packages include proper conflict resolution, systemd services, and follow repository packaging conventions. stalwart and stalwart-foundationdb are mutually exclusive to prevent installation conflicts. --- rpms/libfoundationdb/7.3.71/release | 1 + rpms/libfoundationdb/Dockerfile | 18 +++++++ rpms/libfoundationdb/metadata.yaml | 9 ++++ rpms/libfoundationdb/resources/build.sh | 10 ++++ rpms/libfoundationdb/resources/nfpm.yaml | 36 +++++++++++++ .../resources/scripts/postinstall.sh | 4 ++ rpms/stalwart-cli/0.13.4/release | 1 + rpms/stalwart-cli/Dockerfile | 18 +++++++ rpms/stalwart-cli/metadata.yaml | 9 ++++ rpms/stalwart-cli/resources/build.sh | 13 +++++ rpms/stalwart-cli/resources/nfpm.yaml | 31 +++++++++++ rpms/stalwart-foundationdb/0.13.4/release | 1 + rpms/stalwart-foundationdb/Dockerfile | 18 +++++++ rpms/stalwart-foundationdb/metadata.yaml | 9 ++++ rpms/stalwart-foundationdb/resources/build.sh | 13 +++++ .../stalwart-foundationdb/resources/nfpm.yaml | 50 +++++++++++++++++ .../resources/scripts/postinstall.sh | 54 +++++++++++++++++++ .../resources/scripts/postremove.sh | 7 +++ .../resources/scripts/preinstall.sh | 20 +++++++ .../resources/scripts/preremove.sh | 7 +++ .../resources/stalwart-foundationdb.service | 26 +++++++++ rpms/stalwart/0.13.4/release | 1 + rpms/stalwart/Dockerfile | 18 +++++++ rpms/stalwart/metadata.yaml | 9 ++++ rpms/stalwart/resources/build.sh | 13 +++++ rpms/stalwart/resources/nfpm.yaml | 47 ++++++++++++++++ .../stalwart/resources/scripts/postinstall.sh | 54 +++++++++++++++++++ rpms/stalwart/resources/scripts/postremove.sh | 7 +++ rpms/stalwart/resources/scripts/preinstall.sh | 20 +++++++ rpms/stalwart/resources/scripts/preremove.sh | 7 +++ rpms/stalwart/resources/stalwart.service | 25 +++++++++ 31 files changed, 556 insertions(+) create mode 100644 rpms/libfoundationdb/7.3.71/release create mode 100644 rpms/libfoundationdb/Dockerfile create mode 100644 rpms/libfoundationdb/metadata.yaml create mode 100755 rpms/libfoundationdb/resources/build.sh create mode 100644 rpms/libfoundationdb/resources/nfpm.yaml create mode 100644 rpms/libfoundationdb/resources/scripts/postinstall.sh create mode 100644 rpms/stalwart-cli/0.13.4/release create mode 100644 rpms/stalwart-cli/Dockerfile create mode 100644 rpms/stalwart-cli/metadata.yaml create mode 100755 rpms/stalwart-cli/resources/build.sh create mode 100644 rpms/stalwart-cli/resources/nfpm.yaml create mode 100644 rpms/stalwart-foundationdb/0.13.4/release create mode 100644 rpms/stalwart-foundationdb/Dockerfile create mode 100644 rpms/stalwart-foundationdb/metadata.yaml create mode 100755 rpms/stalwart-foundationdb/resources/build.sh create mode 100644 rpms/stalwart-foundationdb/resources/nfpm.yaml create mode 100644 rpms/stalwart-foundationdb/resources/scripts/postinstall.sh create mode 100644 rpms/stalwart-foundationdb/resources/scripts/postremove.sh create mode 100644 rpms/stalwart-foundationdb/resources/scripts/preinstall.sh create mode 100644 rpms/stalwart-foundationdb/resources/scripts/preremove.sh create mode 100644 rpms/stalwart-foundationdb/resources/stalwart-foundationdb.service create mode 100644 rpms/stalwart/0.13.4/release create mode 100644 rpms/stalwart/Dockerfile create mode 100644 rpms/stalwart/metadata.yaml create mode 100755 rpms/stalwart/resources/build.sh create mode 100644 rpms/stalwart/resources/nfpm.yaml create mode 100644 rpms/stalwart/resources/scripts/postinstall.sh create mode 100644 rpms/stalwart/resources/scripts/postremove.sh create mode 100644 rpms/stalwart/resources/scripts/preinstall.sh create mode 100644 rpms/stalwart/resources/scripts/preremove.sh create mode 100644 rpms/stalwart/resources/stalwart.service diff --git a/rpms/libfoundationdb/7.3.71/release b/rpms/libfoundationdb/7.3.71/release new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/rpms/libfoundationdb/7.3.71/release @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/rpms/libfoundationdb/Dockerfile b/rpms/libfoundationdb/Dockerfile new file mode 100644 index 0000000..539afe6 --- /dev/null +++ b/rpms/libfoundationdb/Dockerfile @@ -0,0 +1,18 @@ +FROM git.unkin.net/unkin/almalinux9-rpmbuilder:latest + +# Create output directory for RPMs +RUN mkdir -p /app/dist + +# Set working directory +WORKDIR /app + +ARG PACKAGE_RELEASE +ENV PACKAGE_RELEASE=${PACKAGE_RELEASE} +ARG PACKAGE_VERSION +ENV PACKAGE_VERSION=${PACKAGE_VERSION} + +# Copy resources from the context into the container +COPY resources /app/resources + +# Default command to build RPMs +CMD /app/resources/build.sh \ No newline at end of file diff --git a/rpms/libfoundationdb/metadata.yaml b/rpms/libfoundationdb/metadata.yaml new file mode 100644 index 0000000..d9a7aca --- /dev/null +++ b/rpms/libfoundationdb/metadata.yaml @@ -0,0 +1,9 @@ +name: libfoundationdb +release: 1 +version: 7.3.71 +github: apple/foundationdb +build: +- distro: el/8 + image: git.unkin.net/unkin/almalinux8-rpmbuilder:latest +- distro: el/9 + image: git.unkin.net/unkin/almalinux9-rpmbuilder:latest \ No newline at end of file diff --git a/rpms/libfoundationdb/resources/build.sh b/rpms/libfoundationdb/resources/build.sh new file mode 100755 index 0000000..ddec6ba --- /dev/null +++ b/rpms/libfoundationdb/resources/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +# Download the required library +curl -L -o /app/libfdb_c.so https://github.com/apple/foundationdb/releases/download/${PACKAGE_VERSION}/libfdb_c.x86_64.so + +# Make the library readable +chmod 755 /app/libfdb_c.so + +# Build the RPM +nfpm pkg --config /app/resources/nfpm.yaml --target /app/dist --packager rpm \ No newline at end of file diff --git a/rpms/libfoundationdb/resources/nfpm.yaml b/rpms/libfoundationdb/resources/nfpm.yaml new file mode 100644 index 0000000..f3692df --- /dev/null +++ b/rpms/libfoundationdb/resources/nfpm.yaml @@ -0,0 +1,36 @@ +# nfpm.yaml + +name: libfoundationdb +version: ${PACKAGE_VERSION} +release: ${PACKAGE_RELEASE} +arch: amd64 +platform: linux +section: default +priority: extra +description: "FoundationDB client library - Shared library for FoundationDB applications" + +maintainer: FoundationDB Community +homepage: https://github.com/apple/foundationdb +license: Apache-2.0 + +disable_globbing: false + +replaces: + - libfoundationdb + +provides: + - libfoundationdb + - libfdb_c.so()(64bit) + +# Files to include in the package +contents: + - src: /app/libfdb_c.so + dst: /usr/lib64/libfdb_c.so + file_info: + mode: 0755 + owner: root + group: root + +# Scripts to run during installation/removal +scripts: + postinstall: /app/resources/scripts/postinstall.sh \ No newline at end of file diff --git a/rpms/libfoundationdb/resources/scripts/postinstall.sh b/rpms/libfoundationdb/resources/scripts/postinstall.sh new file mode 100644 index 0000000..a557617 --- /dev/null +++ b/rpms/libfoundationdb/resources/scripts/postinstall.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Update the dynamic linker cache to include the new library +ldconfig \ No newline at end of file diff --git a/rpms/stalwart-cli/0.13.4/release b/rpms/stalwart-cli/0.13.4/release new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/rpms/stalwart-cli/0.13.4/release @@ -0,0 +1 @@ +1 diff --git a/rpms/stalwart-cli/Dockerfile b/rpms/stalwart-cli/Dockerfile new file mode 100644 index 0000000..539afe6 --- /dev/null +++ b/rpms/stalwart-cli/Dockerfile @@ -0,0 +1,18 @@ +FROM git.unkin.net/unkin/almalinux9-rpmbuilder:latest + +# Create output directory for RPMs +RUN mkdir -p /app/dist + +# Set working directory +WORKDIR /app + +ARG PACKAGE_RELEASE +ENV PACKAGE_RELEASE=${PACKAGE_RELEASE} +ARG PACKAGE_VERSION +ENV PACKAGE_VERSION=${PACKAGE_VERSION} + +# Copy resources from the context into the container +COPY resources /app/resources + +# Default command to build RPMs +CMD /app/resources/build.sh \ No newline at end of file diff --git a/rpms/stalwart-cli/metadata.yaml b/rpms/stalwart-cli/metadata.yaml new file mode 100644 index 0000000..b4aefd5 --- /dev/null +++ b/rpms/stalwart-cli/metadata.yaml @@ -0,0 +1,9 @@ +name: stalwart-cli +release: 1 +version: 0.13.4 +github: stalwartlabs/stalwart +build: +- distro: el/8 + image: git.unkin.net/unkin/almalinux8-rpmbuilder:latest +- distro: el/9 + image: git.unkin.net/unkin/almalinux9-rpmbuilder:latest \ No newline at end of file diff --git a/rpms/stalwart-cli/resources/build.sh b/rpms/stalwart-cli/resources/build.sh new file mode 100755 index 0000000..bca6790 --- /dev/null +++ b/rpms/stalwart-cli/resources/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# Download the required files +curl -L -o /app/stalwart-cli.tar.gz https://github.com/stalwartlabs/stalwart/releases/download/v${PACKAGE_VERSION}/stalwart-cli-x86_64-unknown-linux-gnu.tar.gz + +# Extract the binary +tar -xzf /app/stalwart-cli.tar.gz -C /app + +# Make the binary executable +chmod +x /app/stalwart-cli + +# Build the RPM +nfpm pkg --config /app/resources/nfpm.yaml --target /app/dist --packager rpm \ No newline at end of file diff --git a/rpms/stalwart-cli/resources/nfpm.yaml b/rpms/stalwart-cli/resources/nfpm.yaml new file mode 100644 index 0000000..f44f412 --- /dev/null +++ b/rpms/stalwart-cli/resources/nfpm.yaml @@ -0,0 +1,31 @@ +# nfpm.yaml + +name: stalwart-cli +version: ${PACKAGE_VERSION} +release: ${PACKAGE_RELEASE} +arch: amd64 +platform: linux +section: default +priority: extra +description: "Stalwart CLI - Command line interface for Stalwart Mail Server" + +maintainer: Stalwart Labs +homepage: https://stalw.art +license: AGPL-3.0 + +disable_globbing: false + +replaces: + - stalwart-cli + +provides: + - stalwart-cli + +# Files to include in the package +contents: + - src: /app/stalwart-cli + dst: /usr/bin/stalwart-cli + file_info: + mode: 0755 + owner: root + group: root diff --git a/rpms/stalwart-foundationdb/0.13.4/release b/rpms/stalwart-foundationdb/0.13.4/release new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/rpms/stalwart-foundationdb/0.13.4/release @@ -0,0 +1 @@ +1 diff --git a/rpms/stalwart-foundationdb/Dockerfile b/rpms/stalwart-foundationdb/Dockerfile new file mode 100644 index 0000000..539afe6 --- /dev/null +++ b/rpms/stalwart-foundationdb/Dockerfile @@ -0,0 +1,18 @@ +FROM git.unkin.net/unkin/almalinux9-rpmbuilder:latest + +# Create output directory for RPMs +RUN mkdir -p /app/dist + +# Set working directory +WORKDIR /app + +ARG PACKAGE_RELEASE +ENV PACKAGE_RELEASE=${PACKAGE_RELEASE} +ARG PACKAGE_VERSION +ENV PACKAGE_VERSION=${PACKAGE_VERSION} + +# Copy resources from the context into the container +COPY resources /app/resources + +# Default command to build RPMs +CMD /app/resources/build.sh \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/metadata.yaml b/rpms/stalwart-foundationdb/metadata.yaml new file mode 100644 index 0000000..4de8a8c --- /dev/null +++ b/rpms/stalwart-foundationdb/metadata.yaml @@ -0,0 +1,9 @@ +name: stalwart-foundationdb +release: 1 +version: 0.13.4 +github: stalwartlabs/stalwart +build: +- distro: el/8 + image: git.unkin.net/unkin/almalinux8-rpmbuilder:latest +- distro: el/9 + image: git.unkin.net/unkin/almalinux9-rpmbuilder:latest \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/resources/build.sh b/rpms/stalwart-foundationdb/resources/build.sh new file mode 100755 index 0000000..e9b1e6d --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# Download the required files +curl -L -o /app/stalwart-foundationdb.tar.gz https://github.com/stalwartlabs/stalwart/releases/download/v${PACKAGE_VERSION}/stalwart-foundationdb-x86_64-unknown-linux-gnu.tar.gz + +# Extract the binary +tar -xzf /app/stalwart-foundationdb.tar.gz -C /app + +# Make the binary executable +chmod +x /app/stalwart-foundationdb + +# Build the RPM +nfpm pkg --config /app/resources/nfpm.yaml --target /app/dist --packager rpm \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/resources/nfpm.yaml b/rpms/stalwart-foundationdb/resources/nfpm.yaml new file mode 100644 index 0000000..261e76e --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/nfpm.yaml @@ -0,0 +1,50 @@ +# nfpm.yaml + +name: stalwart-foundationdb +version: ${PACKAGE_VERSION} +release: ${PACKAGE_RELEASE} +arch: amd64 +platform: linux +section: default +priority: extra +description: "Stalwart Mail Server with FoundationDB support - A modern, secure JMAP, IMAP and SMTP mail server" + +maintainer: Stalwart Labs +homepage: https://stalw.art +license: AGPL-3.0 + +disable_globbing: false + +replaces: + - stalwart-foundationdb + +provides: + - stalwart-foundationdb + +conflicts: + - stalwart + +depends: + - libfoundationdb + +# Files to include in the package +contents: + - src: /app/stalwart-foundationdb + dst: /opt/stalwart/bin/stalwart-foundationdb + file_info: + mode: 0755 + owner: stalwart + group: stalwart + - src: /app/resources/stalwart-foundationdb.service + dst: /usr/lib/systemd/system/stalwart-foundationdb.service + file_info: + mode: 0644 + owner: root + group: root + +# Scripts to run during installation/removal +scripts: + preinstall: /app/resources/scripts/preinstall.sh + postinstall: /app/resources/scripts/postinstall.sh + preremove: /app/resources/scripts/preremove.sh + postremove: /app/resources/scripts/postremove.sh diff --git a/rpms/stalwart-foundationdb/resources/scripts/postinstall.sh b/rpms/stalwart-foundationdb/resources/scripts/postinstall.sh new file mode 100644 index 0000000..dd4c4c0 --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/scripts/postinstall.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Create default configuration if it doesn't exist +if [ ! -f /opt/stalwart/etc/config.toml ]; then + cat > /opt/stalwart/etc/config.toml << 'EOF' +# Stalwart Mail Server Configuration with FoundationDB +# This is a minimal configuration file. Please customize according to your needs. +# Full documentation: https://stalw.art/docs/ + +[server] +hostname = "localhost" + +[server.listener.smtp] +bind = ["127.0.0.1:25"] +protocol = "smtp" + +[server.listener.submission] +bind = ["127.0.0.1:587"] +protocol = "smtp" + +[server.listener.imap] +bind = ["127.0.0.1:143"] +protocol = "imap" + +[server.listener.http] +bind = ["127.0.0.1:8080"] +protocol = "http" + +[storage] +data = "foundationdb" +fts = "foundationdb" +blob = "fs" +lookup = "foundationdb" +directory = "internal" + +[store."foundationdb"] +type = "foundationdb" +cluster = "/etc/foundationdb/fdb.cluster" + +[store."fs"] +type = "fs" +path = "/var/lib/stalwart/blobs" + +[directory."internal"] +type = "internal" +store = "foundationdb" +EOF + + chown stalwart:stalwart /opt/stalwart/etc/config.toml + chmod 600 /opt/stalwart/etc/config.toml +fi + +# Reload systemd +systemctl daemon-reload diff --git a/rpms/stalwart-foundationdb/resources/scripts/postremove.sh b/rpms/stalwart-foundationdb/resources/scripts/postremove.sh new file mode 100644 index 0000000..e8f023d --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/scripts/postremove.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Reload systemd after service file removal +systemctl daemon-reload + +# Note: We don't remove user data, logs, or configuration files +# to preserve user data in case of reinstallation \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/resources/scripts/preinstall.sh b/rpms/stalwart-foundationdb/resources/scripts/preinstall.sh new file mode 100644 index 0000000..58783f0 --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/scripts/preinstall.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Create stalwart user and group +if ! getent group stalwart >/dev/null; then + groupadd -r stalwart +fi + +if ! getent passwd stalwart >/dev/null; then + useradd -r -g stalwart -d /opt/stalwart -s /sbin/nologin -c "Stalwart Mail Server" stalwart +fi + +# Create required directories +mkdir -p /opt/stalwart/{bin,etc,data,logs} +mkdir -p /var/lib/stalwart +mkdir -p /var/log/stalwart + +# Set ownership +chown -R stalwart:stalwart /opt/stalwart +chown -R stalwart:stalwart /var/lib/stalwart +chown -R stalwart:stalwart /var/log/stalwart \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/resources/scripts/preremove.sh b/rpms/stalwart-foundationdb/resources/scripts/preremove.sh new file mode 100644 index 0000000..9c756ee --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/scripts/preremove.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Stop and disable the service if it's running +if systemctl is-enabled stalwart-foundationdb.service >/dev/null 2>&1; then + systemctl stop stalwart-foundationdb.service + systemctl disable stalwart-foundationdb.service +fi \ No newline at end of file diff --git a/rpms/stalwart-foundationdb/resources/stalwart-foundationdb.service b/rpms/stalwart-foundationdb/resources/stalwart-foundationdb.service new file mode 100644 index 0000000..db8c414 --- /dev/null +++ b/rpms/stalwart-foundationdb/resources/stalwart-foundationdb.service @@ -0,0 +1,26 @@ +[Unit] +Description=Stalwart Mail Server with FoundationDB +After=network.target foundationdb.service +Requires=foundationdb.service + +[Service] +Type=simple +User=stalwart +Group=stalwart +ExecStart=/opt/stalwart/bin/stalwart-foundationdb --config=/opt/stalwart/etc/config.toml +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=stalwart-foundationdb + +# Security settings +NoNewPrivileges=true +PrivateTmp=true +PrivateDevices=true +ProtectHome=true +ProtectSystem=strict +ReadWritePaths=/var/lib/stalwart /var/log/stalwart /opt/stalwart/data + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/rpms/stalwart/0.13.4/release b/rpms/stalwart/0.13.4/release new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/rpms/stalwart/0.13.4/release @@ -0,0 +1 @@ +1 diff --git a/rpms/stalwart/Dockerfile b/rpms/stalwart/Dockerfile new file mode 100644 index 0000000..539afe6 --- /dev/null +++ b/rpms/stalwart/Dockerfile @@ -0,0 +1,18 @@ +FROM git.unkin.net/unkin/almalinux9-rpmbuilder:latest + +# Create output directory for RPMs +RUN mkdir -p /app/dist + +# Set working directory +WORKDIR /app + +ARG PACKAGE_RELEASE +ENV PACKAGE_RELEASE=${PACKAGE_RELEASE} +ARG PACKAGE_VERSION +ENV PACKAGE_VERSION=${PACKAGE_VERSION} + +# Copy resources from the context into the container +COPY resources /app/resources + +# Default command to build RPMs +CMD /app/resources/build.sh \ No newline at end of file diff --git a/rpms/stalwart/metadata.yaml b/rpms/stalwart/metadata.yaml new file mode 100644 index 0000000..982a906 --- /dev/null +++ b/rpms/stalwart/metadata.yaml @@ -0,0 +1,9 @@ +name: stalwart +release: 1 +version: 0.13.4 +github: stalwartlabs/stalwart +build: +- distro: el/8 + image: git.unkin.net/unkin/almalinux8-rpmbuilder:latest +- distro: el/9 + image: git.unkin.net/unkin/almalinux9-rpmbuilder:latest \ No newline at end of file diff --git a/rpms/stalwart/resources/build.sh b/rpms/stalwart/resources/build.sh new file mode 100755 index 0000000..e13b029 --- /dev/null +++ b/rpms/stalwart/resources/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# Download the required files +curl -L -o /app/stalwart.tar.gz https://github.com/stalwartlabs/stalwart/releases/download/v${PACKAGE_VERSION}/stalwart-x86_64-unknown-linux-gnu.tar.gz + +# Extract the binary +tar -xzf /app/stalwart.tar.gz -C /app + +# Make the binary executable +chmod +x /app/stalwart + +# Build the RPM +nfpm pkg --config /app/resources/nfpm.yaml --target /app/dist --packager rpm \ No newline at end of file diff --git a/rpms/stalwart/resources/nfpm.yaml b/rpms/stalwart/resources/nfpm.yaml new file mode 100644 index 0000000..877ef5d --- /dev/null +++ b/rpms/stalwart/resources/nfpm.yaml @@ -0,0 +1,47 @@ +# nfpm.yaml + +name: stalwart +version: ${PACKAGE_VERSION} +release: ${PACKAGE_RELEASE} +arch: amd64 +platform: linux +section: default +priority: extra +description: "Stalwart Mail Server - A modern, secure JMAP, IMAP and SMTP mail server" + +maintainer: Stalwart Labs +homepage: https://stalw.art +license: AGPL-3.0 + +disable_globbing: false + +replaces: + - stalwart + +provides: + - stalwart + +conflicts: + - stalwart-foundationdb + +# Files to include in the package +contents: + - src: /app/stalwart + dst: /opt/stalwart/bin/stalwart + file_info: + mode: 0755 + owner: stalwart + group: stalwart + - src: /app/resources/stalwart.service + dst: /usr/lib/systemd/system/stalwart.service + file_info: + mode: 0644 + owner: root + group: root + +# Scripts to run during installation/removal +scripts: + preinstall: /app/resources/scripts/preinstall.sh + postinstall: /app/resources/scripts/postinstall.sh + preremove: /app/resources/scripts/preremove.sh + postremove: /app/resources/scripts/postremove.sh \ No newline at end of file diff --git a/rpms/stalwart/resources/scripts/postinstall.sh b/rpms/stalwart/resources/scripts/postinstall.sh new file mode 100644 index 0000000..bfd92ac --- /dev/null +++ b/rpms/stalwart/resources/scripts/postinstall.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Create default configuration if it doesn't exist +if [ ! -f /opt/stalwart/etc/config.toml ]; then + cat > /opt/stalwart/etc/config.toml << 'EOF' +# Stalwart Mail Server Configuration +# This is a minimal configuration file. Please customize according to your needs. +# Full documentation: https://stalw.art/docs/ + +[server] +hostname = "localhost" + +[server.listener.smtp] +bind = ["127.0.0.1:25"] +protocol = "smtp" + +[server.listener.submission] +bind = ["127.0.0.1:587"] +protocol = "smtp" + +[server.listener.imap] +bind = ["127.0.0.1:143"] +protocol = "imap" + +[server.listener.http] +bind = ["127.0.0.1:8080"] +protocol = "http" + +[storage] +data = "sqlite" +fts = "sqlite" +blob = "fs" +lookup = "sqlite" +directory = "internal" + +[store."sqlite"] +type = "sqlite" +path = "/var/lib/stalwart/stalwart.db" + +[store."fs"] +type = "fs" +path = "/var/lib/stalwart/blobs" + +[directory."internal"] +type = "internal" +store = "sqlite" +EOF + + chown stalwart:stalwart /opt/stalwart/etc/config.toml + chmod 600 /opt/stalwart/etc/config.toml +fi + +# Reload systemd +systemctl daemon-reload diff --git a/rpms/stalwart/resources/scripts/postremove.sh b/rpms/stalwart/resources/scripts/postremove.sh new file mode 100644 index 0000000..e8f023d --- /dev/null +++ b/rpms/stalwart/resources/scripts/postremove.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Reload systemd after service file removal +systemctl daemon-reload + +# Note: We don't remove user data, logs, or configuration files +# to preserve user data in case of reinstallation \ No newline at end of file diff --git a/rpms/stalwart/resources/scripts/preinstall.sh b/rpms/stalwart/resources/scripts/preinstall.sh new file mode 100644 index 0000000..58783f0 --- /dev/null +++ b/rpms/stalwart/resources/scripts/preinstall.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Create stalwart user and group +if ! getent group stalwart >/dev/null; then + groupadd -r stalwart +fi + +if ! getent passwd stalwart >/dev/null; then + useradd -r -g stalwart -d /opt/stalwart -s /sbin/nologin -c "Stalwart Mail Server" stalwart +fi + +# Create required directories +mkdir -p /opt/stalwart/{bin,etc,data,logs} +mkdir -p /var/lib/stalwart +mkdir -p /var/log/stalwart + +# Set ownership +chown -R stalwart:stalwart /opt/stalwart +chown -R stalwart:stalwart /var/lib/stalwart +chown -R stalwart:stalwart /var/log/stalwart \ No newline at end of file diff --git a/rpms/stalwart/resources/scripts/preremove.sh b/rpms/stalwart/resources/scripts/preremove.sh new file mode 100644 index 0000000..02a5017 --- /dev/null +++ b/rpms/stalwart/resources/scripts/preremove.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Stop and disable the service if it's running +if systemctl is-enabled stalwart.service >/dev/null 2>&1; then + systemctl stop stalwart.service + systemctl disable stalwart.service +fi \ No newline at end of file diff --git a/rpms/stalwart/resources/stalwart.service b/rpms/stalwart/resources/stalwart.service new file mode 100644 index 0000000..7aa9904 --- /dev/null +++ b/rpms/stalwart/resources/stalwart.service @@ -0,0 +1,25 @@ +[Unit] +Description=Stalwart Mail Server +After=network.target + +[Service] +Type=simple +User=stalwart +Group=stalwart +ExecStart=/opt/stalwart/bin/stalwart --config=/opt/stalwart/etc/config.toml +Restart=always +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=stalwart + +# Security settings +NoNewPrivileges=true +PrivateTmp=true +PrivateDevices=true +ProtectHome=true +ProtectSystem=strict +ReadWritePaths=/var/lib/stalwart /var/log/stalwart /opt/stalwart/data + +[Install] +WantedBy=multi-user.target \ No newline at end of file