rump 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +165 -0
 - data/README.md +118 -0
 - data/Rakefile +14 -0
 - data/VERSION +1 -0
 - data/bin/rump +19 -0
 - data/features/rump.feature +179 -0
 - data/features/step_definitions/rump_steps.rb +143 -0
 - data/features/support/env.rb +11 -0
 - data/features/support/repos/simple/manifests/nodes/.stub +0 -0
 - data/features/support/repos/simple/manifests/site.pp +1 -0
 - data/features/support/repos/simple/modules/test/manifests/init.pp +5 -0
 - data/features/support/repos/simple/var/.stub +0 -0
 - data/features/support/repos/simple/var/reports/.stub +0 -0
 - data/features/support/repos/simple_26/manifests/nodes/.stub +0 -0
 - data/features/support/repos/simple_26/manifests/site.pp +1 -0
 - data/features/support/repos/simple_26/modules/test/files/checkout +0 -0
 - data/features/support/repos/simple_26/modules/test/manifests/init.pp +5 -0
 - data/features/support/repos/simple_26/var/.stub +0 -0
 - data/features/support/repos/simple_26/var/reports/.stub +0 -0
 - data/lib/generators/git/description +1 -0
 - data/lib/generators/git/hooks/pre-commit +29 -0
 - data/lib/generators/git/hooks/pre-receive +0 -0
 - data/lib/generators/git/info/exclude +6 -0
 - data/lib/rump.rb +251 -0
 - data/man/rump.1 +328 -0
 - data/man/rump.1.html +308 -0
 - data/man/rump.1.ronn +214 -0
 - metadata +109 -0
 
| 
         @@ -0,0 +1,143 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Given /^I am working in "([^\"]*)"$/ do |directory|
         
     | 
| 
      
 2 
     | 
    
         
            +
              @basedir = Pathname.new(directory)
         
     | 
| 
      
 3 
     | 
    
         
            +
            end
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Given /^I have an empty git repository named "([^\"]*)"$/ do |repo_name|
         
     | 
| 
      
 6 
     | 
    
         
            +
              repo_path = @basedir.join(repo_name)
         
     | 
| 
      
 7 
     | 
    
         
            +
              FileUtils.rm_rf(repo_path)
         
     | 
| 
      
 8 
     | 
    
         
            +
              FileUtils.mkdir_p(repo_path)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              Dir.chdir(repo_path) do
         
     | 
| 
      
 11 
     | 
    
         
            +
                commands = [ "git init -q",
         
     | 
| 
      
 12 
     | 
    
         
            +
                             "touch foo",
         
     | 
| 
      
 13 
     | 
    
         
            +
                             "git add foo",
         
     | 
| 
      
 14 
     | 
    
         
            +
                             "git commit -qm 'init' ." ]
         
     | 
| 
      
 15 
     | 
    
         
            +
                commands.each do |command|
         
     | 
| 
      
 16 
     | 
    
         
            +
                  system(command).should be_true
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              File.exists?(repo_path.join('.git')).should be_true
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            When /^I run "([^\"]*)"$/ do |cmd|
         
     | 
| 
      
 24 
     | 
    
         
            +
              if cmd.split(' ').first == "rump"
         
     | 
| 
      
 25 
     | 
    
         
            +
                command = %w(ruby -rubygems)
         
     | 
| 
      
 26 
     | 
    
         
            +
                command << ROOT.join('bin', 'rump')
         
     | 
| 
      
 27 
     | 
    
         
            +
                command << cmd.split[1..-1].join(' ')
         
     | 
| 
      
 28 
     | 
    
         
            +
                command = command.join(' ')
         
     | 
| 
      
 29 
     | 
    
         
            +
              else
         
     | 
| 
      
 30 
     | 
    
         
            +
                command = cmd
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              Dir.chdir(@basedir) do
         
     | 
| 
      
 34 
     | 
    
         
            +
                system(command).should be_true
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            Then /^running "([^\"]*)" should fail$/ do |command|
         
     | 
| 
      
 39 
     | 
    
         
            +
              Dir.chdir(@basedir) do
         
     | 
| 
      
 40 
     | 
    
         
            +
                system(command).should be_false
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            Then /^running "([^\"]*)" should succeed$/ do |command|
         
     | 
| 
      
 45 
     | 
    
         
            +
              Dir.chdir(@basedir) do
         
     | 
| 
      
 46 
     | 
    
         
            +
                system(command).should be_true
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            Then /^running "([^\"]*)" should output "([^\"]*)"$/ do |cmd, string|
         
     | 
| 
      
 51 
     | 
    
         
            +
              if cmd.split(' ').first == "rump"
         
     | 
| 
      
 52 
     | 
    
         
            +
                command = %w(ruby -rubygems)
         
     | 
| 
      
 53 
     | 
    
         
            +
                command << ROOT.join('bin', 'rump')
         
     | 
| 
      
 54 
     | 
    
         
            +
                command << cmd.split[1..-1].join(' ')
         
     | 
| 
      
 55 
     | 
    
         
            +
                command = command.join(' ')
         
     | 
| 
      
 56 
     | 
    
         
            +
              else
         
     | 
| 
      
 57 
     | 
    
         
            +
                command = cmd
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              Dir.chdir(@basedir) do
         
     | 
| 
      
 61 
     | 
    
         
            +
                (`#{command}` =~ /#{string}/).should be_true
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            Then /^I should have a git repository at "([^\"]*)"$/ do |repo_name|
         
     | 
| 
      
 66 
     | 
    
         
            +
              repo_path = @basedir.join(repo_name)
         
     | 
| 
      
 67 
     | 
    
         
            +
              File.exists?(repo_path.join('.git')).should be_true
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            Given /^there is no "([^\"]*)" repository$/ do |repo_name|
         
     | 
| 
      
 71 
     | 
    
         
            +
              repo_path = @basedir.join(repo_name)
         
     | 
| 
      
 72 
     | 
    
         
            +
              FileUtils.rm_rf(repo_path)
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            Given /^I have a simple Puppet repository named "([^\"]*)"$/ do |repo_name|
         
     | 
| 
      
 76 
     | 
    
         
            +
              repo_path = @basedir.join(repo_name)
         
     | 
| 
      
 77 
     | 
    
         
            +
              simple_path = ROOT.join('features', 'support', 'repos', 'simple')
         
     | 
| 
      
 78 
     | 
    
         
            +
              hostname = Socket.gethostname.split('.').first
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
              FileUtils.rm_rf(repo_path)
         
     | 
| 
      
 81 
     | 
    
         
            +
              FileUtils.cp_r(simple_path, repo_path)
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              File.open(repo_path.join('manifests', 'nodes', "#{hostname}.pp"), 'w') do |f|
         
     | 
| 
      
 84 
     | 
    
         
            +
                f << "node #{hostname} { include 'test' }"
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              Dir.chdir(repo_path) do
         
     | 
| 
      
 88 
     | 
    
         
            +
                commands = ["git init -q", "git add .", "git commit -qm 'init' ."]
         
     | 
| 
      
 89 
     | 
    
         
            +
                commands.each do |command|
         
     | 
| 
      
 90 
     | 
    
         
            +
                  system(command).should be_true
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              File.exists?(repo_path.join('.git')).should be_true
         
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            Given /^I have a simple Puppet 2.6 repository named "([^"]*)"$/ do |repo_name|
         
     | 
| 
      
 98 
     | 
    
         
            +
              repo_path = @basedir.join(repo_name)
         
     | 
| 
      
 99 
     | 
    
         
            +
              simple_path = ROOT.join('features', 'support', 'repos', 'simple_26')
         
     | 
| 
      
 100 
     | 
    
         
            +
              hostname = Socket.gethostname.split('.').first
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
              FileUtils.rm_rf(repo_path)
         
     | 
| 
      
 103 
     | 
    
         
            +
              FileUtils.cp_r(simple_path, repo_path)
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
              File.open(repo_path.join('manifests', 'nodes', "#{hostname}.pp"), 'w') do |f|
         
     | 
| 
      
 106 
     | 
    
         
            +
                f << "node #{hostname} { include 'test' }"
         
     | 
| 
      
 107 
     | 
    
         
            +
              end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
              Dir.chdir(repo_path) do
         
     | 
| 
      
 110 
     | 
    
         
            +
                commands = ["git init -q", "git add .", "git commit -qm 'init' ."]
         
     | 
| 
      
 111 
     | 
    
         
            +
                commands.each do |command|
         
     | 
| 
      
 112 
     | 
    
         
            +
                  system(command).should be_true
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
              end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
              File.exists?(repo_path.join('.git')).should be_true
         
     | 
| 
      
 117 
     | 
    
         
            +
            end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            Then /^I should see a file at "([^\"]*)"$/ do |path|
         
     | 
| 
      
 120 
     | 
    
         
            +
              File.exists?(path).should be_true
         
     | 
| 
      
 121 
     | 
    
         
            +
            end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            Then /^I should see a directory at "([^\"]*)"$/ do |path|
         
     | 
| 
      
 124 
     | 
    
         
            +
              File.directory?(path).should be_true
         
     | 
| 
      
 125 
     | 
    
         
            +
            end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
            Given /^there is no "([^\"]*)" file$/ do |file|
         
     | 
| 
      
 128 
     | 
    
         
            +
              FileUtils.rm_rf(file).should be_true
         
     | 
| 
      
 129 
     | 
    
         
            +
            end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
            Given /^"([^\"]*)" is on my path$/ do |command|
         
     | 
| 
      
 132 
     | 
    
         
            +
              system("which #{command} > /dev/null").should be_true
         
     | 
| 
      
 133 
     | 
    
         
            +
            end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            Then /^I should see the following directories:$/ do |table|
         
     | 
| 
      
 136 
     | 
    
         
            +
              table.hashes.each do |attrs|
         
     | 
| 
      
 137 
     | 
    
         
            +
                File.directory?(attrs["directory"]).should be_true
         
     | 
| 
      
 138 
     | 
    
         
            +
              end
         
     | 
| 
      
 139 
     | 
    
         
            +
            end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
            When /^I touch "([^\"]*)"$/ do |filename|
         
     | 
| 
      
 142 
     | 
    
         
            +
              system("touch #{filename} > /dev/null").should be_true
         
     | 
| 
      
 143 
     | 
    
         
            +
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import "nodes/*"
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import "nodes/*"
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            a Rump-ified repository of Puppet manifests
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "socket"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            name     = ENV['GIT_AUTHOR_NAME']  || `git config user.name`
         
     | 
| 
      
 6 
     | 
    
         
            +
            email    = ENV['GIT_AUTHOR_EMAIL'] || `git config user.email`
         
     | 
| 
      
 7 
     | 
    
         
            +
            hostname = Socket.gethostname
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            @errors = []
         
     | 
| 
      
 10 
     | 
    
         
            +
            case 
         
     | 
| 
      
 11 
     | 
    
         
            +
            when !name, name.strip.empty?
         
     | 
| 
      
 12 
     | 
    
         
            +
              @errors << "You don't have an author name set."
         
     | 
| 
      
 13 
     | 
    
         
            +
              @errors << "Please set this to your real name before committing."
         
     | 
| 
      
 14 
     | 
    
         
            +
            when !email, email.strip.empty?
         
     | 
| 
      
 15 
     | 
    
         
            +
              @errors << "You don't have an author email address set."
         
     | 
| 
      
 16 
     | 
    
         
            +
              @errors << "Please set this to your real email address before committing."
         
     | 
| 
      
 17 
     | 
    
         
            +
            when name == "root", name =~ /^\s*$/
         
     | 
| 
      
 18 
     | 
    
         
            +
              @errors << "Your author name is '#{name}'."
         
     | 
| 
      
 19 
     | 
    
         
            +
              @errors << "Please set this to your real name before committing."
         
     | 
| 
      
 20 
     | 
    
         
            +
            when email =~ /^\s*$/, email =~ /#{hostname}/
         
     | 
| 
      
 21 
     | 
    
         
            +
              @errors << "You author email is '#{email}'."
         
     | 
| 
      
 22 
     | 
    
         
            +
              @errors << "This matches part of the system hostname (#{hostname})."
         
     | 
| 
      
 23 
     | 
    
         
            +
              @errors << "If this is correct, please run again with --no-verify."
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            if @errors.size > 0
         
     | 
| 
      
 27 
     | 
    
         
            +
              puts @errors
         
     | 
| 
      
 28 
     | 
    
         
            +
              exit 1 
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         
            File without changes
         
     | 
    
        data/lib/rump.rb
    ADDED
    
    | 
         @@ -0,0 +1,251 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'thor'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'pathname'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module Logging
         
     | 
| 
      
 7 
     | 
    
         
            +
              ESCAPES = { :green  => "\033[0;32m",
         
     | 
| 
      
 8 
     | 
    
         
            +
                          :yellow => "\033[0;33m",
         
     | 
| 
      
 9 
     | 
    
         
            +
                          :red    => "\033[47;31m",
         
     | 
| 
      
 10 
     | 
    
         
            +
                          :reset  => "\033[0m" }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              def info(message)
         
     | 
| 
      
 13 
     | 
    
         
            +
                emit(:message => message, :color => :green)
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def warn(message)
         
     | 
| 
      
 17 
     | 
    
         
            +
                emit(:message => message, :color => :yellow)
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def error(message)
         
     | 
| 
      
 21 
     | 
    
         
            +
                emit(:message => message, :color => :red)
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              def emit(opts={})
         
     | 
| 
      
 25 
     | 
    
         
            +
                color   = opts[:color]
         
     | 
| 
      
 26 
     | 
    
         
            +
                message = opts[:message]
         
     | 
| 
      
 27 
     | 
    
         
            +
                print ESCAPES[color]
         
     | 
| 
      
 28 
     | 
    
         
            +
                print message
         
     | 
| 
      
 29 
     | 
    
         
            +
                print ESCAPES[:reset]
         
     | 
| 
      
 30 
     | 
    
         
            +
                print "\n"
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            # Thor's default stack trace on errors is ugly - make it pretty.
         
     | 
| 
      
 35 
     | 
    
         
            +
            class Thor
         
     | 
| 
      
 36 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 37 
     | 
    
         
            +
                def handle_argument_error(task, error)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  puts "#{task.name.inspect} was called incorrectly. Call as #{task.formatted_usage(self, banner_base == "thor").inspect}."
         
     | 
| 
      
 39 
     | 
    
         
            +
                  exit 1
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            class Rump < Thor
         
     | 
| 
      
 46 
     | 
    
         
            +
              include Logging
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 49 
     | 
    
         
            +
                super
         
     | 
| 
      
 50 
     | 
    
         
            +
                @root = Pathname.new(Dir.getwd)
         
     | 
| 
      
 51 
     | 
    
         
            +
                @install_root = Pathname.new(File.expand_path(File.join(File.dirname(__FILE__))))
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              desc "clone <repository> [directory]", "clone a Git repository of Puppet manifests"
         
     | 
| 
      
 55 
     | 
    
         
            +
              def clone(repository, directory=nil)
         
     | 
| 
      
 56 
     | 
    
         
            +
                abort_unless_git_installed
         
     | 
| 
      
 57 
     | 
    
         
            +
                directory ||= File.basename(repository.split('/').last, '.git')
         
     | 
| 
      
 58 
     | 
    
         
            +
                command = "git clone -q #{repository} #{directory}"
         
     | 
| 
      
 59 
     | 
    
         
            +
                system(command)
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                # A cloned repo may have submodules - automatically initialise them.
         
     | 
| 
      
 62 
     | 
    
         
            +
                if File.exists?(File.join(directory, '.gitmodules'))
         
     | 
| 
      
 63 
     | 
    
         
            +
                  Dir.chdir(directory) do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    system("git submodule init")
         
     | 
| 
      
 65 
     | 
    
         
            +
                    system("git submodule update")
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              desc "go [puppet arguments]", "do a local Puppet run"
         
     | 
| 
      
 71 
     | 
    
         
            +
              def go(*puppet_args)
         
     | 
| 
      
 72 
     | 
    
         
            +
                if ENV['USER'] != "root"
         
     | 
| 
      
 73 
     | 
    
         
            +
                  warn "You should probably be root when running this! Proceeding anyway..."
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                args = []
         
     | 
| 
      
 77 
     | 
    
         
            +
                if has_frozen_components?
         
     | 
| 
      
 78 
     | 
    
         
            +
                  args << "ruby"
         
     | 
| 
      
 79 
     | 
    
         
            +
                  Dir.glob("#{@root.join('vendor')}/*").each do |dir|
         
     | 
| 
      
 80 
     | 
    
         
            +
                    args << "-I #{@root.join('vendor', dir, 'lib')}"
         
     | 
| 
      
 81 
     | 
    
         
            +
                  end
         
     | 
| 
      
 82 
     | 
    
         
            +
                  args << "#{@root.join('vendor', 'puppet', 'bin', 'puppet')}"
         
     | 
| 
      
 83 
     | 
    
         
            +
                  info "Using frozen Puppet from #{@root.join('vendor', 'puppet')}."
         
     | 
| 
      
 84 
     | 
    
         
            +
                else
         
     | 
| 
      
 85 
     | 
    
         
            +
                  abort_unless_puppet_installed(:message => "Please either install it on your system or freeze it with 'rump freeze'")
         
     | 
| 
      
 86 
     | 
    
         
            +
                  args << "puppet"
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
                args << "--modulepath #{@root.join('modules')}"
         
     | 
| 
      
 89 
     | 
    
         
            +
                args << "--confdir #{@root.join('etc')}" unless puppet_args.include?("--confdir")
         
     | 
| 
      
 90 
     | 
    
         
            +
                args << "--vardir #{@root.join('var')}" unless puppet_args.include?("--vardir")
         
     | 
| 
      
 91 
     | 
    
         
            +
                args << "#{@root.join('manifests', 'site.pp')}"
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                args += puppet_args
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                command = args.join(' ')
         
     | 
| 
      
 96 
     | 
    
         
            +
                puts command if args.include?("--debug")
         
     | 
| 
      
 97 
     | 
    
         
            +
                system(command) ? exit(0) : exit(2)
         
     | 
| 
      
 98 
     | 
    
         
            +
              end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
              desc "freeze [repository, project]", "freeze Puppet into your manifests repository"
         
     | 
| 
      
 101 
     | 
    
         
            +
              def freeze(*args)
         
     | 
| 
      
 102 
     | 
    
         
            +
                abort_unless_git_installed
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                commands = []
         
     | 
| 
      
 105 
     | 
    
         
            +
                if args.size >= 2
         
     | 
| 
      
 106 
     | 
    
         
            +
                  project    = args[0]
         
     | 
| 
      
 107 
     | 
    
         
            +
                  repository = args[1]
         
     | 
| 
      
 108 
     | 
    
         
            +
                  commands << { :command => "git submodule add #{repository} #{@root.join('vendor', project)}" }
         
     | 
| 
      
 109 
     | 
    
         
            +
                  if args.detect { |arg| arg =~ /^--release\=(.+)/ }
         
     | 
| 
      
 110 
     | 
    
         
            +
                    version = $1
         
     | 
| 
      
 111 
     | 
    
         
            +
                    commands << { :command => "git checkout -b #{version} #{version}", :directory => @root.join('vendor', project) }
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
                  commands << { :command => "git commit --quiet -am 'Froze in #{repository} as a submodule'" }
         
     | 
| 
      
 114 
     | 
    
         
            +
                else
         
     | 
| 
      
 115 
     | 
    
         
            +
                  commands << { :command => "git submodule add git://github.com/puppetlabs/puppet.git #{@root.join('vendor', 'puppet')}" }
         
     | 
| 
      
 116 
     | 
    
         
            +
                  commands << { :command => "git submodule add git://github.com/puppetlabs/facter.git #{@root.join('vendor', 'facter')}" }
         
     | 
| 
      
 117 
     | 
    
         
            +
                  commands << { :command => "git commit --quiet -am 'Froze in Puppet + Facter as submodules'" }
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                commands.each do |attrs|
         
     | 
| 
      
 121 
     | 
    
         
            +
                  dir = attrs[:directory] || @root
         
     | 
| 
      
 122 
     | 
    
         
            +
                  Dir.chdir(dir) do
         
     | 
| 
      
 123 
     | 
    
         
            +
                    exit(2) unless system(attrs[:command])
         
     | 
| 
      
 124 
     | 
    
         
            +
                  end
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                info "Freezing complete."
         
     | 
| 
      
 128 
     | 
    
         
            +
              end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
              desc "scaffold <project>", "generate scaffolding for a repository of Puppet manifests"
         
     | 
| 
      
 131 
     | 
    
         
            +
              def scaffold(project)
         
     | 
| 
      
 132 
     | 
    
         
            +
                [ @root + project,
         
     | 
| 
      
 133 
     | 
    
         
            +
                  @root + project + 'manifests',
         
     | 
| 
      
 134 
     | 
    
         
            +
                  @root + project + 'modules',
         
     | 
| 
      
 135 
     | 
    
         
            +
                  @root + project + 'var/reports',
         
     | 
| 
      
 136 
     | 
    
         
            +
                  @root + project + 'vendor' ].each do |directory|
         
     | 
| 
      
 137 
     | 
    
         
            +
                  FileUtils.mkdir_p(directory)
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                File.open(@root.join(project, 'README.md'), 'w') do |f|
         
     | 
| 
      
 141 
     | 
    
         
            +
                  f << <<-README.gsub(/^ {8}/, '')
         
     | 
| 
      
 142 
     | 
    
         
            +
                    #{project} manifests
         
     | 
| 
      
 143 
     | 
    
         
            +
                    #{"=" * project.size}==========
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                    modules/ <= Puppet modules
         
     | 
| 
      
 146 
     | 
    
         
            +
                    manifests/ <= Puppet nodes
         
     | 
| 
      
 147 
     | 
    
         
            +
                    vendor/ <= frozen Puppet + Facter
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                    Running Puppet with Rump
         
     | 
| 
      
 150 
     | 
    
         
            +
                    ------------------------
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    From within this directory, run:
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                        rump go
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                    You can pass options to Puppet after the 'go':
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                        rump go --debug --test
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                    Freezing Puppet
         
     | 
| 
      
 161 
     | 
    
         
            +
                    ---------------
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                    Firstly, you need to create a git repository:
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                        git init
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                    Now you can freeze Puppet:
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                        rump freeze
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                    Once Rump has frozen Puppet, commit the changes:
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                        git commit -m 'added facter + puppet submodules' .
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                    Now Rump will use the frozen Puppet when you run 'rump go'.
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  README
         
     | 
| 
      
 178 
     | 
    
         
            +
                end
         
     | 
| 
      
 179 
     | 
    
         
            +
              end
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
      
 181 
     | 
    
         
            +
              desc "init <project>", "initialise a repo of scaffolded Puppet manifests"
         
     | 
| 
      
 182 
     | 
    
         
            +
              def init(project)
         
     | 
| 
      
 183 
     | 
    
         
            +
                scaffold(project)
         
     | 
| 
      
 184 
     | 
    
         
            +
                repo_path = @root.join(project)
         
     | 
| 
      
 185 
     | 
    
         
            +
                template_path = @install_root.join('generators', 'git')
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                Dir.chdir(repo_path) do
         
     | 
| 
      
 188 
     | 
    
         
            +
                  commands = [ "git init --quiet --template=#{template_path}",
         
     | 
| 
      
 189 
     | 
    
         
            +
                               "git add .",
         
     | 
| 
      
 190 
     | 
    
         
            +
                               "git commit --quiet -am 'Initial commit.'" ]
         
     | 
| 
      
 191 
     | 
    
         
            +
                  commands.each do |command|
         
     | 
| 
      
 192 
     | 
    
         
            +
                    system(command)
         
     | 
| 
      
 193 
     | 
    
         
            +
                  end
         
     | 
| 
      
 194 
     | 
    
         
            +
                end
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
                info "Your new Rump project has been initialised in #{repo_path}"
         
     | 
| 
      
 197 
     | 
    
         
            +
              end
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
              desc "whoami [rfc2822-address]", "set the current commit author"
         
     | 
| 
      
 200 
     | 
    
         
            +
              def whoami(address=nil)
         
     | 
| 
      
 201 
     | 
    
         
            +
                # getter
         
     | 
| 
      
 202 
     | 
    
         
            +
                if address
         
     | 
| 
      
 203 
     | 
    
         
            +
                  name  = address[/^(.+)\s+</, 1]
         
     | 
| 
      
 204 
     | 
    
         
            +
                  email = address[/<(.+)>$/, 1]
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                  unless name && email
         
     | 
| 
      
 207 
     | 
    
         
            +
                    abort("Supplied address isn't a valid rfc2822 email address")
         
     | 
| 
      
 208 
     | 
    
         
            +
                  end
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                  system("git config user.name '#{name}'")
         
     | 
| 
      
 211 
     | 
    
         
            +
                  system("git config user.email '#{email}'")
         
     | 
| 
      
 212 
     | 
    
         
            +
                # setter
         
     | 
| 
      
 213 
     | 
    
         
            +
                else
         
     | 
| 
      
 214 
     | 
    
         
            +
                  name = `git config user.name`.strip
         
     | 
| 
      
 215 
     | 
    
         
            +
                  email = `git config user.email`.strip
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                  if name.empty? || email.empty?
         
     | 
| 
      
 218 
     | 
    
         
            +
                    warn "You don't have a name or email set."
         
     | 
| 
      
 219 
     | 
    
         
            +
                  else
         
     | 
| 
      
 220 
     | 
    
         
            +
                    puts "#{name} <#{email}>"
         
     | 
| 
      
 221 
     | 
    
         
            +
                  end
         
     | 
| 
      
 222 
     | 
    
         
            +
                end
         
     | 
| 
      
 223 
     | 
    
         
            +
              end
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
              private
         
     | 
| 
      
 226 
     | 
    
         
            +
              def has_frozen_components?
         
     | 
| 
      
 227 
     | 
    
         
            +
                vendored = Dir.glob("#{@root.join('vendor')}/*").map {|v| v.split('/').last}
         
     | 
| 
      
 228 
     | 
    
         
            +
                vendored.include?("puppet") && vendored.include?("facter")
         
     | 
| 
      
 229 
     | 
    
         
            +
              end
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
              # helper + abortive methods
         
     | 
| 
      
 232 
     | 
    
         
            +
              %w(puppet git).each do |bin|
         
     | 
| 
      
 233 
     | 
    
         
            +
                class_eval <<-METHOD, __FILE__, __LINE__
         
     | 
| 
      
 234 
     | 
    
         
            +
                  no_tasks do
         
     | 
| 
      
 235 
     | 
    
         
            +
                    def #{bin}_installed?
         
     | 
| 
      
 236 
     | 
    
         
            +
                      `which #{bin}` =~ /#{bin}$/ ? true : false
         
     | 
| 
      
 237 
     | 
    
         
            +
                    end
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
                    def abort_unless_#{bin}_installed(opts={})
         
     | 
| 
      
 240 
     | 
    
         
            +
                      unless #{bin}_installed?
         
     | 
| 
      
 241 
     | 
    
         
            +
                        error "You don't have #{bin.capitalize} installed!"
         
     | 
| 
      
 242 
     | 
    
         
            +
                        error opts[:message] || "Please install it on your system."
         
     | 
| 
      
 243 
     | 
    
         
            +
                        exit 3
         
     | 
| 
      
 244 
     | 
    
         
            +
                      end
         
     | 
| 
      
 245 
     | 
    
         
            +
                    end
         
     | 
| 
      
 246 
     | 
    
         
            +
                  end
         
     | 
| 
      
 247 
     | 
    
         
            +
                METHOD
         
     | 
| 
      
 248 
     | 
    
         
            +
              end
         
     | 
| 
      
 249 
     | 
    
         
            +
             
     | 
| 
      
 250 
     | 
    
         
            +
            end
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     |