summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/getpr
blob: 9656a6e6b24f097df32534168bf84f644fc7fad7 (plain)
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
#!/usr/bin/perl
#
# MAINTAINER= mharo@FreeBSD.org
#
# $FreeBSD$
#

use strict; 

my $pr = shift;
my $user = shift;
my $ssh;

if ($pr eq "") {
	print STDERR "getpr prnum [username]\n";
	exit 1
}

if( !defined $ENV{"CVS_RSH"} ) {
        $ssh = "ssh";
} else {
	$ssh = $ENV{"CVS_RSH"};
}

if ($user ne "") {
	$user = "$user@";
}

# get the PR off of freefall

open(D, "> $pr") or die "$pr: $!";
open(PATCH, "> pr-patch") or die "pr-patch: $!";
open(PR, " ${ssh} ${user}freefall.freebsd.org query-pr -F $pr | ") or die $!;

my $fix = "";
my $infix = 0;

while(<PR>) {
	print D;

	if (m/^>Release-Note:/) {
		$infix = 0;
	}
	if ($infix == 1) {
		print PATCH;
	}
	if (m/^>Fix:/) {
		$infix = 1;
	}
}
close(D);
close(PR);
close(PATCH);

# decode the submission attempting to find a file attachment by extension
# .tar.gz, .shar or just .gz, if not found, display what we think of as
# the file submission (probably just a patch)

open(PATCH, "pr-patch");
while(<PATCH>) {
	if (m/^# This is a shell archive.  Save it in a file, remove anything before/) {
		&shar;
		exit;
	}
	if (m/^begin (\d+)? (.*)/) {
		&uudecode($2);
		close(PATCH);
		exit;
	}
}

close(PATCH);
system("more pr-patch");

exit;

sub uudecode {
	my ($fname) = @_;

	$fname =~ s/\s+$//g;
	print "$fname\n";

	print `uudecode pr-patch`;
	if (($fname =~ m/.tar.gz$/) || ($fname =~ m/.tgz$/)) {
		print "you may extract this tarball by typing tar xvzf $fname\n";
	} elsif ($fname =~ m/.gz$/) {
		print `gunzip $fname`;
	}
}

sub shar {
	print "you may extract this shar archive by typing sh pr-patch\n";
}
OpenPOWER on IntegriCloud