sub get_date { local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); local $day = $mday; local $month = $mon+1; local $year = $year+1900; if ( length $month == 1 ) { $month = join( "", "0", $month); } if ( length $day== 1 ) { $day = join( "", "0", $day ); } local $date = join( ".", $year,$month,$day ); return $date; } sub gen_snapshot_id { if ( exists $_[0] && exists $_[1] ) { return $_[0] . get_date() . $_[1]; } if ( exists $_[0] ) { return $_[0] . get_date(); } return get_date(); } sub create { die "release_dir not set, cant create\n" unless $release_dir; print "about to clean up old snapshots (Ctrl-C to cancel)"; local $| = 1; for ( my $i=0; $i<5; $i++ ) { print "."; sleep 1; } $| = 0; print "cleaning up previous snapshot\n"; local $release_parent = dirname($release_dir); if ( $^O eq "MSWin32" ) { system("rd /q /s \"$release_parent\""); } else { system("rm -rf \"$release_parent\""); } print "creating the release dir\n"; mkdir $release_parent or die "couldn't create release parent directory\n"; mkdir $release_dir or die "couldn't create release directory\n"; print "changing to the release dir\n"; chdir $release_dir; #version property print "setting up todays properties\n"; `echo version:$snapshot_id> $rk-build.properties`; #processor propertylocal $| = 1; if ( $^O eq "darwin" ) { print "setting processor\n"; if ( `uname -p` eq "i386" ) { `echo processor:intel>> $rk-build.properties`; } elsif ( `uname -p` eq "powerpc" ) { `echo processor:ppc>> $rk-build.properties`; } else { print "unable to determine processor type, using intel\n"; `echo processor:intel>> $rk-build.properties`; } } #branch path property if ( $ENV{'branch_path'} ) { `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`; } #server.exe.location if ( exists $ENV{'SERVER_EXE_LOCATION'} ) { `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`; } print "creating the snapshot using $rk\n"; system( $rk ); } sub upload { print "uploading files\n"; my @munges = (); if ( exists $ENV{'munges'} ) { @munges = split(' ', $ENV{'munges'}); } if ( ! -d "$release_dir/products" ) { die "error: products directory doesn't exist, exiting\n"; } @files = <$release_dir/products/*>; push( @files, "$release_dir/$rk.out" ); for my $file ( @files ) { my $filename = basename($file); if ( !$only_upload || $filename =~ $only_upload ) { #munge for my $m ( @munges ) { $doit="\$filename =~ $m"; eval "$doit"; } #upload print "Uploading '" . basename($file) . "' to '$filename'\n"; my $command = "scp"; if ( $^O eq "MSWin32" ) { $command = "pscp"; } if ( exists $ENV{'UPLOAD_IDENTITY_FILE'} ) { $command .= " -i \"$ENV{'UPLOAD_IDENTITY_FILE'}\""; } $command .= " \"$file\" \"$ENV{'UPLOAD_DIR'}/$filename\""; system($command); } else { print "Skipping upload of '$filename'\n"; } } }