vagrant-export 0.2.0 → 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22ffb620520d9ce8de162db23c13534aaf2c6066
4
+ data.tar.gz: 9384052c5d82e9e8a6927c660dccf4373758a13f
5
+ SHA512:
6
+ metadata.gz: 9cc20fffcfe53286ff5900d86a1d17ebc6f8bed5b3263499580273f960a6b90260779c210bb888d17eae989b2a7a5fd61bd4fe42f38d8fbc85ae0749a0bd45b3
7
+ data.tar.gz: 1f619a25c1733c7eca78d84bef249873ff0f5ebd31d1de98d7b3654a609bf7f4f9d3f20adcd4c8dffa515080b748aa8c45455bd0a367fa018ee4d8d33ffed526
@@ -36,7 +36,7 @@ module VagrantPlugins
36
36
  ex = Exporter.new(@env, @logger)
37
37
 
38
38
  with_target_vms argv, reverse: true do |machine|
39
- ex.handle machine, options[:fast], options[:bare]
39
+ ex.handle(machine, options[:fast], options[:bare])
40
40
  end
41
41
  0
42
42
  end
@@ -19,7 +19,7 @@ module VagrantPlugins
19
19
  # @param vm Vagrant::Machine
20
20
  # @param fast Boolean
21
21
  # @param bare Boolean
22
- def handle vm, fast, bare
22
+ def handle(vm, fast, bare)
23
23
  @vm = vm
24
24
  @did_run = false
25
25
 
@@ -27,16 +27,13 @@ module VagrantPlugins
27
27
  if can_compress
28
28
  compress
29
29
  else
30
- @env.uid.error 'Cannot compress this type of machine'
30
+ @env.uid.error('Cannot compress this type of machine')
31
31
  return 1
32
32
  end
33
33
  end
34
34
 
35
35
  return 1 unless export
36
-
37
- unless bare
38
- return 1 unless files
39
- end
36
+ return 1 unless files(bare)
40
37
 
41
38
  finalize
42
39
  end
@@ -48,14 +45,14 @@ module VagrantPlugins
48
45
  if @vm.state.short_description == 'running'
49
46
  @did_run = true
50
47
  else
51
- @env.ui.info 'Machine not running, bringing it up'
52
- @vm.action :up
48
+ @env.ui.info('Machine not running, bringing it up')
49
+ @vm.action(:up)
53
50
  end
54
51
 
55
52
  compress_supported = false
56
53
 
57
54
  if @vm.config.vm.communicator != :winrm
58
- @vm.communicate.execute 'lsb_release -i -s', error_key: :ssh_bad_exit_status_muted do |type, data|
55
+ @vm.communicate.execute('lsb_release -i -s', error_key: :ssh_bad_exit_status_muted) do |type, data|
59
56
  if type == :stdout && data.to_s =~ /mint|ubuntu|debian/i
60
57
  compress_supported = true
61
58
  end
@@ -71,25 +68,25 @@ module VagrantPlugins
71
68
  source_script = File.expand_path('../../../res/cleanup.sh', __FILE__)
72
69
  comm = @vm.communicate
73
70
 
74
- @logger.debug "Uploading #{source_script} to #{target_script}"
75
- comm.upload source_script, target_script
71
+ @logger.debug("Uploading #{source_script} to #{target_script}")
72
+ comm.upload(source_script, target_script)
76
73
 
77
- sudo comm, "chmod +x #{target_script}"
78
- sudo comm, "#{target_script}"
74
+ sudo(comm, "chmod +x #{target_script}")
75
+ sudo(comm, "#{target_script}")
79
76
 
80
77
  0
81
78
  end
82
79
 
83
- def sudo communicator, command
84
- @logger.debug "Execute '#{command}'"
85
- communicator.sudo command, error_key: :ssh_bad_exit_status_muted do |type, data|
80
+ def sudo(communicator, command)
81
+ @logger.debug("Execute '#{command}'")
82
+ communicator.sudo(command, error_key: :ssh_bad_exit_status_muted) do |type, data|
86
83
  if [:stderr, :stdout].include?(type)
87
84
  return if data.empty?
88
85
  data = data.to_s.chomp.strip
89
86
  if type == :stdout
90
- @vm.ui.info data
87
+ @vm.ui.info(data)
91
88
  else
92
- @vm.ui.error data
89
+ @vm.ui.error(data)
93
90
  end
94
91
  end
95
92
  end
@@ -98,56 +95,74 @@ module VagrantPlugins
98
95
  def export
99
96
  # Halt the machine
100
97
  if @vm.state.short_description == 'running'
101
- @env.ui.info 'Halting VM for export'
98
+ @env.ui.info('Halting VM for export')
102
99
  @vm.action(:halt)
103
100
  end
104
101
 
105
102
  # Export to file
106
- exported_path = File.join @env.tmp_path, Time.now.to_i.to_s
103
+ exported_path = File.join(@env.tmp_path, Time.now.to_i.to_s)
107
104
  @tmp_path = exported_path
108
- FileUtils.mkpath exported_path
105
+ FileUtils.mkdir_p(exported_path)
109
106
 
110
- @env.ui.info I18n.t 'vagrant.actions.vm.export.exporting'
107
+ @env.ui.info('Exporting machine')
111
108
  @vm.provider.driver.export File.join(exported_path, 'box.ovf') do |progress|
112
109
  @env.ui.clear_line
113
- @env.ui.report_progress progress.percent, 100, false
110
+ @env.ui.report_progress(progress.percent, 100, false)
114
111
  end
115
112
 
116
- @logger.debug "Exported VM to #{exported_path}"
113
+ @logger.debug("Exported VM to #{exported_path}")
117
114
  end
118
115
 
119
- def files
116
+ def files(bare)
120
117
 
121
118
  # Add metadata json
122
119
  begin
123
120
  metadata = File.open(File.join(@tmp_path, 'metadata.json'), 'wb')
124
- metadata.write '{"provider":"' + @vm.provider_name.to_s + '"}'
121
+ metadata.write('{"provider":"' + @vm.provider_name.to_s + '"}')
125
122
  ensure
126
123
  metadata.close
127
124
  end
128
125
 
129
- target_include_path = File.join @tmp_path, 'include'
130
- source_include_path = File.join @vm.box.directory, 'include'
126
+ target_include_path = File.join(@tmp_path, 'include')
127
+ source_include_path = File.join(@vm.box.directory, 'include')
131
128
 
132
129
  # Copy includes
133
- if Dir.exist? source_include_path
134
- FileUtils.cp_r source_include_path, @tmp_path
130
+ if Dir.exist?(source_include_path) && !bare
131
+ FileUtils.cp_r(source_include_path, @tmp_path)
132
+ end
135
133
 
136
- # Add the orignal vagrant file as include
137
- else
138
- FileUtils.mkpath target_include_path
139
- Dir.glob(File.join(@vm.box.directory, '**', '*')).each do |file|
140
- if file.to_s =~ /Vagrantfile$/
141
- FileUtils.cp file.to_s, File.join(target_include_path, '_Vagrantfile')
134
+ original_vagrantfile = File.join(@vm.box.directory, 'include')
135
+ vagrantfile_exists = File.exist?(original_vagrantfile)
136
+ vagrantfile_has_mac = false
137
+
138
+ # Check the original vagrant file for a mac settings
139
+ if vagrantfile_exists
140
+ File.readlines(original_vagrantfile).each { |line|
141
+ if line.to_s =~ /base_mac\s*=\s*("|')[a-z0-9]+("|')/i
142
+ vagrantfile_has_mac = true
142
143
  end
143
- end
144
+ }
144
145
  end
145
146
 
146
- # Add the mac address setting as a Vagrantfile
147
- File.open(File.join(@tmp_path, 'Vagrantfile'), 'wb') do |f|
148
- f.write(Vagrant::Util::TemplateRenderer.render('package_Vagrantfile', {
149
- base_mac: @vm.provider.driver.read_mac_address
150
- }))
147
+ # Otherwise, just put copy it
148
+ if vagrantfile_has_mac
149
+ FileUtils.cp(original_vagrantfile, File.join(@tmp_path, 'Vagrantfile'))
150
+
151
+ # If none, create a new one that has the mac setting,
152
+ # and includes the original
153
+ # The new Vagrantfile will include the old one, which
154
+ # is put into the includeds directory
155
+ else
156
+ File.open(File.join(@tmp_path, 'Vagrantfile'), 'wb') do |file|
157
+ file.write(Vagrant::Util::TemplateRenderer.render('package_Vagrantfile', {
158
+ base_mac: @vm.provider.driver.read_mac_address
159
+ }))
160
+ end
161
+
162
+ if vagrantfile_exists
163
+ FileUtils.mkdir_p(target_include_path) unless Dir.exist?(target_include_path)
164
+ FileUtils.cp(original_vagrantfile, File.join(target_include_path, '_Vagrantfile'))
165
+ end
151
166
  end
152
167
 
153
168
  # Make a box file out of it
@@ -163,19 +178,20 @@ module VagrantPlugins
163
178
 
164
179
  def finalize
165
180
  # Rename the box file
166
- if File.exist? @box_file_name
167
- box_name = @vm.box.name.gsub '/', '_'
168
- target_box = File.join @env.cwd, box_name + '.box'
169
- File.rename @box_file_name, target_box
181
+ if File.exist?(@box_file_name)
182
+ box_name = @vm.box.name.gsub('/', '_')
183
+ target_box = File.join(@env.cwd, box_name + '.box')
184
+ FileUtils.mv(@box_file_name, target_box)
185
+ @env.ui.info('Created ' + target_box)
170
186
  end
171
187
 
172
188
  # Remove the tmp files
173
- FileUtils.rm_rf @tmp_path
189
+ FileUtils.rm_rf(@tmp_path)
174
190
 
175
191
  # Resume the machine
176
192
  if @did_run
177
- @env.ui.info 'Bringing the machine back up'
178
- @vm.action :up
193
+ @env.ui.info('Bringing the machine back up')
194
+ @vm.action(:up)
179
195
  end
180
196
  end
181
197
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module VagrantPlugins
7
7
  module Export
8
- VERSION = '0.2.0'
8
+ VERSION = '0.2.1'
9
9
  end
10
10
  end
@@ -3,5 +3,5 @@
3
3
  # the terms of the MIT- / X11 - License #
4
4
  # #
5
5
 
6
- require "vagrant-export/plugin"
7
- require "vagrant-export/version"
6
+ require 'vagrant-export/plugin'
7
+ require 'vagrant-export/version'
data/res/cleanup.sh CHANGED
@@ -1,83 +1,50 @@
1
- #!/bin/bash -eux
1
+ #!/bin/bash
2
2
 
3
- # Removing old kernel packages
3
+ echo "Removing old kernel packages"
4
4
  apt-get -y --purge remove $(dpkg --list | grep '^rc' | awk '{print $2}')
5
5
  apt-get -y --purge remove $(dpkg --list | egrep 'linux-image-[0-9]' | awk '{print $3,$2}' | sort -nr | tail -n +2 | grep -v $(uname -r) | awk '{ print $2}')
6
6
 
7
- # Cleaning up apt
7
+ echo "Cleaning up apt"
8
8
  apt-get -y --purge autoremove
9
9
  apt-get -y clean
10
10
  rm -rf /var/lib/apt/lists/*
11
11
  rm -rf /var/lib/aptitude/*
12
12
 
13
- # Cleaning up home
13
+ echo "Cleaning up home"
14
14
  rm -rf $HOME/.cache
15
15
  rm -rf $HOME/.local
16
16
  rm -rf $HOME/.npm
17
17
  rm -rf $HOME/tmp
18
18
 
19
- # Empty TYPO3 CMS temp files
20
19
  if [[ -d /var/www/typo3temp ]]; then
20
+ echo "Empty TYPO3 CMS temp files"
21
21
  find /var/www/typo3temp -type f -exec rm -f {} \;
22
22
  fi
23
23
 
24
- # Empty Flow temp files
25
24
  if [[ -d /var/www/Data/Temporary ]]; then
26
- rm -rf /var/www/Data/Temporary
25
+ echo "Empty TYPO3 Flow temp files"
26
+ rm -rf /var/www/Data/Temporary/*
27
27
  fi
28
28
 
29
-
30
- # Empty Magento temp files
31
29
  if [[ -d /var/www/downloader/.cache ]]; then
30
+ echo "Empty Magento temp files"
32
31
  rm -rf /var/www/downloader/.cache/*
33
- fi
34
-
35
- if [[ -d /var/www/downloader/pearlib/cache ]]; then
36
32
  rm -rf /var/www/downloader/pearlib/cache/*
37
- fi
38
-
39
- if [[ -d /var/www/downloader/pearlib/download ]]; then
40
33
  rm -rf /var/www/downloader/pearlib/download/*
41
- fi
42
-
43
- if [[ -d /var/www/var/cache ]]; then
44
34
  rm -rf /var/www/var/cache/*
45
- fi
46
-
47
- if [[ -d /var/www/var/locks ]]; then
48
35
  rm -rf /var/www/var/locks/*
49
- fi
50
-
51
- if [[ -d /var/www/var/log ]]; then
52
36
  rm -rf /var/www/var/log/*
53
- fi
54
-
55
- if [[ -d /var/www/var/report ]]; then
56
37
  rm -rf /var/www/var/report/*
57
- fi
58
-
59
- if [[ -d /var/www/var/cache ]]; then
60
- rm -rf /var/www/var/cache/*
61
- fi
62
-
63
- if [[ -d /var/www/var/session ]]; then
64
38
  rm -rf /var/www/var/session/*
65
- fi
66
-
67
- if [[ -d /var/www/var/tmp ]]; then
68
39
  rm -rf /var/www/var/tmp/*
69
40
  fi
70
41
 
71
-
72
- # Empty tmp
73
- rm -rf /tmp/*
74
-
75
- # Make sure we sync before the next step
42
+ echo "Sync to disc"
76
43
  sync
77
44
 
78
- # Zero out the free space to save space in the final image:
79
45
  echo "Zeroing device to make space..."
80
46
  dd if=/dev/zero of=/EMPTY bs=1M
81
47
  rm -f /EMPTY
82
48
 
49
+ echo "Exit happily"
83
50
  exit 0
@@ -1,4 +1,4 @@
1
- $:.unshift File.expand_path("../lib", __FILE__)
1
+ $:.unshift(File.expand_path('../lib', __FILE__))
2
2
 
3
3
  require 'vagrant-export/version'
4
4
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Georg Großberger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-10-11 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Export boxes to .box files including the original Vagrantfile and some
15
14
  cleanups inside the VM
@@ -18,39 +17,38 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
20
+ - ".gitignore"
21
21
  - Gemfile
22
22
  - lib/vagrant-export.rb
23
- - lib/vagrant-export/exporter.rb
24
- - lib/vagrant-export/version.rb
25
23
  - lib/vagrant-export/command.rb
24
+ - lib/vagrant-export/exporter.rb
26
25
  - lib/vagrant-export/plugin.rb
27
- - vagrant-export.gemspec
26
+ - lib/vagrant-export/version.rb
28
27
  - res/cleanup.sh
29
- - .gitignore
28
+ - vagrant-export.gemspec
30
29
  homepage: https://github.com/trenker/vagrant-export
31
30
  licenses:
32
31
  - MIT
32
+ metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
38
  requirements:
40
- - - ! '>='
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  required_rubygems_version: !ruby/object:Gem::Requirement
44
- none: false
45
43
  requirements:
46
- - - ! '>='
44
+ - - ">="
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  requirements: []
50
48
  rubyforge_project:
51
- rubygems_version: 1.8.23
49
+ rubygems_version: 2.2.2
52
50
  signing_key:
53
- specification_version: 3
51
+ specification_version: 4
54
52
  summary: Export boxes to .box files including the original Vagrantfile and some cleanups
55
53
  inside the VM
56
54
  test_files: []