2017-06-22 17:31:45 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2021-03-16 19:13:50 +00:00
|
|
|
#!nix-shell -i perl -p perl perlPackages.LWPProtocolHttps perlPackages.FileSlurp
|
2017-06-22 16:44:52 +01:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use List::Util qw(reduce);
|
2017-06-22 20:08:19 +01:00
|
|
|
use File::Slurp;
|
2017-06-22 16:44:52 +01:00
|
|
|
use LWP::Simple;
|
|
|
|
|
2021-07-03 08:20:31 +01:00
|
|
|
my $only_free = grep { $_ eq "--only-free" } @ARGV;
|
|
|
|
|
2017-06-22 16:44:52 +01:00
|
|
|
sub semantic_less {
|
|
|
|
my ($a, $b) = @_;
|
|
|
|
$a =~ s/\b(\d+)\b/sprintf("%010s", $1)/eg;
|
|
|
|
$b =~ s/\b(\d+)\b/sprintf("%010s", $1)/eg;
|
|
|
|
return $a lt $b;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_latest_versions {
|
2021-07-01 12:42:41 +01:00
|
|
|
my @channels = get("https://www.jetbrains.com/updates/updates.xml") =~ /(<channel .+?<\/channel>)/gs;
|
2017-06-22 16:44:52 +01:00
|
|
|
my %h = {};
|
|
|
|
for my $ch (@channels) {
|
2018-06-13 17:08:00 +01:00
|
|
|
my ($id) = $ch =~ /^<channel id="[^"]+" name="([^"]+)"/;
|
2017-06-22 16:44:52 +01:00
|
|
|
my @builds = $ch =~ /(<build .+?<\/build>)/gs;
|
|
|
|
my $latest_build = reduce {
|
|
|
|
my ($aversion) = $a =~ /^<build [^>]*version="([^"]+)"/; die "no version in $a" unless $aversion;
|
|
|
|
my ($bversion) = $b =~ /^<build [^>]*version="([^"]+)"/; die "no version in $b" unless $bversion;
|
|
|
|
semantic_less($aversion, $bversion) ? $b : $a;
|
|
|
|
} @builds;
|
|
|
|
next unless $latest_build;
|
|
|
|
|
|
|
|
# version as in download url
|
2017-09-13 14:32:51 +01:00
|
|
|
my ($version) = $latest_build =~ /^<build [^>]*version="([^"]+)"/;
|
|
|
|
my ($fullNumber) = $latest_build =~ /^<build [^>]*fullNumber="([^"]+)"/;
|
|
|
|
my $latest_version_full1 = "$version-$fullNumber";
|
|
|
|
$latest_version_full1 =~ s/\s*EAP//;
|
|
|
|
|
2017-06-22 16:44:52 +01:00
|
|
|
my ($latest_version) = $latest_build =~ /^<build [^>]*version="([^"]+)"/;
|
|
|
|
($latest_version) = $latest_build =~ /^<build [^>]*fullNumber="([^"]+)"/ if $latest_version =~ / /;
|
|
|
|
|
|
|
|
$h{$id} = $latest_version;
|
2017-09-13 14:32:51 +01:00
|
|
|
$h{"full1_" . $id} = $latest_version_full1;
|
2017-06-22 16:44:52 +01:00
|
|
|
}
|
|
|
|
return %h;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %latest_versions = get_latest_versions();
|
2017-09-13 14:32:51 +01:00
|
|
|
# for my $ch (sort keys %latest_versions) {
|
2017-06-22 16:44:52 +01:00
|
|
|
# print("$ch $latest_versions{$ch}\n");
|
2017-09-13 14:32:51 +01:00
|
|
|
# }
|
2017-06-22 16:44:52 +01:00
|
|
|
|
|
|
|
sub update_nix_block {
|
|
|
|
my ($block) = @_;
|
|
|
|
my ($channel) = $block =~ /update-channel\s*=\s*"([^"]+)"/;
|
|
|
|
if ($channel) {
|
2017-09-13 14:32:51 +01:00
|
|
|
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");
|
2021-07-03 08:20:31 +01:00
|
|
|
} elsif ($only_free && $block =~ /licenses\.unfree/) {
|
|
|
|
print("$channel is unfree, skipping\n");
|
2017-09-13 14:32:51 +01:00
|
|
|
} 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}/;
|
2021-07-03 08:20:31 +01:00
|
|
|
# Some url pattern contain variables more than once
|
2021-06-05 19:52:32 +01:00
|
|
|
$url =~ s/\$\{name\}/$name/g;
|
|
|
|
$url =~ s/\$\{version\}/$latest_versions{$channel}/g;
|
2017-09-13 14:32:51 +01:00
|
|
|
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;
|
|
|
|
}
|
2017-06-22 16:44:52 +01:00
|
|
|
} else {
|
2017-09-13 14:32:51 +01:00
|
|
|
warn "unknown update-channel $channel";
|
2017-06-22 16:44:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $block;
|
|
|
|
}
|
|
|
|
|
2017-06-22 20:08:19 +01:00
|
|
|
my $nix = read_file 'default.nix';
|
2017-06-22 20:16:19 +01:00
|
|
|
$nix =~ s/(= build\w+ rec \{.+?\n \};\n)/update_nix_block($1)/gse;
|
2017-06-22 20:08:19 +01:00
|
|
|
write_file 'default.nix', $nix;
|