diff options
author | 2020-04-28 00:33:32 -0700 | |
---|---|---|
committer | 2020-04-28 00:43:51 -0700 | |
commit | 4b612418355ae1f3f4b4575db4f7bbae1e8781e4 (patch) | |
tree | e3069d4221d7a6e319fdc10ee81c54cc59e8a6bd | |
parent | Add the host of the mirror to the json files (diff) | |
download | gentoo-mirrorstats-4b612418355ae1f3f4b4575db4f7bbae1e8781e4.tar.gz gentoo-mirrorstats-4b612418355ae1f3f4b4575db4f7bbae1e8781e4.tar.bz2 gentoo-mirrorstats-4b612418355ae1f3f4b4575db4f7bbae1e8781e4.zip |
mirmon: start refactor of probe
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | distfiles_mirrors/mirmon.conf | 2 | ||||
-rwxr-xr-x | probe-mirmon (renamed from distfiles_mirrors/probe-mirmon-distfiles) | 18 | ||||
-rw-r--r-- | rsync_mirrors/mirmon.conf | 2 | ||||
-rwxr-xr-x | rsync_mirrors/probe-mirmon-rsync | 60 |
4 files changed, 18 insertions, 64 deletions
diff --git a/distfiles_mirrors/mirmon.conf b/distfiles_mirrors/mirmon.conf index 7994130..e43d772 100644 --- a/distfiles_mirrors/mirmon.conf +++ b/distfiles_mirrors/mirmon.conf @@ -4,7 +4,7 @@ icons ../icons countries /var/www/mirrorstats.gentoo.org/mirmon/countries.list mirror_list /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/var/g.mirrors state /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/var/mirmon.state -probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/probe-mirmon-distfiles %TIMEOUT% %URL%distfiles/timestamp.mirmon +probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/probe-mirmon %TIMEOUT% %URL%distfiles/timestamp.mirmon project_url http://www.gentoo.org/ project_logo http://www.gentoo.org/images/gentoo-new.gif diff --git a/distfiles_mirrors/probe-mirmon-distfiles b/probe-mirmon index 6e8ae52..7b57923 100755 --- a/distfiles_mirrors/probe-mirmon-distfiles +++ b/probe-mirmon @@ -32,6 +32,8 @@ sub main { sub handle_wget { my ( $timeout, $url ) = @_; + # TODO: replace this with native HTTP + # TODO: munge the output! exec {'/usr/bin/wget'} 'wget', qw( -q --passive-ftp -O - -T ), $timeout, '-t', 1, $url; } @@ -54,8 +56,20 @@ sub handle_rsync { exit 900; # rediculous exit code. }; - print <$fh>; -# print Date::Parse::str2time(<$fh>); + print munge_date(<fh>); exit 0; } + +sub munge_date { + my $timestr = $_; + my $timestamp = int($timestr); + my $year2020 = 1577836800; + my $year2038 = 2145916800; + # If the string starts with an epoch, just use that + if($int_timestamp >= $year2020 && $int_timestamp <= $year2038) { + return $int_timestamp; + } else { + return Date::Parse::str2time($timestr); + } +} diff --git a/rsync_mirrors/mirmon.conf b/rsync_mirrors/mirmon.conf index 6627f55..94887a9 100644 --- a/rsync_mirrors/mirmon.conf +++ b/rsync_mirrors/mirmon.conf @@ -4,7 +4,7 @@ icons ../icons countries /var/www/mirrorstats.gentoo.org/mirmon/countries.list mirror_list /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/var/g.mirrors state /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/var/mirmon.state -probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/probe-mirmon-rsync %TIMEOUT% %URL%gentoo-portage/metadata/timestamp +probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/probe-mirmon %TIMEOUT% %URL%gentoo-portage/metadata/timestamp project_url http://www.gentoo.org/ project_logo http://www.gentoo.org/images/gentoo-new.gif diff --git a/rsync_mirrors/probe-mirmon-rsync b/rsync_mirrors/probe-mirmon-rsync deleted file mode 100755 index 2709319..0000000 --- a/rsync_mirrors/probe-mirmon-rsync +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/perl -# $Id: probe-mirmon,v 1.4 2009/08/19 23:15:46 karl Exp $ -# public domain. Originally written by Karl Berry, 2009. -# -# Probe rsync url's for mirmon; use wget for anything else. -# From description at http://people.cs.uu.nl/henkp/mirmon. -# -# Also requires a patch to mirmon itself to accept rsync urls -# (and I wanted https too): -# --- /usr/local/share/mirmon/ORIG/mirmon 2007-08-18 18:05:47.000000000 +0200 -# +++ /usr/local/share/mirmon/mirmon 2009-07-03 22:38:00.000000000 +0200 -# @@ -386,3 +386,3 @@ -# my ( $type, $site, $home ) ; -# - if ( $url =~ m!^(ftp|http)://([^/:]+)(:\d+)?/! ) -# + if ( $url =~ m!^(ftp|https?|rsync)://([^/:]+)(:\d+)?/! ) -# { $type = $1 ; $site = $2 ; $home = $& ; } - -main(@ARGV); - -use Date::Parse (); # dev-perl/TimeDate -use File::Tempdir; # dev-perl/File-Tempdir - -sub main { - my ( $timeout, $url ) = @_; - if ( $url =~ m,^rsync://, ) { - handle_rsync( $timeout, $url ); - } - else { - handle_wget( $timeout, $url ); - } -} - -sub handle_wget { - my ( $timeout, $url ) = @_; - exec {'/usr/bin/wget'} 'wget', qw( -q --passive-ftp -O - -T ), $timeout, '-t', 1, $url; -} - -sub handle_rsync { - my ( $timeout, $url ) = @_; - - my $tmpdir = File::Tempdir->new(); - my $dir = $tmpdir->name; - my $file = $url; - - $file =~ s/\W/_/g; # translate all non-letters to _ - - if ( my $fail = system '/usr/bin/rsync', qw( --no-motd --timeout ), $timeout, $url, "$dir/$file" ) { - warn "rsync failed, exit code $fail, $! $? $@\n"; - exit $fail; - } - - open my $fh, '<', "$dir/$file" or do { - warn "Opening Downloaded timestamp Failed"; - exit 900; # rediculous exit code. - }; - - print Date::Parse::str2time(<$fh>); - exit 0; - -} |