From d872f005af9f00dceabd1fb7c3204a4667e41991 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 17 Nov 2023 10:51:32 -0600 Subject: [PATCH] improved cleanup --- scripts/clear_data.sh | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/scripts/clear_data.sh b/scripts/clear_data.sh index 7799fab..c10752c 100755 --- a/scripts/clear_data.sh +++ b/scripts/clear_data.sh @@ -1,13 +1,35 @@ #!/bin/bash set -e +cleanup_except() { + local directory=$1 + local except_file=$2 + + # Check if the directory exists + if [[ ! -d "$directory" ]]; then + echo "Directory does not exist: $directory" + return 1 + fi + + # Loop over each file in the directory + for file in "$directory"/* + do + if [[ "$(basename "$file")" != "$except_file" ]]; then + # Delete the file + rm -rf "$file" + fi + done + + echo "Cleanup complete in $directory, except for $except_file" +} + SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) REPO_DIR=$(dirname $SCRIPT_DIR) +COMPOSE_FILE=$REPO_DIR/docker-compose.yml -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 +docker compose -f $COMPOSE_FILE down + +cleanup_except "$REPO_DIR/mosquitto/config" mosquitto.conf +cleanup_except "$REPO_DIR/mosquitto/data" .gitkeep +cleanup_except "$REPO_DIR/mosquitto/log" +cleanup_except "$REPO_DIR/zigbee2mqtt" configuration.yaml