From b95866f549406f07d2b3328fb4bbf5ea11f202e4 Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Mon, 1 Dec 2025 08:19:25 +0000 Subject: [PATCH] Fix MQTT password sync to actually update password.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add scripts/sync-mqtt-config.ts for standalone sync execution - Update change-mqtt-admin-password.sh to use tsx to execute sync - Now properly regenerates password.txt with new hashed password - Mosquitto config is automatically reloaded after sync 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- change-mqtt-admin-password.sh | 47 +++++++++++++++++++++++++++++++---- scripts/sync-mqtt-config.ts | 27 ++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 scripts/sync-mqtt-config.ts diff --git a/change-mqtt-admin-password.sh b/change-mqtt-admin-password.sh index 3b66340..03455d7 100755 --- a/change-mqtt-admin-password.sh +++ b/change-mqtt-admin-password.sh @@ -66,11 +66,48 @@ sleep 5 echo -e "${GREEN}✓ App should be ready${NC}" echo -# Step 4: Manual sync instruction (automatic sync removed due to authentication requirement) -echo -e "${YELLOW}Step 4: MQTT configuration sync${NC}" -echo -e "${YELLOW}Note: Automatic sync requires admin authentication.${NC}" -echo -e "${YELLOW}Please log into the Admin Panel and click 'Sync MQTT Config' to apply the new password.${NC}" -echo -e "${YELLOW}Alternatively, restart Mosquitto: docker compose restart mosquitto${NC}" +# Step 4: Trigger MQTT configuration sync +echo -e "${YELLOW}Step 4: Triggering MQTT configuration sync...${NC}" + +# Create a temporary TypeScript script that calls syncMosquittoConfig +cat > /tmp/sync-mqtt.ts << 'EOF' +import { syncMosquittoConfig } from './lib/mosquitto-sync'; + +async function main() { + try { + console.log('Starting MQTT configuration sync...'); + const result = await syncMosquittoConfig(); + + if (result.success) { + console.log('✓ Success:', result.message); + process.exit(0); + } else { + console.error('✗ Failed:', result.message); + process.exit(1); + } + } catch (error) { + console.error('✗ Error:', error instanceof Error ? error.message : String(error)); + process.exit(1); + } +} + +main(); +EOF + +# Copy script to container +docker cp /tmp/sync-mqtt.ts location-tracker:/app/sync-mqtt.ts + +# Execute with tsx (suppressing npm warnings) +if docker exec location-tracker npx --yes tsx /app/sync-mqtt.ts 2>&1 | grep -v "npm warn"; then + echo -e "${GREEN}✓ MQTT configuration synced successfully${NC}" +else + echo -e "${RED}✗ Sync failed, but password is updated in .env${NC}" + echo -e "${YELLOW}You can manually trigger sync from the Admin Panel or restart Mosquitto${NC}" +fi + +# Cleanup +docker exec location-tracker rm -f /app/sync-mqtt.ts +rm -f /tmp/sync-mqtt.ts echo echo -e "${GREEN}========================================${NC}" diff --git a/scripts/sync-mqtt-config.ts b/scripts/sync-mqtt-config.ts new file mode 100644 index 0000000..01c6beb --- /dev/null +++ b/scripts/sync-mqtt-config.ts @@ -0,0 +1,27 @@ +#!/usr/bin/env node +/** + * Standalone script to sync MQTT configuration + * This can be run directly without authentication + */ + +import { syncMosquittoConfig } from '../lib/mosquitto-sync'; + +async function main() { + try { + console.log('Starting MQTT configuration sync...'); + const result = await syncMosquittoConfig(); + + if (result.success) { + console.log('✓ Success:', result.message); + process.exit(0); + } else { + console.error('✗ Failed:', result.message); + process.exit(1); + } + } catch (error) { + console.error('✗ Error:', error instanceof Error ? error.message : String(error)); + process.exit(1); + } +} + +main();