Skip to content

Commit

Permalink
integrate with ruby-build.
Browse files Browse the repository at this point in the history
Resolves jneen#3 and jneen#4, since jruby and friends can all be installed with
ruby-build.
  • Loading branch information
jneen committed Mar 12, 2012
1 parent 2d38cb0 commit 5d60778
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
64 changes: 40 additions & 24 deletions bin/ry
Expand Up @@ -93,36 +93,48 @@ ry::rubies() {
# ry install <tarball> <name> [config ...]
# Installs the ruby from <tarball> under the given name.
#
# ry install <ruby-name> [<name>]
# If ruby-build is present, use it to install <ruby-name>.
#
ry::install() {
local url="$1"; shift
local name="$1"; shift

[[ -z "$url" ]] && abort "no URL given. usage: ry install <name> <url>"

local dir=$RY_LIB/rubies/$name
local logpath="/tmp/ry.log"

# create build directory
local builddir="$RY_LIB/rubies/$name/src"
mkdir -p $builddir

echo -n "fetching <$url> ..."
# fetch and unpack
cd $builddir \
&& get "$url" | tar xz --strip-components=1 > $logpath 2>&1
echo "done."

# see if things are alright
if test $? -gt 0; then
echo "\033[31mError: installation failed\033[0m"
echo " ry failed to fetch the tarball,"
echo " or tar failed. Try a different"
echo " version or view $logpath for"
echo " error details."
exit 1
# if you've got ruby-build, and you've named one of its recipes,
# use that instead :)
if exists? ruby-build \
&& ruby-build --definitions | grep -qx "$url"; then
[[ -z "$name" ]] && name="$url"
ruby-build "$url" "$RY_LIB/rubies/$name"
else
[[ -z "$url" ]] && abort "no URL given. usage: ry install <name> <url>"

local dir="$RY_LIB/rubies/$name"
local logpath="/tmp/ry.log"

# create build directory
local builddir="$RY_LIB/rubies/$name/src"
mkdir -p $builddir

echo -n "fetching <$url> ..."
# fetch and unpack
cd $builddir \
&& get "$url" | tar xz --strip-components=1 > $logpath 2>&1
echo "done."

# see if things are alright
if test $? -gt 0; then
echo "\033[31mError: installation failed\033[0m"
echo " ry failed to fetch the tarball,"
echo " or tar failed. Try a different"
echo " version or view $logpath for"
echo " error details."
exit 1
fi

ry build "$name" "$@" || abort "build failed."
fi

ry build "$name" "$@" || abort "build failed."
ry use "$name"
}

Expand Down Expand Up @@ -263,6 +275,10 @@ ry::usage() {
Download and compile <tarball>,
and install as <name>.
ry install <ruby-name> [<name>]
Requires \`ruby-build\`. Install the ruby-build
recipe named by <ruby-name>, optionally under
the alias <name>.
ry remove <name> Remove the given rubies
ry rm <name>
Expand Down
5 changes: 5 additions & 0 deletions lib/ry.bash_completion
Expand Up @@ -26,6 +26,11 @@ __complete_ry() {
use|rm|remove|binpath|fullpath|exec)
options="$(ry ls)"
;;
install)
if type ruby-build &>/dev/null; then
options="$(ruby-build --definitions)"
fi
;;
*)
options="$(compgen -f)"
esac
Expand Down

0 comments on commit 5d60778

Please sign in to comment.