3 # Copyright (C) 2008 Andrew Bartlett <abartlet@samba.org>
4 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 use FindBin qw($RealBin);
31 my $db = new hostdb("$RealBin/hostdb.sqlite") or die("Unable to connect to host database: $!");
34 print "Samba Build farm management tool\n";
35 print "================================\n";
42 print "Initialize host database: init\n";
43 print "Add Machine to build farm: add\n";
44 print "Remove Machine from build farm: remove\n";
45 print "Modify build farm account: modify\n";
46 print "Print build farm host info: info\n";
47 print "Print build farm host list: list\n";
48 print "Select Operation: [add] ";
58 if ($op eq "remove") {
59 print "Please enter hostname to delete: ";
62 $db->deletehost($hostname) or die("Unable to delete host $hostname");
63 } elsif ($op eq "modify") {
64 print "Please enter hostname to modify: ";
67 my $host = $db->host($hostname);
68 print "Owner: $host->{owner} <$host->{owner_email}>\n";
69 print "Platform: $host->{platform}\n";
71 print "Modify owner or platform: [platform] ";
77 if ($mod_op eq "platform") {
78 print "Enter new platform: ";
81 $db->update_platform($hostname, $platform) or die "Unable to update platform";
82 } elsif ($mod_op eq "owner") {
83 print "Enter new owner's name: ";
86 print "Enter new owner's e-mail address: ";
89 $db->update_owner($hostname, $owner, $owner_email) or die "Unable to update owner";
92 } elsif ($op eq "add") {
93 print "Machine hostname: ";
96 print "Machine platform (eg Fedora 9 x86_64): ";
99 print "Machine Owner Name: ";
102 print "Machine Owner E-mail: ";
103 my $owner_email = <>;
105 print "Enter password: [generate random] ";
108 if ($password eq "") {
109 $password = `pwgen 16 1`;
111 print "Password will be: $password\n";
113 print "Enter permission e-mail, finish with a .\n";
120 $db->createhost($hostname, $platform, $owner, $owner_email, $password, $permission) or die("Unable to create host $hostname");
124 # send the password in an e-mail to that address
125 my $subject = "Your new build farm host $hostname";
127 print "To: $owner <$owner_email>\n";
128 print "Subject: $subject\n";
131 $msg = new Mail::Send(Subject=>$subject, To=>"\"$owner\" \<$owner_email\>", Bcc=>"build\@samba.org");
132 $msg->set("From", "\"Samba Build Farm\" \<build\@samba.org\>");
136 my $body = << "__EOF__";
137 Welcome to the Samba.org build farm.
139 Your host $hostname has been added to the Samba Build farm.
141 We have recorded that it is running $platform.
143 If you have not already done so, please read:
144 http://build.samba.org/instructions.html
146 The password for your rsync .password file is $password
148 An e-mail asking you to subscribe to the build-farmers mailing
149 list will arrive shortly. Please ensure you maintain your
150 subscription to this list while you have hosts in the build farm.
152 Thank you for your contribution to ensuring portability and quality
153 of Samba.org projects.
165 $msg = new Mail::Send(Subject=>'Subscribe to build-farmers mailing list', To=>'build-farmers-join@lists.samba.org');
166 $msg->set("From", "\"$owner\" \<$owner_email\>");
168 print $fh "Please subscribe $owner to the build-farmers mailing list\n\n";
169 print $fh "Thanks, your friendly Samba build farm administrator <build\@samba.org>";
175 } elsif ($op eq "init") {
177 print "Host database initialized successfully.\n";
178 } elsif ($op eq "info") {
182 my $host = $db->host($hostname);
183 die ("No such host $host") unless ($host);
184 print "Host: $host->{name}";
185 if ($host->{fqdn}) { print " ($host->{fqdn})"; }
187 print "Platform: $host->{platform}\n";
188 print "Owner: $host->{owner} <$host->{owner_email}>\n";
190 # Don't run the update of the text files
192 } elsif ($op eq "list") {
193 my $hosts = $db->host_ages();
196 my $age = util::dhm_time(time() - $h->{last_update});
197 printf "%-12s $h->{host}\n", $age;
199 # print Dumper($hosts);
201 die("Unknown command $op");
204 open(RSYNC_SECRETS, ">$RealBin/../rsyncd.secrets.new") or die("Unable to open rsyncd.secrets file: $!");
205 print RSYNC_SECRETS $db->create_rsync_secrets();
206 close(RSYNC_SECRETS);
208 rename("$RealBin/../rsyncd.secrets.new", "../rsyncd.secrets");
210 open(HOSTS, ">$RealBin/web/hosts.list.new") or die("Unable to open hosts file: $!");
211 print HOSTS $db->create_hosts_list();
214 rename("$RealBin/web/hosts.list.new", "$RealBin/web/hosts.list");