Skip to content

Instantly share code, notes, and snippets.

@mgregoro
Created February 5, 2017 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgregoro/3f981def618a886209d5a70456a25339 to your computer and use it in GitHub Desktop.
Save mgregoro/3f981def618a886209d5a70456a25339 to your computer and use it in GitHub Desktop.
script for slurping down tarballs for openbsd upgrades.
#!/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