Commit fe7c5c64 authored by Stavros Charismiadis's avatar Stavros Charismiadis
Browse files

Create script to remove temporary files and folders in project

parent 5e5dc289
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ monitoring/tempo/tempo-data/*




docs/testing_with_postman/*node_modules*
docs/testing_with_postman/*node_modules*
docs/testing_with_postman/Responses
docs/testing_with_postman/package-lock.json
docs/testing_with_postman/package-lock.json


results
results
+80 −0
Original line number Original line Diff line number Diff line
#!/bin/bash

help() {
  echo "Usage: $1 <options>"
  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