diff --git a/README.md b/README.md index 5af60c0..16e2c68 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ Install a couple of Rubies single_user_rvm::install_ruby { 'ruby-1.9.3-p392': user => 'username' } single_user_rvm::install_ruby { 'ruby-2.0.0-p247': user => 'username' } +Set the default ruby +-------------------- + + single_user_rvm::default {'ruby-1.9.3': user => 'username' } + +ruby-1.9.3 is a grep match on the output of rvm current + More info in [install_ruby.pp](manifests/install_ruby.pp) License diff --git a/manifests/default.pp b/manifests/default.pp new file mode 100644 index 0000000..95b0be2 --- /dev/null +++ b/manifests/default.pp @@ -0,0 +1,47 @@ +# == Define: single_user_rvm::default +# +# Sets the default RVM ruby +# +# # === Parameters +# +# # [*ruby_string*] +# Ruby version to install, be sure to use the full Ruby string as failing to do so will break the mechanism that +# detects if the required ruby is already installed. Defaults to the value of the title string. +# Should match a ruby installed by single_user_rvm::install_ruby +# +# [*user*] +# The user for which this Ruby will be installed. Defaults to 'rvm'. +# +# === Examples +# +# Set Ruby 2.0.0 p247 as default for user 'dude': +# +# single_user_rvm::default { 'ruby-2.0.0-p247': +# user => 'dude', +# } +# +define single_user_rvm::default ( + $user ='rvm') { + + if $home { + $homedir = $home + } else { + $homedir = "/home/${user}" + } + + + $command = "rvm use --default ${title}" + $check_command = "rvm current" + + exec { "su -l ${user} -c '${command}'": + path => "/usr/bin:/usr/sbin:/bin:~/.rvm/bin", + provider => shell, + logoutput => false, + cwd => "/home/${user}", + require => Single_user_rvm::Install[$user], + unless => "su -l ${user} -c '${check_command}' | grep ${title}" + } + + + } +