scriptingEnhancment

This commit is contained in:
SpudGunMan
2024-12-23 12:08:28 -08:00
parent 7a9ee27336
commit 21804cc975
6 changed files with 45 additions and 11 deletions
+1
View File
@@ -188,6 +188,7 @@ enable_read_news = False
news_file_path = news.txt
# only return a single random line from the news file
news_random_line = False
enable_runShellCmd = False
[smtp]
# enable or disable the SMTP module
+11 -3
View File
@@ -769,7 +769,11 @@ def sysinfo(message, message_from_id, deviceID):
if "?" in message:
return "sysinfo command returns system information."
else:
return get_sysinfo(message_from_id, deviceID)
if enable_runShellCmd and file_monitor_enabled:
shellData = call_external_script(message)
return get_sysinfo(message_from_id, deviceID) + "\n" + shellData
else:
return get_sysinfo(message_from_id, deviceID)
def handle_lheard(message, nodeid, deviceID, isDM):
if "?" in message and isDM:
@@ -1275,8 +1279,12 @@ async def start_rx():
logger.debug(f"System: Radio Detection Enabled using rigctld at {rigControlServerAddress} brodcasting to channels: {sigWatchBroadcastCh} for {get_freq_common_name(get_hamlib('f'))}")
if file_monitor_enabled:
logger.debug(f"System: File Monitor Enabled for {file_monitor_file_path}, broadcasting to channels: {file_monitor_broadcastCh}")
if read_news_enabled:
logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}")
if enable_runShellCmd:
logger.debug(f"System: Shell Command monitor enabled")
if read_news_enabled:
logger.debug(f"System: File Monitor News Reader Enabled for {news_file_path}")
if bee_enabled:
logger.debug(f"System: File Monitor Bee Monitor Enabled for bee.txt")
if wxAlertBroadcastEnabled:
logger.debug(f"System: Weather Alert Broadcast Enabled on channels {wxAlertBroadcastChannel}")
if emergencyAlertBrodcastEnabled:
+10 -4
View File
@@ -63,12 +63,18 @@ async def watch_file():
return content
await asyncio.sleep(1) # Check every
def call_external_script(message):
# Call an external script runShell.sh
def call_external_script(message, script="runShell.sh"):
try:
output = os.popen(f"bash runShell.sh {message}").read()
# Debugging: Print the current working directory and resolved script path
current_working_directory = os.getcwd()
script_path = os.path.join(current_working_directory, script)
if not os.path.exists(script_path):
logger.warning(f"FileMon: Script not found: {script_path}")
return "sorry I can't do that"
output = os.popen(f"bash {script_path} {message}").read()
return output
except Exception as e:
logger.warning(f"FileMon: Error calling external script")
logger.warning(f"FileMon: Error calling external script: {e}")
return None
+1
View File
@@ -222,6 +222,7 @@ try:
read_news_enabled = config['fileMon'].getboolean('enable_read_news', False) # default disabled
news_file_path = config['fileMon'].get('news_file_path', 'news.txt') # default news.txt
news_random_line_only = config['fileMon'].getboolean('news_random_line', False) # default False
enable_runShellCmd = config['fileMon'].getboolean('enable_runShellCmd', False) # default False
# games
game_hop_limit = config['messagingSettings'].getint('game_hop_limit', 5) # default 3 hops
+3 -4
View File
@@ -100,10 +100,6 @@ if dad_jokes_enabled:
from modules.games.joke import * # from the spudgunman/meshing-around repo
trap_list = trap_list + ("joke",)
help_message = help_message + ", joke"
# Bee Configuration
if bee_enabled:
trap_list = trap_list + ("🐝",)
# Wikipedia Search Configuration
if wikipedia_enabled:
@@ -199,6 +195,9 @@ if file_monitor_enabled or read_news_enabled:
if read_news_enabled:
trap_list = trap_list + trap_list_filemon # items readnews
help_message = help_message + ", readnews"
# Bee Configuration uses file monitor module
if bee_enabled:
trap_list = trap_list + ("🐝",)
# clean up the help message
help_message = help_message.split(", ")
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
# meshing-around demo script for shell scripting
# runShell.sh
cd "$(dirname "$0")"
program_path=$(pwd)
# get basic telemetry data. Free space, CPU, RAM, and temperature for a raspberry pi
free_space=$(df -h | grep ' /$' | awk '{print $4}')
cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
ram_usage=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
temp=$(vcgencmd measure_temp | sed "s/temp=//" | sed "s/'C//")
# temp in fahrenheit
tempf=$(echo "scale=2; $temp * 9 / 5 + 32" | bc)
# print telemetry data
printf "Free Space: %s\n" "$free_space"
printf "CPU Usage: %.1f%%\n" "$cpu_usage"
printf "RAM Usage: %.2f%%\n" "$ram_usage"
printf "Temperature: %.1f°C (%.1f°F)\n" "$temp" "$tempf"