#/bin/bash
set -e -o pipefail

VERSION=${VERSION:-2.1.1}
PRERELEASE=${PRERELEASE:-true}
FILE_VERSION=$(echo $VERSION | sed 's/\./_/g')
tools=$HOME/tools
dir=$tools/wmail-${VERSION}
echo  "extracting to dir $dir"
mkdir -p $dir
pushd $dir
name="WMail_${FILE_VERSION}_linux_x86_64.tar.gz"
if [[ $PRERELEASE == "true" ]]; then
  name="WMail_${FILE_VERSION}_prerelease_linux_x86_64.tar.gz"
fi
url=https://github.com/Thomas101/wmail/releases/download/v${VERSION}/${name}
echo "downloading $url"
curl -SsfL ${url} | tar xfz - --strip-components 1
set -x
ln -nfs $dir $tools/wmail-current
