lib/getch/void/tarball.rb in getch-0.3.3 vs lib/getch/void/tarball.rb in getch-0.3.4

- old
+ new

@@ -1,8 +1,7 @@ # frozen_string_literal: true -require 'open-uri' require 'open3' module Getch module Void class Tarball @@ -13,11 +12,11 @@ @xbps = false Dir.chdir OPTIONS[:mountpoint] end def x - search_archive + @xbps = search_archive download checksum install end @@ -27,18 +26,23 @@ OPTIONS[:musl] ? /void-x86_64-musl-ROOTFS-[\d._]+.tar.xz/ : /void-x86_64-ROOTFS-[\d._]+.tar.xz/ end - # Search only the glibc x86_64 for now + # Search the name of the last release in @file 'sha256sum.txt' + # Should find a line like this: + # SHA256 (void-x86_64-ROOTFS-20210930.tar.xz) = 8681b060e39e173682e1721a6088280c2b6eade628f5e5e3e8e4b74163d187f6 def search_archive yurl = "#{@url}/#{@file}" @log.info "Opening #{yurl}...\n" Helpers.get_file_online(yurl, @file) File.open(@file).each do |l| - @xbps = l.tr('()', '').split(' ') if l.match(tarball) + matchrule = l.tr('()', '').split(' ') if l.match(tarball) + return matchrule if matchrule && matchrule[1] =~ /^void/ end + + raise "No valid archive found on #{@file}." end def download @log.fatal 'No file found, retry later.' unless @xbps return if File.exist? @xbps[1] @@ -53,14 +57,14 @@ # Should contain 2 spaces... command = "echo #{@xbps[3]} #{@xbps[1]} | sha256sum --check" _, stderr, status = Open3.capture3(command) if status.success? then @log.result_ok - return + else + cleaning + @log.fatal "Problem with the checksum, relaunch getch.\n#{stderr}" end - cleaning - @log.fatal "Problem with the checksum, stderr\n#{stderr}" end def install decompress cleaning @@ -72,13 +76,12 @@ @log.info "Decompressing #{@xbps[1]}..." cmd = "tar xpf #{@xbps[1]} --xattrs-include=\'*.*\' --numeric-owner" _, stderr, status = Open3.capture3(cmd) if status.success? then @log.result_ok - return + else + @log.fatal "Fail to decompressing #{@xbps[1]} - #{stderr}." end - cleaning - @log.fatal "Fail to decompressing #{@xbps[1]} - #{stderr}." end def cleaning Dir.glob('void-x86_64*.tar.xz').each { |f| File.delete(f) } Dir.glob('sha256*').each { |f| File.delete(f) }