1#!/usr/bin/perl -w 2 3#************************************************************** 4# 5# Licensed to the Apache Software Foundation (ASF) under one 6# or more contributor license agreements. See the NOTICE file 7# distributed with this work for additional information 8# regarding copyright ownership. The ASF licenses this file 9# to you under the Apache License, Version 2.0 (the 10# "License"); you may not use this file except in compliance 11# with the License. You may obtain a copy of the License at 12# 13# http://www.apache.org/licenses/LICENSE-2.0 14# 15# Unless required by applicable law or agreed to in writing, 16# software distributed under the License is distributed on an 17# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18# KIND, either express or implied. See the License for the 19# specific language governing permissions and limitations 20# under the License. 21# 22#************************************************************** 23 24use LWP::UserAgent; 25 26use strict; 27 28=head1 NAME 29 30 patch_make_releases_xml.pl - Create a section for the instsetoo_native/data/releases.xml file. 31 32=head1 SYNOPSIS 33 34 patch_make_releases_xml.pl <version-number> 35 36 version-number is the version number (eg 4.0.1) for which to create the releases.xml file. 37 38=head1 DESCRIPTION 39 40 Will contact http://archive.apache.org/dist/openoffice/<version-number>/binaries/ and 41 a) determine the set of languages 42 b) collect sizes and sha256 check sums for all Windows installation sets. 43 44 The result is printed to the console. It has to be added manually to releases.xml. 45 46=cut 47 48 49if (scalar @ARGV != 1) 50{ 51 print STDERR "usage: $0 <version-number>\n"; 52 die; 53} 54 55my $version = $ARGV[0]; 56 57print <<EOT; 58<?xml version='1.0' encoding='UTF-8'?> 59<!--*********************************************************** 60 * 61 * Licensed to the Apache Software Foundation (ASF) under one 62 * or more contributor license agreements. See the NOTICE file 63 * distributed with this work for additional information 64 * regarding copyright ownership. The ASF licenses this file 65 * to you under the Apache License, Version 2.0 (the 66 * "License"); you may not use this file except in compliance 67 * with the License. You may obtain a copy of the License at 68 * 69 * http://www.apache.org/licenses/LICENSE-2.0 70 * 71 * Unless required by applicable law or agreed to in writing, 72 * software distributed under the License is distributed on an 73 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 74 * KIND, either express or implied. See the License for the 75 * specific language governing permissions and limitations 76 * under the License. 77 * 78 ***********************************************************--> 79EOT 80 81sub DownloadFile ($) 82{ 83 my $url = shift; 84 85 my $agent = LWP::UserAgent->new(); 86 $agent->timeout(120); 87 $agent->show_progress(0); 88 89 my $file_content = ""; 90 my $last_was_redirect = 0; 91 my $bytes_read = 0; 92 $agent->add_handler('response_redirect' 93 => sub{ 94 $last_was_redirect = 1; 95 return; 96 }); 97 $agent->add_handler('response_data' 98 => sub{ 99 if ($last_was_redirect) 100 { 101 $last_was_redirect = 0; 102 # Throw away the data we got so far. 103 $file_content = ""; 104 } 105 my($response,$agent,$h,$data)=@_; 106 $file_content .= $data; 107 }); 108 $agent->get($url); 109 110 return $file_content; 111} 112 113 114 115 116sub GetResponse ($) 117{ 118 my $url = shift; 119 120 my $agent = LWP::UserAgent->new(); 121 $agent->timeout(120); 122 $agent->show_progress(0); 123 124 my $file_content = ""; 125 my $last_was_redirect = 0; 126 my $bytes_read = 0; 127 $agent->add_handler('response_redirect' 128 => sub{ 129 $last_was_redirect = 1; 130 return; 131 }); 132 $agent->add_handler('response_data' 133 => sub{ 134 if ($last_was_redirect) 135 { 136 $last_was_redirect = 0; 137 # Throw away the data we got so far. 138 $file_content = ""; 139 } 140 my($response,$agent,$h,$data)=@_; 141 $file_content .= $data; 142 }); 143 return $agent->get($url, 'Range' => "bytes=0-0"); 144} 145 146my @languages = (); 147my @lines = split(/\n/, DownloadFile("http://archive.apache.org/dist/openoffice/".$version."/binaries/")); 148foreach my $line (@lines) 149{ 150 next unless $line =~ /folder.gif/; 151 if ($line =~ /a href=\"([^\"\/]+)\/\"/) 152 { 153 my $language = $1; 154 next if $language eq "SDK"; 155 next if $language =~ /^[A-Z]/; 156 push @languages, $language; 157 } 158} 159 160print "<releases>\n"; 161print " <release>\n"; 162printf " <version>%s</version>\n", $version; 163print " <download>\n"; 164print " <package-format>msi</package-format>\n"; 165print " <url-template>\n"; 166printf " http://archive.apache.org/dist/openoffice/%s/binaries/%%L/Apache_OpenOffice_%s_Win_x86_install_%%L.exe\n",$version, $version; 167print " </url-template>\n"; 168foreach my $language (sort @languages) 169{ 170 print " <item>\n"; 171 printf " <language>%s</language>\n", $language; 172 my $name = sprintf( 173 "Apache_OpenOffice_%s_Win_x86_install_%s.exe", 174 $version, 175 $language, 176 $version, 177 $language); 178 179 my $content = DownloadFile( 180 sprintf("http://archive.apache.org/dist/openoffice/%s/binaries/%s/%s.sha256", $version, $language, $name)); 181 if ($content =~ /^([a-f0-9]+)/) 182 { 183 printf(" <checksum type=\"sha256\">%s</checksum>\n", $1); 184 } 185 my $response = GetResponse( 186 sprintf("http://archive.apache.org/dist/openoffice/%s/binaries/%s/%s", $version, $language, $name)); 187 my $content_range = $response->{'_headers'}->{'content-range'}; 188 if ($content_range =~ /bytes 0-0\/(\d+)/) 189 { 190 printf(" <size>%s</size>\n", $1); 191 } 192 print " </item>\n"; 193} 194 195print " </download>\n"; 196print " </release>\n"; 197print "</releases>\n"; 198