#!/bin/bash

[[ ! -f Makefile.dbg ]] && exit 0

reportName="$(basename "$PWD")"
replaceText="s/CHANGEME/$reportName/g"

read -p "Select Template [1: generic, 2: onepage]: " selectedTemplate

if [[ "$selectedTemplate" == "1" ]]; then
    cp templates/report.tex ./report.tex;
else
    if [[ "$selectedTemplate" == "2" ]]; then
        cp templates/onepage.tex ./report.tex
    else
        echo "Invalid Selection!" && exit 1
    fi
fi

rm Makefile.dbg
mv report.tex $reportName.tex
sed -i $replaceText Makefile
sed -i $replaceText README.md
desc_file=$(mktemp repo-description.XXXXXX)
$EDITOR $desc_file
cat $desc_file >> README.md
rm $desc_file
