diff options
author | Volth <volth@webmaster.ms> | 2017-06-22 15:44:52 +0000 |
---|---|---|
committer | Volth <volth@webmaster.ms> | 2017-06-22 16:06:23 +0000 |
commit | 1a879759103df812fae9d47b8e7773b6185522d9 (patch) | |
tree | 7eadb6a023f8b450679c5c71e81eabc6785b193c /pkgs/applications/editors/jetbrains/update.pl | |
parent | c89efa3cbce9f5534e3d24ec61788c4dc4813399 (diff) | |
download | nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar.gz nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar.bz2 nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar.lz nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar.xz nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.tar.zst nixpkgs-1a879759103df812fae9d47b8e7773b6185522d9.zip |
update script for jetbrains products
Diffstat (limited to 'pkgs/applications/editors/jetbrains/update.pl')
-rwxr-xr-x | pkgs/applications/editors/jetbrains/update.pl | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/pkgs/applications/editors/jetbrains/update.pl b/pkgs/applications/editors/jetbrains/update.pl new file mode 100755 index 00000000000..9503212df43 --- /dev/null +++ b/pkgs/applications/editors/jetbrains/update.pl @@ -0,0 +1,92 @@ +#!/usr/bin/env perl + +use strict; +use List::Util qw(reduce); +use File::Basename qw(dirname); +use LWP::Simple; + +sub readFile { + my ($filename) = @_; + local $/ = undef; + open FILE, $filename or die "readFile($filename) failed: $!"; + binmode FILE; + my $data = <FILE>; + close FILE; + return $data; +} + +sub writeFile { + my ($filename, $content) = @_; + make_path(dirname($filename)) or die "$!" unless -d dirname($filename); + open FH, ">$filename" or die "writeFile($filename) failed: $!"; + binmode FH; # do not emit \r + print FH $content; + close FH; +} + +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 { + my @channels = get("http://www.jetbrains.com/updates/updates.xml") =~ /(<channel .+?<\/channel>)/gs; + my %h = {}; + for my $ch (@channels) { + my ($id) = $ch =~ /^<channel id="([^"]+)"/; + 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 + my ($latest_version) = $latest_build =~ /^<build [^>]*version="([^"]+)"/; + ($latest_version) = $latest_build =~ /^<build [^>]*fullNumber="([^"]+)"/ if $latest_version =~ / /; + + $h{$id} = $latest_version; + } + return %h; +} + +my %latest_versions = get_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"); + } 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})/; + die "invalid sha256 in $url.sha256" unless $sha256; + + $block =~ s#version\s*=\s*"([^"]+)".+$#version = "$latest_versions{$channel}"; /* updated by script */#m; + $block =~ s#sha256\s*=\s*"([^"]+)".+$#sha256 = "$sha256"; /* updated by script */#m; + } + } + return $block; +} + +my $nix = readFile 'default.nix'; +$nix =~ s/(= build\w+ rec \{.+?\};\n\n)/update_nix_block($1)/gse; +writeFile 'default.nix', $nix; |