Commit 749f6a20 authored by satmandu's avatar satmandu Committed by GitHub

Add crew cache option (#4763)

* Add option to cache downloads

* Add CREW_CACHE_DIR const

* fewer quotes

* Adjust cache dir location

* clean up spacing

* remove extraneous option

* add slashes to CREW_CACHE_DIR path
parent d26b9c9a
......@@ -497,15 +497,36 @@ def download
sha256sum = @pkg.binary_sha256[@device[:architecture]]
end
Dir.chdir CREW_BREW_DIR do
unless ENV["CREW_CACHE_OPT"].to_s == ''
unless File.directory?(CREW_CACHE_DIR)
FileUtils.mkdir_p(CREW_CACHE_DIR)
end
if File.file?("#{CREW_CACHE_DIR}#{filename}")
if Digest::SHA256.hexdigest( File.read("#{CREW_CACHE_DIR}#{filename}") ) == sha256sum then
FileUtils.cp "#{CREW_CACHE_DIR}#{filename}", "#{CREW_BREW_DIR}"
puts "Archive found in cache".lightgreen
return {source: source, filename: filename}
else
puts 'Cached archive checksum mismatch. :/ Will download.'.lightred
end
end
end
if @opt_verbose then
system('curl', '-v', '--retry', '3', '--progress-bar', '-C', '-', '--insecure', '-L', '-#', url, '-o', filename)
else
system('curl', '--retry', '3', '--progress-bar', '-C', '-', '--insecure', '-L', '-#', url, '-o', filename)
end
abort 'Checksum mismatch. :/ Try again.'.lightred unless
Digest::SHA256.hexdigest( File.read("./#{filename}") ) == sha256sum
puts "Archive downloaded".lightgreen
unless ENV["CREW_CACHE_OPT"].to_s == ''
puts "Caching downloaded archive".lightgreen
FileUtils.cp filename, CREW_CACHE_DIR
end
end
puts "Archive downloaded".lightgreen
return {source: source, filename: filename}
end
......
# Defines common constants used in different parts of crew
CREW_VERSION = '1.5.1'
CREW_VERSION = '1.5.2'
ARCH_ACTUAL = `uname -m`.strip
# This helps with virtualized builds on aarch64 machines
......@@ -16,9 +16,9 @@ else
CREW_PREFIX = ENV['CREW_PREFIX']
@pkg.build_from_source = true
end
CREW_LIB_PREFIX = CREW_PREFIX + '/' + ARCH_LIB
CREW_MAN_PREFIX = CREW_PREFIX + '/share/man'
CREW_LIB_PATH = CREW_PREFIX + '/lib/crew/'
CREW_CONFIG_PATH = CREW_PREFIX + '/etc/crew/'
CREW_BREW_DIR = CREW_PREFIX + '/tmp/crew/'
......@@ -33,6 +33,12 @@ else
HOME = CREW_PREFIX + ENV['HOME']
end
if ENV['CREW_CACHE_DIR'].to_s == ''
CREW_CACHE_DIR = HOME + '/.cache/crewcache/'
else
CREW_CACHE_DIR = ENV['CREW_CACHE_DIR']
end
CREW_DEST_HOME = CREW_DEST_DIR + HOME
# Set CREW_NPROC from environment variable or `nproc`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment