| 1 |
|
|---|
| 2 |
use warnings; |
|---|
| 3 |
use strict; |
|---|
| 4 |
use Getopt::Long; |
|---|
| 5 |
use Data::Dumper; |
|---|
| 6 |
use Pod::Usage; |
|---|
| 7 |
use File::Basename; |
|---|
| 8 |
use Cwd; |
|---|
| 9 |
use IO::Handle; |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
my %config = ( |
|---|
| 19 |
svnco => 'svn co http://svn.swish-e.org/swish-e/trunk/', |
|---|
| 20 |
|
|---|
| 21 |
tar_keep_days => 15, |
|---|
| 22 |
build_keep_days => 2, |
|---|
| 23 |
timestamp => 1, |
|---|
| 24 |
remove => 1, |
|---|
| 25 |
logs => 1, |
|---|
| 26 |
symlink => 1, |
|---|
| 27 |
srpm => 1, |
|---|
| 28 |
latest => 1, |
|---|
| 29 |
); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
GetOptions( \%config, |
|---|
| 35 |
qw/ |
|---|
| 36 |
topdir=s |
|---|
| 37 |
tardir=s |
|---|
| 38 |
tar_keep_days=i |
|---|
| 39 |
build_keep_days=i |
|---|
| 40 |
svnco=s |
|---|
| 41 |
dump |
|---|
| 42 |
verbose |
|---|
| 43 |
timestamp! |
|---|
| 44 |
fetchtarurl=s |
|---|
| 45 |
remove! |
|---|
| 46 |
logs! |
|---|
| 47 |
symlink! |
|---|
| 48 |
srpm! |
|---|
| 49 |
latest! |
|---|
| 50 |
help man options |
|---|
| 51 |
config_options=s |
|---|
| 52 |
/ |
|---|
| 53 |
) or pod2usage( |
|---|
| 54 |
{ |
|---|
| 55 |
-verbose => 0, |
|---|
| 56 |
-exitval => 1, |
|---|
| 57 |
} ); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
set_dependent_vars( \%config ); |
|---|
| 61 |
|
|---|
| 62 |
if ( $config{dump} ) { |
|---|
| 63 |
print STDERR Dumper \%config; |
|---|
| 64 |
exit; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
my @functions = ( |
|---|
| 68 |
[ \&svn_checkout, 'Check out from svn' ], |
|---|
| 69 |
[ \&configure, 'Run configure' ], |
|---|
| 70 |
[ \&make_install, 'Run make install' ], |
|---|
| 71 |
[ \&make_dist, "Run make dist and move tarball to $config{tardir}" ], |
|---|
| 72 |
[ \&make_src_rpm, "Build swish-e .src.rpm and move it to $config{tardir}" ], |
|---|
| 73 |
[ \&set_symlink, "Make symlink $config{symlink} point to $config{day_dir}" ], |
|---|
| 74 |
[ \&remove_day_dir, "Remove old install and build directories" ], |
|---|
| 75 |
); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
pod2usage( { |
|---|
| 79 |
-verbose => ($config{man} ? 2 : $config{options} ? 1 : 0), |
|---|
| 80 |
-exitval => 1, |
|---|
| 81 |
} ) if $config{man} || $config{help} || $config{options}; |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$functions[0] = [ \&fetch_tar_url, 'Fetch tarball' ] if $config{fetchtarurl}; |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
unless ( chdir $config{topdir} ) { |
|---|
| 89 |
warn "Failed to chdir to $config{topdir}: $!"; |
|---|
| 90 |
|
|---|
| 91 |
mkdir $config{topdir},0777 || die "Failed to mkdir topdir $config{topdir}: $!"; |
|---|
| 92 |
warn "Created top level directory $config{topdir}\n"; |
|---|
| 93 |
chdir $config{topdir} || die "Failed to chdir to $config{topdir}"; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
mkdir $config{day_dir} || die "Failed to create the working day directory '$config{day_dir}': $!\n"; |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
if ( $config{logs} ) { |
|---|
| 108 |
open STDOUT, ">$config{buildlog}" or die "Failed to open build log file '$config{buildlog}': $!\n"; |
|---|
| 109 |
open STDERR, ">$config{errorlog}" or die "Failed to open error log file '$config{errorlog}': $!\n"; |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
STDERR->autoflush(1); |
|---|
| 113 |
STDOUT->autoflush(1); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
for my $step ( @functions ) { |
|---|
| 121 |
next if $step->[2]; |
|---|
| 122 |
log_message( $step->[1] ); |
|---|
| 123 |
$step->[0]->(\%config) || exit_with_error( \%config ); |
|---|
| 124 |
} |
|---|
| 125 |
exit 0; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
sub svn_checkout { |
|---|
| 134 |
my $c = shift; |
|---|
| 135 |
|
|---|
| 136 |
run_command( "$c->{svnco} $c->{srcdir}" ); |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
sub configure { |
|---|
| 148 |
my $c = shift; |
|---|
| 149 |
my $options = $c->{config_options} || ''; |
|---|
| 150 |
|
|---|
| 151 |
mkdir $c->{builddir} || die "Failed to mkdir $c->{builddir}: $!\n"; |
|---|
| 152 |
chdir $c->{builddir} || die "Failed to chdir $c->{builddir}: $!"; |
|---|
| 153 |
log_message( "Changed to build directory: $c->{builddir}" ); |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
my $timestamp = $c->{timestamp} ? '--enable-daystamp' : ''; |
|---|
| 158 |
my $command = "$c->{srcdir}/configure $timestamp $options --prefix=$c->{installdir} $options"; |
|---|
| 159 |
run_command( $command ); |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
sub make_src_rpm { |
|---|
| 179 |
my $c = shift; |
|---|
| 180 |
|
|---|
| 181 |
return 1 unless $c->{srpm}; |
|---|
| 182 |
|
|---|
| 183 |
my ($rpmbuilddir, $rpmrcfile) = setup_rpmbuild_environment( $c ); |
|---|
| 184 |
my $tarball_for_rpm = "$c->{tardir}/swish-e-$c->{version}.tar.gz"; |
|---|
| 185 |
my $srcdir = $c->{srcdir}; |
|---|
| 186 |
my $builddir = $c->{builddir}; |
|---|
| 187 |
my $specversion = $c->{version}; |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
if ($c->{timestamp}) { |
|---|
| 192 |
|
|---|
| 193 |
my $origspecversion = $specversion; |
|---|
| 194 |
$specversion =~ s/-.*//; # remove all after and including the hyphen from 2.5.6-2007-12-12 |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
my $newtarball = $tarball_for_rpm; |
|---|
| 198 |
$newtarball =~ s/-\d+-\d+-\d+\.tar.gz$/.tar.gz/; |
|---|
| 199 |
|
|---|
| 200 |
die "$0: failed to figure out name of new tarball for .src.rpm\n" |
|---|
| 201 |
unless ($newtarball ne $tarball_for_rpm); |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
_rewrite_tarball( $c, $tarball_for_rpm, $newtarball, "swish-e-$origspecversion", "swish-e-$specversion" ); |
|---|
| 205 |
$tarball_for_rpm = $newtarball; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
run_command( "cp $tarball_for_rpm $rpmbuilddir/SOURCES/swish-e-$specversion.tar.gz" ); |
|---|
| 209 |
run_command( "cp $srcdir/rpm/swish-e.xpm $rpmbuilddir/SOURCES/" ); |
|---|
| 210 |
run_command( "cp $builddir/rpm/swish-e.spec $rpmbuilddir/SPECS/" ); |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
_apply_regexes( "$rpmbuilddir/SPECS/swish-e.spec", |
|---|
| 215 |
qq{s/^%define[[:space:]]+version.*/%define version $specversion/ims} ); |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
if ($c->{timestamp}) { |
|---|
| 219 |
chomp(my $specrelease = `date '+%Y%m%d'`); |
|---|
| 220 |
_apply_regexes( "$rpmbuilddir/SPECS/swish-e.spec", |
|---|
| 221 |
qq{s/^%define[[:space:]]+release.*/%define release $specrelease/ims} ); |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
run_command( "rm -f $tarball_for_rpm" ); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
run_command( "rpmbuild --rcfile=$rpmrcfile -bs $rpmbuilddir/SPECS/swish-e.spec" ); |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
run_command( "mv $rpmbuilddir/SRPMS/swish-e-*.src.rpm $c->{tardir}" ); |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
log_message( "new .src.rpm in $c->{tardir}" ); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
sub setup_rpmbuild_environment { |
|---|
| 246 |
my $c = shift; |
|---|
| 247 |
|
|---|
| 248 |
my $cwd = getcwd(); |
|---|
| 249 |
print "debug: cwd is $cwd\n"; |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
my $rpmbuilddir = "$cwd/rpmbuild/"; |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
for my $dir (qw( RPMS SOURCES SPECS SRPMS BUILD ) ) { |
|---|
| 256 |
system( "mkdir -p $rpmbuilddir/$dir" ) unless -d $dir; |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
my $rpmmacrosfile = "$cwd/.rpmmacros"; |
|---|
| 261 |
log_message( "Creating new $rpmmacrosfile" ); |
|---|
| 262 |
open(my $fh, ">", $rpmmacrosfile) || die "$0: Failed to open $rpmmacrosfile: $!"; |
|---|
| 263 |
print $fh "%_topdir $rpmbuilddir\n"; |
|---|
| 264 |
print $fh "%make make\n"; |
|---|
| 265 |
close($fh) || die "$0: Failed to close $rpmmacrosfile: $!"; |
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
my $rpmrcfile = "$rpmbuilddir/rpmrc"; |
|---|
| 269 |
log_message( "Creating new $rpmrcfile" ); |
|---|
| 270 |
run_command( "cp /usr/lib/rpm/rpmrc $rpmrcfile" ); |
|---|
| 271 |
_apply_regexes( $rpmrcfile, q{s!^(macrofiles:.*)!$1:./.rpmmacros!ims} ); |
|---|
| 272 |
|
|---|
| 273 |
return ($rpmbuilddir, $rpmrcfile); |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
sub make_install { |
|---|
| 282 |
my $c = shift; |
|---|
| 283 |
|
|---|
| 284 |
chdir $c->{builddir} || die "Failed to chdir $c->{builddir}: $!"; |
|---|
| 285 |
log_message( "Changed to build directory: $c->{builddir}" ); |
|---|
| 286 |
|
|---|
| 287 |
run_command( "make" ) || return; |
|---|
| 288 |
run_command( "make test" ) || return; |
|---|
| 289 |
run_command( "make install" ) || return; |
|---|
| 290 |
|
|---|
| 291 |
unless ( -d $c->{installdir} ) { |
|---|
| 292 |
warn "Did not find install directory $c->{installdir} after make install"; |
|---|
| 293 |
return; |
|---|
| 294 |
} |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
my $binary = "$c->{installdir}/bin/swish-e"; |
|---|
| 299 |
die "Failed to find swish-e binary $binary: $!\n" unless -x $binary; |
|---|
| 300 |
my $version = `$binary -V`; |
|---|
| 301 |
chomp $version; |
|---|
| 302 |
if ( $version =~ /^SWISH-E\s+(.+)$/ ) { |
|---|
| 303 |
$c->{version} = $1; |
|---|
| 304 |
} |
|---|
| 305 |
return 1; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
sub make_dist { |
|---|
| 314 |
my $c = shift; |
|---|
| 315 |
|
|---|
| 316 |
chdir $c->{builddir} || die "Failed to chdir $c->{builddir}: $!"; |
|---|
| 317 |
log_message( "Changed to build directory: $c->{builddir}" ); |
|---|
| 318 |
|
|---|
| 319 |
run_command( "make dist" ) || return; |
|---|
| 320 |
|
|---|
| 321 |
unless ( $config{tardir} ) { |
|---|
| 322 |
log_message( "tardir option not given -- not moving tarball." ); |
|---|
| 323 |
return 1; |
|---|
| 324 |
} |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
if ( $c->{version} && -e "swish-e-$c->{version}.tar.gz") { |
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
my $latest = "$c->{tardir}/latest.tar.gz"; |
|---|
| 337 |
|
|---|
| 338 |
run_command( "mv swish-e-$c->{version}.tar.gz $c->{tardir}" ); |
|---|
| 339 |
|
|---|
| 340 |
if ($c->{latest}) { |
|---|
| 341 |
run_command( "rm -f $latest" ); |
|---|
| 342 |
run_command( "ln -s $c->{tardir}/swish-e-$c->{version}.tar.gz $latest"); |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
} else { |
|---|
| 346 |
log_message( "Found swish version [$c->{version}] but didn't find [swish-e-$c->{version}.tar.gz]" ) |
|---|
| 347 |
if $c->{version}; |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
purge_old_tarballs_and_srpms( $c ) if $c->{remove}; |
|---|
| 352 |
|
|---|
| 353 |
return 1; |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
sub purge_old_tarballs_and_srpms { |
|---|
| 357 |
my $c = shift; |
|---|
| 358 |
opendir( DIR, $c->{tardir} ) || die "Failed to open tardir: $!"; |
|---|
| 359 |
|
|---|
| 360 |
my $days = $c->{tar_keep_days} || 10; |
|---|
| 361 |
my $old = time - ( 60 * 60 * 24 * $days ); |
|---|
| 362 |
|
|---|
| 363 |
my @deletes; |
|---|
| 364 |
while ( my $file = readdir( DIR ) ) { |
|---|
| 365 |
next unless ($file =~ /^swish-e.*\.tar\.gz$/ || $file =~/^swish-e.*\.src\.rpm$/); |
|---|
| 366 |
next if (stat "$c->{tardir}/$file")[9] > $old; |
|---|
| 367 |
push @deletes, "$c->{tardir}/$file"; |
|---|
| 368 |
} |
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
for ( @deletes ) { |
|---|
| 372 |
my ($type) = ($_ =~ /tar\.gz$/ ? "tar" : "srpm"); |
|---|
| 373 |
print unlink( $_ ) |
|---|
| 374 |
? "Deleted old $type file '$_'\n" |
|---|
| 375 |
: "Failed to delete old $type '$_': $!\n"; |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
return 1; |
|---|
| 379 |
|
|---|
| 380 |
} |
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
sub set_symlink { |
|---|
| 389 |
my $c = shift; |
|---|
| 390 |
|
|---|
| 391 |
return 1 unless $c->{symlink}; |
|---|
| 392 |
|
|---|
| 393 |
run_command( "rm -f $c->{symlink}" ); |
|---|
| 394 |
run_command( "ln -s $c->{day_dir} $c->{symlink}" ); |
|---|
| 395 |
} |
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
sub remove_day_dir { |
|---|
| 403 |
my $c = shift; |
|---|
| 404 |
return 1 unless $c->{remove}; |
|---|
| 405 |
|
|---|
| 406 |
my $days = $c->{build_keep_days} || 2; |
|---|
| 407 |
my $old = time - ( 60 * 60 * 24 * $days ); |
|---|
| 408 |
|
|---|
| 409 |
opendir DIR, $c->{topdir} or die "Failed to open topdir '$c->{topdir}' for reading: $!\n"; |
|---|
| 410 |
my @dirs = grep { |
|---|
| 411 |
/^swish-e-\d\d\d\d-\d+-\d+/ && |
|---|
| 412 |
-d "$c->{topdir}/$_" && |
|---|
| 413 |
(stat "$c->{topdir}/$_")[9] < $old |
|---|
| 414 |
} readdir( DIR ); |
|---|
| 415 |
close DIR; |
|---|
| 416 |
|
|---|
| 417 |
return 1 unless @dirs; |
|---|
| 418 |
|
|---|
| 419 |
run_command( "rm -rf $c->{topdir}/$_" ) for @dirs; |
|---|
| 420 |
|
|---|
| 421 |
return 1; |
|---|
| 422 |
} |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
sub run_command { |
|---|
| 432 |
my $command = shift; |
|---|
| 433 |
log_message( $command ); |
|---|
| 434 |
|
|---|
| 435 |
system( $command ) && die "$0: Command failed: $command: $!"; |
|---|
| 436 |
|
|---|
| 437 |
return 1; |
|---|
| 438 |
} |
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
sub log_message { |
|---|
| 444 |
my $command = shift; |
|---|
| 445 |
print "\n", scalar localtime,"\n $command\n\n"; |
|---|
| 446 |
} |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
sub exit_with_error { |
|---|
| 453 |
my $c = shift; |
|---|
| 454 |
print STDERR `cat $c->{errorlog}` if -e $c->{errorlog}; |
|---|
| 455 |
die "aborted $0\n"; |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
sub set_dependent_vars { |
|---|
| 464 |
my $config = shift; |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
$config->{topdir} ||= getcwd; |
|---|
| 469 |
$config->{topdir} = Cwd::abs_path( $config->{topdir} ); |
|---|
| 470 |
die "Failed to set 'topdir' - perhaps invalid directory: $!\n" unless $config->{topdir}; |
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
$config->{tardir} ||= ''; |
|---|
| 476 |
|
|---|
| 477 |
if ( $config->{tardir} ) { |
|---|
| 478 |
$config->{tardir} = Cwd::abs_path( $config->{tardir} ); |
|---|
| 479 |
|
|---|
| 480 |
die "Invalid tardir specified\n" unless defined $config->{tardir}; |
|---|
| 481 |
die "tardir directory of $config->{tardir} does not exist\n" unless -e $config->{tardir}; |
|---|
| 482 |
die "tardir option of $config->{tardir} is not a directory\n" unless -d $config->{tardir}; |
|---|
| 483 |
die "tardir directory of $config->{tardir} is not writable\n" unless -w $config->{tardir}; |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
my ($d,$m,$y) = (localtime)[3,4,5]; |
|---|
| 489 |
my $today = sprintf('%04d-%02d-%02d', $y+1900, $m+1, $d ); |
|---|
| 490 |
|
|---|
| 491 |
my $day_dir = "$config->{topdir}/swish-e-$today"; |
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
if ( -d $day_dir ) { |
|---|
| 496 |
my $count; |
|---|
| 497 |
1 while $count++ < 100 && -e "$day_dir.$count"; |
|---|
| 498 |
$day_dir = "$day_dir.$count"; |
|---|
| 499 |
} |
|---|
| 500 |
|
|---|
| 501 |
$config->{day_dir} = $day_dir; |
|---|
| 502 |
$config->{symlink} = "$config->{topdir}/latest_swish_build" if $config->{symlink}; |
|---|
| 503 |
$config->{builddir} = "$day_dir/build"; |
|---|
| 504 |
$config->{srcdir} = "$day_dir/source"; |
|---|
| 505 |
$config->{installdir} = "$day_dir/install"; |
|---|
| 506 |
|
|---|
| 507 |
$config->{buildlog} = "$day_dir/build.log"; |
|---|
| 508 |
$config->{errorlog} = "$day_dir/error.log"; |
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
sub fetch_tar_url { |
|---|
| 518 |
my $config = shift; |
|---|
| 519 |
|
|---|
| 520 |
chdir $config->{day_dir} || die "Failed to chdir to $config->{day_dir}\n"; |
|---|
| 521 |
|
|---|
| 522 |
require LWP::Simple; |
|---|
| 523 |
require URI; |
|---|
| 524 |
|
|---|
| 525 |
log_message( "Fetching $config->{fetchtarurl}"); |
|---|
| 526 |
|
|---|
| 527 |
my $u = URI->new( $config->{fetchtarurl} ) || die "$config->{fetchtarurl} doesn't look like a URL: $!"; |
|---|
| 528 |
|
|---|
| 529 |
my ( $name, $path, $suffix ) = fileparse( $u->path, qr/\.tar\.gz/ ); |
|---|
| 530 |
|
|---|
| 531 |
die "Failed to parse $config->{fetchtarurl} [$path $name $suffix]\n" |
|---|
| 532 |
unless $path && $name && $suffix; |
|---|
| 533 |
|
|---|
| 534 |
my $tar = $name . $suffix; |
|---|
| 535 |
|
|---|
| 536 |
my $status = LWP::Simple::getstore( $config->{fetchtarurl}, $tar ) || die "Failed to fetch $config->{fetchtarurl}"; |
|---|
| 537 |
die "fetching $config->{fetchtarurl} returned a status of $status" unless $status == 200; |
|---|
| 538 |
|
|---|
| 539 |
die "Can't find fetched file $tar" unless -e $tar; |
|---|
| 540 |
|
|---|
| 541 |
|
|---|
| 542 |
run_command( "gzip -dc $tar | tar xvf -" ) || return; |
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
unless ( -d $name ) { |
|---|
| 546 |
|
|---|
| 547 |
open( TAR, "gzip -dc $tar | tar tf -|") or die "Failed to pipe from tar:$!"; |
|---|
| 548 |
$name = ''; |
|---|
| 549 |
while ( <TAR> ) { |
|---|
| 550 |
chomp; |
|---|
| 551 |
if ( m!^(.+?)/! && -d "$config->{day_dir}/$1" ) { |
|---|
| 552 |
$name = $1; |
|---|
| 553 |
last; |
|---|
| 554 |
} |
|---|
| 555 |
} |
|---|
| 556 |
close TAR; |
|---|
| 557 |
} |
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
die "Failed to find source directory after unpacking $tar" unless $name; |
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
run_command( "ln -s $config->{day_dir}/$name $config->{srcdir}"); |
|---|
| 565 |
|
|---|
| 566 |
return 1; |
|---|
| 567 |
|
|---|
| 568 |
} |
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
sub _apply_regexes { |
|---|
| 575 |
my ($file, @regexes) = @_; |
|---|
| 576 |
|
|---|
| 577 |
my $tmpfile = "$file.tmp"; |
|---|
| 578 |
open(my $rfh, "<", $file) || die "$0: Can't open $file: $!"; |
|---|
| 579 |
open(my $wfh, ">", $tmpfile) || die "$0: Can't open $tmpfile: $!"; |
|---|
| 580 |
print "Applying regexes:to file $file\n" . join("\n", @regexes) . "\n"; |
|---|
| 581 |
while(<$rfh>) { |
|---|
| 582 |
chomp(); |
|---|
| 583 |
for my $r (@regexes) { |
|---|
| 584 |
|
|---|
| 585 |
eval $r; |
|---|
| 586 |
die "$0: Error in regex: $r: $@" if $@; |
|---|
| 587 |
} |
|---|
| 588 |
print $wfh "$_\n"; |
|---|
| 589 |
} |
|---|
| 590 |
close($rfh) || die "$0: Can't open $file: $!"; |
|---|
| 591 |
close($wfh) || die "$0: Can't close $tmpfile: $!"; |
|---|
| 592 |
rename( $file, "$file.bak" ); |
|---|
| 593 |
rename( $tmpfile, $file ) || die "$0: Can't rename $tmpfile to $file: $!"; |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
sub _rewrite_tarball { |
|---|
| 600 |
my ($c, $fromtarball, $totarball, $fromdir, $todir) = @_; |
|---|
| 601 |
my $builddir = $c->{builddir}; |
|---|
| 602 |
my $cwd = getcwd(); |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
mkdir( "$builddir/tmp" ) || die "$0: Couldn't create $builddir/tmp"; |
|---|
| 608 |
chdir( "$builddir/tmp" ) || die "$0: Couldn't cd into $builddir/tmp"; |
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
die "$0: Couldn't find tarball: $fromtarball\n" unless -f $fromtarball; |
|---|
| 612 |
run_command( "tar -zxf $fromtarball" ); |
|---|
| 613 |
die "$0: tarball didn't extract into $fromdir\n" unless -d $fromdir; |
|---|
| 614 |
run_command( "mv $fromdir $todir" ); |
|---|
| 615 |
run_command( "tar -zcf $totarball $todir" ); |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
chdir( $cwd ) || die "$0: Couldn't cd into $cwd"; |
|---|
| 619 |
} |
|---|
| 620 |
|
|---|
| 621 |
__END__ |
|---|
| 622 |
|
|---|
| 623 |
=head1 NAME |
|---|
| 624 |
|
|---|
| 625 |
swish-daily.pl - Builds a daily snapshot of swish from svn or tarball |
|---|
| 626 |
|
|---|
| 627 |
=head1 SYNOPSIS |
|---|
| 628 |
|
|---|
| 629 |
./swish-daily.pl [options] |
|---|
| 630 |
|
|---|
| 631 |
Options: |
|---|
| 632 |
|
|---|
| 633 |
-help brief help |
|---|
| 634 |
-man longer help |
|---|
| 635 |
-options list options |
|---|
| 636 |
-dump dump configuration and exit. Good for seeing defaults |
|---|
| 637 |
-ask ask what tasks to run |
|---|
| 638 |
-tardir=<path> where to place tarball when finished |
|---|
| 639 |
-tar_keep_days=<int> number of days to keep old tarballs (default 15 days) |
|---|
| 640 |
-build_keep_days=<int> number of days to key old build directories (default 2 days) |
|---|
| 641 |
-svnco=<string> command to checkout from svn |
|---|
| 642 |
-fetchtarurl=<url> specify a URL to a tarball to fetch (instead of using svn) |
|---|
| 643 |
-[no]timestamp if set will create tarball with a timestamp (default is timestamp) |
|---|
| 644 |
-[no]remove remove old tar files or old build directories (default yes) |
|---|
| 645 |
-[no]symlink create symlink pointing to created directory |
|---|
| 646 |
-[no]logs don't create build and error log files |
|---|
| 647 |
-[no]srpms don't create source rpms |
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
mkdir tardir |
|---|
| 652 |
swish-daily.pl \ |
|---|
| 653 |
-svnco='http://svn.swish-e.org/swish-e/trunk/' \ |
|---|
| 654 |
-tardir=tardir |
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
=head1 DESCRIPTION |
|---|
| 658 |
|
|---|
| 659 |
This script fetches the swish-e source, either from svn or from a URL, builds |
|---|
| 660 |
swish and creates a tarball. The script is mostly used for building daily builds, |
|---|
| 661 |
but is also used when creating a new release of swish-e. |
|---|
| 662 |
|
|---|
| 663 |
A build directory is created (using the date and a sequence number). This directory is |
|---|
| 664 |
created under the current directory, or under the directory specified by the topdir option. |
|---|
| 665 |
So, either chdir to a top-level build directory or use the -topdir option. |
|---|
| 666 |
|
|---|
| 667 |
Swish is then checked out via subversion (or from a tarball from the web using the |
|---|
| 668 |
-fetchtarurl option) into a "source" directory. Swish-e is then built from the "build" |
|---|
| 669 |
directory and installed into the "install" directory. Log files "build.log" and |
|---|
| 670 |
"error.log" are also created (unless disabled with -nologs option). |
|---|
| 671 |
|
|---|
| 672 |
A tarball is built and copied to the tar directory if "tardir" is specified. Old |
|---|
| 673 |
tar files will be purged (based on tar_keep_days option). |
|---|
| 674 |
|
|---|
| 675 |
If all goes well a symlink is created in the topdir pointing to the latest build directory. |
|---|
| 676 |
This symlink can be used to link to the latest version of the HTML docs and to the error |
|---|
| 677 |
and build log files. |
|---|
| 678 |
|
|---|
| 679 |
Finally, old build directories are removed (based on build_keep_days option). |
|---|
| 680 |
|
|---|
| 681 |
=head2 Building HTML documentation |
|---|
| 682 |
|
|---|
| 683 |
The swish-e configure script |
|---|
| 684 |
|
|---|
| 685 |
=head2 Examples |
|---|
| 686 |
|
|---|
| 687 |
A daily script might use: |
|---|
| 688 |
|
|---|
| 689 |
swish-daily.pl \ |
|---|
| 690 |
--topdir=$HOME/swish_daily_build \\ |
|---|
| 691 |
--tardir=$HOME/swish-daily |
|---|
| 692 |
|
|---|
| 693 |
Which creates a directory structure like: |
|---|
| 694 |
|
|---|
| 695 |
$ ls -l swish_daily_build/ |
|---|
| 696 |
latest_swish_build -> swish-e-2005-05-29 |
|---|
| 697 |
swish-e-2005-05-26 |
|---|
| 698 |
swish-e-2005-05-27 |
|---|
| 699 |
swish-e-2005-05-28 |
|---|
| 700 |
swish-e-2005-05-29 |
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
When building a release: |
|---|
| 704 |
|
|---|
| 705 |
swish-daily.pl \ |
|---|
| 706 |
--fetchtarurl=<some url> |
|---|
| 707 |
--topdir=$HOME/swish_release_build \ |
|---|
| 708 |
--tardir=$HOME/swish-releases \ |
|---|
| 709 |
--noremove \ |
|---|
| 710 |
--notimestamp \ |
|---|
| 711 |
|
|---|
| 712 |
Use --noremove to avoid purging old builds, and --notimestamp to prevent adding a time |
|---|
| 713 |
stamp to the version (which is done when creating the daily builds). |
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
=head1 OPTIONS |
|---|
| 717 |
|
|---|
| 718 |
=over 8 |
|---|
| 719 |
|
|---|
| 720 |
=item B<-dump> |
|---|
| 721 |
|
|---|
| 722 |
This dumps the configuration and exits. Use to see what paths are going to be used. |
|---|
| 723 |
|
|---|
| 724 |
=item B<-tardir> |
|---|
| 725 |
|
|---|
| 726 |
This is a directory where the finished tarball will be placed. Old tar files |
|---|
| 727 |
(older than -tar_keep_days old) will be removed. The default is 15 days. |
|---|
| 728 |
If not specified then tarfile will not be moved. |
|---|
| 729 |
|
|---|
| 730 |
=item B<-svnco> |
|---|
| 731 |
|
|---|
| 732 |
String for checking out from svn. Run -dump to see an example. |
|---|
| 733 |
|
|---|
| 734 |
=item B<-fetchtarurl> |
|---|
| 735 |
|
|---|
| 736 |
Specifies a URL where to fetch the tarball. This will replace the use of svn for fetching the source. |
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
=item B<-[no]timestamp> |
|---|
| 740 |
|
|---|
| 741 |
This is set by default and causes the tarball to be build with a day stamp. Use -notimestamp |
|---|
| 742 |
to build without a timestamp. (Sets --enable-daystamp in configure). |
|---|
| 743 |
|
|---|
| 744 |
=item B<-[no]romove> |
|---|
| 745 |
|
|---|
| 746 |
Normally the build directory and the last installation directory (from a previous run) |
|---|
| 747 |
are removed when done. This prevents this. |
|---|
| 748 |
|
|---|
| 749 |
=item B<-[no]symlink> |
|---|
| 750 |
|
|---|
| 751 |
Update the symlink pointing to the latest build directory. Default is to update the |
|---|
| 752 |
symlink |
|---|
| 753 |
|
|---|
| 754 |
=item B<-[no]srpm> |
|---|
| 755 |
|
|---|
| 756 |
Create a .src.rpm file. Default is to create .src.rpm files. |
|---|
| 757 |
|
|---|
| 758 |
=item B<-tar_keep_days> |
|---|
| 759 |
|
|---|
| 760 |
Number of days to keep old tarfiles around (must speicify -tardir). Default is 15. |
|---|
| 761 |
|
|---|
| 762 |
=item B<-build_keep_days> |
|---|
| 763 |
|
|---|
| 764 |
Number of days to keep old build directories around. Build dirs are directories |
|---|
| 765 |
located in -topdir that match a given pattern. |
|---|
| 766 |
|
|---|
| 767 |
=item B<-[no]logs> |
|---|
| 768 |
|
|---|
| 769 |
Create build and error logs -- stdout and stderr are not redirectied. |
|---|
| 770 |
The default is to create the log files. |
|---|
| 771 |
|
|---|
| 772 |
=head1 CRON |
|---|
| 773 |
|
|---|
| 774 |
Here's an example of a cron entry: |
|---|
| 775 |
|
|---|
| 776 |
55 1 * * * . $HOME/.bashrc && $HOME/swish-daily.pl --tardir=$HOME/swish-daily --topdir=$HOME/swish_daily_build || echo "Check Swish Daily Build" |
|---|
| 777 |
|
|---|
| 778 |
=head1 COPYRIGHT |
|---|
| 779 |
|
|---|
| 780 |
This library is free software; you can redistribute it |
|---|
| 781 |
and/or modify it under the same terms as Perl itself. |
|---|
| 782 |
|
|---|
| 783 |
|
|---|
| 784 |
=head1 AUTHOR |
|---|
| 785 |
|
|---|
| 786 |
Bill Moseley moseley@hank.org. 2002/2003/2004 |
|---|
| 787 |
|
|---|
| 788 |
=head1 SUPPORT |
|---|
| 789 |
|
|---|
| 790 |
Please contact the Swish-e discussion email list for support with this module |
|---|
| 791 |
or with Swish-e. Please do not contact the developers directly. |
|---|
| 792 |
|
|---|
| 793 |
|
|---|
| 794 |
=cut |
|---|
| 795 |
|
|---|