Files
location-mqtt-tracker-app/change-mqtt-admin-password.sh
Joachim Hummel 60e4199639 Fix MQTT password sync script
Remove automatic sync that required authentication. Users should either:
- Log into Admin Panel and click 'Sync MQTT Config'
- Or restart Mosquitto container to apply changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 08:09:33 +00:00

84 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Script to change MQTT Admin Password
# Usage: ./change-mqtt-admin-password.sh <new-password>
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if password argument is provided
if [ -z "$1" ]; then
echo -e "${RED}Error: No password provided${NC}"
echo "Usage: $0 <new-password>"
exit 1
fi
NEW_PASSWORD="$1"
# Validate password (minimum 8 characters recommended)
if [ ${#NEW_PASSWORD} -lt 8 ]; then
echo -e "${YELLOW}Warning: Password is shorter than 8 characters${NC}"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
echo -e "${GREEN}Starting MQTT Admin Password Change...${NC}"
echo
# Step 1: Update .env file
echo -e "${YELLOW}Step 1: Updating .env file...${NC}"
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found${NC}"
exit 1
fi
# Check if MQTT_ADMIN_PASSWORD exists in .env
if grep -q "^MQTT_ADMIN_PASSWORD=" .env; then
# Update existing password
sed -i "s/^MQTT_ADMIN_PASSWORD=.*/MQTT_ADMIN_PASSWORD=${NEW_PASSWORD}/" .env
echo -e "${GREEN}✓ Updated MQTT_ADMIN_PASSWORD in .env${NC}"
else
# Add password if it doesn't exist
echo "MQTT_ADMIN_PASSWORD=${NEW_PASSWORD}" >> .env
echo -e "${GREEN}✓ Added MQTT_ADMIN_PASSWORD to .env${NC}"
fi
echo
# Step 2: Restart containers
echo -e "${YELLOW}Step 2: Restarting containers...${NC}"
docker-compose restart
echo -e "${GREEN}✓ Containers restarted${NC}"
echo
# Step 3: Wait for app to be ready
echo -e "${YELLOW}Step 3: Waiting for app to be ready...${NC}"
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}"
echo
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}MQTT Admin Password Change Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo
echo -e "New password: ${YELLOW}${NEW_PASSWORD}${NC}"
echo
echo -e "${YELLOW}Note:${NC} All MQTT connections using the old admin password will need to reconnect."
echo