190 lines
5.9 KiB
Bash
Executable File
190 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
source /opt/rustbox-package-builder/scripts/lib.sh
|
|
SRC=${1:?source dir required}
|
|
PKG=${2:?package work dir required}
|
|
BINARY=${3:?binary path required}
|
|
VERSION=${4:?version required}
|
|
PACKAGE_RELEASE=${5:?release required}
|
|
rm -rf "$PKG"
|
|
mkdir -p "$PKG/payload/usr/local/bin" "$PKG/payload/usr/lib/systemd/system" "$PKG/payload/etc/rustbox" "$PKG/payload/etc/logrotate.d" "$PKG/scripts"
|
|
install -m 0755 "$BINARY" "$PKG/payload/usr/local/bin/rustbox"
|
|
install -m 0644 /opt/rustbox-package-builder/packaging/rustbox.service "$PKG/payload/usr/lib/systemd/system/rustbox.service"
|
|
install -m 0640 /opt/rustbox-package-builder/packaging/rustbox.toml "$PKG/payload/etc/rustbox/rustbox.toml"
|
|
install -m 0644 /opt/rustbox-package-builder/packaging/rustbox.logrotate "$PKG/payload/etc/logrotate.d/rustbox"
|
|
|
|
cat > "$PKG/scripts/deb-postinstall.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
getent group rustbox >/dev/null 2>&1 || addgroup --system rustbox >/dev/null
|
|
if ! id rustbox >/dev/null 2>&1; then
|
|
adduser --system --ingroup rustbox --home /var/lib/rustbox --no-create-home --shell /usr/sbin/nologin rustbox >/dev/null
|
|
fi
|
|
install -d -o rustbox -g rustbox -m 0750 /etc/rustbox /var/log/rustbox
|
|
install -d -o rustbox -g rustbox -m 0700 /var/lib/rustbox
|
|
chown rustbox:rustbox /etc/rustbox/rustbox.toml
|
|
chmod 0640 /etc/rustbox/rustbox.toml
|
|
RUSTBOX_CONFIG=/etc/rustbox/rustbox.toml /usr/local/bin/rustbox --check-config
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl daemon-reload || true
|
|
systemctl enable rustbox.service >/dev/null 2>&1 || true
|
|
if [ -d /run/systemd/system ]; then systemctl restart rustbox.service || systemctl start rustbox.service || true; fi
|
|
fi
|
|
SCRIPT
|
|
cat > "$PKG/scripts/deb-preremove.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ "${1:-}" = remove ] && command -v systemctl >/dev/null 2>&1; then
|
|
systemctl disable --now rustbox.service >/dev/null 2>&1 || true
|
|
fi
|
|
SCRIPT
|
|
cat > "$PKG/scripts/deb-postremove.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
command -v systemctl >/dev/null 2>&1 && systemctl daemon-reload >/dev/null 2>&1 || true
|
|
SCRIPT
|
|
cat > "$PKG/scripts/rpm-postinstall.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
getent group rustbox >/dev/null 2>&1 || groupadd --system rustbox
|
|
if ! id rustbox >/dev/null 2>&1; then
|
|
NOLOGIN=/usr/sbin/nologin
|
|
[ -x "$NOLOGIN" ] || NOLOGIN=/sbin/nologin
|
|
useradd --system --gid rustbox --home-dir /var/lib/rustbox --no-create-home --shell "$NOLOGIN" rustbox
|
|
fi
|
|
install -d -o rustbox -g rustbox -m 0750 /etc/rustbox /var/log/rustbox
|
|
install -d -o rustbox -g rustbox -m 0700 /var/lib/rustbox
|
|
chown rustbox:rustbox /etc/rustbox/rustbox.toml
|
|
chmod 0640 /etc/rustbox/rustbox.toml
|
|
RUSTBOX_CONFIG=/etc/rustbox/rustbox.toml /usr/local/bin/rustbox --check-config
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl daemon-reload || true
|
|
systemctl enable rustbox.service >/dev/null 2>&1 || true
|
|
if [ -d /run/systemd/system ]; then systemctl restart rustbox.service || systemctl start rustbox.service || true; fi
|
|
fi
|
|
SCRIPT
|
|
cat > "$PKG/scripts/rpm-preremove.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ "${1:-1}" -eq 0 ] 2>/dev/null && command -v systemctl >/dev/null 2>&1; then
|
|
systemctl disable --now rustbox.service >/dev/null 2>&1 || true
|
|
fi
|
|
SCRIPT
|
|
cat > "$PKG/scripts/rpm-postremove.sh" <<'SCRIPT'
|
|
#!/bin/sh
|
|
set -e
|
|
command -v systemctl >/dev/null 2>&1 && systemctl daemon-reload >/dev/null 2>&1 || true
|
|
SCRIPT
|
|
chmod 0755 "$PKG/scripts"/*.sh
|
|
|
|
CONTENTS="$PKG/contents.yaml"
|
|
cat > "$CONTENTS" <<YAML
|
|
- src: $(yaml_quote "$PKG/payload/usr/local/bin/rustbox")
|
|
dst: /usr/local/bin/rustbox
|
|
file_info:
|
|
mode: 0755
|
|
- src: $(yaml_quote "$PKG/payload/usr/lib/systemd/system/rustbox.service")
|
|
dst: /usr/lib/systemd/system/rustbox.service
|
|
file_info:
|
|
mode: 0644
|
|
- src: $(yaml_quote "$PKG/payload/etc/rustbox/rustbox.toml")
|
|
dst: /etc/rustbox/rustbox.toml
|
|
type: config|noreplace
|
|
file_info:
|
|
mode: 0640
|
|
- src: $(yaml_quote "$PKG/payload/etc/logrotate.d/rustbox")
|
|
dst: /etc/logrotate.d/rustbox
|
|
type: config|noreplace
|
|
file_info:
|
|
mode: 0644
|
|
YAML
|
|
|
|
cat > "$PKG/nfpm-deb.yaml" <<YAML
|
|
name: rustbox
|
|
arch: amd64
|
|
platform: linux
|
|
version: $(yaml_quote "$VERSION")
|
|
release: "$PACKAGE_RELEASE"
|
|
section: mail
|
|
priority: optional
|
|
maintainer: "RustBox"
|
|
description: "RustBox webmail server"
|
|
license: "UNKNOWN"
|
|
contents:
|
|
$(cat "$CONTENTS")
|
|
depends:
|
|
- adduser
|
|
- ca-certificates
|
|
- gnupg
|
|
- libssl3 | libssl3t64
|
|
- logrotate
|
|
- systemd
|
|
scripts:
|
|
postinstall: $(yaml_quote "$PKG/scripts/deb-postinstall.sh")
|
|
preremove: $(yaml_quote "$PKG/scripts/deb-preremove.sh")
|
|
postremove: $(yaml_quote "$PKG/scripts/deb-postremove.sh")
|
|
deb:
|
|
compression: xz
|
|
signature:
|
|
key_file: $(yaml_quote "$GPG_PRIVATE_KEY_FILE")
|
|
type: origin
|
|
YAML
|
|
cat > "$PKG/nfpm-rpm.yaml" <<YAML
|
|
name: rustbox
|
|
arch: amd64
|
|
platform: linux
|
|
version: $(yaml_quote "$VERSION")
|
|
release: "$PACKAGE_RELEASE"
|
|
section: mail
|
|
priority: optional
|
|
maintainer: "RustBox"
|
|
description: "RustBox webmail server"
|
|
license: "UNKNOWN"
|
|
contents:
|
|
$(cat "$CONTENTS")
|
|
depends:
|
|
- ca-certificates
|
|
- gnupg2
|
|
- openssl-libs
|
|
- logrotate
|
|
- shadow-utils
|
|
- systemd
|
|
scripts:
|
|
postinstall: $(yaml_quote "$PKG/scripts/rpm-postinstall.sh")
|
|
preremove: $(yaml_quote "$PKG/scripts/rpm-preremove.sh")
|
|
postremove: $(yaml_quote "$PKG/scripts/rpm-postremove.sh")
|
|
rpm:
|
|
compression: zstd
|
|
signature:
|
|
key_file: $(yaml_quote "$GPG_PRIVATE_KEY_FILE")
|
|
YAML
|
|
cat > "$PKG/nfpm-suse.yaml" <<YAML
|
|
name: rustbox
|
|
arch: amd64
|
|
platform: linux
|
|
version: $(yaml_quote "$VERSION")
|
|
release: "$PACKAGE_RELEASE"
|
|
section: mail
|
|
priority: optional
|
|
maintainer: "RustBox"
|
|
description: "RustBox webmail server"
|
|
license: "UNKNOWN"
|
|
contents:
|
|
$(cat "$CONTENTS")
|
|
depends:
|
|
- ca-certificates
|
|
- gpg2
|
|
- libopenssl3
|
|
- logrotate
|
|
- shadow
|
|
- systemd
|
|
scripts:
|
|
postinstall: $(yaml_quote "$PKG/scripts/rpm-postinstall.sh")
|
|
preremove: $(yaml_quote "$PKG/scripts/rpm-preremove.sh")
|
|
postremove: $(yaml_quote "$PKG/scripts/rpm-postremove.sh")
|
|
rpm:
|
|
compression: gzip
|
|
signature:
|
|
key_file: $(yaml_quote "$GPG_PRIVATE_KEY_FILE")
|
|
YAML
|