crafterm / sprinkle

Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails, or Sinatra stack on a brand new slice directly after its been created

sprinkle / lib / sprinkle / installers / push_text.rb
100644 46 lines (41 sloc) 1.263 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Sprinkle
  module Installers
    # Beware, strange "installer" coming your way.
    #
    # = Text configuration installer
    #
    # This installer pushes simple configuration into a file.
    #
    # == Example Usage
    #
    # Installing magic_beans into apache2.conf
    #
    # package :magic_beans do
    # push_text 'magic_beans', '/etc/apache2/apache2.conf'
    # end
    #
    # If you user has access to 'sudo' and theres a file that requires
    # priveledges, you can pass :sudo => true
    #
    # package :magic_beans do
    # push_text 'magic_beans', '/etc/apache2/apache2.conf', :sudo => true
    # end
    #
    # A special verify step exists for this very installer
    # its known as file_contains, it will test that a file indeed
    # contains a substring that you send it.
    #
    class PushText < Installer
      attr_accessor :text, :path #:nodoc:
 
      def initialize(parent, text, path, options={}, &block) #:nodoc:
        super parent, options, &block
        @text = text
        @path = path
      end
 
      protected
 
        def install_commands #:nodoc:
          "echo -e '#{@text.gsub("'", "'\\\\''").gsub("\n", '\n')}' |#{'sudo ' if option?(:sudo)}tee -a #{@path}"
        end
 
    end
  end
end