#!/bin/bash

set -e

install_dir=$1
if [ -z "$install_dir" ]; then
  echo "usage: $0 INSTALL_DIR"
  exit 1
fi

if [ ! -d "$install_dir/bin" ]; then
  mkdir -p "$install_dir/bin"
fi

os="$(uname -s | tr '[:upper:]' '[:lower:]')"
github_url="https://github.com/kvz/json2hcl"
url="${github_url}/releases/download/v0.0.6/json2hcl_v0.0.6_${os}_amd64"
wget -O "$install_dir/bin/json2hcl" "$url"
chmod +x "$install_dir/bin/json2hcl"
