diff --git a/.gitignore b/.gitignore index 56c9706e..2491f4e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -doc/ pkg/*.tar.gz pkg/*.tar.bz2 pkg/*.zip test/rubies +debian/chruby* +debian/files diff --git a/Makefile b/Makefile index 205c0c82..7deead63 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME=chruby -VERSION=0.3.7 +VERSION=0.4.0 AUTHOR=postmodern URL=https://github.com/$(AUTHOR)/$(NAME) @@ -13,12 +13,26 @@ PKG_NAME=$(NAME)-$(VERSION) PKG=$(PKG_DIR)/$(PKG_NAME).tar.gz SIG=$(PKG).asc +DESTDIR?=/ PREFIX?=/usr/local -DOC_DIR=$(PREFIX)/share/doc/$(PKG_NAME) +INSTALL_PATH=$(DESTDIR)/$(PREFIX) +DOC_DIR?=$(INSTALL_PATH)/share/doc/$(NAME) pkg: mkdir $(PKG_DIR) +share/man/man1/chruby.1: doc/man/chruby.1.md + kramdown-man share/man/man1/chruby.1 + +share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md + kramdown-man share/man/man1/chruby-exec.1 + +man: share/man/man1/chruby.1 + git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 + +man: share/man/man1/chruby-exec.1 + git commit -m "Updated the man pages" doc/man/chruby-exec.1.md share/man/man1/chruby-exec.1 + download: pkg wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz @@ -54,13 +68,13 @@ tag: release: tag download sign install: - for dir in $(INSTALL_DIRS); do mkdir -p $(PREFIX)/$$dir; done - for file in $(INSTALL_FILES); do cp $$file $(PREFIX)/$$file; done + for dir in $(INSTALL_DIRS); do mkdir -p $(INSTALL_PATH)/$$dir; done + for file in $(INSTALL_FILES); do cp $$file $(INSTALL_PATH)/$$file; done mkdir -p $(DOC_DIR) cp -r $(DOC_FILES) $(DOC_DIR)/ uninstall: - for file in $(INSTALL_FILES); do rm -f $(PREFIX)/$$file; done + for file in $(INSTALL_FILES); do rm -f $(INSTALL_PATH)/$$file; done rm -rf $(DOC_DIR) -.PHONY: build download sign verify clean test tag release install uninstall all +.PHONY: build man download sign verify clean test tag release install uninstall all diff --git a/README.md b/README.md index 7dd005fc..220b9602 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,32 @@ Chruby provides detailed instructions for installing additional Rubies: * [Rubinius](https://github.com/postmodern/chruby/wiki/Rubinius) * [MagLev](https://github.com/postmodern/chruby/wiki/MagLev) +#### chruby-install + +If you'd like to use chruby-install to install Rubies, just install +[ruby-install] and add the following after where you have loaded `chruby.sh`: + + source /usr/local/share/chruby/install.sh + +You can then use chruby-install to install additional Rubies, making them +immediately available to chruby. + +List Rubies for installation: + + chruby-install + +Install the current stable version of a Ruby: + + chruby-install ruby + +Install the latest version of a Ruby: + + chruby-install ruby 1.9 + +Install a Ruby with specific configuration: + + chruby-install ruby 2.0.0-p0 -- --enable-shared --enable-dtrace CFLAGS="-O3" + #### ruby-install You can also use [ruby-install] to install additional Rubies: diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..bc762f78 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,12 @@ +chruby (0.4.0) unstable; urgency=low + + * Package upstream version 0.4.0 + + -- Alex Young Sun, 18 Aug 2013 13:44:36 +0100 + + +chruby (0.3.6) unstable; urgency=low + + * Initial package + + -- Alex Young Mon, 01 Jul 2013 10:20:24 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..45a4fb75 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +8 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..8bf9bc00 --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: chruby +Section: devel +Priority: extra +Maintainer: Alex Young +Build-Depends: debhelper (>= 8.0.0) +Standards-Version: 3.9.3 +Homepage: https://github.com/postmodern/chruby#readme + +Package: chruby +Architecture: all +Depends: ${misc:Depends} +Description: Changes the current Ruby. + Updates $PATH, $GEM_HOME and $GEM_PATH to use rubies installed under + /opt/rubies or $HOME/.rubies. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000..0008496e --- /dev/null +++ b/debian/copyright @@ -0,0 +1,24 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: chruby +Source: https://github.com/postmodern/chruby + +Files: * +Copyright: 2012-2013 Hal Brodigan +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/debian/docs b/debian/docs new file mode 100644 index 00000000..637eee12 --- /dev/null +++ b/debian/docs @@ -0,0 +1,4 @@ +LICENSE.txt +README.md +ChangeLog.md +CONTRIBUTING.md diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000..956227c9 --- /dev/null +++ b/debian/rules @@ -0,0 +1,17 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +override_dh_auto_test-indep: + +override_dh_auto_build-indep: + +%: + PREFIX=/usr dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 00000000..89ae9db8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/doc/man/chruby-exec.1.md b/doc/man/chruby-exec.1.md new file mode 100644 index 00000000..fa25af93 --- /dev/null +++ b/doc/man/chruby-exec.1.md @@ -0,0 +1,76 @@ +# chruby-exec(1) -- Run a command with selected Ruby. + +## SYNOPSIS + +`chruby-exec` RUBY [RUBYOPTS] -- COMMAND + +## ARGUMENTS + +*RUBY* + Change current Ruby based on fuzzy matching of Ruby by name. + +*RUBYOPTS* + Additional optional arguments to pass to Ruby. + +*COMMAND* + Command to run under the selected Ruby. + +## OPTIONS + +`-h`, `--help` + +`-v`, `--version` + +## DESCRIPTION +Run a command with the selected Ruby version by correctly setting the appropriate environment variables. + +[https://github.com/postmodern/chruby/blob/master/README.md](https://github.com/postmodern/chruby/blob/master/README.md) + +## EXAMPLES + +Run the command `gem update` under JRuby: + $ chruby-exec jruby -- gem update + +##FILES + +*/opt/rubies* + Primary default Ruby install location. + +*~/.rubies/* + Secondary default Ruby install location. + +*/etc/profile.d/chruby.sh* + Application environment settings for chruby. + +*~/.gem/$ruby/$version* + Default gem install location. + +##ENVIRONMENT + +*PATH* + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. + +*GEM_HOME* + Default repository location for gem installation. + +*GEM_PATH* + A colon-separated list of gem repository directories. + +*GEM_ROOT* + +*RUBY_ROOT* + +*RUBY_ENGINE* + Name of Ruby implementation. + +*RUBY_VERSION* + Ruby version number. + +*RUBYOPT* + Optionally set if additional Ruby options are given. + +##AUTHOR +Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). + +##SEE ALSO +chruby(1), ruby(1), gem(1) diff --git a/doc/man/chruby-install.1.md b/doc/man/chruby-install.1.md new file mode 100644 index 00000000..c8b50e24 --- /dev/null +++ b/doc/man/chruby-install.1.md @@ -0,0 +1,76 @@ +# chruby-install(1) -- Install the selected Ruby with ruby-install. + +## SYNOPSIS + +`chruby-install` [OPTIONS] [RUBY [VERSION]] [-- CONFIGURE_OPTS ...] + +## ARGUMENTS + +*RUBY* + Install Ruby by name. + +*VERSION* + Optionally select Ruby version. + +*CONFIGURE_OPTS* + Additional optional configure arguments. + +## OPTIONS + +`-h`, `--help` + +`-V`, `--version` + +See `man ruby-install` for Ruby installation options. + +## DESCRIPTION +Installs Ruby, JRuby, Rubinius or MagLev with ruby-install. + +[https://github.com/postmodern/ruby-install#readme](https://github.com/postmodern/ruby-install#readme) + +And then reloads chruby Rubies. + +[https://github.com/postmodern/chruby/blob/master/README.md](https://github.com/postmodern/chruby/blob/master/README.md) + +## ARGUMENTS + +*RUBY* + Install Ruby by name. + +*VERSION* + Optionally select the version of selected Ruby. + +*CONFIGURE_OPTS* + Additional optional configure arguments. + +## EXAMPLES + +Install the current stable version of Ruby: + + $ chruby-install ruby + +Install a specific version of Ruby: + + $ chruby-install ruby 1.9.3-p395 + +## FILES + +*/usr/local/src* + Default root user source directory. + +*~/src* + Default non-root user source directory. + +*/opt/rubies/$ruby-$version* + Default root user installation directory. + +*~/.rubies/$ruby-$version* + Default non-root user installation directory. + +## AUTHOR + +Postmodern + +## SEE ALSO + +ruby-install(1), chruby(1), chruby-exec(1), ruby(1), gem(1) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md new file mode 100644 index 00000000..fb1e7631 --- /dev/null +++ b/doc/man/chruby.1.md @@ -0,0 +1,95 @@ +# chruby(1) -- Changes the current Ruby. + +## SYNOPSIS + +`chruby` [] [] + +## ARGUMENTS + +*RUBY|VERSION* + Change current Ruby based on fuzzy matching of Ruby by name. + +*system* + Change current Ruby to system Ruby. + +*RUBY_OPTS* + Additional optional arguments to pass to Ruby. + +## OPTIONS + +`-h`, `--help` + +`-v`, `--version` + +## DESCRIPTION +Changes the current Ruby version by correctly setting the appropriate environment variables. + +[https://github.com/postmodern/chruby/blob/master/README.md](https://github.com/postmodern/chruby/blob/master/README.md) + +## EXAMPLES + +List available Rubies: + $ chruby + ruby-1.9.3-p362 + jruby-1.7.2 + rubinius-2.0.0-rc1 + +Select a Ruby: + $ chruby 1.9.3 + $ chruby + * ruby-1.9.3-p362 + jruby-1.7.2 + rubinius-2.0.0-rc1 + +Switch to JRuby in 1.9 mode: + $ chruby jruby --1.9 + +Switch back to system Ruby: + $ chruby system + +Switch to an arbitrary Ruby on the fly: + $ chruby_use /path/to/ruby + +##FILES + +*/opt/rubies* + Primary default Ruby install location. + +*~/.rubies/* + Secondary default Ruby install location. + +*/etc/profile.d/chruby.sh* + Application environment settings for chruby. + +*~/.gem/$ruby/$version* + Default gem install location. + +##ENVIRONMENT + +*PATH* + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. + +*GEM_HOME* + Default repository location for gem installation. + +*GEM_PATH* + A colon-separated list of gem repository directories. + +*GEM_ROOT* + +*RUBY_ROOT* + +*RUBY_ENGINE* + Name of Ruby implementation. + +*RUBY_VERSION* + Ruby version number. + +*RUBYOPT* + Optionally set if additional Ruby options are given. + +##AUTHOR +Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). + +##SEE ALSO +chruby-exec(1), ruby(1), gem(1) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 4318b501..ce3aec66 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -44,6 +44,7 @@ function chruby_use() begin; require 'rubygems'; rescue LoadError; end puts "export RUBY_ENGINE=#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'};" puts "export RUBY_VERSION=#{RUBY_VERSION};" +puts "export RUBY_PATCHLEVEL=#{RUBY_PATCHLEVEL};" puts "export GEM_ROOT=#{Gem.default_dir.inspect};" if defined?(Gem) EOF` diff --git a/share/chruby/install.sh b/share/chruby/install.sh new file mode 100644 index 00000000..4267cf02 --- /dev/null +++ b/share/chruby/install.sh @@ -0,0 +1,29 @@ +function chruby_reload() +{ + RUBIES=( + `find "$PREFIX"/opt/rubies -mindepth 1 -maxdepth 1 -type d 2>/dev/null` + `find "$HOME"/.rubies -mindepth 1 -maxdepth 1 -type d 2>/dev/null` + ) +} + +function chruby-install() +{ + case "$1" in + -h|--help) + echo "usage: chruby-install [OPTIONS] [RUBY [VERSION]] [-- CONFIGURE_OPTS ...]" + ;; + -V|--version) + chruby --version + [[ -n `command -v ruby-install` ]] && ruby-install --version + ;; + *) + if [[ -z `command -v ruby-install` ]]; then + echo "chruby-install: ruby-install could not be found" >&2 + return 1 + fi + + ruby-install $@ + chruby_reload + ;; + esac +} diff --git a/share/man/man1/chruby-exec.1 b/share/man/man1/chruby-exec.1 new file mode 100644 index 00000000..47704d2f --- /dev/null +++ b/share/man/man1/chruby-exec.1 @@ -0,0 +1,78 @@ +.TH +.BR chruby-exec (1) +\-\- Run a command with selected Ruby. +.SH SYNOPSIS +.PP +\fB\fCchruby-exec\fR RUBY [RUBYOPTS] \-\- COMMAND +.SH ARGUMENTS +.PP +\fIRUBY\fP + Change current Ruby based on fuzzy matching of Ruby by name. +.PP +\fIRUBYOPTS\fP + Additional optional arguements to pass to Ruby. +.PP +\fICOMMAND\fP + Command to run under the selected Ruby. +.SH OPTIONS +.PP +\fB\fC-h\fR, \fB\fC--help\fR +.PP +\fB\fC-v\fR, \fB\fC--version\fR +.SH DESCRIPTION +.PP +Run a command with the selected Ruby version by correctly setting the appropriate environment variables. +.PP +https://github.com/postmodern/chruby/blob/master/README.md +.UR https://github.com/postmodern/chruby/blob/master/README.md +.UE +.SH EXAMPLES +.PP +Run the command \fB\fCgem update\fR under JRuby: + $ chruby\-exec jruby \-\- gem update +.SH FILES +.PP +\fI/opt/rubies\fP + Primary default Ruby install location. +.PP +\fI~/.rubies/\fP + Secondary default Ruby install location. +.PP +\fI/etc/profile.d/chruby.sh\fP + Application environment settings for chruby. +.PP +\fI~/.gem/$ruby/$version\fP + Default gem install location. +.SH ENVIRONMENT +.PP +\fIPATH\fP + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. +.PP +\fIGEM_HOME\fP + Default repository location for gem installation. +.PP +\fIGEM_PATH\fP + A colon\-separated list of gem repository directories. +.PP +\fIGEM_ROOT\fP +.PP +\fIRUBY_ROOT\fP +.PP +\fIRUBY_ENGINE\fP + Name of Ruby implementation. +.PP +\fIRUBY_VERSION\fP + Ruby version number. +.PP +\fIRUBYOPT\fP + Optionally set if additional Ruby options are given. +.SH AUTHOR +.PP +Postmodern postmodern.mod3\@gmail.com +.MT postmodern.mod3@gmail.com +.ME . +.SH SEE ALSO +.PP +.BR chruby (1), +.BR ruby (1), +.BR gem (1) \ No newline at end of file diff --git a/share/man/man1/chruby.1 b/share/man/man1/chruby.1 new file mode 100644 index 00000000..ca52536a --- /dev/null +++ b/share/man/man1/chruby.1 @@ -0,0 +1,94 @@ +.TH +.BR chruby (1) +\-\- Changes the current Ruby. +.SH SYNOPSIS +.PP +\fB\fCchruby\fR [] [] +.SH ARGUMENTS +.PP +\fIRUBY|VERSION\fP + Change current Ruby based on fuzzy matching of Ruby by name. +.PP +\fIsystem\fP + Change current Ruby to system Ruby. +.PP +\fIRUBY_OPTS\fP + Additional optional arguements to pass to Ruby. +.SH OPTIONS +.PP +\fB\fC-h\fR, \fB\fC--help\fR +.SH DESCRIPTION +.PP +Changes the current Ruby version by correctly setting the appropriate environment variables. +.PP +https://github.com/postmodern/chruby/blob/master/README.md +.UR https://github.com/postmodern/chruby/blob/master/README.md +.UE +.SH EXAMPLES +.PP +List available Rubies: + $ chruby + ruby\-1.9.3\-p362 + jruby\-1.7.2 + rubinius\-2.0.0\-rc1 +.PP +Select a Ruby: + $ chruby 1.9.3 + $ chruby + * ruby\-1.9.3\-p362 + jruby\-1.7.2 + rubinius\-2.0.0\-rc1 +.PP +Switch to JRuby in 1.9 mode: + $ chruby jruby \-\-1.9 +.PP +Switch back to system Ruby: + $ chruby system +.PP +Switch to an arbitrary Ruby on the fly: + $ chruby_use /path/to/ruby +.SH FILES +.PP +\fI/opt/rubies\fP + Primary default Ruby install location. +.PP +\fI~/.rubies/\fP + Secondary default Ruby install location. +.PP +\fI/etc/profile.d/chruby.sh\fP + Application environment settings for chruby. +.PP +\fI~/.gem/$ruby/$version\fP + Default gem install location. +.SH ENVIRONMENT +.PP +\fIPATH\fP + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. +.PP +\fIGEM_HOME\fP + Default repository location for gem installation. +.PP +\fIGEM_PATH\fP + A colon\-separated list of gem repository directories. +.PP +\fIGEM_ROOT\fP +.PP +\fIRUBY_ROOT\fP +.PP +\fIRUBY_ENGINE\fP + Name of Ruby implementation. +.PP +\fIRUBY_VERSION\fP + Ruby version number. +.PP +\fIRUBYOPT\fP + Optionally set if additional Ruby options are given. +.SH AUTHOR +.PP +Postmodern postmodern.mod3\@gmail.com +.MT postmodern.mod3@gmail.com +.ME . +.SH SEE ALSO +.PP +.BR ruby (1), +.BR gem (1) \ No newline at end of file diff --git a/test/chruby_install.sh b/test/chruby_install.sh new file mode 100755 index 00000000..f7fcfbff --- /dev/null +++ b/test/chruby_install.sh @@ -0,0 +1,10 @@ +. ./share/chruby/install.sh +. ./test/helper.sh + +test_chruby_install_version() +{ + assertTrue "did not print the chruby version" \ + '[[ `chruby-install --version` == *$CHRUBY_VERSION* ]]' +} + +SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/chruby_reload.sh b/test/chruby_reload.sh new file mode 100755 index 00000000..3bdfc777 --- /dev/null +++ b/test/chruby_reload.sh @@ -0,0 +1,17 @@ +. ./share/chruby/install.sh +. ./test/helper.sh + +test_chruby_reload() +{ + local new_ruby="$HOME/.rubies/newly_installed_ruby" + mkdir -p "$new_ruby" + + chruby_reload + + assertTrue "did not add the new ruby dir to RUBIES" \ + '[[ "${RUBIES[*]}" == *$new_ruby* ]]' + + rmdir "$new_ruby" +} + +SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/chruby_use_test.sh b/test/chruby_use_test.sh index 7e2c8ead..01d66e48 100755 --- a/test/chruby_use_test.sh +++ b/test/chruby_use_test.sh @@ -12,6 +12,7 @@ test_chruby_use() assertEquals "invalid RUBY_ROOT" "$TEST_RUBY_ROOT" "$RUBY_ROOT" assertEquals "invalid RUBY_ENGINE" "$TEST_RUBY_ENGINE" "$RUBY_ENGINE" assertEquals "invalid RUBY_VERSION" "$TEST_RUBY_VERSION" "$RUBY_VERSION" + assertEquals "invalid RUBY_PATCHLEVEL" "$TEST_RUBY_PATCHLEVEL" "$RUBY_PATCHLEVEL" assertEquals "invalid GEM_ROOT" "$TEST_RUBY_ROOT/lib/ruby/gems/$TEST_RUBY_API" "$GEM_ROOT" assertEquals "invalid GEM_HOME" "$TEST_GEM_HOME" "$GEM_HOME" assertEquals "invalid GEM_PATH" "$GEM_HOME:$GEM_ROOT" "$GEM_PATH"