# Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class MercurialConfigurator MAC_MERCURIAL_URL = 'http://mercurial.berkwood.com/binaries/Mercurial-1.8.1-py2.6-macosx10.6.zip' MAC_10_7_MERCURIAL_URL = 'http://mercurial.berkwood.com/binaries/Mercurial-2.0.2-py2.7-macosx10.7.zip' MAC_MERCURIAL_FILE = 'mercurial-1.8.1_20110310-py2.6-macosx10.6' MAC_10_7_MERCURIAL_FILE = 'mercurial-2.0.2_20120104-py2.7-macosx10.7' include Configurator register :mercurial description 'Installs Mercurial' settings :abort_on_failure => 'Whether to abort if Mercurial failed to install (false by default)' # Check whether Mercurial is installed # # === Return # true:: If Mercurial is installed # false:: Otherwise def check_linux report_check("Checking for Mercurial") installed = Command.execute('hg', '--version').success? report_result(installed) installed end alias :check_darwin :check_linux alias :check_windows :check_linux # Install Linux Mercurial package # # === Return # true:: Always return true def run_linux opts = { :report => true }.merge(abort_option('Failed to install Mercurial')) PackageInstaller.install('mercurial', opts) end # Brew does not have a package for mercurial :( # # === Return # true:: Always return true def run_darwin report_check('Installing Mercurial') tempdir = File.join(ENV['HOME'], '.rconf_temp') FileUtils.mkdir_p(tempdir) begin Dir.chdir(tempdir) do Command.execute('curl', '-O', '-f', mac_mercurial_url, abort_option('Failed to download Mercurial')) Command.execute('unzip', File.basename(mac_mercurial_url), abort_option('Failed to unzip Mercurial')) end Dir.chdir(File.join(tempdir, mac_mercurial_file)) do Command.sudo('installer', '-pkg', mac_mercurial_file.gsub('_', '+') + '.mpkg', '-target', '/', abort_option('Failed to install Mercurial')) end ensure FileUtils.rm_rf(tempdir) end report_success end # URL to mercurial installer for Mac OS X def mac_mercurial_url Platform.dispatch { :mac_mercurial_url } end # URL to mercurial installer for Mac OS X < 10.7 def mac_mercurial_url_darwin MAC_MERCURIAL_URL end # URL to mercurial installer for Mac OS X >= 10.7 def mac_mercurial_url_darwin_lion MAC_10_7_MERCURIAL_URL end # File name of mercurial installer for Mac OS X def mac_mercurial_file Platform.dispatch { :mac_mercurial_file } end # File name of mercurial installer for Mac OS X < 10.7 def mac_mercurial_file_darwin MAC_MERCURIAL_FILE end # File name of mercurial installer for Mac OS X >= 10.7 def mac_mercurial_file_darwin_lion MAC_10_7_MERCURIAL_FILE end # Install Windows software # # === Return # true:: Always return true def run_windows # TBD end protected # Produce abort on failure option # # === Parameters # message(String):: Abort message to be used in case abort option should be set # # === Return # {}:: Empty hash if 'abort_on_failure' is notset # opts(Hash):: Abort option with give message otherwise def abort_option(message) opts = abort_on_failure && { :abort_on_failure => message } || {} end end end