diff options
author | 2007-09-01 03:10:35 +0000 | |
---|---|---|
committer | 2007-09-01 03:10:35 +0000 | |
commit | 0163951ef56041d086a4d5dd4bb9269b61afcbd4 (patch) | |
tree | 6a283029e935d401f1ade80980a72a7591b46703 | |
parent | Checkin... (diff) | |
download | nichoj-0163951ef56041d086a4d5dd4bb9269b61afcbd4.tar.gz nichoj-0163951ef56041d086a4d5dd4bb9269b61afcbd4.tar.bz2 nichoj-0163951ef56041d086a4d5dd4bb9269b61afcbd4.zip |
Initial version.
svn path=/; revision=106
-rw-r--r-- | projects/eselect-rails/trunk/rails.eselect | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/projects/eselect-rails/trunk/rails.eselect b/projects/eselect-rails/trunk/rails.eselect new file mode 100644 index 0000000..89b1f37 --- /dev/null +++ b/projects/eselect-rails/trunk/rails.eselect @@ -0,0 +1,194 @@ +# 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 Ruby on Rails versions" +MAINTAINER="graaff@gentoo.org" +SVN_DATE='$Date: 2006-03-30 23:11:55 +0200 (gio, 30 mar 2006) $' +VERSION=$(svn_date_to_version "${SVN_DATE}" ) + +RAILS="${ROOT}/usr/bin/rails" + +# find a list of rails symlink targets, best first +find_targets() { + for f in \ + ${RAILS}-1.2* \ + ${RAILS}-1.1* \ + ; do + if [[ -f ${f} ]] ; then + echo $(basename ${f} ) + fi + done +} + +# try to remove the rails symlink +remove_symlink() { + rm "${RAILS}" &>/dev/null +} + +# determine the version +get_version() { + local basename="$(basename $(canonicalise ${ROOT}/usr/bin/rails ) )" + local version=${basename#*-} + echo ${version} +} + +# set the rails symlink +set_symlink() { + target=${1} + if is_number "${target}" && [[ ${target} -ge 1 ]] ; then + targets=( $(find_targets ) ) + target=${targets[$(( ${target} - 1 ))]} + fi + if [[ -f "${ROOT}/usr/bin/${target}" ]] ; then + remove_symlink + ln -s "${ROOT}/usr/bin/${target}" "${RAILS}" || \ + die "Couldn't set ${target} symlink" + else + die -q "Target \"${1}\" doesn't appear to be valid!" + fi +} + +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_symlink + ln -s ${target} ${RAILS} + else + die -q "No providers available for slot ${slot}" + fi +} + +### show action ### + +describe_show() { + echo "Manage Ruby on Rails versions" +} + +do_show() { + if [[ ${#} -gt 0 ]]; then + die -q "Usage error. No parameters allowed" + fi + + write_list_start "Current Ruby on Rails version:" + if [[ -L "${ROOT}/usr/bin/rails" ]] ; then + write_kv_list_entry "$(basename $(canonicalise ${ROOT}/usr/bin/rails ) )" "" + elif [[ -e "${ROOT}/usr/bin/rails" ]] ; then + write_kv_list_entry "(not a symlink)" "" + else + write_kv_list_entry "(unset)" "" + fi +} + +### list action ### + +describe_list() { + echo "List available Ruby on Rails versions" +} + +do_list() { + if [[ ${#} -gt 0 ]]; then + die -q "Usage error: no parameters allowed" + fi + + local i targets + targets=( $(find_targets ) ) + if [[ -n ${targets[@]} ]] ; then + for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do + [[ ${targets[${i}]} = \ + $(basename $(canonicalise ${ROOT}/usr/bin/rails) ) ]] && + targets[${i}]="${targets[${i}]} $(highlight '*')" + + done + write_list_start "Available Ruby on Rails versions:" + write_numbered_list "${targets[@]}" + else + write_kv_list_entry "(none found)" "" + fi +} + +### set action ### + +describe_set() { + echo "Set a new Ruby on Rails version" +} + +describe_set_options() { + echo "target : Target name or number (from 'list' action)" +} + +describe_set_parameters() { + echo "<target>" +} + +do_set() { + if [[ $# -gt 1 ]]; then + die -q "Too many parameters. Expected only 1." + fi + local version=${1} + if [[ -z ${version} ]] ; then + die -q "You didn't give me a version name" + elif [[ -L "${ROOT}/usr/bin/rails" ]] ; then + if ! remove_symlink ; then + die -q "Can't remove existing cap binary" + elif ! set_symlink "${1}" ; then + die -q "Can't set new cap binary" + fi + elif [[ -e "${ROOT}/usr/bin/rails" ]] ; then + write_warning_msg "Can't set a new rails provider. There's a file in the way at ${ROOT}/usr/bin/rails. You can try removing it manually, and then re-running this command." + else + set_symlink ${version} || die -q "Wasn't able to set a new provider" + fi +} + +### update action ### + +describe_update() { + echo "Helper for the rails ebuild to manage upgrades. If current implementation is in the given slot, then the implementation will be updated to the latest in that slot. If the current implementation wasn't in the given slot and doesn't exist anymore, then the most recent release will be used. If no implementation is selected, the most recent release will be used." +} + +describe_update_options() { + echo "slot: the slot to update" +} + +describe_update_parameters() { + echo "<slot>" +} + + +do_update() { + if [[ ${#} -ne 1 ]]; then + die -q "Usage error: requires a slot to update" + fi + + local slot=${1} + + # symlink exists + if [[ -L "${RAILS}" ]] ; then + # update it if it's the same slot + if [[ $(get_version) =~ ${slot} ]]; then + set_symlink_by_slot ${slot} + + # set to highest if it's set to some slot that isn't around anymore + elif [[ ! -f $(canonicalise ${RAILS}) ]]; then + set_symlink_default + # ignore + else + write_warning_msg "Current implementation, $(get_version), is not in slot ${slot}. Ignoring." + fi + # if it's a file, just warn about it being in the way + elif [[ -e ${RAILS} ]]; then + write_warning_msg "Can't set a new rails provider. There's a file in the way at ${RAILS}. You can try removing it manually, and then re-running this command." + # nothing set, so set to 1st, which is highest available + else + set_symlink_default + fi +} + +# vim: set ft=eselect : + |