##
##  release.sh -- Project Release Utility
##

# Requires: GNU shtool
#
# Usage: ./release version
#        ./release tag
#        ./release dist
#        ./release upload

version () {
    shtool version -l c -n "Europalab schachuhr" -p "schuhr_" -e version.cpp
    V=`shtool version -l c -d long version.cpp`
    sed -e "s/Version .*(.*)/Version $V/g" <docs/readme.txt >docs/readme.txt.n
    mv docs/readme.txt.n docs/readme.txt
}

tag () {
    V=`shtool version -l c -d short version.cpp | sed -e 's;\.;_;g'`
    echo "+++ tagging sources as SCHUR_${V}"
    hg tag SCHUR_${V}
}

dist () {
    echo "+++ cleaning"
    rm -f schachuhr-*.tar.gz
    echo "+++ configuring"
    qmake
    echo "+++ building"
    make clean all -j4
    echo "+++ cleaning"
    make distclean >/dev/null 2>&1
    echo "+++ fixing"
    shtool fixperm -v .
    echo "Please find . -exec grep myusername {}"
    echo "+++ rolling"
    V=`shtool version -l c -d short version.cpp`
    shtool tarball -o schachuhr-${V}.tar.gz -d schachuhr-${V} \
                     -e '\.hg,\.hgignore,\.[ao]$,^\.,*.tar.gz,^#.*,.*~$,*.bak' \
                     -e 'release\.sh,schuhr_stub.cpp,schuhr_stub.h,schuhr_scrap' \
                     -c 'gzip --best' .
    ls -l schachuhr-${V}.tar.gz
    echo "+++ testing"
    gunzip <schachuhr-${V}.tar.gz | tar tvf - | head -10
    echo "[...]"
    gunzip <schachuhr-${V}.tar.gz | tar tvf - | tail -10
}

upload () {
    echo "+++ copying to ftp://ftp.europalab.com/pub/sfw/schachuhr/"
    V=`shtool version -l c -d short version.cpp`
    scp schachuhr-${V}.tar.gz user@dev.host.tld:/z/schuhr/source/
}
