#!/bin/sh
set -eu

if test -w /home/linuxbrew || sudo -v; then
	prefix=/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor
	test -d /home/linuxbrew || sudo mkdir -p /home/linuxbrew
	test -w /home/linuxbrew || sudo chown $USER: /home/linuxbrew
else
	prefix=~/.linuxbrew/Homebrew/Library/Homebrew/vendor
fi
version=2.3.7
tag=`uname -m`_`uname -s | tr A-Z a-z`

echo >&2 "==> Installing Ruby to $prefix"
mkdir -p $prefix
curl -L https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-$version.$tag.bottle.tar.gz \
	| tar -xz -C $prefix
echo >&2 '==> Installing successful'

export "PATH=$prefix/portable-ruby/$version/bin:$PATH"
echo >&2 "==> `which ruby`"
ruby --version 1>&2
echo >&2 "==> Add Ruby to your PATH by running:"
echo "PATH=$prefix/portable-ruby/$version/bin"':$PATH'
