#!/usr/bin/bash

version=1.9.8
dte=$(date +%Y%m%d%H%M)

# Use a specific branch
#branch=ms-preserve-reporter-layout
#branch=ms-audio-device-resize 
#branch=ms-clear-reporter-on-reconnect
#branch=ms-waterfall-maint
#branch=ms-reporter-band-filter
#branch=ms-voice-keyer-improvements
#branch=ms-monitor-audio
#branch=ms-restore-layout
#branch=ms-time-format
#branch=ms-sort-reporter
#branch=ms-reporter-no-session
#branch=ms-reporter-track-freq
#branch=ms-reporter-regressions
#branch=ms-ptt-method-none
#branch=ms-reporter-delete-disconnects
#branch=ms-reporter-rx-timeout
#branch=ms-rig-control-refactor
#branch=ms-filter-exact-freq
#branch=ms-force-rx-only
#branch=ms-freq-reload-on-start
#branch=ms-startup-size
#branch=ms-box-sizing
#branch=ms-reporter-msg
#branch=ms-tx-rx-delay
#branch=ms-status-msg-improvements
#branch=ms-reporter-flicker
#branch=ms-filter-dlg-resize
#branch=ms-col-sizing
#branch=ms-reporter-message-save
#branch=ms-grid-square-math
#branch=ms-frequency-rx-call

# Use a specific commit
githash=

if [[ -d freedv ]]; then
    cd freedv
    # Make sure we are on master branch
    git checkout master
    git pull
else
    git clone https://github.com/drowe67/freedv-gui.git freedv
    cd freedv
fi

if ((${#branch} > 0)); then
    git checkout $branch || exit 1
    git pull
fi

if ((${#githash} > 0)); then
    git checkout $githash || exit 1
fi

# Get the current commit to use in tarball name
githash=$(git log|head -n1|cut -d' ' -f2|cut -c 1-5)

cd ..

cp -r freedv freedv-${version}-${dte}-${githash}

#tar --exclude-vcs -czf freedv-${version}-${dte}-${githash}.tar.gz freedv-${version}-${dte}-${githash}/
tar -czf freedv-${version}-${dte}-${githash}.tar.gz freedv-${version}-${dte}-${githash}/ && \
echo "freedv-${version}-${dte}-${githash}.tar.gz created"
#return "${dte}-${githash}"
