#!/bin/sh

# adds the latest changelog generated by 
#  changelog-generate to the file snapshots.xml or
#  releases.xml

. tools/include/config || {
  echo "must be run from mod-xslt source top level directory" 1>&2 
  exit 1
}

test -n "$library_file" || {
  echo 1>&2 "no library_file provided"
  exit 1;
}

test -n "$library_ymd" || {
  echo 1>&2 "no ymd provided"
  exit 1;
}

test -f "$dir_changelog"/"$library_file" || {
  echo 1>&2 "file does not exist"
  exit 1;
}

pid="$$"

( sed '/<\/description>/q' "$dir_changelog"/"$library_file"
  . "$dir_library"/changelog-generate
  sed -n '/<\/description/,$p' "$dir_changelog"/"$library_file"|tail -n+2
) > "$dir_changelog"/"$library_file"."$pid"

  # Rename & overwrite file
mv "$dir_changelog"/"$library_file"."$pid" "$dir_changelog"/"$library_file"
