Add wiki as a submodule
[buildfarm-client.git] / update_personality.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6
7 See accompanying License file for license details
8
9 =cut 
10
11 use vars qw($VERSION); $VERSION = '0.1';
12
13 use strict;
14 use warnings;
15 no warnings qw(once); # suppress spurious warning about conf structure
16
17 use LWP;
18 use HTTP::Request::Common;
19 use MIME::Base64;
20 use Digest::SHA  qw(sha1_hex);
21 use Getopt::Long;
22
23 # copy command line before processing - so we can later report it
24 # unmunged
25
26 my @invocation_args = (@ARGV);
27
28 my $buildconf = "build-farm.conf"; # default value
29 my ($os_version, $compiler_version,$help);
30
31 GetOptions(
32     'config=s' => \$buildconf,
33     'help' => \$help,
34     'os-version=s' => \$os_version,
35     'compiler-version=s' => \$compiler_version,
36 )|| usage("bad command line");
37
38 usage("No extra args allowed")
39   if @_;
40
41 usage()
42   if $help;
43
44 usage("must specify at least one item to change")
45   unless ($os_version or $compiler_version);
46
47 #
48 # process config file
49 #
50 require $buildconf;
51
52 my ($target,$animal,$secret,$upgrade_target) =
53   @EximBuild::conf{qw(target animal secret upgrade_target)};
54
55 # default for old config files
56 unless ($upgrade_target)
57 {
58     $upgrade_target = $target;
59     $upgrade_target =~ s/eximstatus.pl/upgrade.pl/;
60 }
61
62 # make the base64 data escape-proof; = is probably ok but no harm done
63 # this ensures that what is seen at the other end is EXACTLY what we
64 # see when we calculate the signature
65
66 map{ $_ ||= ""; $_ = encode_base64($_,""); tr/+=/$@/; }
67   ($os_version,$compiler_version);
68
69 my $ts = time;
70
71 my $content = "animal=$animal\&ts=$ts";
72 $content .= "\&new_os=$os_version" if $os_version;
73 $content .= "\&new_compiler=$compiler_version" if $compiler_version;
74
75 my $sig= sha1_hex($content,$secret);
76
77 # set environment from config
78 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
79 {
80     $ENV{$envkey}=$envval;
81 }
82
83 my $ua = new LWP::UserAgent;
84 $ua->agent("Exim Build Farm Reporter");
85 if (my $proxy = $ENV{BF_PROXY})
86 {
87     $ua->proxy('http',$proxy);
88 }
89
90 my $request=HTTP::Request->new(POST => "$upgrade_target/$sig");
91 $request->content_type("application/x-www-form-urlencoded");
92 $request->content($content);
93
94 my $response=$ua->request($request);
95
96 unless ($response->is_success)
97 {
98     print
99       "Query for: animal=$animal&ts=$ts\n",
100       "Target: $upgrade_target/$sig\n",
101       "Query Content: $content\n";
102     print "Status Line: ",$response->status_line,"\n";
103     print "Content: \n", $response->content,"\n";
104     exit 1;
105 }
106
107 exit(0);
108
109 #######################################################################
110
111 sub usage
112 {
113     my $opt_message = shift;
114     print "$opt_message\n" if $opt_message;
115     print  <<EOH;
116 update_personality.pl [ option ... ]
117 where option is one or more of
118   --config=path                 /path/to/buildfarm.conf
119   --os-version=version          new operating system version
120   --compiler-version=version    new compiler version
121   --help                        get this message
122 EOH
123
124     exit defined($opt_message)+0;
125 }
126