#!/bin/bash
#
# Simple script to copy status from the devel release to the passed
# release e.g. 'scripts/release-cycle-released impish'
#
# FIXME: it would be good to fix this script to not add a second entry
#        if the passed release already exists.
# FIXME: does this need to be updated to account for the subprojects
#        tree as well?
#

set -e

REL="$1"
if [ -z "$REL" ]; then
    echo "Which release just released?" >&2
    exit 1
fi

if ! [ -d active/ ]; then
    echo "Where is the active/ directory?" >&2
    exit 2
fi

for f in active/{00boilerplate,CVE-}*; do
  # ignore symlinks so we don't replace twice in the same underlying file
  if [ ! -L "$f" ]; then
    perl -pi -e 's/^((#?)devel_(.*))/${2}'"$REL"'_$3\n$1/g' "$f"
  fi
done

if ! [ -d embargoed/ ]; then
    echo "Unable to find the embargoed/ directory, skipping" >&2
    exit 3
else
    perl -pi -e 's/^((#?)devel_(.*))/${2}'"$REL"'_$3\n$1/g' embargoed/CVE-*
fi
