Skip to content

Instantly share code, notes, and snippets.

@jhunt
Last active March 17, 2022 00:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhunt/6c1261b3a96ca38ce25d3cc3f2f9d492 to your computer and use it in GitHub Desktop.
Save jhunt/6c1261b3a96ca38ce25d3cc3f2f9d492 to your computer and use it in GitHub Desktop.
Watching Upstream HTTP Download Sites for New Versions
#!/bin/bash
set -e
id=$( curl -sL https://api.github.com/repos/docker/compose/releases/latest | jq -r .id)
tag=$( curl -sL https://api.github.com/repos/docker/compose/releases/$id | jq -r .tag_name | sed -e 's/^v//')
file=$(curl -sL https://api.github.com/repos/docker/compose/releases/$id | jq -r '.assets[].browser_download_url' | grep 'docker-compose-Linux-x86_64$')
if [[ $tag != "${1:-none}" ]]; then
echo $file
fi
#!/usr/bin/perl
use strict;
use warnings;
my $have = $ARGV[0] || 'none';
my $url = "https://download.docker.com/linux/static/stable/x86_64";
open my $fh, "-|", "curl -sL $url"
or die "unable to curl: $!\n";
my $v = 0;
my $last = undef;
while (<$fh>) {
next unless m/href="(docker-(\d+)\.(\d+)\.(\d+)\.tgz)"/;
my ($f, $x, $y, $z) = ($1, $2, $3, $4);
my $n = $x * 10**6 + $y * 10**3 + $z;
if ($n > $v) {
$v = $n;
$last = ["$x.$y.$z", $f];
}
}
close($fh);
$last or die "no latest version detected!";
$last->[0] eq $have or print "$url/$last->[1]\n";
#!/usr/bin/perl
use strict;
use warnings;
my $have = $ARGV[0] || 'none';
my $url = "https://mirrors.edge.kernel.org/pub/software/scm/git";
open my $fh, "-|", "curl -sL $url"
or die "unable to curl: $!\n";
my $v = 0;
my $last = undef;
while (<$fh>) {
next unless m/href="(git-(\d+)\.(\d+)\.(\d+)\.tar.gz)"/;
my ($f, $x, $y, $z) = ($1, $2, $3, $4);
my $n = $x * 10**6 + $y * 10**3 + $z;
if ($n > $v) {
$v = $n;
$last = ["$x.$y.$z", $f];
}
}
close($fh);
$last or die "no latest version detected!";
$last->[0] eq $have or print "$url/$last->[1]\n";

Watching Upstream Releases

For a while now I've had an idea for a VERY lightweight CI/CD solution based on Kubernetes CronJobs, and a bespoke set of heuristic "version checkers" that can parse a single source -- HTTP downloads listing, a GitHub repository's release feed, etc. -- and determine if you need to go download a new thing.

This is a quick hacky sketch of what those checkers might look like, because it's late, I can't sleep, and I'm otherwise unoccupied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment