#!/usr/bin/env bash

rvm_load_rvm=0

source "scripts/rvm"
source "scripts/functions/installer"

#
# RVM Installer
#
determine_install_path
determine_install_or_upgrade
install_setup

# Parse RVM Installer CLI arguments.
while (( $# > 0 ))
do
  token="$1"
  shift

  case "$token" in
    --auto)
      rvm_auto_flag=1
      ;;
    --prefix)
      rvm_prefix="$1"
      shift
      ;;
    --path)
      rvm_path="$1"
      shift
      ;;
    --version)
      rvm_path="${PWD%%+(\/)}"
      __rvm_version
      unset rvm_path
      exit
      ;;
    --debug)
      export rvm_debug_flag=1
      set -o verbose
      ;;
    --trace)
      set -o xtrace
      export rvm_trace_flag=1
      echo "$@"
      env | grep '^rvm_'
      export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
      ;;
    --help)
      install_usage
      exit 0
      ;;
    *)
      echo "Unrecognized option: $token"
      install_usage
      exit 1
      ;;
  esac
done
export rvm_prefix rvm_path rvm_debug_flag rvm_trace_flag

create_install_paths

print_install_header

configure_installation

cleanse_old_entities

install_rvm_files

ensure_scripts_are_executable

setup_configuration_files

install_binscripts

automatic_profile_setup

install_gemsets

install_patchsets

cleanse_old_environments

migrate_old_gemsets

migrate_defaults

correct_binary_permissions

install_man_pages

root_canal

setup_rvmrc

setup_user_profile

cleanup_tmp_files

display_notes

display_thank_you

exit 0
