Fix MQTT password sync to actually update password.txt

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-12-01 08:19:25 +00:00
parent c9ce56cbbe
commit b95866f549
2 changed files with 69 additions and 5 deletions

View File

@@ -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}"

View File

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