#!/usr/bin/env bash usage() { printf " Usage: rvm-install-system-wide [options] Options: --trace - Run turn on bash xtrace while the script runs. --debug - Turn on bash verbose while the script runs. --version X - Install RVM version X --revision X - Install RVM revision X (sha1) --help - Display this usage text. " return 0 } __rvm_system_wide_permissions() { [[ -z "$1" ]] && return 1 chown -R root:"$rvm_group_name" "$1" chmod -R g+w "$1" if [[ -d "$1" ]] ; then find "$1" -type d -print0 | xargs -n1 -0 chmod g+s fi return 0 } __rvm_create_user_group() { [[ -z "$1" ]] && return 1 if \grep -q "$1" /etc/group ; then echo "Group '$1' exists, proceeding with installation." else echo "Creating the group '$1'" case "$os_type" in "OpenBSD") groupadd "$rvm_group_name";; "FreeBSD") pw groupadd -q "$rvm_group_name";; "Linux") groupadd -f "$rvm_group_name";; "Darwin") gid="501" #only gids > 500 show up in user preferences #Find an open gid while true; do name=$(dscl . search /groups PrimaryGroupID $gid | cut -f1 -s) if [ -z "$name" ] ; then break fi gid=$[$gid +1] done #Create the group dscl . -create "/Groups/$rvm_group_name" dscl . -create "/Groups/$rvm_group_name" gid "$gid" ;; esac fi return 0 } __rvm_add_user_to_group() { [[ -z "$1" || -z "$2" ]] && return 1 echo "Adding '$1' to the group '$2'" case "$os_type" in "OpenBSD") usermod -G "$2" "$1";; "FreeBSD") pw usermod "$1" -G "$2";; "Linux") usermod -a -G "$2" "$1";; "Darwin") dscl . -append "/Groups/$2" GroupMembership "$1";; esac return 0 } os_type="$(uname)" # Require root to install it. if [[ "$(whoami)" != "root" ]]; then echo "Please rerun this installer as root." >&2 exit 1 # Check for the presence of git. elif [[ -z "$(command -v git)" ]] ; then echo "Please ensure git is installed and available in PATH to continue." >&2 exit 1 else case "$os_type" in OpenBSD|Linux|FreeBSD|Darwin) : # All clear, proceed! ;; *) echo "The rvm system wide installer currently only supports the OS types:" >&2 echo "Linux, FreeBSD, OpenBSD, and Darwin" >&2 echo "'$os_type' is currently unknown." >&2 exit 1 ;; esac fi while [[ $# -gt 0 ]] ; do case $1 in --trace) rvm_trace_flag=1 set -o xtrace ;; --debug) rvm_trace_flag=1 set -o verbose ;; --version|--revision) if [[ -n "${2:-""}" ]] ; then revision="$2" shift else usage exit 1 fi ;; --help) usage exit 0 ;; *) usage exit 1 ;; esac shift done # Load the rvm config. rvm_ignore_rvmrc=${rvm_ignore_rvmrc:-0} if [[ $rvm_ignore_rvmrc -eq 0 ]]; then [[ -s /etc/rvmrc ]] && source /etc/rvmrc [[ -s "$HOME/.rvmrc" ]] && source "$HOME/.rvmrc" fi rvm_path="${rvm_path:-"/usr/local/rvm"}" export rvm_selfcontained=0 rvm_group_name="${rvm_group_name:-"rvm"}" __rvm_create_user_group "$rvm_group_name" __rvm_add_user_to_group "$(whoami)" "$rvm_group_name" 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/ git clone --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git builtin cd rvm if [[ "${revision:-""}" ]]; then echo "Checking out revision $revision" git checkout $revision fi echo "Running the install script." bash ./scripts/install "$@" __rvm_system_wide_permissions "$rvm_path" echo "Setting up group permissions" 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 cat > /etc/rvmrc < "$rvm_parent_dir/lib/rvm" <