From ffe25b99180ef80d30e7e233a911d0a677cb22d7 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 13 Jun 2022 18:43:53 +0200 Subject: Modify purge-one-hour to take two arguments, BASEDIR and BASEURL Use cases, based on what we do with automation today: For the main web: purge-one-hour /var/www/openssl https://www.openssl.org For the docs: purge-one-hour /var/www/docs https://www.openssl.org/docs For the blog: purge-one-hour /var/www/blog https://www.openssl.org/blog --- akamai-tools/purge-one-hour | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/akamai-tools/purge-one-hour b/akamai-tools/purge-one-hour index 895967f..c1dc3b2 100755 --- a/akamai-tools/purge-one-hour +++ b/akamai-tools/purge-one-hour @@ -12,15 +12,35 @@ use strict; use warnings; +use Cwd qw(:DEFAULT abs_path); +use File::Basename; + # Find all .html files that include a .inc file, and create a map my %inc2html = (); my $debug = $ENV{DEBUG}; my $dryrun = $ENV{DRYRUN}; -my $base = '/var/www/openssl'; # MUST NOT end with a slash +if (scalar @ARGV != 2 || $ARGV[0] eq '-h') { + my $prog = basename($0); + print STDERR <<_____; +usage: $prog BASEDIR BASEURL + +where BASEDIR is the base directory where original web files are scanned for, +and BASEURL is the corresponding base URL. +_____ + exit $ARGV[0] eq '-h' ? 0 : 1; +} + +my $basedir = shift @ARGV; # For example, /var/www/openssl +my $baseurl = shift @ARGV; # For example, https://www.openssl.org + +# This ensures that we have an absolute base directory, and that it's +# normalised (i.e. doesn't have duplicated or ending slashes) +my $tmp = abs_path($basedir) or die "$basedir: $!\n"; +$basedir = $tmp; -foreach ( `find $base -type f -name '*.html'` ) { +foreach ( `find $basedir -type f -name '*.html'` ) { chomp; my $file = $_; my ($dn, $fn) = $_ =~ m/^(?:(.*)\/)?([^\/]*)$/; @@ -30,7 +50,7 @@ foreach ( `find $base -type f -name '*.html'` ) { foreach ( ) { if (//) { my $vf = $1; - $vf = ($vf =~ m|^/|) ? "$base$vf" : "$dn/$vf"; + $vf = ($vf =~ m|^/|) ? "$basedir$vf" : "$dn/$vf"; push @incs, "$vf"; } } @@ -56,14 +76,14 @@ if ($debug) { # one with an ending slash and one without. my %files = (); -foreach ( `find $base -type f -mtime -2` ) { +foreach ( `find $basedir -type f -mtime -2` ) { chomp; - next if /^\Q$base\E\/(\.git|bin)/; + next if /^\Q$basedir\E\/(\.git|bin)/; next if /\/\.ht\w+$/; my $x = $_; my @files = defined $inc2html{$x} ? @{$inc2html{$x}} : ( $x ); foreach ( @files ) { - s/^\Q$base\E\//https:\/\/www.openssl.org\//; + s/^\Q$basedir\E\//$baseurl\//; $files{$_} = 1; if ( /^(.*)\/index.(html|cgi|pl|php|xhtml|htm)$/ ) { $files{"$1/"} = $files{"$1"} = 1; -- cgit v1.2.3