diff --git a/.goreleaser.yml b/.goreleaser.yml index 993788b..6b55a29 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -45,7 +45,9 @@ nfpms: - rpm - archlinux bindir: /usr/bin - + scripts: + postinstall: build/postinstall.sh + postremove: build/postremove.sh release: gitea: owner: d3m0k1d diff --git a/build/postinstall.sh b/build/postinstall.sh index e69de29..3ace84a 100644 --- a/build/postinstall.sh +++ b/build/postinstall.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +if command -v systemctl >/dev/null 2>&1; then + # for systemd based systems + banforge init + cat > /etc/systemd/system/banforge.service << 'EOF' +[Unit] +Description=BanForge - IPS log based system +After=network-online.target +Wants=network-online.target +Documentation=https://github.com/d3m0k1d/BanForge + +[Service] +Type=simple +ExecStart=/usr/local/bin/banforge daemon +User=root +Group=root +Restart=always +StandardOutput=journal +StandardError=journal +SyslogIdentifier=banforge +TimeoutStopSec=90 +KillSignal=SIGTERM + +[Install] +WantedBy=multi-user.target +EOF + chmod 644 /etc/systemd/system/banforge.service + systemctl daemon-reload + systemctl enable banforge +fi + +if command -v rc-service >/dev/null 2>&1; then + # for openrc based systems + banforge init + cat > /etc/init.d/banforge << 'EOF' +#!/sbin/openrc-run + +description="BanForge - IPS log based system" +command="/usr/bin/banforge" +command_args="daemon" + +pidfile="/run/${RC_SVCNAME}.pid" +command_background="yes" + +depend() { + need net + after network +} + +start_post() { + einfo "BanForge is now running" +} + +stop_post() { + einfo "BanForge is now stopped" +} +EOF + chmod 755 /etc/init.d/banforge + rc-update add banforge +fi diff --git a/build/postremove.sh b/build/postremove.sh new file mode 100644 index 0000000..0ea1bcb --- /dev/null +++ b/build/postremove.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +if command -v systemctl >/dev/null 2>&1; then + # for systemd based systems + systemctl stop banforge 2>/dev/null || true + systemctl disable banforge 2>/dev/null || true + rm -f /etc/systemd/system/banforge.service + systemctl daemon-reload +fi + +if command -v rc-service >/dev/null 2>&1; then + # for openrc based systems + rc-service banforge stop 2>/dev/null || true + rc-update del banforge 2>/dev/null || true + rm -f /etc/init.d/banforge +fi + +rm -rf /etc/banforge/ +rm -rf /var/lib/banforge/ +rm -rf /var/log/banforge/