vagrant-export 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca43dade64192c5fb5fa7e7791ec719ded8cf48c
4
- data.tar.gz: 54401f0258c8c1760866e480c3ed7b458cb1a040
3
+ metadata.gz: aebbfe47b8cb61c914617b5093dd3eff5cc6685c
4
+ data.tar.gz: e1a2327a50b858faa052da044c0931a217a6e179
5
5
  SHA512:
6
- metadata.gz: 1ce74785f6932ebed41f267313f7e59c0dcb61c4cd68c996dd262a9a189e2e2bb55394a4be18b0be68c526058acfb4be117cafe5536095fc7b8822487d78fd84
7
- data.tar.gz: cd1a40933bbaa940496e55624494b6bd4e1ae53d113bee866a1d46efa80c9d22c5ba1e1a042f8207162370f2e91fcc9b68ab9376809bc78518f322f2522c2e73
6
+ metadata.gz: 051a3a01cd6caca98e9142798c9ed20e967e6094953beb2a6a97bc44ea48de850ec543bbea17a7eddce97c7e4f78f6dc643bba7a2587cca34f531ecb49ff8f8f
7
+ data.tar.gz: 98335fc927b5ef5915220465eae6df1b7af93bb34fe42b885033dbe885c7c618491ec8657976232b2482f7249d7522c61fe95d6f2e360004c502977b6870cf58
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.idea
2
- /.vagrant
3
- /Gemfile.lock
4
- Vagrantfile
1
+ /.idea
2
+ /.vagrant
3
+ /Gemfile.lock
4
+ Vagrantfile
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
5
- end
6
-
7
- group :plugins do
8
- gem 'vagrant-export', path: '.'
9
- end
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
5
+ end
6
+
7
+ group :plugins do
8
+ gem 'vagrant-export', path: '.'
9
+ end
data/README.md CHANGED
@@ -1,50 +1,50 @@
1
- # Vagrant Export
2
-
3
- [Vagrant](http://www.vagrantup.com) plugin to export compressed and optimized linux boxes from virtualbox into a .box file
4
-
5
- ## Installation
6
-
7
- ```bash
8
- vagrant plugin install vagrant-export
9
- ```
10
-
11
- ## Useage
12
-
13
- ```bash
14
- vagrant export
15
- ```
16
- Exports the current box into a .box file. The file name is determined by the setting `config.vm.name`, were slashes are replaced with underscores.
17
-
18
- So a Vagrantfile with this setting:
19
-
20
- ```ruby
21
- Vagrant.configure(2) do |config|
22
- config.vm.name = "hashicorp/precise32"
23
- end
24
- ```
25
-
26
- will be exported to a file named `hashicorp_precise32.box`
27
-
28
- ## License
29
-
30
- The MIT License (MIT)
31
-
32
- Copyright (c) 2015 Georg Großberger
33
-
34
- Permission is hereby granted, free of charge, to any person obtaining a copy
35
- of this software and associated documentation files (the "Software"), to deal
36
- in the Software without restriction, including without limitation the rights
37
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
- copies of the Software, and to permit persons to whom the Software is
39
- furnished to do so, subject to the following conditions:
40
-
41
- The above copyright notice and this permission notice shall be included in
42
- all copies or substantial portions of the Software.
43
-
44
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50
- THE SOFTWARE.
1
+ # Vagrant Export
2
+
3
+ [Vagrant](http://www.vagrantup.com) plugin to export compressed and optimized linux boxes from virtualbox into a .box file
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ vagrant plugin install vagrant-export
9
+ ```
10
+
11
+ ## Useage
12
+
13
+ ```bash
14
+ vagrant export
15
+ ```
16
+ Exports the current box into a .box file. The file name is determined by the setting `config.vm.name`, were slashes are replaced with underscores.
17
+
18
+ So a Vagrantfile with this setting:
19
+
20
+ ```ruby
21
+ Vagrant.configure(2) do |config|
22
+ config.vm.name = "hashicorp/precise32"
23
+ end
24
+ ```
25
+
26
+ will be exported to a file named `hashicorp_precise32.box`
27
+
28
+ ## License
29
+
30
+ The MIT License (MIT)
31
+
32
+ Copyright (c) 2015 Georg Großberger
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy
35
+ of this software and associated documentation files (the "Software"), to deal
36
+ in the Software without restriction, including without limitation the rights
37
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
+ copies of the Software, and to permit persons to whom the Software is
39
+ furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in
42
+ all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50
+ THE SOFTWARE.
@@ -1,7 +1,7 @@
1
- # #
2
- # This is free software; you can redistribute it and/or modify it under #
3
- # the terms of the MIT- / X11 - License #
4
- # #
5
-
6
- require 'vagrant-export/plugin'
7
- require 'vagrant-export/version'
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ require 'vagrant-export/plugin'
7
+ require 'vagrant-export/version'
@@ -1,45 +1,45 @@
1
- # #
2
- # This is free software; you can redistribute it and/or modify it under #
3
- # the terms of the MIT- / X11 - License #
4
- # #
5
-
6
- module VagrantPlugins
7
- module Export
8
- class Command < Vagrant.plugin '2', :command
9
-
10
- def self.synopsis
11
- 'exports a box file with additional actions taken'
12
- end
13
-
14
- def execute
15
- options = {}
16
- options[:fast] = false
17
- options[:bare] = false
18
-
19
- opts = OptionParser.new do |o|
20
- o.banner = 'Usage: vagrant export [switches]'
21
- o.separator ''
22
-
23
- o.on('-f', '--fast', 'Do not perform cleanups.') do |f|
24
- options[:fast] = f
25
- end
26
-
27
- o.on('-b', '--bare', 'Do not include additional files.') do |b|
28
- options[:bare] = b
29
- end
30
- end
31
-
32
- argv = parse_options(opts)
33
- return 1 unless argv
34
-
35
- require_relative 'exporter'
36
- ex = Exporter.new(@env, @logger)
37
-
38
- with_target_vms argv, reverse: true do |machine|
39
- ex.handle(machine, options[:fast], options[:bare])
40
- end
41
- 0
42
- end
43
- end
44
- end
45
- end
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Export
8
+ class Command < Vagrant.plugin '2', :command
9
+
10
+ def self.synopsis
11
+ 'exports a box file with additional actions taken'
12
+ end
13
+
14
+ def execute
15
+ options = {}
16
+ options[:fast] = false
17
+ options[:bare] = false
18
+
19
+ opts = OptionParser.new do |o|
20
+ o.banner = 'Usage: vagrant export [switches]'
21
+ o.separator ''
22
+
23
+ o.on('-f', '--fast', 'Do not perform cleanups.') do |f|
24
+ options[:fast] = f
25
+ end
26
+
27
+ o.on('-b', '--bare', 'Do not include additional files.') do |b|
28
+ options[:bare] = b
29
+ end
30
+ end
31
+
32
+ argv = parse_options(opts)
33
+ return 1 unless argv
34
+
35
+ require_relative 'exporter'
36
+ ex = Exporter.new(@env, @logger)
37
+
38
+ with_target_vms argv, reverse: true do |machine|
39
+ ex.handle(machine, options[:fast], options[:bare])
40
+ end
41
+ 0
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,248 +1,248 @@
1
- # #
2
- # This is free software; you can redistribute it and/or modify it under #
3
- # the terms of the MIT- / X11 - License #
4
- # #
5
-
6
- require 'fileutils'
7
-
8
- module VagrantPlugins
9
- module Export
10
- class Exporter
11
-
12
- # @param env Vagrant::Environment
13
- # @param logger Log4r::Logger
14
- def initialize(env, logger)
15
- @env = env
16
- @logger = logger
17
- end
18
-
19
- # @param vm Vagrant::Machine
20
- # @param fast Boolean
21
- # @param bare Boolean
22
- # @return string
23
- def handle(vm, fast, bare)
24
- @vm = vm
25
- @did_run = false
26
-
27
- unless fast
28
- if can_compress
29
- compress
30
- else
31
- @env.uid.error('Cannot compress this type of machine')
32
- return 1
33
- end
34
- end
35
-
36
- return 1 unless export
37
- return 1 unless files(bare)
38
-
39
- finalize
40
-
41
- @target_box
42
- end
43
-
44
- protected
45
-
46
-
47
- def can_compress
48
- if @vm.state.short_description == 'running'
49
- @did_run = true
50
- else
51
- @env.ui.info('Machine not running, bringing it up')
52
- @vm.action(:up)
53
- end
54
-
55
- compress_supported = false
56
-
57
- if @vm.config.vm.communicator != :winrm
58
- @vm.communicate.execute('lsb_release -i -s', error_key: :ssh_bad_exit_status_muted) do |type, data|
59
- if type == :stdout && data.to_s =~ /mint|ubuntu|debian/i
60
- compress_supported = true
61
- end
62
- end
63
- end
64
-
65
- compress_supported
66
- end
67
-
68
- def compress
69
-
70
- target_script = "/tmp/_cleanup_#{Time.now.to_i.to_s}.sh"
71
- source_script = File.expand_path('../../../res/cleanup.sh', __FILE__)
72
- comm = @vm.communicate
73
-
74
- @logger.debug("Uploading #{source_script} to #{target_script}")
75
- comm.upload(source_script, target_script)
76
-
77
- sudo(comm, "chmod +x #{target_script}")
78
- sudo(comm, "#{target_script}")
79
-
80
- 0
81
- end
82
-
83
- def sudo(communicator, command)
84
- @logger.debug("Execute '#{command}'")
85
- communicator.sudo(command, error_key: :ssh_bad_exit_status_muted) do |type, data|
86
- if [:stderr, :stdout].include?(type)
87
- return if data.empty?
88
- data = data.to_s.chomp.strip
89
- if type == :stdout
90
- @vm.ui.info(data)
91
- else
92
- @vm.ui.error(data)
93
- end
94
- end
95
- end
96
- end
97
-
98
-
99
- # Add the private key if we have one
100
- # Shamelessly stolen from Vagrant::Action::General::Package
101
- def setup_private_key
102
-
103
- # If we don't have a generated private key, we do nothing
104
- path = @vm.data_dir.join('private_key')
105
- return unless path.file?
106
-
107
- # Copy it into our box directory
108
- new_path = @tmp_path.join('vagrant_private_key')
109
- FileUtils.cp(path, new_path)
110
-
111
- # Append it to the Vagrantfile (or create a Vagrantfile)
112
- vf_path = @tmp_path.join('Vagrantfile')
113
- mode = 'w+'
114
- mode = 'a' if vf_path.file?
115
-
116
- vf_path.open(mode) do |f|
117
- f.binmode
118
- f.puts
119
- f.puts %Q[Vagrant.configure("2") do |config|]
120
- f.puts %Q[ config.ssh.private_key_path = File.expand_path("../vagrant_private_key", __FILE__)]
121
- f.puts %Q[end]
122
- end
123
- end
124
-
125
- def export
126
- # Halt the machine
127
- if @vm.state.short_description == 'running'
128
- @env.ui.info('Halting VM for export')
129
- @vm.action(:halt)
130
- end
131
-
132
- # Export to file
133
- exported_path = File.join(@env.tmp_path, Time.now.to_i.to_s)
134
- @tmp_path = exported_path
135
- FileUtils.mkdir_p(exported_path)
136
-
137
- @env.ui.info('Exporting machine')
138
-
139
- provider_name = @vm.provider_name.to_s
140
-
141
- if /vmware/i =~ provider_name
142
- current_dir = File.dirname(@vm.id)
143
- files = Dir.glob(File.join(current_dir, '**', '*')).select {|f|
144
- !File.directory?(f)
145
- }
146
- FileUtils.cp_r(files, exported_path)
147
- else
148
- @vm.provider.driver.export File.join(exported_path, 'box.ovf' + ext) do |progress|
149
- @env.ui.clear_line
150
- @env.ui.report_progress(progress.percent, 100, false)
151
- end
152
- end
153
-
154
- @logger.debug("Exported VM to #{exported_path}")
155
- end
156
-
157
- def files(bare)
158
-
159
- provider_name = @vm.provider_name.to_s
160
-
161
- # Add metadata json
162
- begin
163
- metadata = File.open(File.join(@tmp_path, 'metadata.json'), 'wb')
164
- metadata.write('{"provider":"' + provider_name + '"}')
165
- ensure
166
- metadata.close
167
- end
168
-
169
- target_include_path = File.join(@tmp_path, 'include')
170
- source_include_path = File.join(@vm.box.directory, 'include')
171
-
172
- # Copy includes
173
- if Dir.exist?(source_include_path) && !bare
174
- FileUtils.cp_r(source_include_path, @tmp_path)
175
- end
176
-
177
- original_vagrantfile = File.join(@vm.box.directory, 'Vagrantfile')
178
- vagrantfile_exists = File.exist?(original_vagrantfile)
179
- vagrantfile_has_mac = false
180
- vagrantfile_needs_mac = @vm.provider_name.to_s == 'virtualbox'
181
-
182
- # Check the original vagrant file for a mac settings
183
- if vagrantfile_exists && vagrantfile_needs_mac
184
- File.readlines(original_vagrantfile).each { |line|
185
- if line.to_s =~ /base_mac\s*=\s*("|')/i
186
- vagrantfile_has_mac = true
187
- end
188
- }
189
- end
190
-
191
- # If it has one, just copy it
192
- if vagrantfile_has_mac || (!vagrantfile_needs_mac && vagrantfile_exists)
193
- FileUtils.cp(original_vagrantfile, File.join(@tmp_path, 'Vagrantfile'))
194
-
195
- # If none, create a new one that has the mac setting,
196
- # and includes the original
197
- # The new Vagrantfile will include the old one, which
198
- # is put into the includeds directory
199
- else
200
- File.open(File.join(@tmp_path, 'Vagrantfile'), 'wb') do |file|
201
- file.write(Vagrant::Util::TemplateRenderer.render('package_Vagrantfile', {
202
- base_mac: @vm.provider.driver.read_mac_address
203
- }))
204
- end
205
-
206
- # If there is a Vagrantfile, but without a mac
207
- # ensure it is included
208
- if vagrantfile_exists
209
- FileUtils.mkdir_p(target_include_path) unless Dir.exist?(target_include_path)
210
- FileUtils.cp(original_vagrantfile, File.join(target_include_path, '_Vagrantfile'))
211
- end
212
- end
213
-
214
- # Copy the private key if available
215
- setup_private_key
216
-
217
- # Make a box file out of it
218
- @box_file_name = @tmp_path + '.box'
219
-
220
- Vagrant::Util::SafeChdir.safe_chdir(@tmp_path) do
221
- files = Dir.glob(File.join('.', '**', '*'))
222
- Vagrant::Util::Subprocess.execute('bsdtar', '-czf', @box_file_name, *files)
223
- end
224
-
225
- 0
226
- end
227
-
228
- def finalize
229
- # Rename the box file
230
- if File.exist?(@box_file_name)
231
- box_name = @vm.box.name.gsub('/', '_')
232
- @target_box = File.join(@env.cwd, box_name + '.box')
233
- FileUtils.mv(@box_file_name, @target_box)
234
- @env.ui.info('Created ' + @target_box)
235
- end
236
-
237
- # Remove the tmp files
238
- FileUtils.rm_rf(@tmp_path)
239
-
240
- # Resume the machine
241
- if @did_run
242
- @env.ui.info('Bringing the machine back up')
243
- @vm.action(:up)
244
- end
245
- end
246
- end
247
- end
248
- end
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ require 'fileutils'
7
+
8
+ module VagrantPlugins
9
+ module Export
10
+ class Exporter
11
+
12
+ # @param env Vagrant::Environment
13
+ # @param logger Log4r::Logger
14
+ def initialize(env, logger)
15
+ @env = env
16
+ @logger = logger
17
+ end
18
+
19
+ # @param vm Vagrant::Machine
20
+ # @param fast Boolean
21
+ # @param bare Boolean
22
+ # @return string
23
+ def handle(vm, fast, bare)
24
+ @vm = vm
25
+ @did_run = false
26
+
27
+ unless fast
28
+ if can_compress
29
+ compress
30
+ else
31
+ @env.uid.error('Cannot compress this type of machine')
32
+ return 1
33
+ end
34
+ end
35
+
36
+ return 1 unless export
37
+ return 1 unless files(bare)
38
+
39
+ finalize
40
+
41
+ @target_box
42
+ end
43
+
44
+ protected
45
+
46
+
47
+ def can_compress
48
+ if @vm.state.short_description == 'running'
49
+ @did_run = true
50
+ else
51
+ @env.ui.info('Machine not running, bringing it up')
52
+ @vm.action(:up)
53
+ end
54
+
55
+ compress_supported = false
56
+
57
+ if @vm.config.vm.communicator != :winrm
58
+ @vm.communicate.execute('lsb_release -i -s', error_key: :ssh_bad_exit_status_muted) do |type, data|
59
+ if type == :stdout && data.to_s =~ /mint|ubuntu|debian/i
60
+ compress_supported = true
61
+ end
62
+ end
63
+ end
64
+
65
+ compress_supported
66
+ end
67
+
68
+ def compress
69
+
70
+ target_script = "/tmp/_cleanup_#{Time.now.to_i.to_s}.sh"
71
+ source_script = File.expand_path('../../../res/cleanup.sh', __FILE__)
72
+ comm = @vm.communicate
73
+
74
+ @logger.debug("Uploading #{source_script} to #{target_script}")
75
+ comm.upload(source_script, target_script)
76
+
77
+ sudo(comm, "chmod +x #{target_script}")
78
+ sudo(comm, "#{target_script}")
79
+
80
+ 0
81
+ end
82
+
83
+ def sudo(communicator, command)
84
+ @logger.debug("Execute '#{command}'")
85
+ communicator.sudo(command, error_key: :ssh_bad_exit_status_muted) do |type, data|
86
+ if [:stderr, :stdout].include?(type)
87
+ return if data.empty?
88
+ data = data.to_s.chomp.strip
89
+ if type == :stdout
90
+ @vm.ui.info(data)
91
+ else
92
+ @vm.ui.error(data)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ # Add the private key if we have one
100
+ # Shamelessly stolen from Vagrant::Action::General::Package
101
+ def setup_private_key
102
+
103
+ # If we don't have a generated private key, we do nothing
104
+ path = @vm.data_dir.join('private_key')
105
+ return unless path.file?
106
+
107
+ # Copy it into our box directory
108
+ new_path = File.join(@tmp_path, 'vagrant_private_key')
109
+ FileUtils.cp(path, new_path)
110
+
111
+ # Append it to the Vagrantfile (or create a Vagrantfile)
112
+ vf_path = File.join(@tmp_path, 'Vagrantfile')
113
+ mode = 'w+'
114
+ mode = 'a' if File.file?(vf_path)
115
+
116
+ File.open(vf_path, mode) do |f|
117
+ f.binmode
118
+ f.puts
119
+ f.puts %Q[Vagrant.configure("2") do |config|]
120
+ f.puts %Q[ config.ssh.private_key_path = File.expand_path("../vagrant_private_key", __FILE__)]
121
+ f.puts %Q[end]
122
+ end
123
+ end
124
+
125
+ def export
126
+ # Halt the machine
127
+ if @vm.state.short_description == 'running'
128
+ @env.ui.info('Halting VM for export')
129
+ @vm.action(:halt)
130
+ end
131
+
132
+ # Export to file
133
+ exported_path = File.join(@env.tmp_path, Time.now.to_i.to_s)
134
+ @tmp_path = exported_path
135
+ FileUtils.mkdir_p(exported_path)
136
+
137
+ @env.ui.info('Exporting machine')
138
+
139
+ provider_name = @vm.provider_name.to_s
140
+
141
+ if /vmware/i =~ provider_name
142
+ current_dir = File.dirname(@vm.id)
143
+ files = Dir.glob(File.join(current_dir, '**', '*')).select {|f|
144
+ !File.directory?(f)
145
+ }
146
+ FileUtils.cp_r(files, exported_path)
147
+ else
148
+ @vm.provider.driver.export File.join(exported_path, 'box.ovf' + ext) do |progress|
149
+ @env.ui.clear_line
150
+ @env.ui.report_progress(progress.percent, 100, false)
151
+ end
152
+ end
153
+
154
+ @logger.debug("Exported VM to #{exported_path}")
155
+ end
156
+
157
+ def files(bare)
158
+
159
+ provider_name = @vm.provider_name.to_s
160
+
161
+ # Add metadata json
162
+ begin
163
+ metadata = File.open(File.join(@tmp_path, 'metadata.json'), 'wb')
164
+ metadata.write('{"provider":"' + provider_name + '"}')
165
+ ensure
166
+ metadata.close
167
+ end
168
+
169
+ target_include_path = File.join(@tmp_path, 'include')
170
+ source_include_path = File.join(@vm.box.directory, 'include')
171
+
172
+ # Copy includes
173
+ if Dir.exist?(source_include_path) && !bare
174
+ FileUtils.cp_r(source_include_path, @tmp_path)
175
+ end
176
+
177
+ original_vagrantfile = File.join(@vm.box.directory, 'Vagrantfile')
178
+ vagrantfile_exists = File.exist?(original_vagrantfile)
179
+ vagrantfile_has_mac = false
180
+ vagrantfile_needs_mac = @vm.provider_name.to_s == 'virtualbox'
181
+
182
+ # Check the original vagrant file for a mac settings
183
+ if vagrantfile_exists && vagrantfile_needs_mac
184
+ File.readlines(original_vagrantfile).each { |line|
185
+ if line.to_s =~ /base_mac\s*=\s*("|')/i
186
+ vagrantfile_has_mac = true
187
+ end
188
+ }
189
+ end
190
+
191
+ # If it has one, just copy it
192
+ if vagrantfile_has_mac || (!vagrantfile_needs_mac && vagrantfile_exists)
193
+ FileUtils.cp(original_vagrantfile, File.join(@tmp_path, 'Vagrantfile'))
194
+
195
+ # If none, create a new one that has the mac setting,
196
+ # and includes the original
197
+ # The new Vagrantfile will include the old one, which
198
+ # is put into the includeds directory
199
+ else
200
+ File.open(File.join(@tmp_path, 'Vagrantfile'), 'wb') do |file|
201
+ file.write(Vagrant::Util::TemplateRenderer.render('package_Vagrantfile', {
202
+ base_mac: @vm.provider.driver.read_mac_address
203
+ }))
204
+ end
205
+
206
+ # If there is a Vagrantfile, but without a mac
207
+ # ensure it is included
208
+ if vagrantfile_exists
209
+ FileUtils.mkdir_p(target_include_path) unless Dir.exist?(target_include_path)
210
+ FileUtils.cp(original_vagrantfile, File.join(target_include_path, '_Vagrantfile'))
211
+ end
212
+ end
213
+
214
+ # Copy the private key if available
215
+ setup_private_key
216
+
217
+ # Make a box file out of it
218
+ @box_file_name = @tmp_path + '.box'
219
+
220
+ Vagrant::Util::SafeChdir.safe_chdir(@tmp_path) do
221
+ files = Dir.glob(File.join('.', '**', '*'))
222
+ Vagrant::Util::Subprocess.execute('bsdtar', '-czf', @box_file_name, *files)
223
+ end
224
+
225
+ 0
226
+ end
227
+
228
+ def finalize
229
+ # Rename the box file
230
+ if File.exist?(@box_file_name)
231
+ box_name = @vm.box.name.gsub('/', '_')
232
+ @target_box = File.join(@env.cwd, box_name + '.box')
233
+ FileUtils.mv(@box_file_name, @target_box)
234
+ @env.ui.info('Created ' + @target_box)
235
+ end
236
+
237
+ # Remove the tmp files
238
+ FileUtils.rm_rf(@tmp_path)
239
+
240
+ # Resume the machine
241
+ if @did_run
242
+ @env.ui.info('Bringing the machine back up')
243
+ @vm.action(:up)
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
@@ -1,25 +1,25 @@
1
- # #
2
- # This is free software; you can redistribute it and/or modify it under #
3
- # the terms of the MIT- / X11 - License #
4
- # #
5
-
6
- module VagrantPlugins
7
- module Export
8
- class Plugin < Vagrant.plugin '2'
9
-
10
- name 'Vagrant Export'
11
-
12
- description <<-EOF
13
- Export an existing box to a .box file, like the vagrant repackage command
14
- Additionally it will include the original Vagrantfile and other included
15
- files and perform several cleanup operations inside the VM to reduce its
16
- exported size. The latter requires a Ubuntu or compatible guest.
17
- EOF
18
-
19
- command 'export' do
20
- require_relative 'command'
21
- Command
22
- end
23
- end
24
- end
25
- end
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Export
8
+ class Plugin < Vagrant.plugin '2'
9
+
10
+ name 'Vagrant Export'
11
+
12
+ description <<-EOF
13
+ Export an existing box to a .box file, like the vagrant repackage command
14
+ Additionally it will include the original Vagrantfile and other included
15
+ files and perform several cleanup operations inside the VM to reduce its
16
+ exported size. The latter requires a Ubuntu or compatible guest.
17
+ EOF
18
+
19
+ command 'export' do
20
+ require_relative 'command'
21
+ Command
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,10 +1,10 @@
1
- # #
2
- # This is free software; you can redistribute it and/or modify it under #
3
- # the terms of the MIT- / X11 - License #
4
- # #
5
-
6
- module VagrantPlugins
7
- module Export
8
- VERSION = '0.3.0'
9
- end
10
- end
1
+ # #
2
+ # This is free software; you can redistribute it and/or modify it under #
3
+ # the terms of the MIT- / X11 - License #
4
+ # #
5
+
6
+ module VagrantPlugins
7
+ module Export
8
+ VERSION = '0.3.1'
9
+ end
10
+ end
@@ -1,49 +1,49 @@
1
- $:.unshift(File.expand_path('../lib', __FILE__))
2
-
3
- require 'vagrant-export/version'
4
-
5
- Gem::Specification.new do |g|
6
- g.name = 'vagrant-export'
7
- g.version = VagrantPlugins::Export::VERSION
8
- g.platform = Gem::Platform::RUBY
9
- g.license = 'MIT'
10
- g.authors = 'Georg Großberger'
11
- g.email = 'contact@grossberger-ge.org'
12
- g.homepage = 'https://github.com/trenker/vagrant-export'
13
- g.summary = 'Export boxes to .box files including the original Vagrantfile and some cleanups inside the VM'
14
- g.description = 'Export boxes to .box files including the original Vagrantfile and some cleanups inside the VM'
15
-
16
- # The following block of code determines the files that should be included
17
- # in the gem. It does this by reading all the files in the directory where
18
- # this gemspec is, and parsing out the ignored files from the gitignore.
19
- # Note that the entire gitignore(5) syntax is not supported, specifically
20
- # the "!" syntax, but it should mostly work correctly.
21
- root_path = File.dirname(__FILE__)
22
- all_files = Dir.chdir(root_path) { Dir.glob('**/{*,.*}') }
23
- all_files.reject! { |file| %w(. ..).include?(File.basename(file)) }
24
- gitignore_path = File.join(root_path, '.gitignore')
25
- gitignore = File.readlines(gitignore_path)
26
- gitignore.map! { |line| line.chomp.strip }
27
- gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
28
-
29
- unignored_files = all_files.reject do |file|
30
- # Ignore any directories, the gemspec only cares about files
31
- next true if File.directory?(file)
32
-
33
- # Ignore any paths that match anything in the gitignore. We do
34
- # two tests here:
35
- #
36
- # - First, test to see if the entire path matches the gitignore.
37
- # - Second, match if the basename does, this makes it so that things
38
- # like '.DS_Store' will match sub-directories too (same behavior
39
- # as git).
40
- #
41
- gitignore.any? do |ignore|
42
- File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
43
- File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
44
- end
45
- end
46
-
47
- g.files = unignored_files
48
- g.require_path = 'lib'
49
- end
1
+ $:.unshift(File.expand_path('../lib', __FILE__))
2
+
3
+ require 'vagrant-export/version'
4
+
5
+ Gem::Specification.new do |g|
6
+ g.name = 'vagrant-export'
7
+ g.version = VagrantPlugins::Export::VERSION
8
+ g.platform = Gem::Platform::RUBY
9
+ g.license = 'MIT'
10
+ g.authors = 'Georg Grossberger'
11
+ g.email = 'contact@grossberger-ge.org'
12
+ g.homepage = 'https://github.com/trenker/vagrant-export'
13
+ g.summary = 'Export boxes to .box files including the original Vagrantfile and some cleanups inside the VM'
14
+ g.description = 'Export boxes to .box files including the original Vagrantfile and some cleanups inside the VM'
15
+
16
+ # The following block of code determines the files that should be included
17
+ # in the gem. It does this by reading all the files in the directory where
18
+ # this gemspec is, and parsing out the ignored files from the gitignore.
19
+ # Note that the entire gitignore(5) syntax is not supported, specifically
20
+ # the "!" syntax, but it should mostly work correctly.
21
+ root_path = File.dirname(__FILE__)
22
+ all_files = Dir.chdir(root_path) { Dir.glob('**/{*,.*}') }
23
+ all_files.reject! { |file| %w(. ..).include?(File.basename(file)) }
24
+ gitignore_path = File.join(root_path, '.gitignore')
25
+ gitignore = File.readlines(gitignore_path)
26
+ gitignore.map! { |line| line.chomp.strip }
27
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
28
+
29
+ unignored_files = all_files.reject do |file|
30
+ # Ignore any directories, the gemspec only cares about files
31
+ next true if File.directory?(file)
32
+
33
+ # Ignore any paths that match anything in the gitignore. We do
34
+ # two tests here:
35
+ #
36
+ # - First, test to see if the entire path matches the gitignore.
37
+ # - Second, match if the basename does, this makes it so that things
38
+ # like '.DS_Store' will match sub-directories too (same behavior
39
+ # as git).
40
+ #
41
+ gitignore.any? do |ignore|
42
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
43
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
44
+ end
45
+ end
46
+
47
+ g.files = unignored_files
48
+ g.require_path = 'lib'
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Georg Großberger
7
+ - Georg Grossberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Export boxes to .box files including the original Vagrantfile and some
14
14
  cleanups inside the VM