1 | sub get_date {
|
---|
2 | local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
---|
3 | local $day = $mday;
|
---|
4 | local $month = $mon+1;
|
---|
5 | local $year = $year+1900;
|
---|
6 | if ( length $month == 1 ) {
|
---|
7 | $month = join( "", "0", $month);
|
---|
8 | }
|
---|
9 | if ( length $day== 1 ) {
|
---|
10 | $day = join( "", "0", $day );
|
---|
11 | }
|
---|
12 | local $date = join( ".", $year,$month,$day );
|
---|
13 | return $date;
|
---|
14 | }
|
---|
15 |
|
---|
16 | sub gen_snapshot_id {
|
---|
17 | if ( exists $_[0] && exists $_[1] ) {
|
---|
18 | return $_[0] . get_date() . $_[1];
|
---|
19 | }
|
---|
20 |
|
---|
21 | if ( exists $_[0] ) {
|
---|
22 | return $_[0] . get_date();
|
---|
23 | }
|
---|
24 | return get_date();
|
---|
25 | }
|
---|
26 |
|
---|
27 | sub create {
|
---|
28 |
|
---|
29 | die "release_dir not set, cant create\n" unless $release_dir;
|
---|
30 |
|
---|
31 | print "about to clean up old snapshots (Ctrl-C to cancel)";
|
---|
32 | local $| = 1;
|
---|
33 | for ( my $i=0; $i<5; $i++ ) {
|
---|
34 | print ".";
|
---|
35 | sleep 1;
|
---|
36 | }
|
---|
37 | $| = 0;
|
---|
38 |
|
---|
39 | print "cleaning up previous snapshot\n";
|
---|
40 | local $release_parent = dirname($release_dir);
|
---|
41 | if ( $^O eq "MSWin32" ) {
|
---|
42 | system("rd /q /s \"$release_parent\"");
|
---|
43 | } else {
|
---|
44 | system("rm -rf \"$release_parent\"");
|
---|
45 | }
|
---|
46 |
|
---|
47 | print "creating the release dir\n";
|
---|
48 | mkdir $release_parent or die "couldn't create release parent directory\n";
|
---|
49 | mkdir $release_dir or die "couldn't create release directory\n";
|
---|
50 |
|
---|
51 | print "changing to the release dir\n";
|
---|
52 | chdir $release_dir;
|
---|
53 |
|
---|
54 | #version property
|
---|
55 | print "setting up todays properties\n";
|
---|
56 | `echo version:$snapshot_id> $rk-build.properties`;
|
---|
57 |
|
---|
58 | #processor propertylocal $| = 1;
|
---|
59 | if ( $^O eq "darwin" ) {
|
---|
60 | print "setting processor\n";
|
---|
61 | if ( `uname -p` eq "i386" ) {
|
---|
62 | `echo processor:intel>> $rk-build.properties`;
|
---|
63 | } elsif ( `uname -p` eq "powerpc" ) {
|
---|
64 | `echo processor:ppc>> $rk-build.properties`;
|
---|
65 | } else {
|
---|
66 | print "unable to determine processor type, using intel\n";
|
---|
67 | `echo processor:intel>> $rk-build.properties`;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | #branch path property
|
---|
72 | if ( $ENV{'branch_path'} ) {
|
---|
73 | `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
|
---|
74 | }
|
---|
75 |
|
---|
76 | #server.exe.location
|
---|
77 | if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
|
---|
78 | `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
|
---|
79 | }
|
---|
80 |
|
---|
81 | print "creating the snapshot using $rk\n";
|
---|
82 | system( $rk );
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 | sub upload {
|
---|
87 | print "uploading files\n";
|
---|
88 |
|
---|
89 | my @munges = ();
|
---|
90 | if ( exists $ENV{'munges'} ) {
|
---|
91 | @munges = split(' ', $ENV{'munges'});
|
---|
92 | }
|
---|
93 |
|
---|
94 | if ( ! -d "$release_dir/products" ) {
|
---|
95 | die "error: products directory doesn't exist, exiting\n";
|
---|
96 | }
|
---|
97 |
|
---|
98 | @files = <$release_dir/products/*>;
|
---|
99 | push( @files, "$release_dir/$rk.out" );
|
---|
100 | for my $file ( @files ) {
|
---|
101 | my $filename = basename($file);
|
---|
102 | if ( !$only_upload || $filename =~ $only_upload ) {
|
---|
103 |
|
---|
104 | #munge
|
---|
105 | for my $m ( @munges ) {
|
---|
106 | $doit="\$filename =~ $m"; eval "$doit";
|
---|
107 | }
|
---|
108 |
|
---|
109 | #upload
|
---|
110 | print "Uploading '" . basename($file) . "' to '$filename'\n";
|
---|
111 | my $command = "scp";
|
---|
112 | if ( $^O eq "MSWin32" ) {
|
---|
113 | $command = "pscp";
|
---|
114 | }
|
---|
115 | if ( exists $ENV{'UPLOAD_IDENTITY_FILE'} ) {
|
---|
116 | $command .= " -i \"$ENV{'UPLOAD_IDENTITY_FILE'}\"";
|
---|
117 | }
|
---|
118 | $command .= " \"$file\" \"$ENV{'UPLOAD_DIR'}/$filename\"";
|
---|
119 | system($command);
|
---|
120 |
|
---|
121 | } else {
|
---|
122 | print "Skipping upload of '$filename'\n";
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|