9e320cb8c25295872fbae60b34a8b6db723aec01
[buildfarm-server.git] / scripts / rename_system.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use DBI;
6 use Data::Dumper;
7
8 die "Must pass current and new sysnames\n" unless scalar @ARGV == 2;
9
10 use vars qw($dbhost $dbname $dbuser $dbpass $dbport
11             $user_list_format
12 );
13 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
14
15 die "no dbname" unless $dbname;
16 die "no dbuser" unless $dbuser;
17
18 my $dsn="dbi:Pg:dbname=$dbname";
19 $dsn .= ";host=$dbhost" if $dbhost;
20 $dsn .= ";port=$dbport" if $dbport;
21
22 my $db = DBI->connect($dsn,$dbuser,$dbpass);
23
24 die $DBI::errstr unless $db;
25
26 my $sth_up = $db->prepare(q[
27        UPDATE buildsystems AS b
28        SET name = ?
29        WHERE name = ?
30       ]);
31 $sth_up->execute($ARGV[1],$ARGV[0]);
32
33 my $sth = $db->prepare(q[ 
34        SELECT name, status, operating_system, os_version, sys_owner, owner_email
35        FROM buildsystems AS b
36        ORDER BY name ASC
37       ]);
38 $sth->execute();
39
40 printf $user_list_format,
41        "SysName", "Status", "Owner", "Email", "Distro", "Version";
42 while (my $row = $sth->fetchrow_hashref)
43 {
44   printf $user_list_format,
45                   $row->{name}, $row->{status}, $row->{sys_owner},
46                   $row->{owner_email}, $row->{operating_system},
47                   $row->{os_version};
48 }
49 $db->disconnect();