From 808a5d22e6fd2e3de6d78ecc295671a8e4202129 Mon Sep 17 00:00:00 2001 From: Greg Albrecht Date: Tue, 18 Jun 2024 23:28:49 -0700 Subject: [PATCH] updates --- debian/DEBIAN/postinst | 59 ++++++++++++++++++++++++++++++-- debian/DEBIAN/prerm | 2 ++ debian/etc/AryaOS/adsbxfeed.conf | 3 +- debian/usr/bin/adsbxfeed.sh | 11 ++---- 4 files changed, 62 insertions(+), 13 deletions(-) diff --git a/debian/DEBIAN/postinst b/debian/DEBIAN/postinst index aad1b0c..b4ccc70 100755 --- a/debian/DEBIAN/postinst +++ b/debian/DEBIAN/postinst @@ -2,12 +2,65 @@ echo "adsbxfeed postinst" -UUID_FILE="/etc/AryaOS/UUID.txt" +# shellcheck source=SCRIPTDIR/../etc/AryaOS/adsbxfeed.conf +[ -f "/etc/Aryaos/adsbxfeed.conf" ] && . /etc/Aryaos/adsbxfeed.conf -if [ ! -f $UUID_FILE ]; then +[ -z "$UUID_FILE" ] && UUID_FILE="/etc/AryaOS/UUID.txt" + +if [ ! -f "$UUID_FILE" ]; then mkdir -p /etc/AryaOS echo "$UUID_FILE doesn't exist, initializing." - uuidgen > $UUID_FILE + uuidgen > "$UUID_FILE" +fi + +# Sane defaults: + +[ -z "$SERVER_HOME" ] && SERVER_HOME=/run/adsbxfeed +[ -z "$SERVER_USER" ] && SERVER_USER=adsbxfeed +[ -z "$SERVER_NAME" ] && SERVER_NAME="ADSBExchange.com ADS-B Feed System User" +[ -z "$SERVER_GROUP" ] && SERVER_GROUP=adsbxfeed + +# Groups that the user will be added to, if undefined, then none. +ADDGROUP="" + +# create user to avoid running server as root +# 1. create group if not existing +if ! getent group | grep -q "^$SERVER_GROUP:" ; then + echo -n "Adding group $SERVER_GROUP.." + addgroup --quiet --system "$SERVER_GROUP" 2>/dev/null ||true + echo "..done" +fi +# 2. create homedir if not existing +test -d "$SERVER_HOME" || mkdir "$SERVER_HOME" +# 3. create user if not existing +if ! getent passwd | grep -q "^$SERVER_USER:"; then + echo -n "Adding system user $SERVER_USER.." + adduser --quiet \ + --system \ + --ingroup "$SERVER_GROUP" \ + --no-create-home \ + --disabled-password \ + "$SERVER_USER" 2>/dev/null || true + echo "..done" +fi +# 4. adjust passwd entry +usermod -c "$SERVER_NAME" \ + -d "$SERVER_HOME" \ + -g "$SERVER_GROUP" \ + "$SERVER_USER" +# 5. adjust file and directory permissions +if ! dpkg-statoverride --list "$SERVER_HOME" >/dev/null +then + chown -R "$SERVER_USER":adm "$SERVER_HOME" + chmod u=rwx,g=rxs,o= "$SERVER_HOME" +fi +# 6. Add the user to the ADDGROUP group +if test -n "$ADDGROUP" +then + if ! groups "$SERVER_USER" | cut -d: -f2 | \ + grep -qw "$ADDGROUP"; then + adduser "$SERVER_USER" "$ADDGROUP" + fi fi systemctl enable adsbxfeed diff --git a/debian/DEBIAN/prerm b/debian/DEBIAN/prerm index b4df07c..fa34e0a 100755 --- a/debian/DEBIAN/prerm +++ b/debian/DEBIAN/prerm @@ -5,4 +5,6 @@ echo "adsbxfeed prerm" systemctl disable adsbxfeed systemctl stop adsbxfeed +deluser --system adsbxfeed + exit 0 \ No newline at end of file diff --git a/debian/etc/AryaOS/adsbxfeed.conf b/debian/etc/AryaOS/adsbxfeed.conf index 9b28d72..537300d 100644 --- a/debian/etc/AryaOS/adsbxfeed.conf +++ b/debian/etc/AryaOS/adsbxfeed.conf @@ -15,8 +15,9 @@ # limitations under the License. # -RUN_DIR="/run/adsbxfeed" +ENABLE=1 UUID_FILE="/etc/AryaOS/UUID.txt" +RUN_DIR="/run/adsbxfeed" INPUT="127.0.0.1:30005" REDUCE_INTERVAL="0.5" diff --git a/debian/usr/bin/adsbxfeed.sh b/debian/usr/bin/adsbxfeed.sh index 8f5594d..a853eef 100755 --- a/debian/usr/bin/adsbxfeed.sh +++ b/debian/usr/bin/adsbxfeed.sh @@ -16,15 +16,8 @@ # limitations under the License. # -CONF_FILE="/etc/AryaOS/adsbxfeed.conf" - -if [ -f $CONF_FILE ]; then - # shellcheck source=SCRIPTDIR/../../etc/AryaOS/adsbxfeed.conf - . $CONF_FILE -else - echo "$CONF_FILE doesn't exist, exiting." - exit 1 -fi +# shellcheck source=SCRIPTDIR/../..//etc/AryaOS/adsbxfeed.conf +[ -f "/etc/Aryaos/adsbxfeed.conf" ] && . /etc/Aryaos/adsbxfeed.conf if ! [[ -d $RUN_DIR ]]; then mkdir -p "$RUN_DIR"