Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 27b7b6594004d35fe184af9ad179338b73f50664 @dguerri committed Mar 13, 2011
Showing with 418 additions and 0 deletions.
  1. +30 −0 README
  2. +252 −0 files/install-system-wide
  3. +136 −0 manifests/init.pp
30 README
@@ -0,0 +1,30 @@
+#
+# Puppet Ruby Version Manager Installation Module.
+#
+# Copyright (C) 2010 Davide Guerri (davide.guerri@gmail.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Usage:
+#
+# rvm::system_wide { "rvm": }
+#
+# Supported parameters:
+#
+# none
+#
+# Defines:
+#
+# Exec[ "rvm_installation" ]
+#
252 files/install-system-wide
@@ -0,0 +1,252 @@
+#!/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")
+ if [[ -f "/etc/SuSE-release" ]] ; then
+ groupadd "$rvm_group_name"
+ else
+ groupadd -f "$rvm_group_name"
+ fi
+ ;;
+ "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"
+ ;;
+ "SunOS") groupadd "$rvm_group_name";;
+ 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")
+ if [[ -f "/etc/SuSE-release" ]] ; then
+ groupmod -A "$1" "$2"
+ else
+ /usr/sbin/usermod -a -G "$2" "$1"
+ fi
+ ;;
+ "Darwin") dscl . -append "/Groups/$2" GroupMembership "$1";;
+ "SunOS")
+ groups="`id -G "$1"` \"$2\""
+ csv_groups=$(echo $groups | tr " " ", ")
+ usermod -G "$csv_groups" "$1"
+ esac
+
+ return 0
+}
+
+os_type="$(uname)"
+
+# Require root to install it.
+if [[ $(id | sed -e 's/(.*//' | awk -F= '{print $2}') -ne 0 ]]; 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|SunOS)
+ : # All clear, proceed!
+ ;;
+
+ *)
+ echo "The rvm system wide installer currently only supports the OS types:" >&2
+ echo "Linux, FreeBSD, OpenBSD, Darwin and SunOS" >&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)
+ if [[ -n "${2:-""}" ]] ; then
+ version="$2"
+ shift
+ else
+ usage
+ exit 1
+ fi
+ ;;
+ --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 "${USER:-$(id | sed -e 's/^[^(]*(//' -e 's/).*$//')}" "$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"
+
+[[ -d "$PWD/rvm/" ]] && rm -rf "$PWD/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 fetch --depth=256
+ git checkout $revision
+elif [[ "${version:-""}" ]]; then
+ echo "Checking out version $version"
+ git checkout $version
+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 <<END_OF_RVMRC
+# Setup default configuration for rvm.
+# 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 $rvm_parent_dir/lib/rvm to load rvm"
+mkdir -p "$rvm_parent_dir/lib/"
+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 "${rvm_path:=/usr/local/rvm}/scripts/rvm" ]]; then
+ source "${rvm_path:=/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 "$rvm_parent_dir/lib/rvm" ; do
+ __rvm_system_wide_permissions "$file"
+done; unset file
+
+echo "RVM is now installed. To use, source '$rvm_parent_dir/lib/rvm' to your shell profile."
+
+unset rvm_parent_dir
136 manifests/init.pp
@@ -0,0 +1,136 @@
+#
+# Puppet Ruby Version Manager Installation Module.
+#
+# Copyright (C) 2010 Davide Guerri (davide.guerri@gmail.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Usage:
+#
+# rvm::system_wide { "rvm": }
+#
+# Supported parameters:
+#
+# none
+#
+# Defines:
+#
+# Exec[ "rvm_install" ]
+#
+
+define rvm::system_wide ( ) {
+
+ # Setting global parameters and environment
+ $working_directory = "/tmp"
+ $timeout = 600 # 10 minutes
+
+ Exec {
+ path => [
+ '/usr/local/bin',
+ '/usr/local/sbin',
+ '/usr/bin',
+ '/usr/sbin',
+ '/bin/',
+ '/sbin',
+ ],
+ cwd => $working_directory,
+ }
+
+ # Setting up requisites
+
+ case $operatingsystem {
+ Ubuntu, Debian: {
+ $required_packages = [
+ 'git-core',
+ 'libreadline5-dev',
+ 'zlib1g-dev',
+ 'libssl-dev',
+ 'autoconf',
+ 'curl',
+ 'gettext',
+ 'libxml2-dev',
+ 'libxslt-dev',
+ 'libyaml-dev',
+ 'libncurses5-dev',
+ ]
+ $profile_path = "/etc/profile.d/rvm.sh"
+ }
+ RedHat, Fedora, Centos: { # Untested!
+ $required_packages = [
+ 'git',
+ 'readline-devel',
+ 'zlib-devel',
+ 'openssl-devel',
+ 'autoconf',
+ 'curl',
+ 'gettext',
+ 'libxml2-devel',
+ 'libxslt-devel',
+ 'libyaml-devel',
+ 'ncurses-devel',
+ ]
+ $profile_path = "/etc/profile.d/rvm.sh" # Untested!
+ }
+ default: {
+ fail("Unsupported distribution!")
+ }
+ }
+
+ package { "rvm_required_packages":
+ name => $required_packages,
+ ensure => installed,
+ }
+
+ file { "rvm_install-system-wide_script":
+ path => "${working_directory}/install-system-wide",
+ source => "puppet:///rvm/install-system-wide",
+ owner => root,
+ group => root,
+ mode => 644,
+ ensure => present,
+ }
+
+ # Proceding with install
+
+ exec { "rvm_install":
+ command => "bash < ./install-system-wide",
+ timeout => $timeout,
+ require => [
+ Package[ "rvm_required_packages" ],
+ File[ "rvm_install-system-wide_script" ]
+ ],
+ unless => "test -f /usr/local/rvm/scripts/rvm"
+ }
+
+ file { "rvm_profile":
+ path => $profile_path,
+ content => "[[ -s '/usr/local/lib/rvm' ]] && . '/usr/local/lib/rvm' # This loads RVM into a shell session.",
+ owner => root,
+ group => root,
+ mode => 644,
+ ensure => present,
+ require => Exec[ "rvm_install" ]
+ }
+
+ # Cleanup
+
+ tidy { "rvm_install-system-wide_script_remove":
+ path => "${working_directory}",
+ require => Exec[ "rvm_install" ],
+ recurse => 1,
+ matches => [ "install-system-wide" ],
+ }
+
+}
+

0 comments on commit 27b7b65

Please sign in to comment.
Something went wrong with that request. Please try again.