Created
February 5, 2017 06:39
-
-
Save mgregoro/3f981def618a886209d5a70456a25339 to your computer and use it in GitHub Desktop.
script for slurping down tarballs for openbsd upgrades.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# | |
# Perl implementation of the guide at https://www.openbsd.org/faq/upgrade60.html | |
# | |
# Requires: Mojolicious | |
# | |
my $arch = "amd64"; | |
my $rel = "6.0"; | |
my $rel_source = "http://mirrors.mit.edu/pub/OpenBSD/$rel/$arch/"; | |
use Mojo::UserAgent; | |
my $ua = Mojo::UserAgent; | |
# | |
# Download the release to /usr/rel | |
# | |
my $rnd = join('', split(/\./, $rel)); | |
my @to_fetch = ( | |
(map { "$_$rnd.tgz" } qw/xshare xserv xfont xbase man game comp base/), | |
qw/bsd bsd.mp bsd.rd/ | |
); | |
system("mkdir -p /usr/rel/$rel"); | |
chdir("/usr/rel/$rel"); | |
print "Grabbing SHA256 for OpenBSD $rel...\n"; | |
my $relsums = [split(/[\r\n]+/, $ua->get("$rel_source/SHA256")->res->body)]; | |
print "Downloading release to /usr/rel/$rel...\n"; | |
foreach my $file (@to_fetch) { | |
unless (-e $file && cmp_sum($file)) { | |
print "Downloading $file...\n"; | |
$ua->get("$rel_source/$file")->res->content->asset->move_to("$file"); | |
print "Downloaded\n"; | |
} | |
if (cmp_sum("$file")) { | |
print " + Checksum OK\n"; | |
} else { | |
die "[fatal] sum for $file didn't match what was provided\n"; | |
} | |
} | |
print "Release $rel retrieved from $rel_source\n"; | |
sub cmp_sum { | |
my ($file) = @_; | |
chomp my $output = `sha256 $file`; | |
return scalar grep { /^\Q$output\E$/ } @$relsums; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment