scripts/utility in rvm-0.1.47 vs scripts/utility in rvm-1.0.0

- old
+ new

@@ -3,11 +3,11 @@ __rvm_setup() { # ZSH has 1 based array indexing, bash has 0 based. if [[ -n "$ZSH_VERSION" ]] ; then __shell_array_start=1 # Set clobber for zsh users, for compatibility with bash's append operator ( >> file ) behavior - setopt | grep -qs '^noclobber$' + setopt | \grep -qs '^noclobber$' rvm_zsh_clobber=$? setopt clobber else __shell_array_start=0 fi ; export __shell_array_start @@ -86,16 +86,16 @@ fi fi unset key value variable } -is_a_function() { type $1 | head -n 1 | grep -q "function" ; } +is_a_function() { type $1 | head -n 1 | \grep -q "function" ; } __rvm_quote_args() { local quoted_string="" for quoted_argument in "$@"; do - if printf "%s" "$quoted_argument" | grep -vq "^[[:alnum:]]$"; then + if printf "%s" "$quoted_argument" | \grep -vq "^[[:alnum:]]$"; then quoted_string="$quoted_string '$(printf "%s" "$quoted_argument" | sed "s/'/\'\\\'\'/g")'" else quoted_string="$quoted_string $quoted_argument" fi done @@ -158,11 +158,11 @@ export PATH } # Clean all rvm items out of the current working path. __rvm_remove_rvm_from_path() { - PATH=$(echo $PATH | \tr -s ':' '\n' | grep -v "\.rvm" | \tr -s '\n' ':' | sed 's#:$##') + PATH=$(echo $PATH | \tr -s ':' '\n' | \grep -v "\.rvm" | \tr -s '\n' ':' | sed 's#:$##') export PATH } # Run a specified command and log it. __rvm_run() { @@ -303,11 +303,11 @@ } __rvm_load_rvmrc() { [[ -z "$rvm_ignore_rvmrc" ]] && return for rvmrc in /etc/rvmrc $HOME/.rvmrc ; do if [[ -f "$rvmrc" ]] ; then - if grep -q '^\s*rvm .*$' $rvmrc ; then + if \grep -q '^\s*rvm .*$' $rvmrc ; then $rvm_scripts_path/log "error" "$rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc" return 1 else source "$rvmrc" fi @@ -420,11 +420,11 @@ rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean_path - if echo "$PATH" | grep -q 'rvm\/bin:' ; then + if echo "$PATH" | \grep -q 'rvm\/bin:' ; then PATH="${rvm_bin_path}:$PATH" export PATH fi \mkdir -p "$rvm_src_path" "$rvm_bin_path" "$rvm_archives_path" "$rvm_gems_path" "$rvm_tmp_path" "$rvm_repo_path" @@ -624,11 +624,11 @@ __rvm_strip() { sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:]]\{1,\}/ /g' } __rvm_using_gemset_globalcache() { - $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" | grep -q '^true$' + $rvm_scripts_path/db "$rvm_config_path/user" "use_gemset_globalcache" | \grep -q '^true$' } __rvm_current_gemcache_dir() { if __rvm_using_gemset_globalcache; then echo "$rvm_gems_cache_path" @@ -656,10 +656,122 @@ else rvm use "$1" >/dev/null 2>&1 fi } +__rvm_md5_for() { + if command -v md5 > /dev/null; then + echo "$1" | md5 + else + echo "$1" | md5sum | awk '{print $1}' + fi +} + +__rvm_rvmrc_key() { + __rvm_md5_for "$1" +} + +__rvm_reset_rvmrc_trust() { + touch "$rvm_config_path/rvmrcs" + $rvm_scripts_path/db "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "delete" >/dev/null 2>&1 +} + +__rvm_trust_rvmrc() { + touch "$rvm_config_path/rvmrcs" + __rvm_reset_rvmrc_trust "$1" + $rvm_scripts_path/db "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "1" >/dev/null 2>&1 +} + +__rvm_untrust_rvmrc() { + touch "$rvm_config_path/rvmrcs" + __rvm_reset_rvmrc_trust "$1" + $rvm_scripts_path/db "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "0" >/dev/null 2>&1 +} + +__rvm_rvmrc_stored_trust() { + touch "$rvm_config_path/rvmrcs" + $rvm_scripts_path/db "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" +} + +__rvm_rvmrc_tools() { + local rvmrc_action="$1" + [[ $# -gt 0 ]] && shift + local rvmrc_path="$(builtin cd "${1:-$PWD}" >/dev/null 2>&1; pwd)/.rvmrc" + case "$rvmrc_action" in + reset) + __rvm_reset_rvmrc_trust "$rvmrc_path" + echo "Reset trust for $rvmrc_path" + ;; + trust) + __rvm_trust_rvmrc "$rvmrc_path" + echo "Marked $rvmrc_path as trusted" + ;; + untrust) + __rvm_untrust_rvmrc "$rvmrc_path" + echo "Marked $rvmrc_path as untrusted" + ;; + trusted) + local trusted_value="$(__rvm_rvmrc_stored_trust "$rvmrc_path")" + if [[ "$trusted_value" = "1" ]]; then + echo "The rvmrc at '$rvmrc_path' is currently trusted." + elif [[ "$trusted_value" = "0" ]]; then + echo "The rvmrc at '$rvmrc_path' is currently untrusted." + else + echo "The trustiworthiness of '$rvmrc_path' is currently unknown." + fi + ;; + load) + rvm_trust_rvmrcs=1 __rvm_project_rvmrc "$(dirname "$rvmrc_path")" + ;; + *) + echo "Usage: rvm rvmrc {trust,untrust,trusted,load,reset}" + return 1 + ;; + esac +} + +__rvm_check_rvmrc_trustworthiness() { + # Trust when they have the flag... of doom! + [[ -z "$1" || "$rvm_trust_rvmrcs" = "1" ]] && return + value="$(__rvm_rvmrc_stored_trust "$1")" + if [[ -z "$value" ]] ; then + __rvm_ask_to_trust "$1" + else + [[ "$value" = "1" ]] + fi +} + +__rvm_ask_to_trust() { + echo "Changing into a directory with an untrusted .rvmrc" + echo "Do you wish to trust the rvmrc in this directory? It contains:" + echo "---" + echo "" + cat "$1" + echo "" + echo "---" + echo "So, do you wish to trust it? (y for yes, n for no)" + local trusted="" + while [[ -z "$trusted" ]] ; do + printf ">> " + read -r value + value="$(echo "$value" | tr '[[:upper:]]' '[[:lower:]]' | __rvm_strip)" + if [[ "$value" = "y"* ]]; then + trusted=1 + elif [[ "$value" = "n"* ]]; then + trusted=0 + fi + done + unset value + if [[ "$trusted" == "1" ]] ; then + __rvm_trust_rvmrc "$1" + return 0 + else + __rvm_untrust_rvmrc "$1" + return 1 + fi +} + # Checks the rvmrc for the given directory. Note that if # argument is passed, it will be used instead of pwd. __rvm_project_rvmrc() { local cwd # Get the first argument or the pwd. @@ -675,13 +787,15 @@ fi break else if [[ -f "$cwd/.rvmrc" ]] ; then if [[ "$rvm_rvmrc_cwd" != "$cwd" ]] ; then - rvm_previous_environment="$(__rvm_environment_identifier)" - rvm_rvmrc_cwd="$cwd" - source "$cwd/.rvmrc" + if __rvm_check_rvmrc_trustworthiness "$cwd/.rvmrc" ; then + rvm_previous_environment="$(__rvm_environment_identifier)" + rvm_rvmrc_cwd="$cwd" + source "$cwd/.rvmrc" + fi fi break else cwd="$(dirname "$cwd")" fi @@ -694,60 +808,62 @@ local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")" local rvm_install_record_file="$rvm_config_path/installs" local rvm_install_command="$(echo "$recorded_ruby_name $rvm_install_arguments" | __rvm_strip)" \touch "$rvm_install_record_file" \rm -f "$rvm_install_record_file.tmp" - cat "$rvm_install_record_file" | grep -v "^$recorded_ruby_name " > "$rvm_install_record_file.tmp" + cat "$rvm_install_record_file" | \grep -v "^$recorded_ruby_name " > "$rvm_install_record_file.tmp" echo "$rvm_install_command" >> "$rvm_install_record_file.tmp" \rm -f "$rvm_install_record_file" mv "$rvm_install_record_file.tmp" "$rvm_install_record_file" } __rvm_remove_install_record() { local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")" local rvm_install_record_file="$rvm_config_path/installs" if [[ -s "$rvm_install_record_file" ]]; then mv "$rvm_install_record_file" "$rvm_install_record_file.tmp" - cat "$rvm_install_record_file.tmp" | grep -v "^$recorded_ruby_name " > "$rvm_install_record_file" + cat "$rvm_install_record_file.tmp" | \grep -v "^$recorded_ruby_name " > "$rvm_install_record_file" \rm -f "$rvm_install_record_file.tmp" fi } __rvm_recorded_install_command() { local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1" | awk -F"$rvm_gemset_separator" '{print $1}')" [[ -z "$recorded_ruby_name" ]] && return 1 local recorded_ruby_match="^$recorded_ruby_name " - if [[ -s "$rvm_config_path/installs" ]] && grep -q "$recorded_ruby_match" "$rvm_config_path/installs" ; then - cat "$rvm_config_path/installs" | grep "$recorded_ruby_match" | head -n1 + if [[ -s "$rvm_config_path/installs" ]] && \grep -q "$recorded_ruby_match" "$rvm_config_path/installs" ; then + cat "$rvm_config_path/installs" | \grep "$recorded_ruby_match" | head -n1 else return 1 fi } __rvm_environment_identifier() { ruby_string="$(command -v ruby)" - if [ -n "$ruby_string" ] && echo "$ruby_string" | grep -q -F "$rvm_rubies_path"; then + if [ -n "$ruby_string" ] && echo "$ruby_string" | \grep -q -F "$rvm_rubies_path"; then echo "$GEM_HOME" | xargs basename else echo "system" fi unset ruby_string } __rvm_expand_ruby_string() { if [[ -z "$1" || "$1" = "all" ]]; then $rvm_scripts_path/list strings | tr ' ' "\n" | __rvm_strip - elif [[ "$1" = "all" || "$1" == "all-gemsets" ]]; then + elif [[ "$1" = "all-gemsets" ]]; then $rvm_scripts_path/list gemsets strings | __rvm_strip - elif [[ "$1" == "default-with-rvmrc" || "$1" == "rvmrc" ]]; then + elif [[ "$1" = "default-with-rvmrc" || "$1" = "rvmrc" ]]; then $rvm_scripts_path/tools path-identifier "$(pwd)" - elif [[ "$1" == "all-rubies" || "$1" == "rubies" ]]; then + elif [[ "$1" == "all-rubies" || "$1" = "rubies" ]]; then $rvm_scripts_path/list rubies strings | __rvm_strip - elif [[ "$1" == "current" || "$1" == "gemsets" ]]; then + elif [[ "$1" == "current-ruby" || "$1" = "gemsets" ]]; then local current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')" rvm_silence_logging=1 $rvm_scripts_path/gemsets list | sed "s/^/$current_ruby$rvm_gemset_separator/" | __rvm_strip - elif [[ "$1" == "aliases" ]]; then + elif [[ "$1" = "current" ]]; then + __rvm_environment_identifier + elif [[ "$1" = "aliases" ]]; then cat "$rvm_config_path/alias" | awk -F= '{print $1}' | __rvm_strip else echo "$1" | tr "," "\n" | __rvm_strip fi -} +} \ No newline at end of file