summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Graaff <hans@degraaff.org>2009-04-18 22:24:18 +0200
committerHans de Graaff <hans@degraaff.org>2009-04-18 22:24:18 +0200
commit4d19622e0d54a194a257f8be1966d6984a80529a (patch)
tree0a27c1c4042adb773513e3fd16fcd44b8ae08bd6 /eselect-gem
parentFix typo (diff)
downloadruby-scripts-4d19622e0d54a194a257f8be1966d6984a80529a.tar.gz
ruby-scripts-4d19622e0d54a194a257f8be1966d6984a80529a.tar.bz2
ruby-scripts-4d19622e0d54a194a257f8be1966d6984a80529a.zip
Initial version that seems to work more or less.
Intended for some testing, not yet for release.
Diffstat (limited to 'eselect-gem')
-rw-r--r--eselect-gem/gem.eselect205
1 files changed, 205 insertions, 0 deletions
diff --git a/eselect-gem/gem.eselect b/eselect-gem/gem.eselect
new file mode 100644
index 0000000..40bf7f5
--- /dev/null
+++ b/eselect-gem/gem.eselect
@@ -0,0 +1,205 @@
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: vi.eselect 261 2006-03-30 21:11:55Z kugelfang $
+
+DESCRIPTION="Manage binaries provided by slotted gems."
+MAINTAINER="graaff@gentoo.org"
+
+# Manage binaries installed by gems. Since gems install their binaries
+# in a standard manner we can handle them with a single eselect
+# module.
+
+# Usage: eselect gems <gemname> <version> <binaries>
+
+# This creates symlinks in /usr/bin to the versioned binaries in the
+# gem bin directory.
+
+GEM_DIR="$(gem env gemdir)"
+GEM_BIN_DIR="$GEM_DIR/bin"
+
+# get_executables(gemname)
+find_executables() {
+ # Parse the specifications file to get the list of executables as
+ # specified by the gem. Pick the last version.
+ echo $(grep -h s.executables "$GEM_DIR/specifications/${1}"-*.gemspec | tail -n 1 | cut --delimiter="=" --fields=2 | tr -d "[]\"/,")
+}
+
+# find a list of versions for this gem
+find_targets() {
+ for f in "${GEM_DIR}/gems/${1}-"* ; do
+ if [[ -d ${f} ]] ; then
+ echo $(basename ${f} )
+ fi
+ done
+}
+
+# Try to remove the current symlinks for all the current executables
+remove_symlinks() {
+ local executables=( $( find_executables ${1} ) )
+
+ for (( i = 0 ; i < ${#executables[@]} ; i = i + 1 )) ; do
+ target="${ROOT}/usr/bin/${executables[${i}]}"
+ rm ${target} &>/dev/null
+ done
+}
+
+# set the symlinks for all the executables
+set_symlinks() {
+ local gem=${1}
+ local target=${2}
+
+ if is_number "${target}" && [[ ${target} -ge 1 ]] ; then
+ targets=( $(find_targets ${1}) )
+ target=${targets[$(( ${target} - 1 ))]}
+ target=$(echo $target | cut --delimiter="-" --fields=2)
+ fi
+
+ local executables=( $( find_executables ${1} ) )
+
+ for (( i = 0 ; i < ${#executables[@]} ; i = i + 1 )) ; do
+ executable="${ROOT}/usr/bin/${executables[${i}]}"
+
+ if [[ -f "${executable}-${target}" ]] ; then
+ ln -s "${executable}-${target}" "${executable}" || \
+ die "Couldn't set ${target} symlink"
+ else
+ die -q "Target \"${target}\" doesn't appear to be valid!"
+ fi
+ done
+}
+
+set_symlink_default() {
+ set_symlink 1
+}
+
+set_symlink_by_slot() {
+ slot=${1}
+ local target=$(ls ${RAILS}-${slot}* 2>/dev/null)
+ if [[ -n ${target} ]]; then
+ remove_symlinks
+ ln -s ${target} ${RAILS}
+ else
+ die -q "No providers available for slot ${slot}"
+ fi
+}
+
+### show action ###
+
+describe_show() {
+ echo "Show the currently selected version for the specific gem"
+}
+
+do_show() {
+ if [[ "x${1}" == "x" ]]; then
+ die -q "Usage error: a gem name is required."
+ fi
+
+ local executables=( $( find_executables ${1} ) )
+ local executable="${ROOT}/usr/bin/${executables[0]}"
+
+ write_list_start "Current ${1} version:"
+ if [[ -L "${executable}" ]] ; then
+ write_kv_list_entry "$(basename $(canonicalise ${executable} ) )" ""
+ elif [[ -e "${executable}" ]] ; then
+ write_kv_list_entry "(not a symlink: ${executable})" ""
+ else
+ write_kv_list_entry "(unset)" ""
+ fi
+}
+
+### list action ###
+
+describe_list() {
+ echo "List available versions for the specific gem"
+}
+
+do_list() {
+ if [[ "x${1}" == "x" ]]; then
+ die -q "Usage error: a gem name is required."
+ fi
+
+ local executables=( $( find_executables ${1} ) )
+ local executable="${ROOT}/usr/bin/${executables[0]}"
+
+ # Find all the targets. Basically this means all the versions of
+ # the gem that are installed.
+ local i targets
+ targets=( $(find_targets ${1}) )
+ if [[ -n ${targets[@]} ]] ; then
+ for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do
+ [[ ${targets[${i}]} = \
+ $(basename $(canonicalise ${executable}) ) ]] &&
+ targets[${i}]="${targets[${i}]} $(highlight '*')"
+ done
+ write_list_start "Available ${1} versions:"
+ write_numbered_list "${targets[@]}"
+ else
+ write_kv_list_entry "(none found)" ""
+ fi
+}
+
+### set action ###
+
+describe_set() {
+ echo "Set a new version for the specific gem"
+}
+
+describe_set_options() {
+ echo "target : Target name or number (from 'list' action)"
+}
+
+describe_set_parameters() {
+ echo "<target>"
+}
+
+do_set() {
+ if [[ $# != 2 ]]; then
+ die -q "Usage error: a gem name and a new setting are required."
+ fi
+
+ local gem=${1}
+ local version=${2}
+
+ local executables=( $( find_executables ${gem} ) )
+ local executable="${ROOT}/usr/bin/${executables[0]}"
+
+ if [[ -z ${version} ]] ; then
+ die -q "You didn't give me a version name"
+ elif [[ -L "${executable}" ]] ; then
+ if ! remove_symlinks ${gem} ; then
+ die -q "Can't remove existing ${executable} binary"
+ elif ! set_symlinks ${gem} "${version}" ; then
+ die -q "Can't set new ${executable} binary"
+ fi
+ elif [[ -e "${executable}" ]] ; then
+ write_warning_msg "Can't set a new ${executable} provider. There's a file in the way at ${executable}. You can try removing it manually, and then re-running this command."
+ else
+ set_symlinks ${gem} ${version} || die -q "Wasn't able to set a new provider"
+ fi
+}
+
+### update action ###
+
+describe_update() {
+ echo "Updates the symlink(s) to the latest version available"
+}
+
+do_update() {
+ # Only set a symlink if there are any version of rails present
+ local target=1
+ local targets=( $(find_targets ) )
+
+ if [[ -z ${targets[@]} ]] ; then
+ remove_symlinks
+ fi
+
+ target=${targets[$(( ${target} - 1 ))]}
+ if [[ -f "${ROOT}/usr/bin/${target}" ]] ; then
+ set_symlink_default
+ fi
+
+ do_show
+}
+
+# vim: set ft=eselect :
+