From ee685ecb0aa5ee5406bd7367aafb13e555ea7412 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 29 Jan 2024 19:49:51 +0100 Subject: [PATCH] Implemented validate function to substitute trigger directory --- README.md | 2 +- cleanup.sh | 48 +++++++++++++++++++++++------------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9b09ef5..510d0eb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ For more detailed information about the script's workings, refer to the comments To use this script, clone this repository to your local system and run the script with the necessary arguments. The command should be structured as follows: ```bash -bash cleanup.sh BACKUP_HASH TRIGGER_DIRECTORY +bash cleanup.sh BACKUP_HASH ``` Replace ```BACKUP_HASH``` and ```TRIGGER_DIRECTORY``` with your actual values. diff --git a/cleanup.sh b/cleanup.sh index 6e580d3..c85bb93 100644 --- a/cleanup.sh +++ b/cleanup.sh @@ -12,36 +12,34 @@ else exit 1 fi -# Define trigger directory argument as TRIGGER_DIR -TRIGGER_DIR="$2" - # Loop through all subdirectories in the main directory for SUBDIR in "$MAIN_DIRECTORY"/*; do # Only proceed if it is a directory if [ -d "$SUBDIR" ]; then - echo "Validating directory: $SUBDIR" - # Only proceed if the specified trigger directory does not exist within the subdirectory - FULL_TRIGGER_DIR_PATH="$SUBDIR/$TRIGGER_DIR" - if [ ! -d "$FULL_TRIGGER_DIR_PATH" ]; then - echo "Validation: error" - echo "Missing directory: $FULL_TRIGGER_DIR_PATH" - # Display the subdirectory contents - echo "Contents of subdirectory: $SUBDIR" - ls "$SUBDIR" + echo "Validating directory: $SUBDIR" - # Ask for user confirmation before deletion - read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r - echo # move to a new line - if [[ $REPLY =~ ^[Yy]$ ]] - then - # Notify the user of the deletion, then delete the subdirectory - echo "Deleting subdirectory: $SUBDIR" - rm -vrf "$SUBDIR" - fi - else - echo "Validation: ok" - echo "$SUBDIR contains $FULL_TRIGGER_DIR_PATH." + # Call the Python script for validation + python ../directory-validator/directory-validator.py "$SUBDIR" --validate + VALIDATION_STATUS=$? + + if [ $VALIDATION_STATUS -eq 0 ]; then + echo "Validation: ok" + else + echo "Validation: error" + # Display the subdirectory contents + echo "Contents of subdirectory: $SUBDIR" + ls "$SUBDIR" + + # Ask for user confirmation before deletion + read -p "Are you sure you want to delete this subdirectory? (y/n) " -n 1 -r + echo # move to a new line + if [[ $REPLY =~ ^[Yy]$ ]] + then + # Notify the user of the deletion, then delete the subdirectory + echo "Deleting subdirectory: $SUBDIR" + rm -vrf "$SUBDIR" fi + fi fi -done +done \ No newline at end of file