jetbrains: update.pl fixes

* indentation, retab
  * url handling for alternative version names
  * handling for alt. download url format
  * made unknown channel error non-fatal
This commit is contained in:
Brandon Barker 2017-09-13 13:32:51 +00:00 committed by Edward Tjörnhammar
parent 42be8dbe15
commit 14f2e0cd36
No known key found for this signature in database
GPG key ID: 7B82CE4A866B6845

View file

@ -27,46 +27,61 @@ sub get_latest_versions {
next unless $latest_build;
# version as in download url
my ($version) = $latest_build =~ /^<build [^>]*version="([^"]+)"/;
my ($fullNumber) = $latest_build =~ /^<build [^>]*fullNumber="([^"]+)"/;
my $latest_version_full1 = "$version-$fullNumber";
$latest_version_full1 =~ s/\s*EAP//;
my ($latest_version) = $latest_build =~ /^<build [^>]*version="([^"]+)"/;
($latest_version) = $latest_build =~ /^<build [^>]*fullNumber="([^"]+)"/ if $latest_version =~ / /;
$h{$id} = $latest_version;
$h{"full1_" . $id} = $latest_version_full1;
}
return %h;
}
my %latest_versions = get_latest_versions();
#for my $ch (sort keys %latest_versions) {
# for my $ch (sort keys %latest_versions) {
# print("$ch $latest_versions{$ch}\n");
#}
# }
sub update_nix_block {
my ($block) = @_;
my ($channel) = $block =~ /update-channel\s*=\s*"([^"]+)"/;
if ($channel) {
die "unknown update-channel $channel" unless $latest_versions{$channel};
my ($version) = $block =~ /version\s*=\s*"([^"]+)"/;
die "no version in $block" unless $version;
if ($version eq $latest_versions{$channel}) {
print("$channel is up to date at $version\n");
if ($latest_versions{$channel}) {
my ($version) = $block =~ /version\s*=\s*"([^"]+)"/;
die "no version in $block" unless $version;
if ($version eq $latest_versions{$channel}) {
print("$channel is up to date at $version\n");
} else {
print("updating $channel: $version -> $latest_versions{$channel}\n");
my ($url) = $block =~ /url\s*=\s*"([^"]+)"/;
# try to interpret some nix
my ($name) = $block =~ /name\s*=\s*"([^"]+)"/;
$name =~ s/\$\{version\}/$latest_versions{$channel}/;
$url =~ s/\$\{name\}/$name/;
$url =~ s/\$\{version\}/$latest_versions{$channel}/;
die "$url still has some interpolation" if $url =~ /\$/;
my ($sha256) = get("$url.sha256") =~ /^([0-9a-f]{64})/;
my $version_string = $latest_versions{$channel};
unless ( $sha256 ) {
my $full_version = $latest_versions{"full1_" . $channel};
$url =~ s/$version_string/$full_version/;
($sha256) = get("$url.sha256") =~ /^([0-9a-f]{64})/;
$version_string = $full_version;
}
die "invalid sha256 in $url.sha256" unless $sha256;
my ($sha256Base32) = readpipe("nix-hash --type sha256 --to-base32 $sha256");
chomp $sha256Base32;
print "Jetbrains published SHA256: $sha256\n";
print "Conversion into base32 yields: $sha256Base32\n";
$block =~ s#version\s*=\s*"([^"]+)".+$#version = "$version_string"; /* updated by script */#m;
$block =~ s#sha256\s*=\s*"([^"]+)".+$#sha256 = "$sha256Base32"; /* updated by script */#m;
}
} else {
print("updating $channel: $version -> $latest_versions{$channel}\n");
my ($url) = $block =~ /url\s*=\s*"([^"]+)"/;
# try to interpret some nix
my ($name) = $block =~ /name\s*=\s*"([^"]+)"/;
$name =~ s/\$\{version\}/$latest_versions{$channel}/;
$url =~ s/\$\{name\}/$name/;
$url =~ s/\$\{version\}/$latest_versions{$channel}/;
die "$url still has some interpolation" if $url =~ /\$/;
my ($sha256) = get("$url.sha256") =~ /^([0-9a-f]{64})/;
my ($sha256Base32) = readpipe("nix-hash --type sha256 --to-base32 $sha256");
chomp $sha256Base32;
print "Jetbrains published SHA256: $sha256\n";
print "Conversion into base32 yeilds: $sha256Base32\n";
$block =~ s#version\s*=\s*"([^"]+)".+$#version = "$latest_versions{$channel}"; /* updated by script */#m;
$block =~ s#sha256\s*=\s*"([^"]+)".+$#sha256 = "$sha256Base32"; /* updated by script */#m;
warn "unknown update-channel $channel";
}
}
return $block;