getrepos 0.1.0

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 (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/README.md +154 -0
  4. data/Rakefile +16 -0
  5. data/bin/getrepos +68 -0
  6. data/getrepos.gemspec +29 -0
  7. data/lib/getrepos/init.rb +34 -0
  8. data/lib/getrepos/install.rb +115 -0
  9. data/lib/getrepos/util.rb +48 -0
  10. data/lib/getrepos/version.rb +3 -0
  11. data/lib/getrepos.rb +3 -0
  12. data/test/basic-usage-test.sh +80 -0
  13. data/test/check-test.sh +60 -0
  14. data/test/common-archives-test.sh +63 -0
  15. data/test/github-archives-test.sh +108 -0
  16. data/test/helper/roundup.sh +307 -0
  17. data/test/helper/valid_json.rb +25 -0
  18. data/test/path-filter-test.sh +28 -0
  19. data/test/repos-basic-usage.json +24 -0
  20. data/test/repos-check-absent-all.json +3 -0
  21. data/test/repos-check-absent-name.json +3 -0
  22. data/test/repos-check-absent-repos.json +3 -0
  23. data/test/repos-check-absent-url.json +3 -0
  24. data/test/repos-check-absent-version.json +3 -0
  25. data/test/repos-check-invalid-filetype.json +3 -0
  26. data/test/repos-common-httpd-tar-bz2.json +3 -0
  27. data/test/repos-common-httpd-tar-gz.json +3 -0
  28. data/test/repos-common-mod_fcgid-tar-bz2.json +3 -0
  29. data/test/repos-common-mod_fcgid-tar-gz.json +3 -0
  30. data/test/repos-common-python-tar-xz.json +3 -0
  31. data/test/repos-common-python-tgz.json +3 -0
  32. data/test/repos-common-ruby-tar-bz2.json +3 -0
  33. data/test/repos-common-ruby-tar-gz.json +3 -0
  34. data/test/repos-common-ruby-tar-xz.json +3 -0
  35. data/test/repos-common-ruby-zip.json +3 -0
  36. data/test/repos-github-hiredis-git.json +3 -0
  37. data/test/repos-github-hiredis-tar-gz.json +3 -0
  38. data/test/repos-github-hiredis-zip.json +3 -0
  39. data/test/repos-github-libmaxminddb-git.json +3 -0
  40. data/test/repos-github-libmaxminddb-release-tar-gz.json +3 -0
  41. data/test/repos-github-libmaxminddb-tar-gz.json +3 -0
  42. data/test/repos-github-libmaxminddb-zip.json +3 -0
  43. data/test/repos-github-other-name-id-tar-gz.json +3 -0
  44. data/test/repos-github-other-name-id-zip.json +3 -0
  45. data/test/repos-github-other-name-id.json +3 -0
  46. data/test/repos-github-other-name-tag-tar-gz.json +3 -0
  47. data/test/repos-github-other-name-tag-zip.json +3 -0
  48. data/test/repos-github-other-name-tag.json +3 -0
  49. data/test/repos-github-same-name-id-tar-gz.json +3 -0
  50. data/test/repos-github-same-name-id-zip.json +3 -0
  51. data/test/repos-github-same-name-id.json +3 -0
  52. data/test/repos-github-same-name-tag-tar-gz.json +3 -0
  53. data/test/repos-github-same-name-tag-zip.json +3 -0
  54. data/test/repos-github-same-name-tag.json +3 -0
  55. data/test/repos-path-filter-git.json +5 -0
  56. data/test/repos-path-filter-tar-gz.json +5 -0
  57. data/test/repos-path-filter-zip.json +5 -0
  58. metadata +181 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26c87a9d420ba019d3484fa10d85fb617acaa31f
4
+ data.tar.gz: 64de56514c2b8d83e0a08a41f72c742e174af176
5
+ SHA512:
6
+ metadata.gz: d3e7deb628a44a5c5dcc71ef377e60ecd6f6b36edebbc52f4d8fe6f61652537048b416d14f510ed9695f4e2f294662d42a728fb5d456b5b4bdcbaeb41e731947
7
+ data.tar.gz: ef4d517245dacc05e85f4d5c158c9182134209cf94bb388d6a4bd767017b8225ecafe1960ff3ffd5c55014721ad0d3e4a4efb5655cfb07de1f0b96ad0db34b16
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ /pkg
3
+ /build
4
+ /test/build
5
+ /test/init.json
6
+ /test/.roundup.*
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # getrepos
2
+
3
+ ### Installation
4
+
5
+ ```bash
6
+ gem install getrepos
7
+ ```
8
+
9
+ ### Usage
10
+
11
+ ```bash
12
+ getrepos -h/--help
13
+ ```
14
+
15
+ ```bash
16
+ NAME:
17
+
18
+ getrepos
19
+
20
+ DESCRIPTION:
21
+
22
+ Download, extract and filter content from repositories (Git/Tarball)
23
+
24
+ COMMANDS:
25
+
26
+ help Display global or [command] help documentation
27
+ init Create sample JSON
28
+ install Download and install archives
29
+
30
+ GLOBAL OPTIONS:
31
+
32
+ -h, --help
33
+ Display help documentation
34
+
35
+ -v, --version
36
+ Display version information
37
+ ```
38
+
39
+ ```bash
40
+ getrepos init
41
+ ```
42
+
43
+ ```bash
44
+ NAME:
45
+
46
+ init
47
+
48
+ SYNOPSIS:
49
+
50
+ getrepos init <file.json> [-f]
51
+
52
+ DESCRIPTION:
53
+
54
+ Create <file.json> with sample configuration
55
+
56
+ EXAMPLES:
57
+
58
+ # Generate repos.json
59
+ getrepos init repos.json
60
+
61
+ # Overwrite repos.json
62
+ getrepos init repos.json -f
63
+
64
+ OPTIONS:
65
+
66
+ -f, --force
67
+ Force file overwrite
68
+ ```
69
+
70
+ ```bash
71
+ getrepos install
72
+ ```
73
+
74
+ ```bash
75
+ NAME:
76
+
77
+ install
78
+
79
+ SYNOPSIS:
80
+
81
+ getrepos install <file.json>
82
+
83
+ DESCRIPTION:
84
+
85
+ Download and install archives from URLs defined in <file.json>
86
+
87
+ EXAMPLES:
88
+
89
+ # Process URLs from repos.json
90
+ getrepos install repos.json
91
+ ```
92
+
93
+ ### Sample JSON config file
94
+
95
+ ```bash
96
+ getrepos init repos.json
97
+ ```
98
+
99
+ * repos.json with some Nginx modules
100
+
101
+ ```json
102
+ {"repos": [
103
+ {"name": "nginx", "version": "1.9.12", "url": "http://nginx.org/download/nginx-1.9.12.tar.gz"},
104
+
105
+ {"name": "luajit", "version": "2.1.0-beta2", "url": "http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz"},
106
+ {"name": "lua-cjson", "version": "2.1.0.3", "url": "https://github.com/openresty/lua-cjson.git"},
107
+ {"name": "hiredis", "version": "v0.13.3", "url": "https://github.com/redis/hiredis.git"},
108
+ {"name": "libmaxminddb", "version": "1.1.4", "url": "https://github.com/maxmind/libmaxminddb/releases/download/1.1.4/libmaxminddb-1.1.4.tar.gz"},
109
+
110
+ {"name": "lua-nginx", "version": "v0.10.2", "url": "https://github.com/openresty/lua-nginx-module.git"},
111
+ {"name": "lua-upstream-nginx", "version": "v0.05", "url": "https://github.com/openresty/lua-upstream-nginx-module.git"},
112
+ {"name": "redis2-nginx", "version": "v0.12", "url": "https://github.com/openresty/redis2-nginx-module.git"},
113
+ {"name": "set-misc-nginx", "version": "v0.30", "url": "https://github.com/openresty/set-misc-nginx-module.git"},
114
+ {"name": "ngx_cache_purge", "version": "2.3", "url": "https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz"},
115
+ {"name": "nginx-push-stream", "version": "0.5.1", "url": "https://github.com/wandenberg/nginx-push-stream-module.git"},
116
+ {"name": "ngx_http_auth_request", "version": "662785733552", "url": "http://mdounin.ru/hg/ngx_http_auth_request_module/archive/tip.tar.gz", "path": "ngx_http_auth_request_module-662785733552"},
117
+
118
+ {"name": "lua-resty-core", "version": "v0.1.5", "url": "https://github.com/openresty/lua-resty-core.git"},
119
+ {"name": "lua-resty-dns", "version": "v0.15", "url": "https://github.com/openresty/lua-resty-dns.git"},
120
+ {"name": "lua-resty-redis", "version": "v0.22", "url": "https://github.com/openresty/lua-resty-redis.git"},
121
+ {"name": "lua-resty-upstream-healthcheck", "version": "v0.04", "url": "https://github.com/openresty/lua-resty-upstream-healthcheck.git"},
122
+
123
+ {"name": "log4j", "version": "1.2.17", "url": "https://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar"}
124
+ ]}
125
+ ```
126
+
127
+ * Result after installation
128
+
129
+ ```bash
130
+ getrepos install repos.json
131
+ tree -L 2 build
132
+
133
+ build
134
+ └── repos
135
+ ├── hiredis-v0.13.3
136
+ ├── libmaxminddb-1.1.4
137
+ ├── log4j-1.2.17
138
+ ├── lua-cjson-2.1.0.3
139
+ ├── lua-nginx-v0.10.2
140
+ ├── lua-resty-core-v0.1.5
141
+ ├── lua-resty-dns-v0.15
142
+ ├── lua-resty-redis-v0.22
143
+ ├── lua-resty-upstream-healthcheck-v0.04
144
+ ├── lua-upstream-nginx-v0.05
145
+ ├── luajit-2.1.0-beta2
146
+ ├── nginx-1.9.12
147
+ ├── nginx-aaa-v0.9.1
148
+ ├── nginx-push-stream-0.5.1
149
+ ├── ngx_cache_purge-2.3
150
+ ├── ngx_http_auth_request-662785733552
151
+ ├── pcre-8.38
152
+ ├── redis2-nginx-v0.12
153
+ └── set-misc-nginx-v0.30
154
+ ```
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ # Default
4
+ task :default => :help
5
+
6
+ # Help
7
+ desc 'Show help'
8
+ task :help do
9
+ system('rake -T')
10
+ end
11
+
12
+ # Test
13
+ desc 'Run tests'
14
+ task :test do
15
+ system('cd test && ./helper/roundup.sh')
16
+ end
data/bin/getrepos ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'getrepos'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'colorize'
8
+ require 'open-uri'
9
+ require 'commander/import'
10
+
11
+ program :version, GetRepos::VERSION
12
+ program :description, 'Download, extract and filter content from repositories (Git/Tarball)'
13
+
14
+ never_trace!
15
+
16
+ command :init do |c|
17
+ c.syntax = 'getrepos init <file.json> [-f]'
18
+ c.summary = 'Create sample JSON'
19
+ c.description = 'Create <file.json> with sample configuration'
20
+ c.example 'Generate repos.json', 'getrepos init repos.json'
21
+ c.example 'Overwrite repos.json', 'getrepos init repos.json -f'
22
+ c.option '-f', '--force', 'Force file overwrite'
23
+
24
+ c.action do |args, options|
25
+ if args.length != 1
26
+ puts 'Wrong number of arguments'.light_red
27
+ command(:help).run(:init)
28
+ exit 1
29
+ end
30
+
31
+ filename = args.first
32
+ if File.exists?(filename) && ! options.force
33
+ puts "File '#{filename}' already exists (use -f to overwrite)".light_red
34
+ exit 1
35
+ end
36
+
37
+ GetRepos.init(filename)
38
+ end
39
+ end
40
+
41
+ command :install do |c|
42
+ c.syntax = 'getrepos install <file.json>'
43
+ c.summary = 'Download and install archives'
44
+ c.description = 'Download and install archives from URLs defined in <file.json>'
45
+ c.example 'Process URLs from repos.json', 'getrepos install repos.json'
46
+ c.action do |args, options|
47
+ if args.length != 1
48
+ puts 'Wrong number of arguments'.light_red
49
+ command(:help).run(:install)
50
+ exit 1
51
+ end
52
+
53
+ filename = args.first
54
+ if ! File.exists?(filename)
55
+ puts "File '#{filename}' not found".light_red
56
+ exit 1
57
+ end
58
+
59
+ GetRepos.install(filename)
60
+ end
61
+ end
62
+
63
+ if ARGV.empty?
64
+ global_option '-h', '--help', 'Display help documentation'
65
+ global_option '-v', '--version', 'Display version information'
66
+ command(:help).run
67
+ exit 1
68
+ end
data/getrepos.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+
4
+ require 'getrepos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'getrepos'
8
+ spec.version = GetRepos::VERSION
9
+ spec.authors = ['Rogério Schneider']
10
+ spec.email = ['stockrt@gmail.com']
11
+ spec.summary = %q(Get content from repositories and URLs)
12
+ spec.description = %q(Download, expand and filter content from Git and
13
+ Tarball repositories into local directories. Works similar to a Berksfile or
14
+ a librarian-puppet catalog but is not coupled to any technology other than
15
+ keeping a directory filled with exploded archives from remote repositories
16
+ and URLs. For example, it can be used to download Nginx modules before
17
+ compiling.)
18
+
19
+ spec.homepage = 'https://github.com/stockrt/getrepos'
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files`.split($/)
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_runtime_dependency('commander', '~> 4.4')
28
+ spec.add_runtime_dependency('colorize', '~> 0.7')
29
+ end
@@ -0,0 +1,34 @@
1
+ module GetRepos
2
+ module_function
3
+
4
+ def init(filename)
5
+ sample_json = %q({"repos": [
6
+ // Nginx
7
+ {"name": "nginx", "version": "1.9.12", "url": "http://nginx.org/download/nginx-1.9.12.tar.gz"},
8
+ // Deps
9
+ {"name": "luajit", "version": "2.1.0-beta2", "url": "http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz"},
10
+ {"name": "lua-cjson", "version": "2.1.0.3", "url": "https://github.com/openresty/lua-cjson.git"},
11
+ {"name": "hiredis", "version": "v0.13.3", "url": "https://github.com/redis/hiredis.git"},
12
+ {"name": "libmaxminddb", "version": "1.1.4", "url": "https://github.com/maxmind/libmaxminddb/releases/download/1.1.4/libmaxminddb-1.1.4.tar.gz"},
13
+ // Native modules
14
+ {"name": "lua-nginx", "version": "v0.10.2", "url": "https://github.com/openresty/lua-nginx-module.git"},
15
+ {"name": "lua-upstream-nginx", "version": "v0.05", "url": "https://github.com/openresty/lua-upstream-nginx-module.git"},
16
+ {"name": "redis2-nginx", "version": "v0.12", "url": "https://github.com/openresty/redis2-nginx-module.git"},
17
+ {"name": "set-misc-nginx", "version": "v0.30", "url": "https://github.com/openresty/set-misc-nginx-module.git"},
18
+ {"name": "ngx_cache_purge", "version": "2.3", "url": "https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz"},
19
+ {"name": "nginx-push-stream", "version": "0.5.1", "url": "https://github.com/wandenberg/nginx-push-stream-module.git"},
20
+ {"name": "ngx_http_auth_request", "version": "662785733552", "url": "http://mdounin.ru/hg/ngx_http_auth_request_module/archive/tip.tar.gz", "path": "ngx_http_auth_request_module-662785733552"},
21
+ // Lua modules
22
+ {"name": "lua-resty-core", "version": "v0.1.5", "url": "https://github.com/openresty/lua-resty-core.git"},
23
+ {"name": "lua-resty-dns", "version": "v0.15", "url": "https://github.com/openresty/lua-resty-dns.git"},
24
+ {"name": "lua-resty-redis", "version": "v0.22", "url": "https://github.com/openresty/lua-resty-redis.git"},
25
+ {"name": "lua-resty-upstream-healthcheck", "version": "v0.04", "url": "https://github.com/openresty/lua-resty-upstream-healthcheck.git"},
26
+ // Strange
27
+ {"name": "log4j", "version": "1.2.17", "url": "https://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar"}
28
+ ]}
29
+ )
30
+
31
+ File.write(filename, sample_json)
32
+ puts "Generated '#{filename}'".light_green
33
+ end
34
+ end
@@ -0,0 +1,115 @@
1
+ require 'getrepos/util'
2
+
3
+ module GetRepos
4
+ module_function
5
+
6
+ def install(filename)
7
+ FileUtils.mkdir_p('build/repos')
8
+ repos = JSON.parse(open(filename).read, symbolize_names: true)
9
+
10
+ unless is_valid_json_root?(repos)
11
+ puts "Invalid JSON '#{filename}' (missing required field)".light_red
12
+ exit 1
13
+ end
14
+
15
+ repos[:repos].each do |repo|
16
+ unless is_valid_json_repo?(repo)
17
+ puts "Invalid JSON entry '#{repo}' (missing required field)".light_red
18
+ exit 1
19
+ end
20
+
21
+ puts
22
+ puts 'Processing entry: '.light_cyan + repo.to_s
23
+ if is_git_url?(repo[:url])
24
+ # Git
25
+ install_git(repo)
26
+ else
27
+ # Archive
28
+ archive = URI(repo[:url]).path
29
+ if archive.end_with?('.tar.gz')
30
+ install_archive(repo, 'tar.gz')
31
+ elsif archive.end_with?('.tgz')
32
+ install_archive(repo, 'tgz')
33
+ elsif archive.end_with?('.tar.bz2')
34
+ install_archive(repo, 'tar.bz2')
35
+ elsif archive.end_with?('.tar.xz')
36
+ install_archive(repo, 'tar.xz')
37
+ elsif archive.end_with?('.zip')
38
+ install_archive(repo, 'zip')
39
+ elsif archive.end_with?('.jar')
40
+ install_archive(repo, 'jar')
41
+ elsif archive.end_with?('.war')
42
+ install_archive(repo, 'war')
43
+ elsif archive.end_with?('.ear')
44
+ install_archive(repo, 'ear')
45
+ else
46
+ puts "Unsupported file extension in URL '#{repo[:url]}'".light_red
47
+ exit 1
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def install_git(repo)
54
+ dest_dir = "build/repos/#{repo[:name]}-#{repo[:version]}"
55
+ gitbare_dest_dir = "build/.gitbare/#{repo[:name]}"
56
+
57
+ # Clone
58
+ if File.exists?("#{gitbare_dest_dir}/HEAD")
59
+ puts "Updating cloned '#{repo[:url]}' inside '#{gitbare_dest_dir}'".light_green
60
+ ret = run_local("cd #{gitbare_dest_dir} && git fetch -q")
61
+ exit ret if ret != 0
62
+ else
63
+ puts "Cloning '#{repo[:url]}' to '#{gitbare_dest_dir}'".light_cyan
64
+ ret = run_local("git clone -q --mirror '#{repo[:url]}' '#{gitbare_dest_dir}'")
65
+ exit ret if ret != 0
66
+ end
67
+
68
+ # Extract
69
+ puts "Extracting and filtering '#{gitbare_dest_dir}' to '#{dest_dir}'".light_cyan
70
+ prep_dest_dir(dest_dir)
71
+ ret = run_local("cd #{gitbare_dest_dir} &&
72
+ git archive '#{repo[:version]}' -- #{repo[:path]} | tar xf - -C '../../.tmprepo/'")
73
+ exit ret if ret != 0
74
+ FileUtils.mv("build/.tmprepo/#{repo[:path]}", dest_dir)
75
+ end
76
+
77
+ def install_archive(repo, ext)
78
+ dest_dir = "build/repos/#{repo[:name]}-#{repo[:version]}"
79
+ archive_dest_file = "build/.archive/#{repo[:name]}-#{repo[:version]}.#{ext}"
80
+
81
+ # Download
82
+ if File.exists?(archive_dest_file)
83
+ puts "Already downloaded '#{repo[:url]}' to '#{archive_dest_file}'".light_green
84
+ else
85
+ puts "Saving '#{repo[:url]}' to '#{archive_dest_file}'".light_cyan
86
+ FileUtils.mkdir_p(File.dirname(archive_dest_file))
87
+ IO.copy_stream(open(repo[:url]), archive_dest_file)
88
+ end
89
+
90
+ # Extract
91
+ puts "Extracting and filtering '#{archive_dest_file}' to '#{dest_dir}'".light_cyan
92
+ prep_dest_dir(dest_dir)
93
+ ret = 0
94
+ if ext == 'tar.gz' || ext == 'tgz'
95
+ ret = run_local("tar xzf '#{archive_dest_file}' -C 'build/.tmprepo/'")
96
+ elsif ext == 'tar.bz2'
97
+ ret = run_local("tar xjf '#{archive_dest_file}' -C 'build/.tmprepo/'")
98
+ elsif ext == 'tar.xz'
99
+ ret = run_local("tar xJf '#{archive_dest_file}' -C 'build/.tmprepo/'")
100
+ elsif ext == 'zip' || ext == 'jar' || ext == 'war' || ext == 'ear'
101
+ ret = run_local("unzip -o '#{archive_dest_file}' -d 'build/.tmprepo/'")
102
+ else
103
+ puts "Unsupported file extension '#{ext}'".light_red
104
+ exit 1
105
+ end
106
+ exit ret if ret != 0
107
+ # Was the archive expanded to the usual directory 'name-version'?
108
+ archive_usual_dir = "build/.tmprepo/#{repo[:name]}-#{repo[:version]}/#{repo[:path]}"
109
+ if File.directory?(archive_usual_dir)
110
+ FileUtils.mv(archive_usual_dir, dest_dir)
111
+ else
112
+ FileUtils.mv("build/.tmprepo/#{repo[:path]}", dest_dir)
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,48 @@
1
+ def is_valid_json_root?(data)
2
+ if data[:repos].nil?
3
+ puts 'Missing required key "repos"'.light_red
4
+ return false
5
+ else
6
+ return true
7
+ end
8
+ end
9
+
10
+ def is_valid_json_repo?(data)
11
+ return_flag = true
12
+
13
+ [:name, :version, :url].each do |key|
14
+ if data[key].nil?
15
+ puts "Missing required key \"#{key}\"".light_red
16
+ return_flag = false
17
+ end
18
+ end
19
+
20
+ return return_flag
21
+ end
22
+
23
+ def is_git_url?(url)
24
+ if File.extname(URI(url).path) == '.git'
25
+ return true
26
+ else
27
+ return false
28
+ end
29
+ end
30
+
31
+ def run_local(command)
32
+ response = %x(#{command})
33
+ exit_status = $?.to_i
34
+
35
+ if exit_status != 0
36
+ puts "Error: #{command} (exit status: #{exit_status})"
37
+ puts response
38
+ end
39
+
40
+ return exit_status
41
+ end
42
+
43
+ def prep_dest_dir(dest_dir)
44
+ FileUtils.rm_rf('build/.tmprepo')
45
+ FileUtils.mkdir_p('build/.tmprepo')
46
+ FileUtils.rm_rf(dest_dir)
47
+ FileUtils.mkdir_p(File.dirname(dest_dir))
48
+ end
@@ -0,0 +1,3 @@
1
+ module GetRepos
2
+ VERSION = '0.1.0'
3
+ end
data/lib/getrepos.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'getrepos/init'
2
+ require 'getrepos/install'
3
+ require 'getrepos/version'
@@ -0,0 +1,80 @@
1
+ #!/bin/bash
2
+
3
+ # http://bmizerany.github.io/roundup
4
+ # https://github.com/bmizerany/roundup
5
+ # wget https://raw.githubusercontent.com/bmizerany/roundup/master/roundup.sh
6
+
7
+ describe "Basic usage and sample config JSON"
8
+
9
+ validate_build_repo() {
10
+ # Nginx
11
+ test -f build/repos/nginx-1.9.12/configure
12
+ # Deps
13
+ test -f build/repos/luajit-2.1.0-beta2/Makefile
14
+ test -f build/repos/lua-cjson-2.1.0.3/Makefile
15
+ test -f build/repos/hiredis-v0.13.3/Makefile
16
+ test -f build/repos/libmaxminddb-1.1.4/configure
17
+ # Native modules
18
+ test -f build/repos/lua-nginx-v0.10.2/config
19
+ test -f build/repos/lua-upstream-nginx-v0.05/config
20
+ test -f build/repos/redis2-nginx-v0.12/config
21
+ test -f build/repos/set-misc-nginx-v0.30/config
22
+ test -f build/repos/ngx_cache_purge-2.3/config
23
+ test -f build/repos/nginx-push-stream-0.5.1/config
24
+ test -f build/repos/ngx_http_auth_request-662785733552/config
25
+ # Lua modules
26
+ test -d build/repos/lua-resty-core-v0.1.5/lib/resty
27
+ test -d build/repos/lua-resty-dns-v0.15/lib/resty
28
+ test -d build/repos/lua-resty-redis-v0.22/lib/resty
29
+ test -d build/repos/lua-resty-upstream-healthcheck-v0.04/lib/resty
30
+ }
31
+
32
+ before() {
33
+ rm -f init.json
34
+ rm -rf build
35
+ }
36
+
37
+ after() {
38
+ rm -f init.json
39
+ rm -rf build
40
+ }
41
+
42
+ it_display_help() {
43
+ ../bin/getrepos | grep "help documentation"
44
+ ../bin/getrepos init | grep "getrepos init"
45
+ ../bin/getrepos install | grep "getrepos install"
46
+ }
47
+
48
+ it_display_version() {
49
+ ../bin/getrepos -v | grep -E "getrepos [[:digit:]]"
50
+ }
51
+
52
+ it_init() {
53
+ ../bin/getrepos init init.json
54
+ test -f init.json
55
+ }
56
+
57
+ it_init_force() {
58
+ ../bin/getrepos init init.json
59
+ test -f init.json
60
+ ../bin/getrepos init init.json -f
61
+ }
62
+
63
+ it_init_is_valid_json() {
64
+ ../bin/getrepos init init.json
65
+ grep nginx-push-stream init.json
66
+ ./helper/valid_json.rb init.json
67
+ }
68
+
69
+ it_init_generate_valid_build_repo() {
70
+ ../bin/getrepos init init.json
71
+ ../bin/getrepos install init.json
72
+ validate_build_repo
73
+ }
74
+
75
+ it_install() {
76
+ ../bin/getrepos install repos-basic-usage.json
77
+ validate_build_repo
78
+ }
79
+
80
+ # EOF
@@ -0,0 +1,60 @@
1
+ #!/bin/bash
2
+
3
+ describe "Check for absent and invalid values inside config JSON"
4
+
5
+ before() {
6
+ rm -rf build
7
+ }
8
+
9
+ after() {
10
+ rm -rf build
11
+ }
12
+
13
+ it_check_absent_all() {
14
+ set +e
15
+ ret=$(../bin/getrepos install repos-check-absent-all.json)
16
+ set -e
17
+ echo "$ret" | grep 'Missing required key'
18
+ echo "$ret" | grep 'Invalid JSON entry.*missing required field'
19
+ }
20
+
21
+ it_check_absent_name() {
22
+ set +e
23
+ ret=$(../bin/getrepos install repos-check-absent-name.json)
24
+ set -e
25
+ echo "$ret" | grep 'Missing required key "name"'
26
+ echo "$ret" | grep 'Invalid JSON entry.*missing required field'
27
+ }
28
+
29
+ it_check_absent_repos() {
30
+ set +e
31
+ ret=$(../bin/getrepos install repos-check-absent-repos.json)
32
+ set -e
33
+ echo "$ret" | grep 'Missing required key "repos"'
34
+ echo "$ret" | grep 'Invalid JSON.*missing required field'
35
+ }
36
+
37
+ it_check_absent_url() {
38
+ set +e
39
+ ret=$(../bin/getrepos install repos-check-absent-url.json)
40
+ set -e
41
+ echo "$ret" | grep 'Missing required key "url"'
42
+ echo "$ret" | grep 'Invalid JSON entry.*missing required field'
43
+ }
44
+
45
+ it_check_absent_version() {
46
+ set +e
47
+ ret=$(../bin/getrepos install repos-check-absent-version.json)
48
+ set -e
49
+ echo "$ret" | grep 'Missing required key "version"'
50
+ echo "$ret" | grep 'Invalid JSON entry.*missing required field'
51
+ }
52
+
53
+ it_check_invalid_filetype() {
54
+ set +e
55
+ ret=$(../bin/getrepos install repos-check-invalid-filetype.json)
56
+ set -e
57
+ echo "$ret" | grep 'Unsupported file extension in URL'
58
+ }
59
+
60
+ # EOF