Permalink
Browse files

Initial SysAdmin root level support -- specficially targeted to hosti…

…ng environments.
  • Loading branch information...
1 parent 989979d commit cd5d0ede273e9fcbdf6645bca778691dc78d8080 @wayneeseguin wayneeseguin committed Nov 5, 2009
View
2 Rakefile
@@ -39,7 +39,7 @@ begin
gemspec.date = Time.now.strftime("%Y-%m-%d")
gemspec.description = "Manages Ruby interpreter installations and switching between them."
gemspec.platform = Gem::Platform::RUBY
- gemspec.files = ["install", "README", "LICENCE", "rvm.gemspec", "bash/*", "scripts/*", "examples/*", "config/*", Dir::glob("lib/**/**")].flatten
+ gemspec.files = ["install", "README", "LICENCE", "rvm.gemspec", "bash/*", "binscripts/*", "scripts/*", "examples/*", "config/*", Dir::glob("lib/**/**")].flatten
gemspec.executables = Dir::glob("bin/rvm-*").map{ |script| File::basename script }
gemspec.require_path = "lib"
gemspec.has_rdoc = File::exist?("doc")
View
2 bin/rvm-install
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
# Hot potato!!! Bash it!
-exec "bash -l -c 'cd #{File.dirname(File.dirname(__FILE__))} && ./install #{ARGV.join(' ')} && source ~/.rvm/scripts/rvm'"
+exec "bash -l -c 'cd #{File.dirname(File.dirname(__FILE__))} && ./install #{ARGV.join(' ')}'"
View
0 scripts/gemsync → binscripts/gemsync
File renamed without changes.
View
0 scripts/rvm-prompt → binscripts/rvm-prompt
File renamed without changes.
View
2 lib/VERSION.yml
@@ -1,4 +1,4 @@
---
:major: 0
:minor: 0
-:patch: 74
+:patch: 75
View
10 scripts/cli
@@ -1,17 +1,17 @@
#!/bin/bash
-function __rvm_meta {
+__rvm_meta() {
rvm_meta_author="Wayne E. Seguin"
rvm_meta_author_email="wayneeseguin@gmail.com"
rvm_meta_website="http://rvm.beginrescueend.com/"
rvm_meta_version="${rvm_version}"
}
-function __rvm_version { __rvm_meta ; echo "rvm ${rvm_meta_version} by ${rvm_meta_author} (${rvm_meta_author_email}) [${rvm_meta_website}]" ; }
+__rvm_version() { __rvm_meta ; echo "rvm ${rvm_meta_version} by ${rvm_meta_author} (${rvm_meta_author_email}) [${rvm_meta_website}]" ; }
-function __rvm_usage { cat "${rvm_path:-$HOME/.rvm}/README" | ${PAGER:-less} ; }
+__rvm_usage() { cat "${rvm_path:-$HOME/.rvm}/README" | ${PAGER:-less} ; }
-function __rvm_parse_args {
+__rvm_parse_args() {
if [[ ! -z "$(echo "$*" | awk '/trace/')" ]] ; then echo "$*" ; fi
while [[ $# -gt 0 ]] ; do
@@ -352,7 +352,7 @@ function __rvm_parse_args {
if [[ ! -z "$rvm_error_message" ]] ; then __rvm_pushpop ; return 1 ; fi
}
-function rvm {
+rvm() {
trap '__rvm_cleanup_variables ; rm -rf "/tmp/rvm/$$" >/dev/null 2>&1' 0 1 2 3 15
View
1 scripts/completion
@@ -156,7 +156,6 @@ function _rvm {
usage|help) __rvm_usage ; result=$? ;;
bench|benchmark) __rvm_benchmark ; result=$? ;;
rubydo|rakedo|gemdo) __rvm_do ; result=$? ;;
- reload) source ~/.rvm/scripts/rvm ; result=$? ;;
gemsync)
result=0
View
112 scripts/install
@@ -1,79 +1,68 @@
#!/bin/bash
-user="$(whoami)"
-if [[ "root" = "$user" ]] ; then
- echo -e "$(tput setaf 1) <e> root user support is not yet implemented.$(tput sgr0)"
- exit 1
+rc_files="$HOME/.bash_profile $HOME/.bashrc $HOME/.zshrc"
+if [[ "root" = "$(whoami)" ]] ; then
+ rvm_path=/usr/local/rvm
+ rc_files="$rc_files /etc/profile /etc/zshenv"
+else
+ rvm_path=$HOME/.rvm
fi
+#
+# Setup
+#
item="$(tput setaf 2)* $(tput sgr0)"
question="\n$(tput setaf 2)<?>$(tput sgr0)"
cwd=$(pwd)
source_dir="${source_dir:-"$(dirname $0 | xargs dirname)"}"
if [[ ! -d "$source_dir" ]] ; then unset source_dir ; fi
source_dir="${source_dir:-$cwd}"
-rvm_path=~/.rvm
# State what is required to use rvm
echo -e "\n$(tput setaf 2)rvm$(tput sgr0)\n\n shell scripts that allows a user to manage multiple ruby versions in their own account."
-echo -e "\n Installing rvm to ~/.rvm/ ..."
+echo -e "\n Installing rvm to $rvm_path ..."
for dir_name in src scripts bin log archives config gems examples ; do
- mkdir -p $rvm_path/$dir_name
+ mkdir -p "$rvm_path/$dir_name"
done
+cp -f "$source_dir/README" "$rvm_path/"
+#
+# Scripts
+#
rm -rf $rvm_path/scripts # Clear the old scripts directory so that the old style rvm- scripts are cleared out.
for dir_name in config scripts examples lib ; do
mkdir -p "$rvm_path/$dir_name"
cp -Rf "$source_dir/$dir_name" "$rvm_path"
done ; unset dir_name
-for file_name in rvm-prompt gemsync ; do
- mv $rvm_path/scripts/$file_name $rvm_path/bin/
- chmod +x $rvm_path/bin/$file_name
-done ; unset file_name
-
-cp -f $source_dir/README $rvm_path/
+#
+# Bin Scripts
+#
+cp -Rf "$source_dir/binscripts" $rvm_path/bin
+chmod +x $rvm_path/bin/*
+ln -nfs $rvm_path/scripts/rvm $rvm_path/bin/rvm
+#
+# RC Files
+#
if [[ -z "$rvm_loaded_flag" ]] ; then
- for rcfile in .bash_profile .bashrc .zshrc ; do
- if [[ ! -e ~/$rcfile ]] ; then touch ~/$rcfile ; fi
- if [[ -z "$(awk '/\.rvm\/scripts\/rvm/' ~/$rcfile)" ]] ; then
- echo "Adding 'if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi' to your ~/$rcfile."
- echo -e "\n# rvm-install added line:\nif [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi\n" >> ~/$rcfile
+ for rcfile in $(echo $rc_files) ; do
+ if [[ ! -f $rcfile ]] ; then touch $rcfile ; fi
+ if [[ -z "$(awk '/\.rvm\/scripts\/rvm/' $rcfile)" ]] ; then
+ echo " Adding 'if [[ -s $rvm_path/scripts/rvm ]] ; then source $rvm_path/scripts/rvm ; fi' to $rcfile."
+ echo -e "\n# rvm-install added line:\nif [[ -s $rvm_path/scripts/rvm ]] ; then source $rvm_path/scripts/rvm ; fi\n" >> $rcfile
fi
done
fi
-echo -e "\n Ensuring that rvm script location in $file is scripts/rvm not bin/rvm for: ~/.bash_profile, ~/.bashrc, ~/.zshrc..."
-for file in ~/.bash_profile ~/.bashrc ~/.zshrc ; do
- if [[ -s $file ]] ; then
- if [[ -L $file ]] ; then # If the file is a symlink,
- actual_file="$(readlink $file)" # read the link target so we can preserve it.
- else
- actual_file="$file"
- fi
-
- grep 'rvm\/bin\/rvm' "$actual_file" > /dev/null
- if [[ $? -eq 0 ]] ; then
- sed -i.orig 's#rvm/bin/rvm #rvm/scripts/rvm #g' "$actual_file"
- rm -f "$actual_file.orig"
- fi
-
- if [[ -f ~/.profile ]] ; then
- grep '.profile' "$actual_file" > /dev/null
- if [[ $? -gt 0 ]] ; then
- profile=~/.profile
- echo -e "\nsource ${profile}" >> "$actual_file"
- fi
- fi
- fi
-done
-
-if [[ -f ~/.rvm/bin/rvm ]] ; then
- echo -e "\n Removing old rvm file from ~/.rvm/bin/rvm..."
- rm -f ~/.rvm/bin/rvm
+if [[ "root" = "$(whoami)" ]] ; then
+ ln -nfs $rvm_path/scripts/rvm /usr/local/bin/rvm
+ chmod +x /usr/local/bin/rvm
fi
+#
+# System Checks
+#
system="$(uname)"
echo -e "\n $(tput setaf 3)NOTES: $(tput sgr0)\n"
if [[ "Linux" = "$system" ]] ; then
@@ -83,36 +72,36 @@ if [[ "Linux" = "$system" ]] ; then
rvm_yum_binary="$(which yum 2> /dev/null)"
if [[ ! -z "$rvm_apt_get_binary" ]] ; then
- echo -e " $item For jRuby (if you wish to use it) you will need:"
- echo -e " $ sudo aptitude install sun-java6-bin sun-java6-jre sun-java6-jdk"
- echo -e " $item For ree (if you wish to use it) you will need:"
- echo -e " $ sudo aptitude install libreadline5-dev libssl-dev bison"
- echo -e " $item For 1.9.X (if you wish to use it) we additionally recommend:"
- echo -e " $ sudo aptitude install libxml2-dev"
+ echo -e " $item For jRuby (if you wish to use it) you will need:"
+ echo -e " $ sudo aptitude install sun-java6-bin sun-java6-jre sun-java6-jdk"
+ echo -e " $item For ree (if you wish to use it) you will need:"
+ echo -e " $ sudo aptitude install libreadline5-dev libssl-dev bison"
+ echo -e " $item For 1.9.X (if you wish to use it) we additionally recommend:"
+ echo -e " $ sudo aptitude install libxml2-dev"
elif [[ ! -z "$rvm_emerge_binary" ]] ; then
- echo -e " $item For jRuby (if you wish to use it) you will need:"
- echo -e " $ sudo emerge dev-java/sun-jdk dev-java/sun-jre-bin"
+ echo -e " $item For jRuby (if you wish to use it) you will need:"
+ echo -e " $ sudo emerge dev-java/sun-jdk dev-java/sun-jre-bin"
elif [[ ! -z "$rvm_pacman_binary" ]] ; then
- echo -e " $item For jRuby (if you wish to use it) you will need:"
- echo -e " $ sudo pacman -Sy jdk jre"
+ echo -e " $item For jRuby (if you wish to use it) you will need:"
+ echo -e " $ sudo pacman -Sy jdk jre"
elif [[ ! -z "$rvm_yum_binary" ]] ; then
- echo -e " $item For ree (if you wish to use it) you will need:"
- echo -e " $ yum install -y rpm-build gcc gcc-c++ redhat-rpm-config ; then download and rpmbuild and install the sdk, Have fun..."
+ echo -e " $item For ree (if you wish to use it) you will need:"
+ echo -e " $ yum install -y rpm-build gcc gcc-c++ redhat-rpm-config ; then download and rpmbuild and install the sdk, Have fun..."
else
- echo -e " $item For jRuby (if you wish to use it) you will need:"
- echo -e " The SUN java runtime environment and development kit."
+ echo -e " $item For jRuby (if you wish to use it) you will need:"
+ echo -e " The SUN java runtime environment and development kit."
fi
elif [[ "Darwin" = "$system" ]] ; then
echo -e " $item Be sure that you have XCode Tools installed in order to use rvm."
echo -e " $item If you intend on installing MacRuby you must install LLVM first."
fi
echo -e " $item In order to use rvm the following line must occur in your shell's loading files, after all path/variable settings.:"
-echo -e " $item if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi"
+echo -e " $item if [[ -s $rvm_path/scripts/rvm ]] ; then source $rvm_path/scripts/rvm ; fi"
echo -e " $item CLOSE THIS SHELL AND OPEN A NEW ONE in order to use rvm."
echo -e "\n \033[0;33mRTFM: $(tput sgr0) http://rvm.beginrescueend.com/ \n"
@@ -123,3 +112,4 @@ source $rvm_path/scripts/rvm
rvm -v
echo
+exit 0
View
19 scripts/rvm
@@ -6,8 +6,17 @@
# http://gitub.com/wayneeseguin/rvm
#
-if [[ -s ~/.rvmrc ]] ; then source ~/.rvmrc ; fi
-eval rvm_path="${rvm_path:-~/.rvm}"
+if [[ "root" = "$(whoami)" ]] ; then
+ rvm_prefix_path="${rvm_prefix_path:-/usr/local/}"
+else
+ rvm_prefix_path="${rvm_prefix_path:-"$HOME/."}"
+fi
+
+if [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '.' ]] || [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '/' ]] ; then
+ rvm_path="${rvm_prefix_path}rvm"
+else
+ rvm_path="${rvm_prefix_path}/rvm"
+fi
source $rvm_path/scripts/color
source $rvm_path/scripts/utility
@@ -17,9 +26,13 @@ source $rvm_path/scripts/cli
source $rvm_path/scripts/gems
rvm_loaded_flag=1 ; export rvm_loaded_flag
+
rvm_version="$(cat "${rvm_path}/lib/VERSION.yml" | tail -n 3 | sed 's/^.*: //g' | tr "\n" '.' | sed 's/\.$//')" ; export rvm_version
alias rvm-restart="source \"${rvm_path}/scripts/rvm\""
-if [[ -f "$rvm_path/default" ]] ; then source $rvm_path/default ; fi
+if [[ -f "$rvm_path/default" ]] ; then source "$rvm_path/default" ; fi
+
+# Ok now we determine if we were called or sourced... under assumption of course ;)
+if [[ $# -gt 0 ]] ; then rvm "$*" ; fi
View
12 scripts/selector
@@ -192,6 +192,12 @@ __rvm_use() {
fi
fi
+ if [[ "root" = "$(whoami)" ]] ; then
+ for binary in erb gem irb rake rdoc ri ruby testrb ; do
+ rm -f /usr/local/bin/$binary
+ done
+ fi
+
else
GEM_HOME=$rvm_ruby_gem_home ; export GEM_HOME
GEM_PATH=$rvm_ruby_gem_home ; export GEM_PATH
@@ -213,6 +219,12 @@ __rvm_use() {
PATH=$rvm_bin_path:$PATH ; export PATH
PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:$rvm_path/bin:$PATH ; export PATH
+ if [[ "root" = "$(whoami)" ]] ; then
+ for binary in erb gem irb rake rdoc ri ruby testrb ; do
+ rm -f /usr/local/bin/$binary
+ ln -nfs $rvm_ruby_home/bin/$binary /usr/local/bin/$binary
+ done
+ fi
fi
if [[ ! -z "$rvm_default_flag" ]] && [[ "default" != "$rvm_ruby_interpreter" ]] ; then
View
55 scripts/utility
@@ -47,13 +47,19 @@ __rvm_debug() {
__rvm_log "debug" "/Developer/SDKs/*:$(basename -a /Developer/SDKs/* | tr "\n" ',')"
fi
- for file_name in ~/.bash_profile ~/.bashrc ~/.zshrc ; do
+ for file_name in $(echo $rc_files) ; do
if [[ -s "$file_name" ]] ; then
__rvm_log "debug" "$file_name:\n$(grep 'rvm' $file_name)"
fi
done
- for file_name in $rvm_path/default $rvm_path/system $rvm_path/config/db ~/.rvmrc ~/.gemrc; do
+ if [[ "root" = "$(whoami)" ]] ; then
+ debug_files="$rvm_path/default $rvm_path/system $rvm_path/config/db /etc/rvmrc /etc/gemrc"
+ else
+ debug_files="$rvm_path/default $rvm_path/system $rvm_path/config/db $HOME/.rvmrc $HOME/.gemrc"
+ fi
+
+ for file_name in $(echo $debug_files); do
if [[ -f "$file_name" ]] && [[ -s "$file_name" ]] ; then
__rvm_log "debug" "$file_name (filtered):\n$(cat $file_name | awk '!/assword|_key/')\n"
fi
@@ -131,9 +137,9 @@ __rvm_unset_ruby_variables() {
unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_string rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag rvm_ruby_configure_flags rvm_ruby_configure
}
-# TODO: root user loadng of /etc/rvmrc
__rvm_load_rvmrc() {
- if [[ -s ~/.rvmrc ]] ; then source ~/.rvmrc ; fi
+ if [[ -f /etc/rvmrc ]] ; then source /etc/rvmrc ; fi
+ if [[ -f $HOME/.rvmrc ]] ; then source $HOME/.rvmrc ; fi
}
__rvm_bin_scripts() {
@@ -325,7 +331,7 @@ __rvm_gemdup() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi
__rvm_log "debug" "$rvm_ruby_interpreter"
if [[ "default" = "$rvm_ruby_interpreter" ]] ; then
- # TODO: ~/.rvm/default first, then system user
+ # TODO: $rvm_path/default first, then system user
rvm_source_gem_path="$rvm_system_user_gem_path"
elif [[ "user" = "$rvm_ruby_interpreter" ]] ; then
rvm_source_gem_path="$rvm_system_user_gem_path"
@@ -466,7 +472,7 @@ __rvm_list() {
fi
if [[ -f "$rvm_path/default" ]] && [[ -s $rvm_path/default ]] ; then
- version=$(grep '^MY_RUBY_HOME' ~/.rvm/default | awk -F"'" '{print $2}' | xargs basename)
+ version=$(grep '^MY_RUBY_HOME' $rvm_path/default | awk -F"'" '{print $2}' | xargs basename)
if [[ ! -z "$version" ]] ; then
echo -e "\ndefault:\n"
string=$($rvm_path/$version/bin/ruby -v)
@@ -492,25 +498,21 @@ __rvm_list() {
}
__rvm_initialize() {
- rvm_fetch=$(which curl)
- if [[ $? -ne 0 ]] ; then
- __rvm_log "fail" "rvm requires curl, which does not seem to exist in your path :("
- else
- rvm_fetch="$rvm_fetch -O -L --create-dirs -C - " # -s for silent
- fi
-
# TODO: Sanitize user input, ensure that there is a / a the end...
if [[ "root" = "$(whoami)" ]] ; then
- __rvm_log "fail" "root user support is not yet implemented."
rvm_prefix_path="${rvm_prefix_path:-/usr/local/}"
+ rc_files="/etc/profile /etc/zshenv"
else
rvm_prefix_path="${rvm_prefix_path:-"$HOME/."}"
+ rc_files="$HOME/.bash_profile $HOME/.bashrc $HOME/.zshrc"
fi
+
if [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '.' ]] || [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '/' ]] ; then
rvm_path="${rvm_prefix_path}rvm"
else
rvm_path="${rvm_prefix_path}/rvm"
fi
+
rvm_archives_path="${rvm_archives_path:-"$rvm_path/archives"}"
rvm_src_path="${rvm_src_path:-"$rvm_path/src"}"
rvm_log_path="${rvm_log_path:-"$rvm_path/log"}"
@@ -528,6 +530,14 @@ __rvm_initialize() {
rvm_ruby_require=""
__rvm_clean_path
+
+ rvm_fetch=$(which curl)
+ if [[ $? -ne 0 ]] ; then
+ __rvm_log "fail" "rvm requires curl, which does not seem to exist in your path :("
+ else
+ rvm_fetch="$rvm_fetch -O -L --create-dirs -C - " # -s for silent
+ fi
+
rvm_result=$(echo $PATH | grep 'rvm\/bin:')
if [[ -z "$rvm_result" ]] ; then
PATH=$rvm_bin_path:$PATH ; export PATH
@@ -556,7 +566,7 @@ __rvm_update_rvm() {
fi
else
# TODO: rvm_install_path:
- gem install rvm --no-rdoc --no-ri -q rvm && $(gem env gemdir user)/bin/rvm-install && source ~/.rvm/scripts/rvm
+ gem install rvm --no-rdoc --no-ri -q rvm && $(gem env gemdir user)/bin/rvm-install && source $rvm_path/scripts/rvm
fi
__rvm_pushpop
}
@@ -565,25 +575,16 @@ __rvm_reboot() {
__rvm_log "warn" "Do you wish to reset rvm? ('yes', or 'no')"
read response
if [[ "yes" = "$response" ]] ; then
- cd
+ cd $rvm_path
__rvm_reset
- mv ~/.rvm/archives ~/.archives
+ mv $rvm_path/archives ~/.archives
if [[ "/" = "$rvm_path" ]] ; then
__rvm_log "error" "remove '/' ?!... NO!"
else
if [[ -d "$rvm_path" ]] ; then rm -rf "$rvm_path/" ; fi
fi
gem install rvm --no-rdoc --no-ri -q
- which rvm-install 2> /dev/null
- if [[ $? -gt 0 ]] ; then
- if [[ -x "~/.gem/ruby/1.8/bin/rvm-install" ]] ; then
- ~/.gem/ruby/1.8/bin/rvm-install
- else
- __rvm_log "error" "Could not find an executable rvm-install in your path :("
- fi
- else
- rvm-install
- fi
+ __rvm_update_rvm
source ~/.rvm/scripts/rvm
else
__rvm_log "info" "Carry on then..."

0 comments on commit cd5d0ed

Please sign in to comment.