-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblfs-chapter06.php
151 lines (115 loc) · 3.48 KB
/
blfs-chapter06.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
#! /usr/bin/php
<?php
include 'blfs-include.php';
$CHAPTER = '6';
$CHAPTERS = 'Chapters 6-8';
$START_PACKAGE = 'bluefish';
$STOP_PACKAGE = 'qemu';
$renames = array();
$renames[ 'zsh1' ] = 'zsh-doc';
$ignores = array();
//$current="bluefish"; // For debugging
$regex = array();
$regex[ 'joe' ] = "/^.*Download joe-(\d[\d\.]+).tar.*$/";
$sf = 'sourceforge.net';
$url_fix = array (
array( 'pkg' => 'joe',
'match' => '^.*$',
'replace' => "http://$sf/projects/joe-editor/files" ),
array( 'pkg' => 'vim',
'match' => '^.*$',
'replace' => "http://mirrors-usa.go-parts.com/pub/vim/unix" ),
array( 'pkg' => 'tcsh',
'match' => '^.*$',
'replace' => "http://www.sfr-fresh.com/unix/misc" ),
);
function get_packages( $package, $dirpath )
{
global $exceptions;
global $regex;
global $book_index;
global $url_fix;
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;
}
}
}
if ( preg_match( "/^ftp/", $dirpath ) ) $dirpath .= "/";
$lines = http_get_file( "$dirpath" );
if ( ! is_array( $lines ) ) return $lines;
if ( isset( $regex[ $package ] ) )
{
// Custom search for latest package name
foreach ( $lines as $l )
{
$ver = preg_replace( $regex[ $package ], "$1", $l );
if ( $ver == $l ) continue;
if ( $package == 'krb' ) $ver = "5-$ver";
return $ver; // Return first match of regex
}
return 0; // This is an error
}
if ( $book_index == "joe" )
{
$dir = find_max( $lines, '/^.*joe-[\d\.]+.*$/', '/^.*(joe-[\d\.]+).tar.*$/' );
$lines = http_get_file( "$dirpath/$dir" );
}
// vim language pack
if ( $book_index == "vim1" )
return find_max( $lines, '/^.*vim-[\d\.]+-lang.*$/', '/^.*vim-([\d\.]+)-lang.*$/' );
if ( $book_index == "nano" )
return find_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
// zsh docs
if ( $book_index == "zsh1" )
return find_max( $lines, '/doc/', '/^.*zsh-([\d\.]+)-doc.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[ 0 ] = array( 'pkg' => 'ntfs',
// 'regex' => "/ntfs-3g_ntfsprogs-(\d.*\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( $base, $url );
$vers[ $book_index ] = $v;
}
html(); // Write html output
?>