diff --git a/README.md b/README.md index 742f481..7599ff3 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,11 @@ Zigbee smarthome stack -## Mosquitto ([eclipse-mosquitto](https://hub.docker.com/_/eclipse-mosquitto)) - -Start the MQTT broker and create the password for `homeassistant` - -```shell -docker compose run -it --rm mqtt mosquitto_passwd -c /mosquitto/config/pwfile homeassistant +``` +./scripts/setup.sh ``` -### +## Mosquitto ([eclipse-mosquitto](https://hub.docker.com/_/eclipse-mosquitto)) ## Zigbee2MQTT (koenkk/[zigbee2mqtt](https://hub.docker.com/r/koenkk/zigbee2mqtt/)) -Put the password in `./zigbee2mqtt/secret.yaml` - -``` -echo "password: " > ./zigbee2mqtt/secret.yaml -``` diff --git a/clear_data.sh b/clear_data.sh deleted file mode 100755 index 2fb9279..0000000 --- a/clear_data.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) - -rm -rf $SCRIPT_DIR/mosquitto/data/mosquitto.db $SCRIPT_DIR/zigbee2mqtt/log/* $SCRIPT_DIR/zigbee2mqtt/database.db $SCRIPT_DIR/zigbee2mqtt/*.json \ No newline at end of file diff --git a/scripts/clear_data.sh b/scripts/clear_data.sh new file mode 100755 index 0000000..7799fab --- /dev/null +++ b/scripts/clear_data.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) +REPO_DIR=$(dirname $SCRIPT_DIR) + +rm -rf \ + $REPO_DIR/mosquitto/config/pwfile \ + $REPO_DIR/mosquitto/data/mosquitto.db \ + $REPO_DIR/zigbee2mqtt/secret.yaml \ + $REPO_DIR/zigbee2mqtt/*.json \ + $REPO_DIR/zigbee2mqtt/log/* \ + $REPO_DIR/zigbee2mqtt/database.db \ \ No newline at end of file diff --git a/scripts/create_password.sh b/scripts/create_password.sh new file mode 100755 index 0000000..6dce3d2 --- /dev/null +++ b/scripts/create_password.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) +REPO_DIR=$(dirname $SCRIPT_DIR) +COMPOSE_FILE=$REPO_DIR/docker-compose.yml +ENV_FILE=$REPO_DIR/.env + +if [ ! -f "$ENV_FILE" ]; then + echo "Error: .env file not found." + exit 1 +else + source "$ENV_FILE" +fi + +if [ -z "$MOSQUITTO_PASSWORD" ]; then + echo "MOSQUITTO_PASSWORD is not set. Exiting." + exit 1 +fi + +docker compose -f $COMPOSE_FILE run -it --rm mqtt mosquitto_passwd -b -c /mosquitto/config/pwfile homeassistant $MOSQUITTO_PASSWORD + +echo "password: $MOSQUITTO_PASSWORD" > $REPO_DIR/zigbee2mqtt/secret.yaml \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 0000000..fe5b947 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) + +$SCRIPT_DIR/clear_data.sh +$SCRIPT_DIR/create_password.sh \ No newline at end of file