#!/bin/sh

# Author Adam Wujek for CERN
#
# From file $1 save the text between ".. last_release_start::" and
# ".. last_release_end::" fo file $2

# Parameters:
# $1 - source filename
# $2 - destination filename

set -e
set -o pipefail

if [ $# -ne 2 ]; then
    echo "$0: Not enough parameters!"
    echo "usage: $0 src_file dest_file"
    exit 1
fi

file_changelog="$1"
start_tag=".. last_release_start::"
end_tag=".. last_release_end::"
start_line=$(grep -n "$start_tag" "$file_changelog" | cut -d':' -f1)
end_line=$(grep -n "$end_tag" "$file_changelog" | cut -d':' -f1)
start_line=$((start_line + 1))
end_line=$((end_line - 1))

head -n $end_line $file_changelog | tail -n +$start_line > "$2"
