From fe7c5c64b182557d885d3242e97ece8bb9c06b90 Mon Sep 17 00:00:00 2001 From: Stavros Charismiadis Date: Wed, 13 Mar 2024 11:58:33 +0200 Subject: [PATCH 1/3] Create script to remove temporary files and folders in project --- .gitignore | 1 + services/clean_capif_temporary_files.sh | 80 +++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 services/clean_capif_temporary_files.sh diff --git a/.gitignore b/.gitignore index 9a67eb9..66e4e33 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ monitoring/tempo/tempo-data/* docs/testing_with_postman/*node_modules* +docs/testing_with_postman/Responses docs/testing_with_postman/package-lock.json results diff --git a/services/clean_capif_temporary_files.sh b/services/clean_capif_temporary_files.sh new file mode 100755 index 0000000..d626273 --- /dev/null +++ b/services/clean_capif_temporary_files.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +help() { + echo "Usage: $1 " + echo " -c : Clean capif services tmp files" + echo " -m : Clean monitoring service tmp files" + echo " -t : Clean robot-test service tmp files" + echo " -d : Clean docs folder tmp files" + echo " -a : Clean all tmp files" + echo " -h : show this help" + exit 1 +} + +if [[ $# -lt 1 ]] +then + echo "You must specify an option before run script." + help +fi + +cd .. + +FILES=() +echo "${FILES[@]}" + +# Read params +while getopts "cmtdah" opt; do + case $opt in + c) + echo "Remove capif services temporary files" + FILES+=("services") + ;; + m) + echo "Remove monitoring service temporary files" + FILES+=("monitoring") + ;; + t) + echo "Remove robot-test service temporary files" + FILES+=("tests") + ;; + d) + echo "Remove docs folder temporary files" + FILES+=("docs") + ;; + a) + echo "Remove all temporary files" + FILES=("services" "monitoring" "tests" "docs") + ;; + h) + help + ;; + \?) + echo "Not valid option: -$OPTARG" >&2 + help + exit 1 + ;; + :) + echo "The -$OPTARG option requires an argument." >&2 + help + exit 1 + ;; + esac +done +echo "after check" +echo "${FILES[@]}" + +for FILE in "${FILES[@]}"; do + echo "Remove temporary files for $FILE" + sudo rm -r $(git ls-files . --ignored --exclude-standard --others --directory | grep "$FILE") + status=$? + echo $status + if [ $status -eq 0 ]; then + echo "*** Removed tmp files from $FILE ***" + else + echo "*** Some files from $FILE failed on removing ***" + fi +done + + +echo "Clean complete." +cd ./services \ No newline at end of file -- GitLab From 57f3c12494d6a48645b494c3d55c12fa22fe08eb Mon Sep 17 00:00:00 2001 From: Stavros Charismiadis Date: Wed, 13 Mar 2024 15:39:13 +0200 Subject: [PATCH 2/3] Some more fixes --- services/clean_capif_temporary_files.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/services/clean_capif_temporary_files.sh b/services/clean_capif_temporary_files.sh index d626273..747be29 100755 --- a/services/clean_capif_temporary_files.sh +++ b/services/clean_capif_temporary_files.sh @@ -17,7 +17,6 @@ then help fi -cd .. FILES=() echo "${FILES[@]}" @@ -65,16 +64,15 @@ echo "${FILES[@]}" for FILE in "${FILES[@]}"; do echo "Remove temporary files for $FILE" - sudo rm -r $(git ls-files . --ignored --exclude-standard --others --directory | grep "$FILE") + sudo rm -r $(git ls-files . --ignored --exclude-standard --others --directory | grep $FILE) status=$? - echo $status - if [ $status -eq 0 ]; then - echo "*** Removed tmp files from $FILE ***" - else - echo "*** Some files from $FILE failed on removing ***" - fi + if [ $status -eq 0 ]; then + echo "*** Removed tmp files from $FILE ***" + else + echo "*** Some files from $FILE failed on removing ***" + fi done -echo "Clean complete." +echo "Remove tmp files complete." cd ./services \ No newline at end of file -- GitLab From 1dba822499f58ba674145299d637435c7af93f78 Mon Sep 17 00:00:00 2001 From: Stavros-Anastasios Charismiadis Date: Thu, 14 Mar 2024 12:05:47 +0200 Subject: [PATCH 3/3] Check if tmp files exist to supress rm command errors --- services/clean_capif_temporary_files.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/services/clean_capif_temporary_files.sh b/services/clean_capif_temporary_files.sh index 747be29..4becd8b 100755 --- a/services/clean_capif_temporary_files.sh +++ b/services/clean_capif_temporary_files.sh @@ -62,14 +62,21 @@ done echo "after check" echo "${FILES[@]}" +cd .. + for FILE in "${FILES[@]}"; do echo "Remove temporary files for $FILE" - sudo rm -r $(git ls-files . --ignored --exclude-standard --others --directory | grep $FILE) - status=$? - if [ $status -eq 0 ]; then - echo "*** Removed tmp files from $FILE ***" + tmp_files=$(git ls-files . --ignored --exclude-standard --others --directory | grep $FILE) + if [[ $tmp_files ]]; then + sudo rm -r $tmp_files + status=$? + if [ $status -eq 0 ]; then + echo "*** Removed tmp files from $FILE ***" + else + echo "*** Some files from $FILE failed on removing ***" + fi else - echo "*** Some files from $FILE failed on removing ***" + echo "No files found" fi done -- GitLab