Skip to content

Instantly share code, notes, and snippets.

@joehand
Last active July 6, 2019 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehand/24f15a88c13dc628fd3dc459d9810429 to your computer and use it in GitHub Desktop.
Save joehand/24f15a88c13dc628fd3dc459d9810429 to your computer and use it in GitHub Desktop.
Basic cabal install

Install cabal binary:

wget -qO- https://gist.githubusercontent.com/joehand/24f15a88c13dc628fd3dc459d9810429/raw/f02b5278a15a3fa2ce834e4647f78a4a8f45f957/install-cabal.sh | bash
#!/bin/bash
# gets latest cabal release zip for platform and extracts runnable binary into ~/.cabal
# usage: wget -qO- https://raw.githubusercontent.com/cabal-club/cabal-cli/master/bin/install.sh | bash
# based on https://github.com/jpillora/installer/blob/master/scripts/download.sh
CABAL_DIR="$HOME/.cabal/releases"
function cleanup {
rm -rf $CABAL_DIR/tmp.zip > /dev/null
}
function fail {
cleanup
msg=$1
echo "============"
echo "Error: $msg" 1>&2
exit 1
}
function install {
# bash check
[ ! "$BASH_VERSION" ] && fail "Please use bash instead"
GET=""
if which curl > /dev/null; then
GET="curl"
GET="$GET --fail -# -L"
elif which wget > /dev/null; then
GET="wget"
GET="$GET -qO-"
else
fail "neither wget/curl are installed"
fi
case `uname -s` in
Darwin) OS="macos";;
Linux) OS="linux";;
*) fail "unsupported os: $(uname -s)";;
esac
if uname -m | grep 64 > /dev/null; then
ARCH="x64"
else
fail "only arch x64 is currently supported for single file install. please use npm instead. your arch is: $(uname -m)"
fi
echo "Fetching latest Cabal release version from GitHub"
LATEST=$($GET -qs https://api.github.com/repos/cabal-club/cabal-cli/releases/latest | grep tag_name | head -n 1 | cut -d '"' -f 4);
mkdir -p $CABAL_DIR || fail "Could not create directory $CABAL_DIR, try manually downloading zip and extracting instead."
cd $CABAL_DIR
RELEASE="cabal-${LATEST:1}-${OS}-${ARCH}"
URL="https://github.com/cabal-club/cabal-cli/releases/download/${LATEST}/${RELEASE}.zip"
which unzip > /dev/null || fail "unzip is not installed"
echo "Downloading $URL"
bash -c "$GET $URL" > $CABAL_DIR/tmp.zip || fail "download failed"
unzip -o -qq $CABAL_DIR/tmp.zip || fail "unzip failed"
BIN="$CABAL_DIR/$RELEASE/cabal"
chmod +x $BIN || fail "chmod +x failed"
cleanup
printf "Cabal $LATEST has been downloaded successfully. Execute it with this command:\n\n${BIN}\n\nAdd it to your PATH with this command (add this to .bash_profile/.bashrc):\n\nexport PATH=\"\$PATH:$CABAL_DIR/$RELEASE\"\n"
}
install
@joehand
Copy link
Author

joehand commented Jul 4, 2019

Questions I have:

  • Is ~/.cabal/releases the best place to install?
  • Can we make that exit message nicer?
  • What if the latest release isn't published? (this happened in Dat because we released a new one but the binary didn't get built b/c tests failed causing this script to break)
  • Should we prefer this distribution to npm? (e.g. zeit/now installs the binary when you do npm install)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment