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();