#!/bin/bash # validate-mosquitto.sh - Validate Mosquitto setup configuration # Run on Pi Zero 2 W to verify configuration before deployment set -e echo "=== Validating Mosquitto Configuration ===" # Check if configuration files exist echo "[CHECK 1/5] Verifying configuration files exist..." if [ -f /etc/mosquitto/conf.d/mosquitto.conf ]; then echo " ✓ mosquitto.conf exists" else echo " ✗ mosquitto.conf missing" exit 1 fi if [ -f /etc/mosquitto/acl/acl.conf ]; then echo " ✓ acl.conf exists" else echo " ✗ acl.conf missing" exit 1 fi # Check if mosquitto is installed echo "[CHECK 2/5] Verifying Mosquitto installation..." if command -v mosquitto &> /dev/null; then echo " ✓ mosquitto binary found" else echo " ✗ mosquitto binary not found" exit 1 fi # Validate configuration syntax echo "[CHECK 3/5] Validating configuration syntax..." if mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf -t; then echo " ✓ Configuration syntax is valid" else echo " ✗ Configuration has syntax errors" exit 1 fi # Check persistence directory echo "[CHECK 4/5] Verifying persistence directory..." if [ -d /var/lib/mosquitto/data ]; then echo " ✓ Persistence directory exists" else echo " ✗ Persistence directory missing" exit 1 fi # Check ACL file permissions echo "[CHECK 5/5] Verifying file permissions..." if [ -f /etc/mosquitto/passwd ]; then if [ "$(stat -c %a /etc/mosquitto/passwd)" = "600" ]; then echo " ✓ Password file has secure permissions (600)" else echo " ⚠ Password file permissions should be 600" fi else echo " ⚠ Password file not yet created (create with mosquitto_passwd)" fi echo "" echo "=== Validation Complete ===" echo "Configuration is ready for deployment to Pi Zero 2 W (10.60.1.101)" echo ""