First commit for wrapper script approach

pull/9/head
Jeremiah K 2023-09-06 11:49:00 -05:00
rodzic e47d3560c7
commit 9921a3a6f1
2 zmienionych plików z 95 dodań i 6 usunięć

Wyświetl plik

@ -0,0 +1,58 @@
import os
import yaml
# Read environment variables and construct the configuration dictionary
relay_config = {
"matrix": {
"homeserver": os.environ.get('MATRIX_HOMESERVER'),
"access_token": os.environ.get('MATRIX_ACCESS_TOKEN'),
"bot_user_id": os.environ.get('MATRIX_BOT_USER_ID')
},
"meshtastic": {
"connection_type": os.environ.get('MESHTASTIC_CONNECTION_TYPE'),
"serial_port": os.environ.get('MESHTASTIC_SERIAL_PORT'),
"host": os.environ.get('MESHTASTIC_HOST'),
"meshnet_name": os.environ.get('MESHTASTIC_MESHNET_NAME'),
"broadcast_enabled": os.environ.get('MESHTASTIC_BROADCAST_ENABLED') == 'true'
},
"logging": {
"level": os.environ.get('LOGGING_LEVEL')
}
}
# Construct the matrix_rooms list based on environment variables
matrix_rooms = []
for i in range(1, 9): # Loop for 8 rooms
room_id = os.environ.get(f'MATRIX_ROOMS_ID_{i}')
meshtastic_channel = os.environ.get(f'MATRIX_ROOMS_MESHTASTIC_CHANNEL_{i}')
if room_id and meshtastic_channel is not None:
matrix_rooms.append({
"id": room_id,
"meshtastic_channel": int(meshtastic_channel)
})
# Add the matrix_rooms list to the relay_config dictionary
relay_config["matrix_rooms"] = matrix_rooms
# Construct the plugins dictionary based on environment variables
plugins_config = {}
health_plugin_active = os.environ.get('HEALTH_PLUGIN_ACTIVE')
if health_plugin_active:
plugins_config["health"] = {"active": health_plugin_active.lower() == "true"}
map_plugin_active = os.environ.get('MAP_PLUGIN_ACTIVE')
if map_plugin_active:
plugins_config["map"] = {"active": map_plugin_active.lower() == "true"}
nodes_plugin_active = os.environ.get('NODES_PLUGIN_ACTIVE')
if nodes_plugin_active:
plugins_config["nodes"] = {"active": nodes_plugin_active.lower() == "true"}
# Add the plugins dictionary to the relay_config if it's not empty
if plugins_config:
relay_config["plugins"] = plugins_config
# Write the configuration to config.yaml
with open("config.yaml", "w") as f:
yaml.dump(relay_config, f)

Wyświetl plik

@ -1,4 +1,5 @@
version: "3"
version: '3.8'
services:
mmrelaynode:
build: node
@ -24,11 +25,41 @@ services:
- mesh:/home/mesh
networks:
- mesh
command: ["sleep 30"]
entrypoint: ["python3", "main.py"]
volumes:
mesh:
command: ["sh", "-c", "python3 config_wrapper.py && sleep 30 && python3 main.py"]
environment:
MATRIX_HOMESERVER: "https://example.matrix.org"
MATRIX_ACCESS_TOKEN: "your_access_token"
MATRIX_BOT_USER_ID: "@botuser:example.matrix.org"
MATRIX_ROOMS_ID_1: "#someroomalias1:example.matrix.org"
MATRIX_ROOMS_MESHTASTIC_CHANNEL_1: "0"
# MATRIX_ROOMS_ID_2: "#someroomalias2:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_2: "1"
# MATRIX_ROOMS_ID_3: "#someroomalias3:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_3: "2"
# MATRIX_ROOMS_ID_4: "#someroomalias4:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_4: "3"
# MATRIX_ROOMS_ID_5: "#someroomalias5:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_5: "4"
# MATRIX_ROOMS_ID_6: "#someroomalias6:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_6: "5"
# MATRIX_ROOMS_ID_7: "#someroomalias7:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_7: "6"
# MATRIX_ROOMS_ID_8: "#someroomalias8:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_8: "7"
MESHTASTIC_CONNECTION_TYPE: "serial" # "serial" or "network"
MESHTASTIC_SERIAL_PORT: "/dev/ttyUSB0"
MESHTASTIC_HOST: "meshtastic.local"
MESHTASTIC_MESHNET_NAME: "Your Meshnet Name"
MESHTASTIC_BROADCAST_ENABLED: "true"
LOGGING_LEVEL: "info"
# Plugin environment variables (commented out for reference)
# HEALTH_PLUGIN_ACTIVE: "true"
# MAP_PLUGIN_ACTIVE: "true"
# NODES_PLUGIN_ACTIVE: "true"
networks:
mesh:
driver: bridge
volumes:
mesh: