From cefd684545fd7c78a342e1cf384cd3d639378912 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 29 Dec 2011 18:48:33 -0600 Subject: [PATCH] Add installer --- README.md | 14 ++++++++++++++ install.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 install.sh diff --git a/README.md b/README.md index 5ada479..c2f0ad1 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,17 @@ in the test file. * `$BATS_TMPDIR` is the location to a directory that may be used to store temporary files. +### Installing Bats + +Check out a copy of the Bats repository. Then, either add the Bats +`bin` directory to your `$PATH`, or run the provided `install.sh` +command with the location to the prefix in which you want to install +Bats. For example, to install Bats into `/usr/local`, + + $ git clone https://github.com/sstephenson/bats.git + $ cd bats + $ ./install.sh /usr/local + +Note that you may need to run `install.sh` with `sudo` if you do not +have permission to write to the installation prefix. + diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8254168 --- /dev/null +++ b/install.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -e + +resolve_link() { + $(type -p greadlink readlink | head -1) "$1" +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + +PREFIX="$1" +if [ -z "$1" ]; then + { echo "usage: $0 " + echo " e.g. $0 /usr/local" + } >&2 + exit 1 +fi + +BATS_ROOT="$(abs_dirname "$0")" +mkdir -p "$PREFIX"/{bin,libexec} +cp -R "$BATS_ROOT"/bin/* "$PREFIX"/bin +cp -R "$BATS_ROOT"/libexec/* "$PREFIX"/libexec + +echo "Installed Bats to $PREFIX/bin/bats"