1 |
commit: 4b612418355ae1f3f4b4575db4f7bbae1e8781e4 |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Apr 28 07:33:32 2020 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Apr 28 07:43:51 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=4b612418 |
7 |
|
8 |
mirmon: start refactor of probe |
9 |
|
10 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
11 |
|
12 |
distfiles_mirrors/mirmon.conf | 2 +- |
13 |
.../probe-mirmon-distfiles => probe-mirmon | 18 ++++++- |
14 |
rsync_mirrors/mirmon.conf | 2 +- |
15 |
rsync_mirrors/probe-mirmon-rsync | 60 ---------------------- |
16 |
4 files changed, 18 insertions(+), 64 deletions(-) |
17 |
|
18 |
diff --git a/distfiles_mirrors/mirmon.conf b/distfiles_mirrors/mirmon.conf |
19 |
index 7994130..e43d772 100644 |
20 |
--- a/distfiles_mirrors/mirmon.conf |
21 |
+++ b/distfiles_mirrors/mirmon.conf |
22 |
@@ -4,7 +4,7 @@ icons ../icons |
23 |
countries /var/www/mirrorstats.gentoo.org/mirmon/countries.list |
24 |
mirror_list /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/var/g.mirrors |
25 |
state /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/var/mirmon.state |
26 |
-probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/probe-mirmon-distfiles %TIMEOUT% %URL%distfiles/timestamp.mirmon |
27 |
+probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/probe-mirmon %TIMEOUT% %URL%distfiles/timestamp.mirmon |
28 |
project_url http://www.gentoo.org/ |
29 |
project_logo http://www.gentoo.org/images/gentoo-new.gif |
30 |
|
31 |
|
32 |
diff --git a/distfiles_mirrors/probe-mirmon-distfiles b/probe-mirmon |
33 |
similarity index 79% |
34 |
rename from distfiles_mirrors/probe-mirmon-distfiles |
35 |
rename to probe-mirmon |
36 |
index 6e8ae52..7b57923 100755 |
37 |
--- a/distfiles_mirrors/probe-mirmon-distfiles |
38 |
+++ b/probe-mirmon |
39 |
@@ -32,6 +32,8 @@ sub main { |
40 |
|
41 |
sub handle_wget { |
42 |
my ( $timeout, $url ) = @_; |
43 |
+ # TODO: replace this with native HTTP |
44 |
+ # TODO: munge the output! |
45 |
exec {'/usr/bin/wget'} 'wget', qw( -q --passive-ftp -O - -T ), $timeout, '-t', 1, $url; |
46 |
} |
47 |
|
48 |
@@ -54,8 +56,20 @@ sub handle_rsync { |
49 |
exit 900; # rediculous exit code. |
50 |
}; |
51 |
|
52 |
- print <$fh>; |
53 |
-# print Date::Parse::str2time(<$fh>); |
54 |
+ print munge_date(<fh>); |
55 |
exit 0; |
56 |
|
57 |
} |
58 |
+ |
59 |
+sub munge_date { |
60 |
+ my $timestr = $_; |
61 |
+ my $timestamp = int($timestr); |
62 |
+ my $year2020 = 1577836800; |
63 |
+ my $year2038 = 2145916800; |
64 |
+ # If the string starts with an epoch, just use that |
65 |
+ if($int_timestamp >= $year2020 && $int_timestamp <= $year2038) { |
66 |
+ return $int_timestamp; |
67 |
+ } else { |
68 |
+ return Date::Parse::str2time($timestr); |
69 |
+ } |
70 |
+} |
71 |
|
72 |
diff --git a/rsync_mirrors/mirmon.conf b/rsync_mirrors/mirmon.conf |
73 |
index 6627f55..94887a9 100644 |
74 |
--- a/rsync_mirrors/mirmon.conf |
75 |
+++ b/rsync_mirrors/mirmon.conf |
76 |
@@ -4,7 +4,7 @@ icons ../icons |
77 |
countries /var/www/mirrorstats.gentoo.org/mirmon/countries.list |
78 |
mirror_list /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/var/g.mirrors |
79 |
state /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/var/mirmon.state |
80 |
-probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/probe-mirmon-rsync %TIMEOUT% %URL%gentoo-portage/metadata/timestamp |
81 |
+probe /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/probe-mirmon %TIMEOUT% %URL%gentoo-portage/metadata/timestamp |
82 |
project_url http://www.gentoo.org/ |
83 |
project_logo http://www.gentoo.org/images/gentoo-new.gif |
84 |
|
85 |
|
86 |
diff --git a/rsync_mirrors/probe-mirmon-rsync b/rsync_mirrors/probe-mirmon-rsync |
87 |
deleted file mode 100755 |
88 |
index 2709319..0000000 |
89 |
--- a/rsync_mirrors/probe-mirmon-rsync |
90 |
+++ /dev/null |
91 |
@@ -1,60 +0,0 @@ |
92 |
-#!/usr/bin/perl |
93 |
-# $Id: probe-mirmon,v 1.4 2009/08/19 23:15:46 karl Exp $ |
94 |
-# public domain. Originally written by Karl Berry, 2009. |
95 |
-# |
96 |
-# Probe rsync url's for mirmon; use wget for anything else. |
97 |
-# From description at http://people.cs.uu.nl/henkp/mirmon. |
98 |
-# |
99 |
-# Also requires a patch to mirmon itself to accept rsync urls |
100 |
-# (and I wanted https too): |
101 |
-# --- /usr/local/share/mirmon/ORIG/mirmon 2007-08-18 18:05:47.000000000 +0200 |
102 |
-# +++ /usr/local/share/mirmon/mirmon 2009-07-03 22:38:00.000000000 +0200 |
103 |
-# @@ -386,3 +386,3 @@ |
104 |
-# my ( $type, $site, $home ) ; |
105 |
-# - if ( $url =~ m!^(ftp|http)://([^/:]+)(:\d+)?/! ) |
106 |
-# + if ( $url =~ m!^(ftp|https?|rsync)://([^/:]+)(:\d+)?/! ) |
107 |
-# { $type = $1 ; $site = $2 ; $home = $& ; } |
108 |
- |
109 |
-main(@ARGV); |
110 |
- |
111 |
-use Date::Parse (); # dev-perl/TimeDate |
112 |
-use File::Tempdir; # dev-perl/File-Tempdir |
113 |
- |
114 |
-sub main { |
115 |
- my ( $timeout, $url ) = @_; |
116 |
- if ( $url =~ m,^rsync://, ) { |
117 |
- handle_rsync( $timeout, $url ); |
118 |
- } |
119 |
- else { |
120 |
- handle_wget( $timeout, $url ); |
121 |
- } |
122 |
-} |
123 |
- |
124 |
-sub handle_wget { |
125 |
- my ( $timeout, $url ) = @_; |
126 |
- exec {'/usr/bin/wget'} 'wget', qw( -q --passive-ftp -O - -T ), $timeout, '-t', 1, $url; |
127 |
-} |
128 |
- |
129 |
-sub handle_rsync { |
130 |
- my ( $timeout, $url ) = @_; |
131 |
- |
132 |
- my $tmpdir = File::Tempdir->new(); |
133 |
- my $dir = $tmpdir->name; |
134 |
- my $file = $url; |
135 |
- |
136 |
- $file =~ s/\W/_/g; # translate all non-letters to _ |
137 |
- |
138 |
- if ( my $fail = system '/usr/bin/rsync', qw( --no-motd --timeout ), $timeout, $url, "$dir/$file" ) { |
139 |
- warn "rsync failed, exit code $fail, $! $? $@\n"; |
140 |
- exit $fail; |
141 |
- } |
142 |
- |
143 |
- open my $fh, '<', "$dir/$file" or do { |
144 |
- warn "Opening Downloaded timestamp Failed"; |
145 |
- exit 900; # rediculous exit code. |
146 |
- }; |
147 |
- |
148 |
- print Date::Parse::str2time(<$fh>); |
149 |
- exit 0; |
150 |
- |
151 |
-} |