#!/bin/bash
#
# hampton_deletion.sh
#
# Bill Barrett January 2020
#
# A script to delete superseded directories from Hampton University
# This script is run via ssh on the Hampton server

# The directory where the AIM CIPS data is archived
hampton_base_directory="/mnt/home/aim_cips/interim_archive/cips/data"

# The superseded version
superseded_version="ver_05.20/rev_04"

# PMC data occurs in the following two seasons
declare -a seasons=("north" "south")
# The superseded data will be in one or more of the
# following levels
declare -a data_levels=("level_2" "level_3")
# Start at the beginning of the mission (2007) and
# continue to the present
first_year=2007
current_year=`date "+%Y"`

# Cycle through the years, seasons, and levels
for (( year=$first_year; year<=$current_year; year++)); do
  for season in "${seasons[@]}"; do
    season_year=${season}_${year}
    for level in "${data_levels[@]}"; do
      base_directory="${hampton_base_directory}/${season_year}/${level}"
      # Is there a superseded directory?
      superseded_directory="${base_directory}/${superseded_version}"
      if [ -d "${superseded_directory}" ]; then
        echo "superseded directory: ${superseded_directory}"
        rm -rf "${superseded_directory}"
      fi
    done
  done
done
exit 0

