forked from OSInside/kiwi-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.doit
executable file
·262 lines (255 loc) · 8.34 KB
/
.doit
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
#!/usr/bin/perl
# Copyright (c) 2000 SuSE GmbH Nuernberg, Germany. All rights reserved.
#
# Author: Marcus Schaefer <[email protected]>, 2005
# Build script for kiwi RPM package(s)
#
# Syntax:
# -------
# doit -p | --prepare --local
#
# ---
#
use strict;
use Time::localtime;
use Time::Local;
use Getopt::Long;
use File::lchown qw( lutimes );
use POSIX qw( ENOENT );
use Env;
#=====================================
# Globals...
#-------------------------------------
my $Prepare;
my $LocalSource;
#----[ main ]-----------------#
sub main {
#-----------------------------------------------
# main routine to prepare for all the
# package and version stuff
#
my $result = GetOptions(
"prepare|p" => \$Prepare,
"local|L" => \$LocalSource,
"help|h" => \&usage,
"<>" => \&usage
);
if ( $result != 1 ) {
usage();
}
#==============================================
# Check user privileges...
#----------------------------------------------
if (! defined $Prepare) {
usage();
}
#==============================================
# Checkout source
#----------------------------------------------
my $pacdir = checkout ( $LocalSource );
#==============================================
# Add %changelog
#----------------------------------------------
if (open (FD,">>$pacdir/kiwi.spec")) {
print FD "\n";
print FD '%changelog -n kiwi';
print FD "\n";
convert_changes_to_rpm_changelog ("$pacdir/kiwi.changes",*FD);
close FD;
}
#==============================================
# convert spec to utf8
#----------------------------------------------
qx (iconv -f ISO-8859-1 -t utf8 $pacdir/kiwi.spec > $pacdir/kiwi.spec.new);
qx (mv $pacdir/kiwi.spec.new $pacdir/kiwi.spec);
qx (iconv -f ISO-8859-1 -t utf8 $pacdir/kiwi.changes > $pacdir/kiwi.c.new);
qx (mv $pacdir/kiwi.c.new $pacdir/kiwi.changes);
#==============================================
# Cleanup
#----------------------------------------------
my $host = qx (hostname);
chomp ($host);
print 'Retrieve archive with: ';
print '[ scp -r root@'.$host.':'.$pacdir." . ]\n";
}
#---[ checkout ]-----#
sub checkout {
#-------------------------------------------------
# checkout sources and create a package directory
# ready to go to /work/src/done
#
my $pacdir = repoup (@_);
chdir $pacdir;
qx( cp -a -p kiwi/rpm/* . );
chdir "./kiwi";
qx (./.archive);
chdir $pacdir;
qx( mv kiwi/*.bz2 . );
qx( rm -rf kiwi );
return $pacdir;
}
#----[ repoup ]----------------#
sub repoup {
#-----------------------------------------------
# checkout kiwi source according to an optional
# tag and return the pathname of the temp directory
# where the new sources are located
#
#===========================================
# create tmp directory and change into it
#-------------------------------------------
my $parent = qx ( pwd );
my $tmpdir = qx (
mktemp -q -d /tmp/gitkiwi.XXXXXX
);
chomp $parent;
chomp $tmpdir;
chdir $tmpdir
|| die "Could not create temp dir: $!";
#===========================================
# pack up local source
#-------------------------------------------
print "Checkout source level [local]...\n";
qx( cp -a -p $parent/ $tmpdir/kiwi );
qx ($parent/.lutime $parent $tmpdir);
chdir $tmpdir
|| die "Could not create temp dir: $!";
return $tmpdir;
}
#----[ usage ]------------#
sub usage {
#----------------------------------------
# give me a usage message
#
print "usage: doit -p --local\n";
print "--\n";
exit (0);
}
#----[ convert_changes_to_rpm_changelog ]------------#
sub convert_changes_to_rpm_changelog {
#----------------------------------------
# convert changes to rpm changelog
#
my $file = shift;
local *FD = shift;
my @entries = ();
my %entries = ();
my @datarray= ();
my @hourarray=();
my $outstr;
my $rpm_birth = 852159600;
my $rpm_birth_str = "Thu Jan 02 1997";
my $actual = 999999999999;
my %month_to_num = (Jan=>0,Feb=>1,Mar=>2,Apr=>3,May=>4,Jun=>5,Jul=>6,Aug=>7,Sep=>8,Oct=>9,Nov=>10,Dec=>11);
# handle first line in entry specially
my $firstline = 0;
open (LG,$file);
while (<LG>) {
chomp ($_);
next if (/^--------------/);
next if (/^========================/);
if (
/^[A-Za-z]*\s*[A-Za-z]*\s*[0-9]*\s*[0-9][0-9]:[0-9][0-9].*-.*\@.*/
|| /^[A-Za-z]*\s*[A-Za-z]*\s*[0-9]*\s*[0-9][0-9][0-9][0-9]\s*-.*\@.*/
) {
#warn ("found changes style dateline $_\n");
if (
/^Mon / || /^Tue / || /^Wed / || /^Thu / || /^Fri /
|| /^Sat / || /^Sun /
) {
my @xline = split ( '-', $_);
my $datestr = shift ( @xline );
my $address = join ('-', @xline);
#my ($datestr,$address) = split ( '-', $_);
$datestr =~ s/CEST/MEST/;
@datarray = split ( ' ',$datestr);
if ($datarray[3] =~ /:/) {
@hourarray = split ( ':',$datarray[3]);
} else {
@hourarray = ("00","00","00");
}
$actual = timelocal ($hourarray[2],$hourarray[1],$hourarray[0],
$datarray[2],$month_to_num{$datarray[1]},
$datarray[$#datarray]-1900);
$address =~ s/^\s*(.*)/\1/;
$address =~ s/\s+/ /g;
my $datestr;
if ( ! $actual ) {
print "INVALID DATESTR=\"$datestr\" !!!";
print "$actual Skipping rest...";
exit 1;
}
if ( $actual < $rpm_birth ) {
$datestr = $rpm_birth_str;
} else {
my $ltime = localtime $actual;
$datestr = sprintf("%s %s %02d %4d",
(qw(Sun Mon Tue Wed Thu Fri Sat Sun))[$ltime->wday],
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$ltime->mon],
$ltime->mday,1900+$ltime->year);
}
chomp ($datestr);
$outstr = "$datestr - $address";
if ( $entries{$actual} =~ /$outstr/ ) {
# nope
} else {
$entries{$actual} .= "* $outstr\n";
}
$firstline = 1;
next;
} else {
warn ("$_ is not in english locale\n");
$actual = timelocal ( 0,0,0,1,0,100); # Jan 1st 2000
$entries{$actual} .= "* Tue Jan 01 2000 - nobody\@suse.de\n" unless ( $entries{$actual} =~ /$outstr/ );
}
}
if (
/^\* Mon / || /^\* Tue / || /^\* Wed / || /^\* Thu / ||
/^\* Fri / || /^\* Sat / || /^\* Sun /
) {
my ($datestr,$address) = split ( '-', $_);
@datarray = split ( ' ',$datestr);
$actual = timelocal(0,0,0,$datarray[3],$month_to_num{$datarray[2]},
$datarray[$#datarray]-1900);
$address =~ s/^\s*(.*)/\1/;
$address =~ s/\s+/ /g;
if ( ! $actual ) {
print "INVALID DATESTR=\"$datestr\" !!!";
print "$actual Skipping rest...";
exit 1;
}
$entries{$actual} .= "$_\n";
$firstline = 1;
next;
}
$_ =~ s/([^%])%([^%])/\1%%\2/g;
if (/^-/ || /^\s*-/) {
$_ =~ s/^\s*(\S*)/\1/ if($firstline);
$_ =~ s/(\S*)\s*$/\1/;
$entries{$actual} .= "$_\n";
$firstline = 0;
next;
}
if (/^\s*\#/) {
# hash is comment, try to escape
s/^(\s*)(\#\d*)/$1\[$2\]/;
}
if (/\S/) {
$_ =~ s/^\s*(\S*)/\1/;
$_ =~ s/(\S*)\s*$/\1/;
$entries{$actual} .= " $_\n";
$firstline = 0;
}
}
my $first = "1";
foreach my $key (sort {0+$b <=> 0+$a} (keys %entries)) {
if ( $first eq "1" && $entries{$key} !~ /^\*/ ) {
my $dst = `date`;
chomp ($dst);
print "* $dst - broken\@suse.de\n";
}
$first = "0";
print FD "$entries{$key}";
}
}
main();