Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FL-617 Fix eselect-ruby to properly set symlink

  • Loading branch information...
commit 70c9cdd58559fad4cc097b085ed347320e8a392a 1 parent ee7dfa2
Ryan Harris authored
View
15 app-admin/eselect-ruby/eselect-ruby-20110605-r1.ebuild
@@ -0,0 +1,15 @@
+# Distributed under the terms of the GNU General Public License v2
+
+DESCRIPTION="Manages multiple Ruby versions"
+HOMEPAGE="http://www.gentoo.org"
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="*"
+IUSE=""
+
+RDEPEND=">=app-admin/eselect-1.0.2"
+
+src_install() {
+ insinto /usr/share/eselect/modules
+ newins "${FILESDIR}/ruby.eselect-${PVR}" ruby.eselect || die
+}
View
220 app-admin/eselect-ruby/files/ruby.eselect-20110605-r1
@@ -0,0 +1,220 @@
+# Copyright 1999-2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+DESCRIPTION="Manage ruby symlinks"
+MAINTAINER="a3li@gentoo.org"
+SVN_DATE="20100603"
+VERSION="20100603"
+
+bindir=/usr/bin
+man1dir=/usr/share/man/man1
+
+find_targets() {
+ for t in ${ROOT}${bindir}/${1:-ruby}{18,19,20,ee18} ; do
+ [[ -e $t ]] || continue
+ echo ${t}
+ done
+}
+
+check_target() {
+ local target=${1} targets
+ targets=( $(find_targets ) )
+
+ # number from the list
+ if is_number ${target} && [[ ${target} -ge 1 ]] ; then
+ if [[ ${target} -gt ${#targets[@]} ]] ; then
+ target="invalid"
+ elif [[ -e "${targets[$(( ${target} - 1 ))]}" ]] ; then
+ target=$(basename ${targets[$((${target} - 1 ))]} )
+ else
+ write_warning_msg ${targets[$((${target} - 1 ))]}
+ target="invalid"
+ fi
+ # `rubyXX' string
+ else
+ [[ -e "${ROOT}${bindir}/${target}" ]] || \
+ target="invalid"
+ fi
+
+ echo ${target}
+}
+
+remove_symlinks() {
+ rm -f ${ROOT}${bindir}/{ruby,gem,irb,erb,ri,rdoc,testrb} && \
+ rm -f ${ROOT}${man1dir}/ruby.{1,1.gz,1.bz2,1.lzma}
+ for x in ${ROOT}${bindir}/ruby[0-9].[0-9]; do
+ # remove ruby1.9 -> ruby19 symlink if it exists:
+ if [ -L "$x" ]; then
+ rm -f "$x"
+ fi
+ done
+}
+
+create_man_symlinks() {
+ local version=${1}
+
+ for m in ${ROOT}${man1dir}/ruby${version}.{1,1.gz,1.bz2,1.lzma}
+ do
+ if [[ -e ${m} ]] ; then
+ break
+ fi
+ done
+
+ ln -s "${m}" "${m/ruby${version}/ruby}" || \
+ write_error_msg "Could not set man symlink"
+}
+
+create_symlinks() {
+ local target=${1} version
+
+ version=${target##*ruby}
+
+ local path="${ROOT}${bindir}/"
+ # these have to work
+ for f in "ruby" "irb" "erb" "ri" "testrb" "rdoc" ; do
+ ln -s "${f}${version}" "${path}${f}" || \
+ die -q "Could not set ${f} symlink"
+ done
+
+ case $version in
+ [0-9][0-9])
+ # create ruby1.9 symlink if we have ruby19, for example:
+ ln -s "ruby${version}" "${path}/ruby${version:0:1}.${version:1:2}"
+ ;;
+ esac
+
+ # these can fail
+ if [[ -e "${path}gem${version}" ]] ; then
+ ln -s "gem${version}" "${path}gem" || \
+ die -q "Could not set gem symlink"
+ else
+ write_warning_msg "Could not set gem symlink"
+ echo "It appears you do not have RubyGems installed for this profile."
+ echo "If you need RubyGems, emerge dev-ruby/rubygems with the appropriate RUBY_TARGETS setting."
+ echo
+ fi
+
+ create_man_symlinks ${version}
+
+ write_list_start "Successfully switched to profile:"
+ write_kv_list_entry "${target}" ""
+}
+
+### show action ###
+describe_show() {
+ echo "Prints the current configuration."
+}
+
+do_show() {
+ [[ -z "${@}" ]] || die -q "This function does not expect any arguments"
+
+ local rb=""
+
+ write_list_start "Current Ruby version:"
+ if [[ -L "${ROOT}${bindir}/ruby" ]] ; then
+ rb=$(basename $(canonicalise ${ROOT}${bindir}/ruby ) )
+ write_kv_list_entry $rb ""
+ elif [[ -e "${ROOT}${bindir}/ruby" ]] ; then
+ write_warning_msg "${bindir}/ruby is a SLOT incompatible version."
+ write_kv_list_entry "$(basename $(canonicalise ${ROOT}${bindir}/ruby ) )" ""
+ else
+ write_kv_list_entry "(none)"
+ return 1
+ fi
+
+ write_list_start "Current Rubygems version:"
+ if [[ -L "${ROOT}${bindir}/gem" ]] ; then
+ write_kv_list_entry "$(basename $(canonicalise ${ROOT}${bindir}/gem ) )" ""
+ elif [[ -e "${ROOT}${bindir}/gem" ]] ; then
+ write_warning_msg "${bindir}/gem is a SLOT incompatible version."
+ write_kv_list_entry "$(basename $(canonicalise ${ROOT}${bindir}/gem) )" ""
+ else
+ write_kv_list_entry "gem??" "(not found)"
+ fi
+}
+
+### list action ###
+describe_list() {
+ echo "Lists available Ruby profiles."
+}
+
+do_list() {
+ write_list_start "Available Ruby profiles:"
+ local targets=( $(find_targets) )
+ local i line
+
+ i=0
+ while [ $i -lt ${#targets[@]} ]; do
+ if [ -L "${targets[i]}" ]; then
+ unset targets[i]
+ continue
+ fi
+ line=$(basename "${targets[i]}")
+
+ # Do we have a matching rubygems?
+ if [[ -e ${targets[i]/ruby/gem} ]] ; then
+ line="${line} (with Rubygems)"
+ fi
+
+ # find out the current version
+ if [[ ${targets[i]} = $(canonicalise "${ROOT}${bindir}/ruby") ]] ; then
+ targets[i]=$(highlight_marker "${line}")
+ else
+ targets[i]=${line}
+ fi
+ i=$(( $i + 1 ))
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+}
+
+### set action ###
+describe_set() {
+ echo "Switches to a ruby profile."
+}
+
+describe_set_options() {
+ echo "target : Target name or number (from 'list' action)"
+}
+
+describe_set_parameters() {
+ echo "<target>"
+}
+
+do_set() {
+ [[ -z ${@} ]] && die -q "Parameter expected."
+
+ local target=$(check_target ${1})
+
+ [[ $target = "invalid" ]] && die -q "Can't use that profile. No suitable Ruby interpreter found."
+
+ remove_symlinks || die -q "Could not remove symlinks"
+
+ create_symlinks ${target}
+}
+
+### cleanup action ###
+describe_cleanup() {
+ echo "This action is not to be called manually."
+}
+
+do_cleanup() {
+ [[ -z ${@} ]] || die -q "This function does not expect any arguments"
+
+ # Do we need to clean up?
+ if [[ -e "${ROOT}${bindir}"/$(readlink "${ROOT}${bindir}/ruby") ]]; then
+ echo "Nothing to clean up."
+ return
+ fi
+
+ local targets=( $(find_targets) )
+
+ remove_symlinks || \
+ die -q "Could not remove symlinks"
+
+ if [[ ${#targets[@]} -ne 0 ]] ; then
+ echo "Marking the latest still installed version as default..."
+ create_symlinks $(basename ${targets[@]: -1})
+ else
+ echo "No ruby profiles left on the system. Stale symlinks removed."
+ fi
+}
Please sign in to comment.
Something went wrong with that request. Please try again.