From 18b269a39d91feeea7329ac1df61df21a29c49f4 Mon Sep 17 00:00:00 2001 From: Hemna Date: Sun, 20 Dec 2020 17:16:15 -0500 Subject: [PATCH] Ensure fortune is installed This patch uses python3's shutil to find the path to fortune app, which can be very different depending on the host OS that aprsd is running on. --- ChangeLog | 2 ++ Dockerfile | 2 +- Dockerfile-dev | 3 +-- aprsd/plugin.py | 9 ++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9249a65..d100a41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ CHANGES v1.1.0 ------ +* Ensure fortune is installed +* Updated docker-compose * Added Changelog * Fixed issue when RX ack * Updated the aprsd-slack-plugin required version diff --git a/Dockerfile b/Dockerfile index 382d43f..db69a13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV HOME=/home/aprs ENV VIRTUAL_ENV=$HOME/.venv3 ENV INSTALL=$HOME/install -RUN apk add --update git wget py3-pip py3-virtualenv bash +RUN apk add --update git wget py3-pip py3-virtualenv bash fortune # Setup Timezone ENV TZ=US/Eastern diff --git a/Dockerfile-dev b/Dockerfile-dev index 9ea1682..217a0a6 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -10,7 +10,7 @@ ENV APRSD_BRANCH="master" ENV VIRTUAL_ENV=$HOME/.venv3 ENV INSTALL=$HOME/install -RUN apk add --update git vim wget py3-pip py3-virtualenv bash +RUN apk add --update git vim wget py3-pip py3-virtualenv bash fortune # Setup Timezone ENV TZ=US/Eastern @@ -19,7 +19,6 @@ ENV TZ=US/Eastern #RUN dpkg-reconfigure --frontend noninteractive tzdata RUN addgroup --gid 1001 $APRS_USER -RUN adduser --help RUN adduser -h $HOME -D -u 1001 -G $APRS_USER $APRS_USER ENV LC_ALL=C.UTF-8 diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 7c8c07e..47e491b 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -7,6 +7,7 @@ import json import logging import os import re +import shutil import subprocess import time @@ -246,9 +247,15 @@ class FortunePlugin(APRSDPluginBase): def command(self, fromcall, message, ack): LOG.info("FortunePlugin") reply = None + + fortune_path = shutil.which("fortune") + if not fortune_path: + reply = "Fortune command not installed" + return reply + try: process = subprocess.Popen( - ["/usr/games/fortune", "-s", "-n 60"], stdout=subprocess.PIPE + [fortune_path, "-s", "-n 60"], stdout=subprocess.PIPE ) reply = process.communicate()[0] reply = reply.decode(errors="ignore").rstrip()