Skip to content

Instantly share code, notes, and snippets.

@ndrluis
Forked from fnando/ruby.sh
Created October 31, 2012 19:59
Show Gist options
  • Save ndrluis/3989424 to your computer and use it in GitHub Desktop.
Save ndrluis/3989424 to your computer and use it in GitHub Desktop.
Install Ruby
#!/usr/bin/env bash
INSTALL_DIR="${INSTALL_DIR:-/opt/local}"
VERSION=$2
APP_NAME="ruby"
URL="http://ftp.ruby-lang.org/pub/ruby/ruby-$VERSION.tar.bz2"
PREFIX="$INSTALL_DIR/$APP_NAME/$VERSION"
CURRENT="$INSTALL_DIR/$APP_NAME/current"
TGZ="$INSTALL_DIR/src/$(basename $URL)"
COMMAND=$1
if [[ -z "$COMMAND" ]]; then
${0} help
exit 1
elif [[ -z "$VERSION" && "$COMMAND" != "help" && "$COMMAND" != "deactivate" ]]; then
${0} help
fi
case "$COMMAND" in
install)
if [[ "$(uname)" != "Darwin" ]]; then
sudo apt-get install -y autoconf automake bison build-essential \
curl libc6-dev libffi-dev libreadline-dev libreadline6 libreadline6-dev \
libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev libxslt1-dev \
libyaml-dev ncurses-dev openssl sqlite3 zlib1g zlib1g-dev
fi
mkdir -p $INSTALL_DIR/src
cd $INSTALL_DIR/src
[ ! -f "$TGZ" ] && wget $URL
tar xvf $TGZ
cd "ruby-$VERSION"
./configure --prefix=$PREFIX
make
make install
;;
activate)
if [[ ! -d $PREFIX ]]; then
${0} install $VERSION
fi
${0} deactivate
ln -s "$PREFIX" "$CURRENT"
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
mkdir -p "$INSTALL_DIR/$dir"
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
ln -s "$CURRENT/$dir/$bin" "$INSTALL_DIR/$dir/$bin"
done
done
;;
deactivate)
if [[ ! -L "$CURRENT" ]]; then
exit
fi
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
[ -L "$INSTALL_DIR/$dir/$bin" ] && rm "$INSTALL_DIR/$dir/$bin"
done
done
rm "$CURRENT"
;;
*)
echo "Usage: ${0} {install|uninstall|activate|deactivate|help} {version}" >&2
exit 3
;;
esac
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment