improved cleanup
This commit is contained in:
@@ -1,13 +1,35 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
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]}"))
|
SCRIPT_DIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
|
||||||
REPO_DIR=$(dirname $SCRIPT_DIR)
|
REPO_DIR=$(dirname $SCRIPT_DIR)
|
||||||
|
COMPOSE_FILE=$REPO_DIR/docker-compose.yml
|
||||||
|
|
||||||
rm -rf \
|
docker compose -f $COMPOSE_FILE down
|
||||||
$REPO_DIR/mosquitto/config/pwfile \
|
|
||||||
$REPO_DIR/mosquitto/data/mosquitto.db \
|
cleanup_except "$REPO_DIR/mosquitto/config" mosquitto.conf
|
||||||
$REPO_DIR/zigbee2mqtt/secret.yaml \
|
cleanup_except "$REPO_DIR/mosquitto/data" .gitkeep
|
||||||
$REPO_DIR/zigbee2mqtt/*.json \
|
cleanup_except "$REPO_DIR/mosquitto/log"
|
||||||
$REPO_DIR/zigbee2mqtt/log/* \
|
cleanup_except "$REPO_DIR/zigbee2mqtt" configuration.yaml
|
||||||
$REPO_DIR/zigbee2mqtt/database.db \
|
|
||||||
|
|||||||
Reference in New Issue
Block a user