From 9d847657d1720133108e7397a17cfb04c585546c Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Wed, 20 Dec 2023 15:56:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20=E2=80=94=20Add=20a=20make=20tar?= =?UTF-8?q?get=20for=20Debian=20packaging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + DEBIAN/control | 9 ++++++++ DEBIAN/postinst | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ DEBIAN/postrm | 40 ++++++++++++++++++++++++++++++++++ DEBIAN/prerm | 6 ++++++ Makefile | 15 ++++++++++++- reaction.service | 12 +++++++++++ 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 DEBIAN/control create mode 100755 DEBIAN/postinst create mode 100755 DEBIAN/postrm create mode 100755 DEBIAN/prerm create mode 100644 reaction.service diff --git a/.gitignore b/.gitignore index d5699c3..1e5e397 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /reaction*.sock /result /wiki +*.deb diff --git a/DEBIAN/control b/DEBIAN/control new file mode 100644 index 0000000..84f3aa0 --- /dev/null +++ b/DEBIAN/control @@ -0,0 +1,9 @@ +Package: reaction +Version: LAST_TAG +Architecture: amd64 +Maintainer: ppom <> +Sections: utils +Package-Type: deb +Priority: Optional +Homepage: https://framagit.org/ppom/reaction +Description: A daemon that scans program outputs for repeated patterns, and takes action. diff --git a/DEBIAN/postinst b/DEBIAN/postinst new file mode 100755 index 0000000..100f225 --- /dev/null +++ b/DEBIAN/postinst @@ -0,0 +1,56 @@ +#! /bin/sh +# postinst script for reaction +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package +# + +case "$1" in + configure|abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + + +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # The following line should be removed in trixie or trixie+1 + deb-systemd-helper unmask 'reaction.service' >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled 'reaction.service'; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable 'reaction.service' >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state 'reaction.service' >/dev/null || true + fi +fi + + +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + fi +fi + + +exit 0 diff --git a/DEBIAN/postrm b/DEBIAN/postrm new file mode 100755 index 0000000..6319a3b --- /dev/null +++ b/DEBIAN/postrm @@ -0,0 +1,40 @@ +#! /bin/sh +# postrm script for reaction +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' overwrit>r> +# for details, see /usr/doc/packaging-manual/ + + +case "$1" in + purge|disappear) + # Remove configuration + rm -f /etc/reaction.yml + # Remove database + rm -f /var/lib/reaction/* + ;; + remove|upgrade|failed-upgrade|abort-install|abort-upgrade) + # nothing + ;; +esac + +if [ "$1" = remove ] && [ -d /run/systemd/system ] ; then + systemctl --system daemon-reload >/dev/null || true +fi + +if [ "$1" = "purge" ]; then + if [ -x "/usr/bin/deb-systemd-helper" ]; then + deb-systemd-helper purge 'reaction.service' >/dev/null || true + fi +fi diff --git a/DEBIAN/prerm b/DEBIAN/prerm new file mode 100755 index 0000000..7e9504c --- /dev/null +++ b/DEBIAN/prerm @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +if [ -z "${DPKG_ROOT:-}" ] && [ "$1" = remove ] && [ -d /run/systemd/system ] ; then + deb-systemd-invoke stop 'reaction.service' >/dev/null || true +fi diff --git a/Makefile b/Makefile index e063026..3c28f22 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,22 @@ all: reaction ip46tables clean: - rm -f reaction ip46tables + rm -f reaction ip46tables reaction.deb + ip46tables: ip46tables.d/ip46tables.c gcc -static ip46tables.d/ip46tables.c -o ip46tables reaction: app/* reaction.go go.mod go.sum CGO_ENABLED=0 go build -buildvcs=false . + +reaction.deb: reaction ip46tables + chmod +x reaction ip46tables + mkdir -p deb/reaction/usr/bin/ deb/reaction/usr/sbin/ deb/reaction/lib/systemd/system/ + cp reaction deb/reaction/usr/bin/ + cp ip46tables deb/reaction/usr/sbin/ + cp reaction.service deb/reaction/lib/systemd/system/ + cp -r DEBIAN/ deb/reaction/DEBIAN + sed -e "s/LAST_TAG/`git tag --sort=v:refname | tail -n1`/" -e "s/Version: v/Version: /" -i deb/reaction/DEBIAN/* + cd deb && dpkg-deb --root-owner-group --build reaction + mv deb/reaction.deb reaction.deb + rm -rf deb/ diff --git a/reaction.service b/reaction.service new file mode 100644 index 0000000..f4840ad --- /dev/null +++ b/reaction.service @@ -0,0 +1,12 @@ +[Unit] +Description=A daemon that scans program outputs for repeated patterns, and takes action. +Documentation=https://framagit.org/ppom/reaction-wiki + +[Service] +ExecStart=/usr/bin/reaction start -c /etc/reaction.yml +StateDirectory=reaction +RuntimeDirectory=reaction +WorkingDirectory=/var/lib/reaction + +[Install] +WantedBy=multi-user.target