From e36d92340e1bf74023c7fc316dadf97080cdeaa5 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:36:59 -0500 Subject: [PATCH] more robust first time install script, ensure it creates config_secrets --- first_time_install.sh | 37 +++++++++++++++++++++++++++++++++++++ ledmatrix-web.service | 1 + start_web_conditionally.py | 1 + templates/index_v2.html | 22 +++++++++++----------- web_interface_v2.py | 33 +++++++++++++++++++++++++-------- 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/first_time_install.sh b/first_time_install.sh index 99b36c30..90e1479c 100644 --- a/first_time_install.sh +++ b/first_time_install.sh @@ -233,6 +233,37 @@ else fi echo "" +CURRENT_STEP="Ensure secrets configuration exists" +echo "Step 3.1: Ensuring secrets configuration exists..." +echo "-----------------------------------------------" + +# Ensure config directory exists +mkdir -p "$PROJECT_ROOT_DIR/config" + +# Create config_secrets.json from template if missing +if [ ! -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then + if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.template.json" ]; then + echo "Creating config/config_secrets.json from template..." + cp "$PROJECT_ROOT_DIR/config/config_secrets.template.json" "$PROJECT_ROOT_DIR/config/config_secrets.json" + chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json" + echo "✓ Secrets file created from template" + else + echo "⚠ Template config/config_secrets.template.json not found; creating a minimal secrets file" + cat > "$PROJECT_ROOT_DIR/config/config_secrets.json" <<'EOF' +{ + "weather": { + "api_key": "YOUR_OPENWEATHERMAP_API_KEY" + } +} +EOF + chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json" + echo "✓ Minimal secrets file created" + fi +else + echo "Secrets file already exists; leaving as-is" +fi +echo "" + CURRENT_STEP="Install project Python dependencies" echo "Step 4: Installing Python project dependencies..." echo "-----------------------------------------------" @@ -413,6 +444,12 @@ if [ -f "$PROJECT_ROOT_DIR/config/config.json" ]; then echo "✓ Config file permissions set" fi +# Set proper permissions for secrets file (restrictive) +if [ -f "$PROJECT_ROOT_DIR/config/config_secrets.json" ]; then + chmod 600 "$PROJECT_ROOT_DIR/config/config_secrets.json" + echo "✓ Secrets file permissions set" +fi + echo "✓ File ownership configured" echo "" diff --git a/ledmatrix-web.service b/ledmatrix-web.service index 12d37573..11b0ad91 100644 --- a/ledmatrix-web.service +++ b/ledmatrix-web.service @@ -7,6 +7,7 @@ Wants=ledmatrix.service Type=simple User=root WorkingDirectory=/home/ledpi/LEDMatrix +Environment=USE_THREADING=1 ExecStart=/usr/bin/python3 /home/ledpi/LEDMatrix/start_web_conditionally.py Restart=on-failure RestartSec=10 diff --git a/start_web_conditionally.py b/start_web_conditionally.py index bdd14710..3de5b0c1 100644 --- a/start_web_conditionally.py +++ b/start_web_conditionally.py @@ -58,6 +58,7 @@ def main(): # This is important for systemd to correctly manage the web server process. # Ensure PYTHONPATH is set correctly if web_interface.py has relative imports to src # The WorkingDirectory in systemd service should handle this for web_interface.py + print(f"Launching web interface: {sys.executable} {WEB_INTERFACE_SCRIPT} (USE_THREADING={os.getenv('USE_THREADING','0')}, FORCE_THREADING={os.getenv('FORCE_THREADING','0')})") os.execvp(sys.executable, [sys.executable, WEB_INTERFACE_SCRIPT]) except Exception as e: print(f"Failed to exec web interface: {e}") diff --git a/templates/index_v2.html b/templates/index_v2.html index 5b8ef708..60276621 100644 --- a/templates/index_v2.html +++ b/templates/index_v2.html @@ -692,17 +692,17 @@ Service {{ 'Active' if system_status.service_active else 'Inactive' }} -