diff --git a/Makefile b/Makefile index a81c6a61b..e35d64e1f 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,9 @@ scaffold_module: read -p "addons Path[eg:addons, extra-addons, exercise]: " ModulePath; \ ${PYTHON} odoo-bin scaffold $$ModuleName && \ mv $$ModuleName ${PWD}/$$ModulePath; +cleanup_addons: + ${PWD}/setup/clean_up_addon.sh ${PWD}/exercise + ##### Docker Deployment ######### run_test_docker: sudo ${DOCKER_EXEC} ${CONTAINER_ID} odoo --test-tags :TestAccountMove.test_out_invoice_auto_post_monthly,TestAccountMove.test_included_tax --log-level=test --test-enable -d testdb-${TAG} --stop-after-init --config=/etc/odoo/${CONFIG} --xmlrpc-port=8071 && \ diff --git a/extra-addons b/extra-addons index 97630f9e8..fe85bbdc1 160000 --- a/extra-addons +++ b/extra-addons @@ -1 +1 @@ -Subproject commit 97630f9e8f3ba689ef0e2984cee440b89fa68e92 +Subproject commit fe85bbdc1376ddf54d14f6ff0adbe800101c562f diff --git a/protected.txt b/protected.txt new file mode 100644 index 000000000..d73c25008 --- /dev/null +++ b/protected.txt @@ -0,0 +1,9 @@ +odoo +odoo-bin +Makefile +*.tf +*.go +odoo/* +requirements.txt +Dockerfile +automation diff --git a/setup/clean_up_addon.sh b/setup/clean_up_addon.sh index 034e82044..8ac385db3 100755 --- a/setup/clean_up_addon.sh +++ b/setup/clean_up_addon.sh @@ -1,21 +1,51 @@ #!/bin/bash -# Check if a root folder is provided as an argument -if [ -z "$1" ]; then - echo "Usage: $0 " - echo "Please provide a root folder path." +# Check if at least one root folder is provided as an argument +if [ $# -eq 0 ]; then + echo "Usage: $0 [...]" + echo "Please provide at least one root folder path." exit 1 fi -# Assign the input root folder to a variable -ROOT_FOLDER="$1" - -# Check if the root folder exists and is a directory -if [ ! -d "$ROOT_FOLDER" ]; then - echo "Error: '$ROOT_FOLDER' is not a valid directory." +# Define the protected items list file +PROTECTED_LIST="protected.txt" +if [ ! -f "$PROTECTED_LIST" ]; then + echo "Error: '$PROTECTED_LIST' not found." + echo "Please create 'protected.txt' one directory up with a list of protected files/folders (one per line)." exit 1 fi +# Safeguard: Check if any file/folder matching patterns in protected.txt exists in a root folder +check_protected_items() { + local root_dir="$1" + while IFS= read -r pattern; do + # Skip empty lines + [ -z "$pattern" ] && continue + + # Handle wildcards by using find for pattern matching + if [[ "$pattern" == *"*"* ]]; then + # Convert pattern to a find-compatible search + if [[ "$pattern" == /* ]]; then + search_path="${root_dir}${pattern}" + else + search_path="${root_dir}/${pattern}" + fi + + # Use find to check if any files match the pattern + if find "$root_dir" -path "$search_path" 2>/dev/null | grep -q .; then + echo "Error: Protected pattern '$pattern' matches files in '$root_dir'. Aborting execution." + exit 1 + fi + else + # Exact match for non-wildcard entries + if [ -e "$root_dir/$pattern" ]; then + echo "Error: Protected item '$pattern' found in '$root_dir'. Aborting execution." + exit 1 + fi + fi + done < "$PROTECTED_LIST" +} + # Function to check and delete subfolders delete_non_manifest_folders() { local dir="$1" @@ -35,15 +65,37 @@ delete_non_manifest_folders() { done } -# Change to the root folder to handle relative paths cleanly -cd "$ROOT_FOLDER" || { - echo "Error: Could not change to directory '$ROOT_FOLDER'" - exit 1 -} +# Process each root folder provided as an argument +for ROOT_FOLDER in "$@"; do + # Check if the root folder exists and is a directory + if [ ! -d "$ROOT_FOLDER" ]; then + echo "Error: '$ROOT_FOLDER' is not a valid directory. Skipping." + continue + fi -# Call the function with the root folder -delete_non_manifest_folders "." + # Perform the safeguard check for this root folder + echo "Checking for protected items in '$ROOT_FOLDER' from '$PROTECTED_LIST'..." + check_protected_items "$ROOT_FOLDER" -echo "Cleanup complete!" + # Change to the root folder to handle relative paths cleanly + cd "$ROOT_FOLDER" || { + echo "Error: Could not change to directory '$ROOT_FOLDER'. Skipping." + continue + } + + # Call the function with the current root folder + echo "Processing '$ROOT_FOLDER'..." + delete_non_manifest_folders "." + + # Return to the original directory to process the next root folder + cd - > /dev/null || { + echo "Error: Could not return from '$ROOT_FOLDER'. Exiting." + exit 1 + } + + echo "Cleanup complete for '$ROOT_FOLDER'!" +done + +echo "All root folders processed!" exit 0 \ No newline at end of file