#!/bin/bash

set -e

function cleanupTempDir() {
  temp=$1
  echo "cleaning up $temp"

  rm -r $temp

  echo "cleaned up tempdir"
}

tempdir=$(mktemp -d -t "devhamctl")
trap "cleanupTempDir $tempdir" EXIT

pushd $tempdir
echo "fetching release manager [hamctl]"
wget -q https://github.com/lunarway/release-manager/releases/download/$1/hamctl-darwin-amd64 -O binhamctl
shift
echo "calling release manager [hamctl] with args [$@]"
chmod +x binhamctl
HAMCTL_URL="http://some-url" ./binhamctl "$@"
popd