vagrant-layout 0.0.3
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 +7 -0
- data/.gitignore +34 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/vagrant-layout/command.rb +46 -0
- data/lib/vagrant-layout/command_init.rb +147 -0
- data/lib/vagrant-layout/plugin.rb +21 -0
- data/lib/vagrant-layout/tar_gz.rb +46 -0
- data/lib/vagrant-layout/version.rb +8 -0
- data/lib/vagrant-layout.rb +2 -0
- data/vagrant-layout.gemspec +23 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73ddd9ac2f7cad2e705aee342f12c58e5d705069
|
4
|
+
data.tar.gz: 3ede32863115db622a18260426edc254dbffc3e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0e65c0b69596edfb8d1f3caac4d10b65ddaef4b552d000df60fbc8fb95bf9a9b945d5122e36db9d15906eab586319249dcb5936e0947b9e74dad41541fe7622
|
7
|
+
data.tar.gz: 30c31beb60abf06f088918cb607ef7b7ed0bcb299d050dc566c0b0c62a83d1df49049abad248dac70de6e5f8de7fdf331dde9cabd5ed231d304499d16ec259e0
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
|
24
|
+
*~
|
25
|
+
\#*
|
26
|
+
.\#*
|
27
|
+
tmp
|
28
|
+
.DS_Store
|
29
|
+
Thumbs.db
|
30
|
+
ehthumbs.db
|
31
|
+
Desktop.ini
|
32
|
+
.project
|
33
|
+
*.ignore
|
34
|
+
.vagrant
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
# https://github.com/mitchellh/vagrant/pull/4869
|
5
|
+
gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git', :ref => 'v1.6.5'
|
6
|
+
end
|
7
|
+
|
8
|
+
group :plugins do
|
9
|
+
gemspec
|
10
|
+
# gem 'vagrant-layout', path: '.'
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 KOSEKI Kengo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Vagrant::Layout
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vagrant-layout'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vagrant-layout
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/vagrant-layout/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'open-uri'
|
5
|
+
require_relative 'tar_gz'
|
6
|
+
require_relative 'command_init'
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module Layout
|
10
|
+
#
|
11
|
+
# Command implementation
|
12
|
+
# https://docs.vagrantup.com/v2/plugins/commands.html
|
13
|
+
#
|
14
|
+
class Command < Vagrant.plugin(2, :command)
|
15
|
+
def self.synopsis
|
16
|
+
'TODO: synopsis'
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute
|
20
|
+
@opts = OptionParser.new do |o|
|
21
|
+
o.banner = 'Usage: vagrant layout init [gist-url]'
|
22
|
+
o.separator ''
|
23
|
+
end
|
24
|
+
|
25
|
+
@argv = parse_options(@opts)
|
26
|
+
if @argv.empty?
|
27
|
+
puts @opts.help
|
28
|
+
return -1
|
29
|
+
end
|
30
|
+
|
31
|
+
command = @argv.shift
|
32
|
+
|
33
|
+
result = -1
|
34
|
+
if command == 'help'
|
35
|
+
puts @opts.help
|
36
|
+
result = 0
|
37
|
+
elsif command == 'init'
|
38
|
+
result = CommandInit.new(@argv).execute
|
39
|
+
end
|
40
|
+
|
41
|
+
puts @opts.help unless result == 0
|
42
|
+
return result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Layout
|
5
|
+
#
|
6
|
+
# init command
|
7
|
+
#
|
8
|
+
class CommandInit
|
9
|
+
|
10
|
+
DEFAULT_REPOSITORY = ['koseki', 'vagrant-layout', 'master']
|
11
|
+
|
12
|
+
def initialize(argv)
|
13
|
+
@argv = argv
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
target = parse_target(@argv.shift)
|
18
|
+
return -1 unless target
|
19
|
+
|
20
|
+
Dir.mktmpdir do |root|
|
21
|
+
dir = download_layout(root, target)
|
22
|
+
copy_layout(dir)
|
23
|
+
end
|
24
|
+
|
25
|
+
0
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_target(target)
|
29
|
+
unless target
|
30
|
+
return github_target(DEFAULT_REPOSITORY)
|
31
|
+
end
|
32
|
+
|
33
|
+
if target =~ %r{\A(https://gist\.github\.com/[^/]+/[0-9a-f]+)(/(download)?)?}
|
34
|
+
url = Regexp.last_match[1]
|
35
|
+
path = Regexp.last_match[2]
|
36
|
+
if path == '/'
|
37
|
+
url += 'download'
|
38
|
+
elsif path.to_s == ''
|
39
|
+
url += '/download'
|
40
|
+
else
|
41
|
+
url += path
|
42
|
+
end
|
43
|
+
|
44
|
+
return [:gist, url]
|
45
|
+
end
|
46
|
+
|
47
|
+
target = target.split('/')
|
48
|
+
if target.length == 1
|
49
|
+
target = [DEFAULT_REPOSITORY[0], DEFAULT_REPOSITORY[1], target[0]]
|
50
|
+
elsif target.length == 2
|
51
|
+
target = [target[0], DEFAULT_REPOSITORY[1], target[1]]
|
52
|
+
elsif target.length >= 4
|
53
|
+
target = target[0..3]
|
54
|
+
end
|
55
|
+
|
56
|
+
return github_target(target)
|
57
|
+
end
|
58
|
+
|
59
|
+
def github_target(target)
|
60
|
+
url = "https://github.com/#{ target[0] }/#{ target[1] }/archive/#{ target[2] }.tar.gz"
|
61
|
+
return [:github, url]
|
62
|
+
end
|
63
|
+
|
64
|
+
def download_layout(root, target)
|
65
|
+
if target[0] == :github
|
66
|
+
return download_github(root, target)
|
67
|
+
elsif target[0] == :gist
|
68
|
+
dir = download_gist(root, target)
|
69
|
+
return merge_gist_to_github(root, dir)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def download_github(root, target)
|
74
|
+
puts "Downloading: #{ target[1] }"
|
75
|
+
targz = File.join(root, 'base.targz')
|
76
|
+
dest = File.join(root, 'github')
|
77
|
+
extract_tgz(target[1], targz, dest)
|
78
|
+
first_dir(dest)
|
79
|
+
end
|
80
|
+
|
81
|
+
def download_gist(root, target)
|
82
|
+
puts "Downloading: #{ target[1] }"
|
83
|
+
targz = File.join(root, 'gist.tar.gz')
|
84
|
+
dest = File.join(root, 'gist')
|
85
|
+
extract_tgz(target[1], targz, dest)
|
86
|
+
first_dir(dest)
|
87
|
+
end
|
88
|
+
|
89
|
+
def extract_tgz(url, file, dest_dir)
|
90
|
+
open(file, 'wb') do |output|
|
91
|
+
open(url) do |data|
|
92
|
+
output.write(data.read)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
TarGz.new.extract(file, dest_dir)
|
96
|
+
end
|
97
|
+
|
98
|
+
def first_dir(base)
|
99
|
+
Dir.open(base).each do |dir|
|
100
|
+
next if dir =~ /\A\.\.?\z/
|
101
|
+
return File.join(base, dir)
|
102
|
+
end
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def merge_gist_to_github(root, gist_dir)
|
107
|
+
dotfile = File.join(gist_dir, '.vagrant-layout')
|
108
|
+
github_dir = nil
|
109
|
+
if File.file?(dotfile)
|
110
|
+
dot = YAML.load(File.read(dotfile))
|
111
|
+
if dot['base']
|
112
|
+
if dot['base'] =~ %r{https://github.com/([-\w]+)/([-\w]+)/tree/([0-9a-f]{40})}
|
113
|
+
github_dir = download_github(root, github_target(Regexp.last_match[1..3]))
|
114
|
+
else
|
115
|
+
msg = 'Illegal base url. Base URL must be like '
|
116
|
+
msg += 'https://github.com/{user}/{repos}/tree/[0-9a-f]{40}'
|
117
|
+
raise Exception.new(msg)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
unless github_dir
|
122
|
+
github_dir = File.join(root, 'github/empty')
|
123
|
+
FileUtils.mkdir_p(github_dir)
|
124
|
+
end
|
125
|
+
|
126
|
+
copy_gist_files(gist_dir, github_dir)
|
127
|
+
github_dir
|
128
|
+
end
|
129
|
+
|
130
|
+
def copy_gist_files(gist_dir, github_dir)
|
131
|
+
Dir.chdir(gist_dir) do
|
132
|
+
Dir.glob('*').each do |file|
|
133
|
+
dest_file = File.join(github_dir, file.gsub('__', '/'))
|
134
|
+
FileUtils.copy_entry(File.join(gist_dir, file), dest_file)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def copy_layout(dir)
|
140
|
+
Dir.open(dir).each do |src|
|
141
|
+
next if src.to_s =~ /\A(README|\.git|LICENSE|\.\.?\z)/
|
142
|
+
FileUtils.cp_r(File.join(dir, src), '.')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Layout
|
5
|
+
#
|
6
|
+
# Plugin definition
|
7
|
+
# https://docs.vagrantup.com/v2/plugins/development-basics.html
|
8
|
+
#
|
9
|
+
class Plugin < Vagrant.plugin('2')
|
10
|
+
name 'layout'
|
11
|
+
description <<-DESC
|
12
|
+
TODO: description
|
13
|
+
DESC
|
14
|
+
|
15
|
+
command('layout') do
|
16
|
+
require_relative 'command'
|
17
|
+
Command
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems/package'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Extract .tar.gz archive
|
6
|
+
# http://dracoater.blogspot.jp/2013/10/extracting-files-from-targz-with-ruby.html
|
7
|
+
#
|
8
|
+
class TarGz
|
9
|
+
TAR_LONGLINK = '././@LongLink'
|
10
|
+
|
11
|
+
def extract(source, destination)
|
12
|
+
files = []
|
13
|
+
Gem::Package::TarReader.new(Zlib::GzipReader.open(source)) do |tar|
|
14
|
+
dest = nil
|
15
|
+
tar.each do |entry|
|
16
|
+
if entry.full_name == TAR_LONGLINK
|
17
|
+
dest = File.join(destination, entry.read.strip)
|
18
|
+
next
|
19
|
+
end
|
20
|
+
dest ||= File.join(destination, entry.full_name)
|
21
|
+
files << write_entry(entry, dest, files)
|
22
|
+
dest = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
files
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_entry(entry, dest, files)
|
29
|
+
if entry.directory?
|
30
|
+
FileUtils.rm_rf(dest) unless File.directory?(dest)
|
31
|
+
FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false)
|
32
|
+
return [:dir, dest]
|
33
|
+
elsif entry.file?
|
34
|
+
FileUtils.rm_rf(dest) unless File.file?(dest)
|
35
|
+
File.open(dest, 'wb') do |f|
|
36
|
+
f.print entry.read
|
37
|
+
end
|
38
|
+
FileUtils.chmod(entry.header.mode, dest, verbose: false)
|
39
|
+
return [:file, dest]
|
40
|
+
elsif entry.header.typeflag == '2'
|
41
|
+
File.symlink(entry.header.linkname, dest)
|
42
|
+
return [:symlink, dest]
|
43
|
+
end
|
44
|
+
[:other, entry]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-layout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-layout"
|
8
|
+
spec.version = VagrantPlugins::Layout::VERSION
|
9
|
+
spec.authors = ["KOSEKI Kengo"]
|
10
|
+
spec.email = ["koseki@gmail.com"]
|
11
|
+
spec.summary = %q{vagrant layout plugin}
|
12
|
+
spec.description = %q{vagrant layout plugin}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-layout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- KOSEKI Kengo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: vagrant layout plugin
|
42
|
+
email:
|
43
|
+
- koseki@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rubocop.yml
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/vagrant-layout.rb
|
55
|
+
- lib/vagrant-layout/command.rb
|
56
|
+
- lib/vagrant-layout/command_init.rb
|
57
|
+
- lib/vagrant-layout/plugin.rb
|
58
|
+
- lib/vagrant-layout/tar_gz.rb
|
59
|
+
- lib/vagrant-layout/version.rb
|
60
|
+
- vagrant-layout.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.14
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: vagrant layout plugin
|
85
|
+
test_files: []
|