1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-09-14 04:37:50 -04:00

Look in multiple places for fortune bin

Update the fortune plugin to look in multiple places for the
fortune binary.  It lives in different places for debian vs alpine.
This commit is contained in:
Hemna 2025-01-25 12:32:15 -05:00
parent c1319c3ab8
commit 97ffffc10d

View File

@ -5,32 +5,38 @@ import subprocess
from aprsd import packets, plugin from aprsd import packets, plugin
from aprsd.utils import trace from aprsd.utils import trace
LOG = logging.getLogger('APRSD')
LOG = logging.getLogger("APRSD") FORTUNE_PATHS = [
'/usr/games/fortune',
DEFAULT_FORTUNE_PATH = "/usr/games/fortune" '/usr/local/bin/fortune',
'/usr/bin/fortune',
]
class FortunePlugin(plugin.APRSDRegexCommandPluginBase): class FortunePlugin(plugin.APRSDRegexCommandPluginBase):
"""Fortune.""" """Fortune."""
command_regex = r"^([f]|[f]\s|fortune)" command_regex = r'^([f]|[f]\s|fortune)'
command_name = "fortune" command_name = 'fortune'
short_description = "Give me a fortune" short_description = 'Give me a fortune'
fortune_path = None fortune_path = None
def setup(self): def setup(self):
self.fortune_path = shutil.which(DEFAULT_FORTUNE_PATH) for path in FORTUNE_PATHS:
LOG.info(f"Fortune path {self.fortune_path}") if shutil.which(path):
self.fortune_path = path
break
if not self.fortune_path: if not self.fortune_path:
self.enabled = False self.enabled = False
else: else:
self.enabled = True self.enabled = True
LOG.info(f'Fortune path {self.fortune_path}')
@trace.trace @trace.trace
def process(self, packet: packets.MessagePacket): def process(self, packet: packets.MessagePacket):
LOG.info("FortunePlugin") LOG.info('FortunePlugin')
# fromcall = packet.get("from") # fromcall = packet.get("from")
# message = packet.get("message_text", None) # message = packet.get("message_text", None)
@ -39,8 +45,8 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase):
reply = None reply = None
try: try:
cmnd = [self.fortune_path, "-s", "-n 60"] cmnd = [self.fortune_path, '-s', '-n 60']
command = " ".join(cmnd) command = ' '.join(cmnd)
output = subprocess.check_output( output = subprocess.check_output(
command, command,
shell=True, shell=True,
@ -48,10 +54,10 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase):
text=True, text=True,
) )
output = ( output = (
output.replace("\r", "") output.replace('\r', '')
.replace("\n", "") .replace('\n', '')
.replace(" ", "") .replace(' ', '')
.replace("\t", " ") .replace('\t', ' ')
) )
except subprocess.CalledProcessError as ex: except subprocess.CalledProcessError as ex:
reply = f"Fortune command failed '{ex.output}'" reply = f"Fortune command failed '{ex.output}'"