#!/bin/bash
# This file is for the CVEs that were entered while devel was closed,
# between releases. No-op is nearly expected. -- sarnold
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

if ! [ -d embargoed/ ]; then
    # just warn, don't exit
    echo "Unable to find embargoed directory, is it set up?" >&2
fi

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