machines 0.5.4 → 0.5.6

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.
Files changed (93) hide show
  1. data/.yardopts +7 -1
  2. data/CHANGELOG.md +16 -4
  3. data/INSTALL.md +3 -0
  4. data/LICENSE +1 -2
  5. data/README.md +47 -28
  6. data/Rakefile +0 -8
  7. data/TODO.md +66 -59
  8. data/bin/machines +1 -2
  9. data/lib/machines.rb +16 -1
  10. data/lib/machines/app_settings.rb +1 -1
  11. data/lib/machines/cloud_machine.rb +1 -1
  12. data/lib/machines/command.rb +0 -2
  13. data/lib/machines/commandline.rb +23 -29
  14. data/lib/machines/commands/checks.rb +67 -0
  15. data/lib/machines/commands/configuration.rb +50 -0
  16. data/lib/machines/commands/database.rb +18 -0
  17. data/lib/machines/commands/file_operations.rb +105 -0
  18. data/lib/machines/commands/installation.rb +184 -0
  19. data/lib/machines/commands/questions.rb +16 -0
  20. data/lib/machines/commands/services.rb +26 -0
  21. data/lib/machines/core.rb +55 -25
  22. data/lib/machines/logger.rb +0 -2
  23. data/lib/machines/named_buffer.rb +7 -6
  24. data/lib/machines/version.rb +1 -1
  25. data/lib/packages/awstats.rb +2 -2
  26. data/lib/packages/docky.rb +0 -1
  27. data/lib/packages/dwm.rb +5 -0
  28. data/lib/packages/nginx_logrotate.rb +2 -2
  29. data/lib/packages/timezone.rb +2 -4
  30. data/lib/template/Machinesfile +2 -1
  31. data/lib/template/config.yml +3 -0
  32. data/spec/lib/machines/app_settings_spec.rb +13 -12
  33. data/spec/lib/machines/cloud_machine_spec.rb +9 -8
  34. data/spec/lib/machines/commandline_spec.rb +69 -90
  35. data/spec/lib/machines/{checks_spec.rb → commands/checks_spec.rb} +1 -1
  36. data/spec/lib/machines/{configuration_spec.rb → commands/configuration_spec.rb} +2 -3
  37. data/spec/lib/machines/{database_spec.rb → commands/database_spec.rb} +4 -10
  38. data/spec/lib/machines/{file_operations_spec.rb → commands/file_operations_spec.rb} +3 -7
  39. data/spec/lib/machines/{installation_spec.rb → commands/installation_spec.rb} +10 -4
  40. data/spec/lib/machines/{questions_spec.rb → commands/questions_spec.rb} +1 -3
  41. data/spec/lib/machines/{services_spec.rb → commands/services_spec.rb} +1 -4
  42. data/spec/lib/machines/core_spec.rb +81 -65
  43. data/spec/lib/packages/abiword_spec.rb +1 -5
  44. data/spec/lib/packages/amazon_mp3_spec.rb +0 -4
  45. data/spec/lib/packages/awstats_spec.rb +3 -4
  46. data/spec/lib/packages/base_spec.rb +0 -1
  47. data/spec/lib/packages/chrome_spec.rb +0 -4
  48. data/spec/lib/packages/cruisecontrol_spec.rb +1 -2
  49. data/spec/lib/packages/dependencies_spec.rb +1 -2
  50. data/spec/lib/packages/docky_spec.rb +0 -4
  51. data/spec/lib/packages/dotfiles_spec.rb +5 -4
  52. data/spec/lib/packages/dwm_spec.rb +23 -0
  53. data/spec/lib/packages/file_roller_spec.rb +1 -5
  54. data/spec/lib/packages/firefox_spec.rb +0 -4
  55. data/spec/lib/packages/gedit_spec.rb +1 -5
  56. data/spec/lib/packages/git_spec.rb +0 -4
  57. data/spec/lib/packages/gmate_spec.rb +1 -5
  58. data/spec/lib/packages/gnome_spec.rb +0 -4
  59. data/spec/lib/packages/gnumeric_spec.rb +1 -5
  60. data/spec/lib/packages/hosts_spec.rb +0 -1
  61. data/spec/lib/packages/load_machines_spec.rb +16 -15
  62. data/spec/lib/packages/monit_spec.rb +0 -1
  63. data/spec/lib/packages/mysql_spec.rb +1 -3
  64. data/spec/lib/packages/nginx_logrotate_spec.rb +17 -18
  65. data/spec/lib/packages/nginx_spec.rb +0 -1
  66. data/spec/lib/packages/openbox_spec.rb +0 -4
  67. data/spec/lib/packages/passenger_nginx_spec.rb +0 -1
  68. data/spec/lib/packages/passenger_spec.rb +0 -1
  69. data/spec/lib/packages/postfix_spec.rb +1 -5
  70. data/spec/lib/packages/questions_spec.rb +3 -4
  71. data/spec/lib/packages/rbenv_spec.rb +1 -4
  72. data/spec/lib/packages/rvm_spec.rb +1 -4
  73. data/spec/lib/packages/save_machines_spec.rb +0 -1
  74. data/spec/lib/packages/slim_spec.rb +1 -2
  75. data/spec/lib/packages/sqlserver_spec.rb +0 -4
  76. data/spec/lib/packages/timezone_spec.rb +2 -3
  77. data/spec/lib/packages/unison_spec.rb +1 -2
  78. data/spec/lib/packages/virtualbox_guest_spec.rb +0 -4
  79. data/spec/lib/packages/virtualbox_spec.rb +1 -2
  80. data/spec/lib/packages/webapps_spec.rb +1 -3
  81. data/spec/spec_helper.rb +59 -61
  82. data/spec/support/minitest.rb +4 -62
  83. metadata +27 -28
  84. data/lib/machines/base.rb +0 -13
  85. data/lib/machines/checks.rb +0 -63
  86. data/lib/machines/configuration.rb +0 -49
  87. data/lib/machines/database.rb +0 -17
  88. data/lib/machines/file_operations.rb +0 -104
  89. data/lib/machines/installation.rb +0 -171
  90. data/lib/machines/machinesfile.rb +0 -25
  91. data/lib/machines/questions.rb +0 -15
  92. data/lib/machines/services.rb +0 -24
  93. data/spec/lib/machines/machinesfile_spec.rb +0 -34
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -339,23 +339,21 @@ files:
339
339
  - bin/machines
340
340
  - lib/machines.rb
341
341
  - lib/machines/app_settings.rb
342
- - lib/machines/base.rb
343
- - lib/machines/checks.rb
344
342
  - lib/machines/cloud_machine.rb
345
343
  - lib/machines/command.rb
346
344
  - lib/machines/commandline.rb
347
- - lib/machines/configuration.rb
345
+ - lib/machines/commands/checks.rb
346
+ - lib/machines/commands/configuration.rb
347
+ - lib/machines/commands/database.rb
348
+ - lib/machines/commands/file_operations.rb
349
+ - lib/machines/commands/installation.rb
350
+ - lib/machines/commands/questions.rb
351
+ - lib/machines/commands/services.rb
348
352
  - lib/machines/core.rb
349
- - lib/machines/database.rb
350
- - lib/machines/file_operations.rb
351
353
  - lib/machines/help.rb
352
- - lib/machines/installation.rb
353
354
  - lib/machines/log_command.rb
354
355
  - lib/machines/logger.rb
355
- - lib/machines/machinesfile.rb
356
356
  - lib/machines/named_buffer.rb
357
- - lib/machines/questions.rb
358
- - lib/machines/services.rb
359
357
  - lib/machines/upload.rb
360
358
  - lib/machines/version.rb
361
359
  - lib/packages/abiword.rb
@@ -367,6 +365,7 @@ files:
367
365
  - lib/packages/dependencies.rb
368
366
  - lib/packages/docky.rb
369
367
  - lib/packages/dotfiles.rb
368
+ - lib/packages/dwm.rb
370
369
  - lib/packages/file_roller.rb
371
370
  - lib/packages/finalise.rb
372
371
  - lib/packages/firefox.rb
@@ -446,21 +445,20 @@ files:
446
445
  - machines.gemspec
447
446
  - spec/acceptance/dev_machine_spec.rb
448
447
  - spec/lib/machines/app_settings_spec.rb
449
- - spec/lib/machines/checks_spec.rb
450
448
  - spec/lib/machines/cloud_machine_spec.rb
451
449
  - spec/lib/machines/command_spec.rb
452
450
  - spec/lib/machines/commandline_spec.rb
453
- - spec/lib/machines/configuration_spec.rb
451
+ - spec/lib/machines/commands/checks_spec.rb
452
+ - spec/lib/machines/commands/configuration_spec.rb
453
+ - spec/lib/machines/commands/database_spec.rb
454
+ - spec/lib/machines/commands/file_operations_spec.rb
455
+ - spec/lib/machines/commands/installation_spec.rb
456
+ - spec/lib/machines/commands/questions_spec.rb
457
+ - spec/lib/machines/commands/services_spec.rb
454
458
  - spec/lib/machines/core_spec.rb
455
- - spec/lib/machines/database_spec.rb
456
- - spec/lib/machines/file_operations_spec.rb
457
459
  - spec/lib/machines/help_spec.rb
458
- - spec/lib/machines/installation_spec.rb
459
460
  - spec/lib/machines/log_command_spec.rb
460
461
  - spec/lib/machines/logger_spec.rb
461
- - spec/lib/machines/machinesfile_spec.rb
462
- - spec/lib/machines/questions_spec.rb
463
- - spec/lib/machines/services_spec.rb
464
462
  - spec/lib/machines/upload_spec.rb
465
463
  - spec/lib/packages/abiword_spec.rb
466
464
  - spec/lib/packages/amazon_mp3_spec.rb
@@ -471,6 +469,7 @@ files:
471
469
  - spec/lib/packages/dependencies_spec.rb
472
470
  - spec/lib/packages/docky_spec.rb
473
471
  - spec/lib/packages/dotfiles_spec.rb
472
+ - spec/lib/packages/dwm_spec.rb
474
473
  - spec/lib/packages/file_roller_spec.rb
475
474
  - spec/lib/packages/firefox_spec.rb
476
475
  - spec/lib/packages/gedit_spec.rb
@@ -520,7 +519,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
520
519
  version: '0'
521
520
  segments:
522
521
  - 0
523
- hash: -3397019508806936970
522
+ hash: 2425270342975201528
524
523
  required_rubygems_version: !ruby/object:Gem::Requirement
525
524
  none: false
526
525
  requirements:
@@ -537,21 +536,20 @@ summary: Simple configuration of development, staging and production computers o
537
536
  test_files:
538
537
  - spec/acceptance/dev_machine_spec.rb
539
538
  - spec/lib/machines/app_settings_spec.rb
540
- - spec/lib/machines/checks_spec.rb
541
539
  - spec/lib/machines/cloud_machine_spec.rb
542
540
  - spec/lib/machines/command_spec.rb
543
541
  - spec/lib/machines/commandline_spec.rb
544
- - spec/lib/machines/configuration_spec.rb
542
+ - spec/lib/machines/commands/checks_spec.rb
543
+ - spec/lib/machines/commands/configuration_spec.rb
544
+ - spec/lib/machines/commands/database_spec.rb
545
+ - spec/lib/machines/commands/file_operations_spec.rb
546
+ - spec/lib/machines/commands/installation_spec.rb
547
+ - spec/lib/machines/commands/questions_spec.rb
548
+ - spec/lib/machines/commands/services_spec.rb
545
549
  - spec/lib/machines/core_spec.rb
546
- - spec/lib/machines/database_spec.rb
547
- - spec/lib/machines/file_operations_spec.rb
548
550
  - spec/lib/machines/help_spec.rb
549
- - spec/lib/machines/installation_spec.rb
550
551
  - spec/lib/machines/log_command_spec.rb
551
552
  - spec/lib/machines/logger_spec.rb
552
- - spec/lib/machines/machinesfile_spec.rb
553
- - spec/lib/machines/questions_spec.rb
554
- - spec/lib/machines/services_spec.rb
555
553
  - spec/lib/machines/upload_spec.rb
556
554
  - spec/lib/packages/abiword_spec.rb
557
555
  - spec/lib/packages/amazon_mp3_spec.rb
@@ -562,6 +560,7 @@ test_files:
562
560
  - spec/lib/packages/dependencies_spec.rb
563
561
  - spec/lib/packages/docky_spec.rb
564
562
  - spec/lib/packages/dotfiles_spec.rb
563
+ - spec/lib/packages/dwm_spec.rb
565
564
  - spec/lib/packages/file_roller_spec.rb
566
565
  - spec/lib/packages/firefox_spec.rb
567
566
  - spec/lib/packages/gedit_spec.rb
@@ -1,13 +0,0 @@
1
- module Machines
2
- class Base
3
- files = Dir[File.join($conf.application_dir, 'machines/**/*.rb')]
4
- files.reject!{|name| File.basename(name) == 'base.rb' }
5
- files.sort.each do |lib|
6
- require lib
7
- path = ActiveSupport::Inflector.camelize(File.basename(lib, '.rb'))
8
- module_or_class = eval(path, nil, "eval: #{path}") rescue nil
9
- include module_or_class unless module_or_class.nil? || module_or_class.is_a?(Class)
10
- end
11
- end
12
- end
13
-
@@ -1,63 +0,0 @@
1
- module Machines
2
- module Checks
3
- def echo_result
4
- '&& echo CHECK PASSED || echo CHECK FAILED'
5
- end
6
-
7
- def check_package package, exists = true
8
- "dpkg --get-selections | grep #{package}.*#{exists ? '' : 'de'}install #{echo_result}"
9
- end
10
-
11
- def check_gem gem, version = nil
12
- version = " -v #{version}" if version
13
- "gem search #{gem}#{version} --installed #{echo_result}"
14
- end
15
-
16
- def check_file file, exists = true
17
- "test #{exists ? '' : '! '}-s #{file} #{echo_result}"
18
- end
19
-
20
- def check_link link
21
- "test -L #{link} #{echo_result}"
22
- end
23
-
24
- def check_dir dir, exists = true
25
- "test #{exists ? '' : '! '}-d #{dir} #{echo_result}"
26
- end
27
-
28
- def check_perms perms, path
29
- perms = perms.to_s
30
- mods = %w(--- --x -w- -wx r-- r-x rw- rwx)
31
- "ls -la #{path} | grep #{mods[perms[0..0].to_i]}#{mods[perms[1..1].to_i]}#{mods[perms[2..2].to_i]} #{echo_result}"
32
- end
33
-
34
- def check_owner user, path
35
- "ls -la #{path} | grep \"#{user}.*#{user}\" #{echo_result}"
36
- end
37
-
38
- def check_string string, file
39
- "grep \"#{string}\" #{file} #{echo_result}"
40
- end
41
-
42
- def check_daemon daemon, exists = true
43
- command = 'ps aux'
44
- search_for = "| grep #{daemon}"
45
- remove_grep = '| grep -v grep'
46
- negative = "| grep -v #{daemon} " unless exists
47
- "#{command} #{search_for} #{remove_grep} #{negative}#{echo_result}"
48
- end
49
-
50
- def check_init_d name
51
- "test -L /etc/rc0.d/K20#{name} #{echo_result}"
52
- end
53
-
54
- def check_command command, match = nil
55
- if match
56
- "#{command} | grep #{match} #{echo_result}"
57
- else
58
- "#{command} #{echo_result}"
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,49 +0,0 @@
1
- module Machines
2
- module Configuration
3
- # Add a new user
4
- # (uses the lowlevel useradd so doesn't set a password unless specified)
5
- # @param [String] login User name to create
6
- # @param [Hash] options
7
- # @option options [String] :password
8
- # @option options [Boolean] :admin Adds the user to the admin group when true
9
- def add_user login, options = {}
10
- password = "-p #{`openssl passwd #{options[:password]}`.gsub("\n", '')} " if options[:password]
11
- admin = "-G admin " if options[:admin]
12
- Command.new(
13
- "useradd -s /bin/bash -d /home/#{login} -m #{password}#{admin}#{login}",
14
- check_dir("/home/#{login}")
15
- )
16
- end
17
-
18
- # Add an existing user to a secondary group
19
- # @param [Hash] options
20
- # @option options [String] :user The user to add
21
- # @option options [String] :to Adds an existing user to the specified group
22
- def add options
23
- required_options options, [:user, :to]
24
- Command.new("usermod -a -G #{options[:to]} #{options[:user]}", check_command("groups #{options[:user]}", options[:to]))
25
- end
26
-
27
- # Sets gconf key value pairs
28
- # @param [Hash] options One or many key/value pairs to set
29
- def configure options
30
- options.map do |key, value|
31
- types = {String => 'string', Fixnum => 'int', TrueClass => 'bool',
32
- FalseClass => 'bool', Float => 'float', Array => 'list --list-type=string'}
33
- type = types[value.class]
34
- raise 'Invalid type for configure' unless type
35
- value = value.to_json if value.is_a?(Array)
36
- value = %("#{value}") if type == 'string'
37
- check = "gconftool-2 --get \"#{key}\" | grep #{value} #{echo_result}"
38
- Command.new("gconftool-2 --set \"#{key}\" --type #{type} #{value}", check)
39
- end
40
- end
41
-
42
- # Removes a user, home and any other related files
43
- # @param [String] login User name to remove
44
- def del_user login
45
- Command.new("deluser #{login} --remove-home -q", check_file('/home/login', false))
46
- end
47
- end
48
- end
49
-
@@ -1,17 +0,0 @@
1
- module Machines
2
- module Database
3
- # Write the database.yml file from webapps.yml
4
- # @param [AppBuilder] app
5
- def write_database_yml app
6
- yml = {$conf.environment.to_s => {
7
- 'adapter' => 'mysql',
8
- 'database' => app.database || app.name,
9
- 'username' => app.username || app.name,
10
- 'password' => app.password,
11
- 'host' => $conf.db_server.address,
12
- 'encoding' => 'utf8'}}.to_yaml
13
- write yml, :to => File.join(app.path, 'shared/config/database.yml'), :name => 'database.yml'
14
- end
15
- end
16
- end
17
-
@@ -1,104 +0,0 @@
1
- module Machines
2
- module FileOperations
3
- # Add a line of text to the end of a file unless it already exists
4
- # @param [String] text Text to add
5
- # @param [Hash] options
6
- # @option options [String] :to File to append to
7
- def append text, options
8
- text = text.gsub(/([\\$"`])/, '\\\\\1')
9
- Command.new("grep \"#{text}\" #{options[:to]} || echo \"#{text}\" >> #{options[:to]}", check_string(text, options[:to]))
10
- end
11
-
12
- # Change permissions of a path
13
- # @param [String, Integer] mode chmod permissions to set
14
- # @param [String] path Path to set
15
- def chmod mode, path
16
- Command.new("chmod #{mode} #{path}", check_perms(mode, path))
17
- end
18
-
19
- # Change ownership of a path
20
- # @param [String] user sets user and group unless user:group is specified
21
- # @param [String] path Path to set
22
- # @param [Hash] options
23
- # @option options [String] :recursive Chowns recursively if true
24
- def chown user, path, options = {}
25
- recursive = '-R ' if options[:recursive]
26
- user = "#{user}:#{user}" unless user.index(':')
27
- Command.new("chown #{recursive}#{user} #{path}", check_owner(user, path))
28
- end
29
-
30
- # Copy a remote file or folder (will overwrite)
31
- # @param [String] from Existing path
32
- # @param [String] to Path to copy to
33
- def copy from, to
34
- Command.new("cp -rf #{from} #{to}", check_file(to))
35
- end
36
-
37
- # Write a file from an ERB template
38
- # @param [String] erb_path Path to the ERB file to process
39
- # @param [Hash] options
40
- # @option options [AppBuilder] :settings Contains the settings as OpenStruct method calls for calling from the template
41
- # @option options [String] :to File to write to
42
- def create_from erb_path, options
43
- erb = ERB.new(File.read(erb_path), nil, '<>')
44
- binding = options[:settings] ? options[:settings].get_binding : nil
45
- options[:name] = erb_path
46
- write erb.result(binding), options
47
- end
48
-
49
- # Add a symlink
50
- # @param [String] target Existing path to link
51
- # @param [String] link_name path name for the link
52
- def link target, link_name
53
- Command.new("ln -sf #{target} #{link_name}", check_link(link_name))
54
- end
55
-
56
- # Create a path or paths on the remote host (Uses -p to be safe and create full path)
57
- # @param [String, Array] dirs A single path, multiple paths or array of paths to create
58
- def mkdir *dirs
59
- dirs.flatten.map do |dir|
60
- Command.new("mkdir -p #{dir}", check_dir(dir))
61
- end
62
- end
63
-
64
- # Rename a remote file or folder
65
- # @param [String] oldname Existing filename
66
- # @param [String] newname Rename to this
67
- def rename oldname, newname
68
- Command.new("mv -f #{oldname} #{newname}", check_file(newname))
69
- end
70
-
71
- # Remove a remote file or folder
72
- # @param [String] file or folder to remove (uses rm with -rf which ignores non-existent files and is recursive)
73
- def remove file
74
- Command.new("rm -rf #{file}", check_file(file, false))
75
- end
76
-
77
- # Take off the version numbers from a path name
78
- # @param [String] name Name of the path to rename
79
- def remove_version_info name
80
- Command.new("find . -maxdepth 1 -name \"#{name}*\" -a -type d | xargs -I xxx mv xxx #{name}", check_file(name))
81
- end
82
-
83
- # Replace some text in a file
84
- # @param [String] regex The expression to search for
85
- # @param [Hash] options
86
- # @option options [String] :with Text to use as the replacement
87
- # @option options [String] :in Filename to replace text in
88
- def replace regex, options
89
- required_options options, [:with, :in]
90
- with = options[:with].gsub(/([\n\/\\$"`])/, '\\\\\1')
91
- Command.new("sed -i \"s/#{regex}/#{with}/\" #{options[:in]}", check_string(with, options[:in]))
92
- end
93
-
94
- # (Over)write a file with the specified content
95
- # @param [String] text Text to add
96
- # @param [Hash] options
97
- # @option options [String] :to File to write to
98
- # @option options [String] :name Give the buffer a displayable name (e.g. when generated from a template)
99
- def write text, options
100
- Upload.new(NamedBuffer.new(options[:name], text), options[:to], check_string(text, options[:to]))
101
- end
102
- end
103
- end
104
-
@@ -1,171 +0,0 @@
1
- module Machines
2
- module Installation
3
- include FileOperations
4
-
5
- APTGET_QUIET = 'apt-get -q -y'
6
-
7
- # Adds a PPA source and updates apt
8
- # @param [String] name Name of the PPA
9
- # @param [String] key_name What to check in apt-key list to ensure it installed
10
- # add_ppa 'mozillateam/firefox-stable', 'mozilla'
11
- def add_ppa name, key_name
12
- [
13
- Command.new("add-apt-repository ppa:#{name}", "apt-key list | grep -i #{key_name} #{echo_result}"),
14
- update
15
- ]
16
- end
17
-
18
- # Adds a DEB source
19
- # @param [String] source URL of the package. If `YOUR_UBUNTU_VERSION_HERE` is included then it
20
- # is replaced by the Ubuntu version name
21
- # @param [Hash] options
22
- # @option options [String] :key URL of key
23
- # @option options [String] :name Used to check `apt-key list` to ensure it installed
24
- # sudo deb 'http://dl.google.com/linux/deb/ stable main',
25
- # :key => 'https://dl-ssl.google.com/linux/linux_signing_key.pub',
26
- # :name => 'Google'
27
- def deb source, options
28
- command = "echo deb #{source} >> /etc/apt/sources.list"
29
- if source =~ /YOUR_UBUNTU_VERSION_HERE/
30
- command = "expr substr `cat /etc/lsb-release | grep DISTRIB_CODENAME` 18 20 | xargs -I YOUR_UBUNTU_VERSION_HERE #{command}"
31
- end
32
- [
33
- Command.new(command, check_string(source.gsub(/ .*$/, ''), '/etc/apt/sources.list')),
34
- Command.new("wget -q #{options[:key]} -O - | apt-key add -", "apt-key list | grep -i #{options[:name]} #{echo_result}"),
35
- update
36
- ]
37
- end
38
-
39
- # Preseed debconf to allow silent installs
40
- # @param [String] app Name of application to configure
41
- # @param [String] setting The setting to set
42
- # @param [String] type Data type of the value
43
- # @param value The value to set (Ruby types supported)
44
- def debconf app, setting, type, value
45
- command = "echo #{app} #{setting} #{type} #{value} | debconf-set-selections"
46
- check = "debconf-get-selections | grep #{app} #{echo_result}"
47
- Command.new(command, check)
48
- end
49
-
50
- # Download, extract, and remove an archive. Currently supports `zip`, `tar.gz`, `tar.bz2`.
51
- # @param [String] package Package name to extract
52
- # @param [Hash] options
53
- # @option options [Optional String] :to folder to clone or extract to (defaults to /usr/local/src)
54
- def extract package, options = {}
55
- name = File.basename(package)
56
- if package[/.zip/]
57
- cmd = 'unzip -qq'
58
- elsif package[/.tar.gz/]
59
- cmd = 'tar -zxf'
60
- elsif package[/.tar.bz2/]
61
- cmd = 'tar -jxf'
62
- else
63
- raise "extract: Unknown extension for #{package}"
64
- end
65
- dir = cmd =~ /unzip/ ? File.basename(name, '.zip') : File.basename(name).gsub(/\.tar.*/, '')
66
- dest = options[:to] || '/usr/local/src'
67
- Command.new("cd #{dest} && wget #{package} && #{cmd} #{name} && rm #{name} && cd -", check_dir("#{File.join(dest, dir)}"))
68
- end
69
-
70
- # Install a gem
71
- # @param [String] package Name of the gem
72
- # @param [Hash] options
73
- # @option options [String] :version Optional version number
74
- def gem package, options = {}
75
- version = " -v \"#{options[:version]}\"" if options[:version]
76
- Command.new("gem install #{package}#{version}", check_gem(package, options[:version]))
77
- end
78
-
79
- # Update gems
80
- # @example Update Rubygems
81
- # gem_update '--system'
82
- def gem_update options = ''
83
- Command.new("gem update #{options}", nil)
84
- end
85
-
86
- # Clone (or update) a project from a Git repository
87
- # @param [String] url URL to clone
88
- # @param [Hash] options
89
- # @option options [Optional String] :to Folder to clone to
90
- # @option options [Optional String] :tag Checkout this tag after cloning (requires :to)
91
- # @option options [Optional String] :branch Switch this branch when cloning
92
- def git_clone url, options = {}
93
- raise ArgumentError.new('git_clone Must include a url and folder') if url.nil? || url.empty?
94
- raise ArgumentError.new('specifying :tag also requires :to') if options[:tag] && options[:to].nil?
95
- branch = "--branch #{options[:branch]} " if options[:branch]
96
- dir = options[:to] || url.gsub(/^.*\/|.git/, '')
97
- command = "test -d #{dir} && (cd #{dir} && git pull) || git clone --quiet #{branch}#{url}"
98
- command << " #{options[:to]}" if options[:to]
99
- command = Command.new(command, check_dir(options[:to]))
100
- command = [command, Command.new("cd #{options[:to]} && git checkout #{options[:tag]}", "git name-rev --name-only HEAD | grep #{options[:tag]}")] if options[:tag]
101
- command
102
- end
103
-
104
- # Installs one or more packages using apt, deb or git clone and install.sh (Ignores architecture differences)
105
- # (See `extract` to just uncompress tar.gz or zip files)
106
- # @param [Symbol, String, Array] packages can be:
107
- # URL::
108
- # Download from URL and run `dpkg` (if `:as => :dpkg`)
109
- # Download URL to `/usr/local/lib` and link `:bin` to `/usr/local/bin`
110
- # Array or string (with no URL)::
111
- # Run `apt` to install specified packages in the array or string
112
- # Packages are installed separately to aid progress feedback
113
- # Ensure this is the main package as dpkg get-selections is used to validate installation
114
- # install %w(build-essential libssl-dev mysql-server) #=> Installs apt packages
115
- # install 'http://example.com/my_package.deb', :cleanup => true #=> Installs a deb using dpkg then removes the deb
116
- # @param [Hash] options
117
- # @option options [Optional Symbol] :as Identify the package type so appropriate command can run. Currently supports `:dpkg` only
118
- # @option options [Optional String] :bin Specify the bin file to link to (e.g. '/bin/executable' will create a link /usr/local/bin/executable that points to /usr/local/lib/bin/executable)
119
- def install packages, options = {}
120
- if packages.is_a?(String)
121
- if packages =~ /^http:\/\//
122
- commands = []
123
- if packages =~ /\.deb$/i
124
- name = File.basename(packages)
125
- commands << Command.new("cd /tmp && wget #{packages} && dpkg -i --force-architecture #{name} && rm #{name} && cd -", nil)
126
- elsif options[:as] == :dpkg
127
- commands << extract(packages, :to => '/tmp')
128
- name = File.basename(packages).gsub(/\.(tar|zip).*/, '')
129
- commands << Command.new("cd /tmp/#{name} && dpkg -i --force-architecture *.deb && cd - && rm -rf /tmp/#{name}", nil)
130
- elsif options[:bin]
131
- commands << extract(packages, :to => '/tmp')
132
- name = File.basename(packages).gsub(/\.(tar|zip).*/, '')
133
- commands << rename("/tmp/#{name}", "/usr/local/lib")
134
- commands << link("/usr/local/lib/#{name}/#{options[:bin]}", "/usr/local/bin/#{File.basename(options[:bin])}")
135
- end
136
- return commands
137
- else
138
- packages = [packages]
139
- end
140
- end
141
-
142
- if packages.is_a?(Array)
143
- commands = packages.map do |package|
144
- Command.new("#{APTGET_QUIET} install #{package}", check_package(package))
145
- end
146
- end
147
- commands
148
- end
149
-
150
- # Remove one or more packages
151
- # @param [Array] packages Packages to remove
152
- def uninstall packages
153
- packages.map do |package|
154
- Command.new("#{APTGET_QUIET} purge #{package}", check_package(package, false))
155
- end
156
- end
157
-
158
- def update
159
- Command.new("#{APTGET_QUIET} update > /tmp/apt-update.log", check_string('Reading package lists', '/tmp/apt-update.log'))
160
- end
161
-
162
- # Update, upgrade, autoremove, autoclean apt packages
163
- # TODO: Check that check_command really checks the correct command with 'echo $?'
164
- def upgrade
165
- %w(update upgrade autoremove autoclean).map do |command|
166
- Command.new("#{APTGET_QUIET} #{command}", check_command('echo $?', '0'))
167
- end
168
- end
169
- end
170
- end
171
-