#!/bin/bash

if [ $# -eq 0 ]; then
  echo "[ERROR] Please select an action: close or delete"
  exit 1
fi

action="$1"

if [ "$action" != "close" ] && [ "$action" != "delete" ]; then
  echo "[ERROR] Incorrect action must be: close or delete"
  exit 1
fi

for file in $(ls /vitam/conf/curator/curator.d/${action}_index_*.yml); do
  if [ -f "$file" ]; then
    /vitam/bin/curator/run_curator --config /vitam/conf/curator/curator.yml $file
  fi
done
