contrib/install-system-wide in rvm-0.1.45 vs contrib/install-system-wide in rvm-0.1.46

- old
+ new

@@ -1,17 +1,25 @@ #!/usr/bin/env bash +__rvm_system_wide_permissions() { + [[ -z "$1" ]] && return 1 + chown -R root:"$rvm_group_name" "$1" + chmod -R g+w "$1" + [[ -d "$1" ]] && find "$1" -type d | xargs -n1 chmod g+s +} + # Require root to install it. if [[ "$(whoami)" != "root" ]]; then echo "Please rerun this installer as root." >&2 exit 1 -fi - # Check for the presence of git. -if ! command -v git >/dev/null 2>&1 ; then +elif ! command -v git >/dev/null 2>&1 ; then echo "Please ensure git is installed and available in PATH to continue." >&2 exit 1 +elif [[ "$(uname)" != "Linux" ]]; then + echo "The rvm system wide installer is currently Linux only." >&2 + exit 1 fi # Load the rvm config. if [[ -z "$rvm_ignore_rvmrc" ]]; then [[ -s /etc/rvmrc ]] && source /etc/rvmrc @@ -19,65 +27,73 @@ fi rvm_path="${rvm_path:-"/usr/local/rvm"}" export rvm_selfcontained=0 -mkdir -p "$rvm_path/src/" +rvm_group_name="${rvm_group_name:-"rvm"}" +if cat /etc/group | cut -d: -f1 | grep -q "^${rvm_group_name}$"; then + echo "Group exists, proceeding with installation." +else + echo "Creating the group '$rvm_group_name'" + groupadd -f "$rvm_group_name" +fi +echo "Adding $(whoami) the '$rvm_group_name'" +usermod -a -G "$rvm_group_name" "$(whoami)" + +echo "Creating the destination dir and making sure the permissions are correct" +\mkdir -p "$rvm_path" +__rvm_system_wide_permissions "$rvm_path" + +\mkdir -p "$rvm_path/src/" builtin cd "$rvm_path/src" -rm -rf ./rvm/ +\rm -rf ./rvm/ git clone --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git builtin cd rvm echo "Running the install script." bash ./scripts/install "$@" -rvm_group_name="${rvm_group_name:-"rvm"}" +__rvm_system_wide_permissions "$rvm_path" -if cat /etc/group | cut -d: -f1 | grep -q "^${rvm_group_name}$"; then - echo "Group exists, proceeding with installation." -else - echo "Creating the group '$rvm_group_name'" - groupadd -f "$rvm_group_name" -fi -echo "Adding root the '$rvm_group_name'" -usermod -a -G "$rvm_group_name" "$(whoami)" - echo "Setting up group permissions" -for dir in rvm bin share/man; do - chown -R root:"$rvm_group_name" /usr/local/$dir - chmod -R g+w /usr/local/$dir +rvm_parent_dir="$(dirname "$rvm_path")" +for dir in bin share/man; do + __rvm_system_wide_permissions "$rvm_parent_dir/$dir" done; unset dir echo "Generating system wide rvmrc" -rm -f /etc/rvmrc -touch /etc/rvmrc +\rm -f /etc/rvmrc +\touch /etc/rvmrc cat > /etc/rvmrc <<END_OF_RVMRC # Setup default configuration for rvm. -umask g+w -export rvm_selfcontained=0 -export rvm_prefix="/usr/local/" +# If an rvm install exists in the home directory, don't load this.' +if [[ ! -s "\$HOME/.rvm/scripts/rvm" ]]; then + umask g+w + export rvm_selfcontained=0 + export rvm_prefix="$rvm_parent_dir/" +fi END_OF_RVMRC -echo "Generating /usr/local/lib/rvm to load rvm" -rm -f /usr/local/lib/rvm -touch /usr/local/lib/rvm -cat > /usr/local/lib/rvm <<END_OF_RVM_SH +echo "Generating $rvm_parent_dir/lib/rvm to load rvm" +\rm -f "$rvm_parent_dir/lib/rvm" +\touch "$rvm_parent_dir/lib/rvm" +cat > "$rvm_parent_dir/lib/rvm" <<END_OF_RVM_SH # Automatically source rvm if [[ -s "\$HOME/.rvm/scripts/rvm" ]]; then source "\$HOME/.rvm/scripts/rvm" elif [[ -s "/usr/local/rvm/scripts/rvm" ]]; then source "/usr/local/rvm/scripts/rvm" fi END_OF_RVM_SH echo "Correct permissions on rvmrc and the rvm loader" # Finally, ensure the rvmrc is owned by the group. -for file in /etc/rvmrc /usr/local/lib/rvm ; do - chown root:"$rvm_group_name" "$file" - chmod g+w "$file" +for file in /etc/rvmrc "$rvm_parent_dir/lib/rvm" ; do + __rvm_system_wide_permissions "$file" done; unset file -echo "To use, source '/usr/local/lib/rvm' to your shell profile." +echo "RVM is now installed. To use, source '$rvm_parent_dir/lib/rvm' to your shell profile." +unset rvm_parent_dir