Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created January 27, 2012 21:17
Show Gist options
  • Save hugoduncan/1690974 to your computer and use it in GitHub Desktop.
Save hugoduncan/1690974 to your computer and use it in GitHub Desktop.
rvm crate
(ns pallet.crate.rvm
"Standard rvm install"
(:require
[pallet.crate.git :as git]
[pallet.action.conditional :as conditional]
[pallet.action.exec-script :as exec-script]
[pallet.action.package :as package]
[pallet.action.remote-file :as remote-file]
[pallet.action.user :as user]
[pallet.context :as context]
[pallet.core :as core]
[pallet.parameter :as parameter]
[pallet.phase :as phase]
[pallet.session :as session]
[pallet.stevedore :as stevedore]
[pallet.thread-expr :as thread-expr]))
(def default-settings-map
{:installer-url
"https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer"
:installer-version "latest"
:versions ["ruby"]})
(defn settings-map
[settings-map]
(merge default-settings-map settings-map))
(defn settings
[session settings-map & {:keys [instance]}]
(context/with-phase-context
:rvm-settings "rvm settings"
(when (string? (:versions settings-map))
(context/invalid-argument
"Invalid versions specified for rvm settings"
"should be a sequence"
(:versions settings-map)))
(parameter/assoc-target-settings
session :rvm instance (merge default-settings-map settings-map))))
(defn install-ruby-version
"Install a specific ruby version using rvm."
[session ruby-version & {:keys [instance]}]
(->
session
(exec-script/exec-checked-script
(format "Install %s using rvm" ruby-version)
("/usr/local/rvm/bin/rvm" install ~ruby-version))))
(defn install-ruby
"Install the ruby versions specified in the settings, using rvm."
[session & {:keys [instance]}]
(let [settings (parameter/get-target-settings session :rvm instance)]
(->
session
(thread-expr/for->
[ruby-version (:versions settings)]
(install-ruby-version ruby-version :instance instance)))))
(defn install-rvm
"Install rvm using the rvm install script downloaded from beginrescueend."
[session & {:keys [instance]}]
(let [settings (parameter/get-target-settings session :rvm instance)]
(context/with-phase-context
:install-rvm "Install rvm"
(->
session
(conditional/when
(not (file-exists? "/usr/local/rvm/scripts/rvm"))
(git/git)
(package/package "curl")
(user/group "rvm" :system true)
(user/user
"root" :append true :groups "rvm")
(user/user
(-> (session/admin-user session) :username) :append true :groups "rvm")
(remote-file/remote-file
"rvm-installer"
:url (:installer-url settings)
:chmod 755)
(exec-script/exec-checked-script
"Install rvm"
("./rvm-installer" --version ~(:installer-version settings))
(echo "Sourcing .bash-profile")
(if (file-exists? ".bash-profile")
(source ".bash-profile"))
(echo "/usr/local/rvm/scripts/rvm")
(if (file-exists? "/usr/local/rvm/scripts/rvm")
(source "/usr/local/rvm/scripts/rvm"))
(echo "rvm requirements and notes")
(rvm requirements)
(rvm notes)))))))
(defn ruby-server-spec
"Return a server spec, for installing the specified ruby versions"
[{:keys [versions installer-url] :as settings-map}]
(core/server-spec
:phases {:settings (phase/phase-fn (settings settings-map))
:configure (phase/phase-fn
(install-rvm)
(install-ruby))}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment