5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
11 use vars qw($VERSION); $VERSION = '0.1';
15 no warnings qw(once); # suppress spurious warning about conf structure
18 use HTTP::Request::Common;
20 use Digest::SHA qw(sha1_hex);
23 # copy command line before processing - so we can later report it
26 my @invocation_args = (@ARGV);
28 my $buildconf = "build-farm.conf"; # default value
29 my ($os_version, $compiler_version,$help);
31 if ($0 =~ /(.*)\.pl$/) {
32 die "$0: Please use `$1@{[@ARGV ? qq{ @ARGV} : '']}` instead\n"
38 'config=s' => \$buildconf,
40 'os-version=s' => \$os_version,
41 'compiler-version=s' => \$compiler_version,
42 )|| usage("bad command line");
44 usage("No extra args allowed")
50 usage("must specify at least one item to change")
51 unless ($os_version or $compiler_version);
58 my ($target,$animal,$secret,$upgrade_target) =
59 @EximBuild::conf{qw(target animal secret upgrade_target)};
61 # default for old config files
62 unless ($upgrade_target)
64 $upgrade_target = $target;
65 $upgrade_target =~ s/eximstatus.pl/upgrade.pl/;
68 # make the base64 data escape-proof; = is probably ok but no harm done
69 # this ensures that what is seen at the other end is EXACTLY what we
70 # see when we calculate the signature
72 map{ $_ ||= ""; $_ = encode_base64($_,""); tr/+=/$@/; }
73 ($os_version,$compiler_version);
77 my $content = "animal=$animal\&ts=$ts";
78 $content .= "\&new_os=$os_version" if $os_version;
79 $content .= "\&new_compiler=$compiler_version" if $compiler_version;
81 my $sig= sha1_hex($content,$secret);
83 # set environment from config
84 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
86 $ENV{$envkey}=$envval;
89 my $ua = new LWP::UserAgent;
90 $ua->agent("Exim Build Farm Reporter");
91 if (my $proxy = $ENV{BF_PROXY})
93 $ua->proxy('http',$proxy);
96 my $request=HTTP::Request->new(POST => "$upgrade_target/$sig");
97 $request->content_type("application/x-www-form-urlencoded");
98 $request->content($content);
100 my $response=$ua->request($request);
102 unless ($response->is_success)
105 "Query for: animal=$animal&ts=$ts\n",
106 "Target: $upgrade_target/$sig\n",
107 "Query Content: $content\n";
108 print "Status Line: ",$response->status_line,"\n";
109 print "Content: \n", $response->content,"\n";
115 #######################################################################
119 my $opt_message = shift;
120 print "$opt_message\n" if $opt_message;
122 update_personality [ option ... ]
123 where option is one or more of
124 --config=path /path/to/buildfarm.conf
125 --os-version=version new operating system version
126 --compiler-version=version new compiler version
127 --help get this message
130 exit defined($opt_message)+0;