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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
#!/usr/bin/perl -w
#
# rpmbuildupdate by Julien Danjou <jdanjou at mandrakesoft dot com>
#
# Copyright (c) 2003 by MandrakeSoft
#
# Permission to use, copy, modify, and distribute this software and its
# documentation under the terms of the GNU General Public License is hereby
# granted. No representations are made about the suitability of this software
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
use strict;
use AppConfig;
my $defaultrelease = "1mdk";
my %config;
sub build_from_src
{
$_ = shift;
my $nv = shift;
my $b = qx[basename $_];
if($b =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
{ &build($1, $nv, $_); }
}
sub build
{
my $pkg = shift;
my $newversion = shift;
my $pkgrpm = shift;
my $found = 0;
my ($pkge, $version, $release, $email);
my ($spec, @url, $basename);
my (@rpms, %specvars);
print "===> Building $pkg $newversion\n";
$pkge = $pkg;
$pkge =~ s/\+/\\\+/;
# Search for file if we do not use --src
if(!$config{src})
{
opendir(MP, $config{mountpoint}) or die "$config{mountpoint} is not a directory";
@rpms = readdir(MP);
foreach (@rpms)
{
if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
{ $pkgrpm = $_; $version = $2; $release = $3; $found = 1;}
}
closedir(MP);
if($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return; }
}
else
{
my $pkgrpm_basename = qx[basename $pkgrpm];
if($pkgrpm_basename =~ m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
{ $version = $2; $release = $3; $found = 1;}
}
if ($config{src}) {
system("rpm -ivh $pkgrpm");
wait;
} else {
system("sudo /usr/sbin/urpmi --auto --force ".$config{mountpoint}."/".$pkgrpm);
#{ print "Error while urpmi $pkgrpm\n"; return; };
wait;
system("/usr/sbin/urpmi --install-src --force ".$config{mountpoint}."/".$pkgrpm);
#{ print "Error while urpmi --install-src $pkgrpm\n"; return; }
wait;
}
my $top = `rpm --eval '%_topdir'`;
chop($top);
chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES";
$found = 0;
if(!open(SPECFILE, "../SPECS/".$pkg.".spec"))
{
print STDERR "Unable to open spec file !\n";
return;
}
while(<SPECFILE>)
{
# s/// version
s/\%define\s+version\s+$version/\%define version $newversion/g;
s/Version:\s+$version/Version: $newversion/g;
$spec .= $_;
$spec =~ s/\%define(\s+)release(\s+)(.*)/\%define release $defaultrelease/;
push(@url, $2) if(/(Source|Url|Source0):\s+(\S+)/i);
# For %vars !
$specvars{$1} = $2 if(/\%define\s+(.+?)\s+(.+)/g);
$specvars{version} = $1 if(!$specvars{version} && /Version:\s+(.+)/gi);
$specvars{name} = $1 if(!$specvars{name} && /Name:\s+(.+)/gi);
if(/\%changelog/)
{
$email = $ENV{EMAIL} ||
qx[awk -F: '/$ENV{USER}/{print \$5}' /etc/passwd|tr -d '\n']." <$ENV{USER}\@mandrakesoft.com> ";
$spec .= "* ".qx[LC_TIME=C date '+%a %b %d %Y'|tr -d '\n']." ".$email.
" ".$newversion."-".$defaultrelease."\n";
$spec .= "- New release $newversion\n\n";
}
}
close(SPECFILE);
if(!$url[0])
{ print "URL was not found ! Skipping...\n"; return; }
open(SPECFILE, ">../SPECS/".$pkg.".spec");
print SPECFILE $spec;
close(SPECFILE);
$found = 0;
foreach (@url)
{
# Replace variable from spec (%blabla)
while(/\%/)
{
s/\%\{(.*?)\}/$specvars{$1}/g;
s/\%(\w+)/$specvars{$1}/g;
s/\%\{name\}/$pkg/gi;
s/\%\{version\}/$newversion/gi;
}
print "Trying $_...\n";
system("wget ".$_);
$basename = `basename $_`; chomp($basename);
if($basename =~ /gz/)
{
s/gz/bz2/;
$basename = `basename $_`; chomp($basename);
print "Trying to fetch .bz2...\n";
system("wget ".$_);
}
elsif($basename =~ /bz2/)
{
s/bz2/gz/;
print "Trying to fetch .gz...\n";
system("wget ".$_);
$basename = `basename $_`; chomp($basename);
# If gz was downloaded, recompressing it in bz2
if(-f $basename)
{
system("bzme ".$basename);
$basename =~ s/bz2/gz/;
}
}
$found = 1 if(-e $basename);
$basename =~ s/bz2/gz/;
$found = 1 if(-e $basename);
}
if(!$found)
{ print "Unable to download file: URL is not valid ! :-/\n\n"; return; }
if(system("rpm -ba ../SPECS/".$pkg.".spec"))
{
wait;
print "Build fails: building source only\n";
system("rpm -bs ../SPECS/".$pkg.".spec");
}
wait;
}
sub wget_check
{
my $wgetv = `wget --version`;
$wgetv =~ /Wget/ or die "You need `wget' binary for FTP/HTTP download\n";
}
sub parse_argv
{
my $conf = AppConfig->new({ CASE => 1 });
$conf->define("rpmmon",
{ ARGS => "=s",
ALIAS => "r",
ARGCOUNT => AppConfig::ARGCOUNT_NONE }
);
$conf->define("mountpoint",
{ ARGS => "=s",
ALIAS => "m",
DEFAULT => "/mnt/BIG/distrib/cooker/SRPMS/",
ARGCOUNT => AppConfig::ARGCOUNT_ONE }
);
$conf->define("src",
{ ARGS => "=s",
ALIAS => "s",
ARGCOUNT => AppConfig::ARGCOUNT_ONE }
);
$conf->args();
$config{rpmmon} = $conf->get("rpmmon");
$config{mountpoint} = $conf->get("mountpoint");
$config{src} = $conf->get("src");
}
sub usage
{
print "rpmbuildupdate v0.2 helps you build up to date RPMs.\n\n";
print "By Julien Danjou <jdanjou\@mandrakesoft.com>\n";
print "Copyright (c) 2003 by MandrakeSoft.\n";
print "This is free software under the GPL License.\n";
print "Usage: rpmbuildupdate [options] [pkg] [newversion]\n\n";
print " --rpmmon <file>: Parse output of rpmmon from file\n";
print " -m <mount point>: Specify mount point of \n";
print " --src <src.rpm file> <new version>: Build new version from this source RPM\n";
exit 0;
}
sub parse_rpmmon
{
my $f;
($f = shift());
-f $f or die "Error: $f is not a file.\n";
open(RPMMON, $f);
while(<RPMMON>)
{ &build($1, $3) if(/^\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/);
&build($2, $4) if(/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/); }
close(RPMMON);
}
sub main
{
&parse_argv;
&wget_check;
if($config{rpmmon})
{
-d $config{mountpoint} or die $config{mountpoint}." is not a directory.\n";
&parse_rpmmon($config{rpmmon});
}
elsif($config{src} && $ARGV[0]) { &build_from_src($config{src}, $ARGV[0]); }
elsif($ARGV[0] && $ARGV[1])
{
-d $config{mountpoint} or die $config{mountpoint}." is not a directory.\n";
&build($ARGV[0], $ARGV[1]);
}
else
{ &usage; }
}
&main;
|