Skip to content

Instantly share code, notes, and snippets.

@martok
Last active April 7, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martok/228b1c9a1a95b3c680d1104489e6f6f3 to your computer and use it in GitHub Desktop.
Save martok/228b1c9a1a95b3c680d1104489e6f6f3 to your computer and use it in GitHub Desktop.
Ruby source installation manager
#!/bin/bash
CONF=/etc/profile.d/optruby.sh
INSTALLED=/opt/ruby
do_status() {
current=$(OPTRUBY=system ; [ -f $CONF ] && . $CONF ; echo $OPTRUBY )
echo "Currently enabled version via profile.d: $current"
echo "Currently selected by this shell: $(ruby -v)"
}
do_list() {
echo "Available rubies:"
find "$INSTALLED" -mindepth 1 -maxdepth 1 -execdir test -f "{}/bin/ruby" \; -ls
}
do_set() {
set_ruby=$1
if [ -z $set_ruby ]; then
echo "Usage: $0 set {VERSION|system}" >&2
exit 3
fi
if [ "$set_ruby" == "system" ] ; then
echo "Using system ruby"
[ -f "$CONF" ] && rm -f "$CONF"
else
tee $CONF <<-EOF
OPTRUBY=$set_ruby
export PATH="$INSTALLED/\$OPTRUBY/bin:\$PATH"
EOF
fi
}
do_install() {
install_ruby=$1
if [ -z $install_ruby ]; then
echo "Usage: $0 install VERSION" >&2
exit 3
fi
ruby-build $install_ruby "$INSTALLED/$install_ruby"
}
case "$1" in
status)
shift
do_status $*
;;
list)
shift
do_list $*
;;
set)
shift
do_set $*
;;
install)
shift
do_install $*
;;
*)
echo "Usage: $0 {status|list|set|install}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment