forked from elkrejzi/blfs-currency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blfs-chapter17.php
244 lines (196 loc) · 6.79 KB
/
blfs-chapter17.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#! /usr/bin/php
<?php
include 'blfs-include.php';
$CHAPTER = '17';
$CHAPTERS = 'Chapters 17-19';
$START_PACKAGE = 'curl';
$STOP_PACKAGE = 're-alpine';
$renames = array();
$renames[ 'geoclue1' ] = 'geoclue2';
$ignores = array();
$ignores[ 'rpcnis-headers' ] = '';
//$current="libndp";
$regex = array();
$regex[ 're-alpine' ] = "/^.*Download re-alpine-(\d[\d\.]+\d).tar.*$/";
$regex[ 'w3m' ] = "/^.*Download w3m-(\d[\d\.]+\d).tar.*$/";
$regex[ 'serf' ] = "/^.*serf-([\d\.]*).tar.*$/";
$regex[ 'neon' ] = "/^.*Source code: neon-(\d[\d\.]*).tar.*$/";
$regex[ 'geoclue' ] = "/^.*geoclue-(\d[\d\.]+).tar.*$/";
$regex[ 'libevent' ] = "/^.*release-(\d[\d\.]*)-stable.*$/";
$url_fix = array (
array( //'pkg' => 'gnome',
'match' => '^ftp:\/\/ftp.gnome',
'replace' => "http://ftp.gnome" ),
array( 'pkg' => 're-alpine',
'match' => '^.*$',
'replace' => "http://sourceforge.net/projects/re-alpine/files" ),
array( 'pkg' => 'w3m',
'match' => '^.*$',
'replace' => "http://sourceforge.net/projects/w3m/files" ),
array( 'pkg' => 'links',
'match' => '^.*$',
'replace' => "http://links.twibright.com/download" ),
array( 'pkg' => 'serf',
'match' => '^.*$',
'replace' => "https://code.google.com/p/serf" ),
array( 'pkg' => 'libtirpc',
'match' => '^.*$',
'replace' => "http://sourceforge.net/projects/libtirpc/files/libtirpc" ),
array( 'pkg' => 'libevent',
'match' => '^.*$',
'replace' => "https://github.com/nmathewson/Libevent/releases" ),
array( 'pkg' => 'geoclue',
'match' => '^.*$',
'replace' => "https://launchpad.net/geoclue/trunk" ),
array( 'pkg' => 'libpcap',
'match' => '^.*$',
'replace' => "http://www.tcpdump.org/#latest-release" ),
array( 'pkg' => 'mutt',
'match' => '^.*$',
'replace' => "http://www.mutt.org/download.html" ),
array( 'pkg' => 'libndp',
'match' => '^.*$',
'replace' => "https://github.com/jpirko/libndp/releases" ),
array( 'pkg' => 'lynx',
'match' => '^.*$',
'replace' => "ftp://lynx.isc.org" ),
);
function get_packages( $package, $dirpath )
{
global $regex;
global $book_index;
global $url_fix;
global $current;
if ( isset( $current ) && $book_index != "$current" ) return 0;
// Fix up directory path
foreach ( $url_fix as $u )
{
$replace = $u[ 'replace' ];
$match = $u[ 'match' ];
if ( isset( $u[ 'pkg' ] ) )
{
if ( $package == $u[ 'pkg' ] )
{
$dirpath = preg_replace( "/$match/", "$replace", $dirpath );
break;
}
}
else
{
if ( preg_match( "/$match/", $dirpath ) )
{
$dirpath = preg_replace( "/$match/", "$replace", $dirpath );
break;
}
}
}
// Check for ftp
if ( preg_match( "/^ftp/", $dirpath ) )
{
// glib type packages
if ( $book_index == "glib-networking" ||
$book_index == "libsoup" )
{
// Parent listing
$dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
$position = strrpos( $dirpath, "/" );
$dirpath = substr ( $dirpath, 0, $position );
$lines = http_get_file( "$dirpath/" );
$dir = find_even_max( $lines, '/^[\d\.]+$/', '/^([\d\.]+)$/' );
$dirpath .= "/$dir/";
}
// lynx - really has odd name format
if ( $book_index == "lynx" )
{
$lines = http_get_file( $dirpath );
$dir = find_max( $lines, "/lynx/", "/^.*(lynx\d[\d\.]+).*$/" );
$dirpath .= "/$dir/";
$lines = http_get_file( "$dirpath" );
$max = find_max( $lines, "/rel/", "/^.*lynx(\d[\d\.]+rel\.\d).tar.*$/" );
return $max;
}
// Get listing
$lines = http_get_file( "$dirpath/" );
}
else // http
{
// Customize http directories as needed
if ( $book_index == "glib-networking" ||
$book_index == "libsoup" ||
$book_index == "geoclue1" )
{
// Parent listing
$dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
$position = strrpos( $dirpath, "/" );
$dirpath = substr ( $dirpath, 0, $position );
$lines1 = http_get_file( $dirpath );
if ( $book_index == "geoclue1" )
$dir = find_max ( $lines1, '/^\s*[\d\.]+\/.*$/', '/^\s*([\d\.]+).*$/' );
else
$dir = find_even_max( $lines1, '/^\s*[\d\.]+\/.*$/', '/^\s*([\d\.]+).*$/' );
$dirpath .= "/$dir/";
}
$lines = http_get_file( $dirpath );
if ( ! is_array( $lines ) ) return $lines;
} // End fetch
if ( isset( $regex[ $package ] ) )
{
// Custom search for latest package name
foreach ( $lines as $l )
{
if ( preg_match( '/^\h*$/', $l ) ) continue;
$ver = preg_replace( $regex[ $package ], "$1", $l );
if ( $ver == $l ) continue;
//if ( $book_index == "exiv" ) $ver = "2-$ver";
return $ver; // Return first match of regex
}
return 0; // This is an error
}
if ( $book_index == "libndp" )
return find_max( $lines, '/v\d/', '/^.*v([\d\.]+)$/' );
if ( $book_index == "heirloom-mailx_" )
return find_max( $lines, '/orig/', '/^.*_([\d\.]+)\.orig.*$/' );
if ( $book_index == "libpcap" )
return find_max( $lines, '/libpcap-[\d\.]+/', '/^.*libpcap-([\d\.]+).tar.*$/' );
if ( $book_index == "mutt" )
return find_max( $lines, '/mutt-/', '/^.*mutt-([\d\.]+).tar.*$/' );
// libtirpc (sourceforge is inconsistent here)
if ( $book_index == "libtirpc" )
return find_max( $lines, '/^\s*0\.[\d\.]+\s*$/', '/^\s*(0\.[\d\.]+)\s*$/' );
if ( $book_index == "geoclue1" )
return find_max( $lines, "/geoclue/", "/^.*geoclue-([\d\.]*\d)\.tar.*$/" );
// Most packages are in the form $package-n.n.n
// Occasionally there are dashes (e.g. 201-1)
$max = find_max( $lines, "/$package/", "/^.*$package-([\d\.]*\d)\.tar.*$/" );
return $max;
}
Function get_pattern( $line )
{
// Set up specific patter matches for extracting book versions
$match = array();
$match = array(
array( 'pkg' => 'w3m',
'regex' => "/w3m-(\d[\d\.]+)/" ),
);
foreach( $match as $m )
{
$pkg = $m[ 'pkg' ];
if ( preg_match( "/$pkg/", $line ) )
return $m[ 'regex' ];
}
return "/\D*(\d.*\d)\D*$/";
}
get_current(); // Get what is in the book
// Get latest version for each package
foreach ( $book as $pkg => $data )
{
$book_index = $pkg;
$base = $data[ 'basename' ];
$url = $data[ 'url' ];
$bver = $data[ 'version' ];
echo "book index: $book_index $bver $url \n";
$v = get_packages( $book_index, $url );
$vers[ $book_index ] = $v;
}
html(); // Write html output
?>