Create Debian package for beszel-agent (#497)

* Add Debian package to build

Signed-off-by: Daniel Lo Nigro <git@d.sb>

* Fix Lintian issues

Signed-off-by: Daniel Lo Nigro <git@d.sb>

* - Add prerm script to stop and disable service
- Add security/sandboxing options to systemd unit

Signed-off-by: Daniel Lo Nigro <git@d.sb>

---------

Signed-off-by: Daniel Lo Nigro <git@d.sb>
This commit is contained in:
Daniel Lo Nigro
2025-02-03 16:08:01 -08:00
committed by GitHub
parent 5a8e8c1512
commit e689f547ef
9 changed files with 172 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#!/bin/sh
set -e
[ "$1" = "configure" ] || exit 0
CONFIG_FILE=/etc/beszel-agent.conf
SERVICE=beszel-agent
SERVICE_USER=beszel
. /usr/share/debconf/confmodule
# This would normally be in the config control file, however this is currently
# broken in goreleaser. Temporarily do it here.
# https://github.com/goreleaser/goreleaser/issues/5487
db_version 2.0
db_input high beszel-agent/key || true
db_go
# Create group and user
if ! getent group "$SERVICE_USER" >/dev/null; then
echo "Creating $SERVICE_USER group"
addgroup --quiet --system "$SERVICE_USER"
fi
if ! getent passwd "$SERVICE_USER" >/dev/null; then
echo "Creating $SERVICE_USER user"
adduser --quiet --system "$SERVICE_USER" \
--ingroup "$SERVICE_USER" \
--no-create-home \
--home /nonexistent \
--gecos "System user for $SERVICE"
fi
# Create config file if it doesn't already exist
if [ ! -f "$CONFIG_FILE" ]; then
touch "$CONFIG_FILE"
chmod 0600 "$CONFIG_FILE"
chown "$SERVICE_USER":"$SERVICE_USER" "$CONFIG_FILE"
fi;
# Only add key to config if it's not already present
if ! grep -q "^KEY=" "$CONFIG_FILE"; then
db_get beszel-agent/key
echo "KEY=$RET" > "$CONFIG_FILE"
fi;
deb-systemd-helper enable "$SERVICE".service
systemctl daemon-reload
deb-systemd-invoke start "$SERVICE".service || echo "could not start $SERVICE.service!"