module GetRepos
Constants
- VERSION
Public Instance Methods
init(filename)
click to toggle source
# File lib/getrepos/init.rb, line 4 def init(filename) sample_json = %q({"repos": [ // Nginx {"name": "nginx", "version": "1.9.12", "url": "http://nginx.org/download/nginx-1.9.12.tar.gz"}, // Deps {"name": "luajit", "version": "2.1.0-beta2", "url": "http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz", "path": "LuaJIT-2.1.0-beta2"}, {"name": "lua-cjson", "version": "2.1.0.3", "url": "https://github.com/openresty/lua-cjson.git"}, {"name": "hiredis", "version": "v0.13.3", "url": "https://github.com/redis/hiredis.git"}, {"name": "libmaxminddb", "version": "1.1.4", "url": "https://github.com/maxmind/libmaxminddb/releases/download/1.1.4/libmaxminddb-1.1.4.tar.gz"}, // Native modules {"name": "lua-nginx", "version": "v0.10.2", "url": "https://github.com/openresty/lua-nginx-module.git"}, {"name": "lua-upstream-nginx", "version": "v0.05", "url": "https://github.com/openresty/lua-upstream-nginx-module.git"}, {"name": "redis2-nginx", "version": "v0.12", "url": "https://github.com/openresty/redis2-nginx-module.git"}, {"name": "set-misc-nginx", "version": "v0.30", "url": "https://github.com/openresty/set-misc-nginx-module.git"}, {"name": "ngx_cache_purge", "version": "2.3", "url": "https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz"}, {"name": "nginx-push-stream", "version": "0.5.1", "url": "https://github.com/wandenberg/nginx-push-stream-module.git"}, {"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"}, // Lua modules {"name": "lua-resty-core", "version": "v0.1.5", "url": "https://github.com/openresty/lua-resty-core.git"}, {"name": "lua-resty-dns", "version": "v0.15", "url": "https://github.com/openresty/lua-resty-dns.git"}, {"name": "lua-resty-redis", "version": "v0.22", "url": "https://github.com/openresty/lua-resty-redis.git"}, {"name": "lua-resty-upstream-healthcheck", "version": "v0.04", "url": "https://github.com/openresty/lua-resty-upstream-healthcheck.git"}, // Strange {"name": "log4j", "version": "1.2.17", "url": "https://repo1.maven.org/maven2/log4j/log4j/1.2.17/log4j-1.2.17.jar"} ]} ) File.write(filename, sample_json) puts "Generated '#{filename}'".light_green end
install(filename)
click to toggle source
# File lib/getrepos/install.rb, line 6 def install(filename) FileUtils.mkdir_p('build/repos') repos = JSON.parse(open(filename).read, symbolize_names: true) unless is_valid_json_root?(repos) puts "Invalid JSON '#{filename}' (missing required field)".light_red exit 1 end repos[:repos].each do |repo| unless is_valid_json_repo?(repo) puts "Invalid JSON entry '#{repo}' (missing required field)".light_red exit 1 end puts puts 'Processing entry: '.light_cyan + repo.to_s if is_git_url?(repo[:url]) # Git install_git(repo) else # Archive archive = URI(repo[:url]).path if archive.end_with?('.tar.gz') install_archive(repo, 'tar.gz') elsif archive.end_with?('.tgz') install_archive(repo, 'tgz') elsif archive.end_with?('.tar.bz2') install_archive(repo, 'tar.bz2') elsif archive.end_with?('.tar.xz') install_archive(repo, 'tar.xz') elsif archive.end_with?('.zip') install_archive(repo, 'zip') elsif archive.end_with?('.jar') install_archive(repo, 'jar') elsif archive.end_with?('.war') install_archive(repo, 'war') elsif archive.end_with?('.ear') install_archive(repo, 'ear') else puts "Unsupported file extension in URL '#{repo[:url]}'".light_red exit 1 end end end end
install_archive(repo, ext)
click to toggle source
# File lib/getrepos/install.rb, line 77 def install_archive(repo, ext) dest_dir = "build/repos/#{repo[:name]}-#{repo[:version]}" archive_dest_file = "build/.archive/#{repo[:name]}-#{repo[:version]}.#{ext}" # Download if File.exists?(archive_dest_file) puts "Already downloaded '#{repo[:url]}' to '#{archive_dest_file}'".light_green else puts "Saving '#{repo[:url]}' to '#{archive_dest_file}'".light_cyan FileUtils.mkdir_p(File.dirname(archive_dest_file)) IO.copy_stream(open(repo[:url]), archive_dest_file) end # Extract puts "Extracting and filtering '#{archive_dest_file}' to '#{dest_dir}'".light_cyan prep_dest_dir(dest_dir) ret = 0 if ext == 'tar.gz' || ext == 'tgz' ret = run_local("tar xzf '#{archive_dest_file}' -C 'build/.tmprepo/'") elsif ext == 'tar.bz2' ret = run_local("tar xjf '#{archive_dest_file}' -C 'build/.tmprepo/'") elsif ext == 'tar.xz' ret = run_local("tar xJf '#{archive_dest_file}' -C 'build/.tmprepo/'") elsif ext == 'zip' || ext == 'jar' || ext == 'war' || ext == 'ear' ret = run_local("unzip -o '#{archive_dest_file}' -d 'build/.tmprepo/'") else puts "Unsupported file extension '#{ext}'".light_red exit 1 end exit ret if ret != 0 # Was the archive expanded to the usual directory 'name-version'? archive_usual_dir = "build/.tmprepo/#{repo[:name]}-#{repo[:version]}/#{repo[:path]}" if File.directory?(archive_usual_dir) FileUtils.mv(archive_usual_dir, dest_dir) else FileUtils.mv("build/.tmprepo/#{repo[:path]}", dest_dir) end end
install_git(repo)
click to toggle source
# File lib/getrepos/install.rb, line 53 def install_git(repo) dest_dir = "build/repos/#{repo[:name]}-#{repo[:version]}" gitbare_dest_dir = "build/.gitbare/#{repo[:name]}" # Clone if File.exists?("#{gitbare_dest_dir}/HEAD") puts "Updating cloned '#{repo[:url]}' inside '#{gitbare_dest_dir}'".light_green ret = run_local("cd #{gitbare_dest_dir} && git fetch -q") exit ret if ret != 0 else puts "Cloning '#{repo[:url]}' to '#{gitbare_dest_dir}'".light_cyan ret = run_local("git clone -q --mirror '#{repo[:url]}' '#{gitbare_dest_dir}'") exit ret if ret != 0 end # Extract puts "Extracting and filtering '#{gitbare_dest_dir}' to '#{dest_dir}'".light_cyan prep_dest_dir(dest_dir) ret = run_local("cd #{gitbare_dest_dir} && git archive '#{repo[:version]}' -- #{repo[:path]} | tar xf - -C '../../.tmprepo/'") exit ret if ret != 0 FileUtils.mv("build/.tmprepo/#{repo[:path]}", dest_dir) end