summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPreston Cody <codeman@gentoo.org>2007-12-24 06:27:16 +0000
committerPreston Cody <codeman@gentoo.org>2007-12-24 06:27:16 +0000
commit4b32204d45762c527ac1266e5314c0eb66d48e18 (patch)
treef5daf837649aca5986baa83053dd4f1ad6e43d0e /client
parenttoss in a comment...just because (diff)
downloadscire-4b32204d45762c527ac1266e5314c0eb66d48e18.tar.gz
scire-4b32204d45762c527ac1266e5314c0eb66d48e18.tar.bz2
scire-4b32204d45762c527ac1266e5314c0eb66d48e18.zip
config touchups.
added a register function. it needs a fingerprint or digest to verify the client. svn path=/branches/new-fu/; revision=259
Diffstat (limited to 'client')
-rwxr-xr-xclient/scireclient.pl74
1 files changed, 55 insertions, 19 deletions
diff --git a/client/scireclient.pl b/client/scireclient.pl
index 47fd7b9..d027d59 100755
--- a/client/scireclient.pl
+++ b/client/scireclient.pl
@@ -1,16 +1,21 @@
#!/usr/bin/perl
+# $Id$
+
use strict;
use warnings;
use IPC::Open2;
+use Getopt::Long;
+use Data::Dumper;
-my $SCIRE_CONFIG_FILE = '../etc/scire.conf';
+my $SCIRE_CONFIG_FILE = '../etc/scire.conf'; #will be /etc/scire.conf when released.
my %conf;
my ($SERVER_STDOUT, $SERVER_STDIN);
parse_command_line();
-read_config();
+my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
+read_config($conf_file);
# Build the connection command.
# This will eventually be something like "ssh scire@${scireserver} /usr/bin/scireserver.pl"
@@ -20,14 +25,15 @@ if(defined($conf{port})) {
}
$connection_command .= "$conf{user}\@$conf{host} $conf{server_script}";
-if(-d ".svn") {
+if (-d ".svn") {
# Overwrite $connection_command in the case of a dev environment for now
$connection_command = "../server/scireserver.pl";
}
-if(! -d $conf{job_dir}) {
- print "WARNING! $conf{job_dir} does not exist...creating\n";
- mkdir $conf{job_dir}, 0660;
+if (! -d $conf{job_dir}) {
+ print "WARNING! $conf{job_dir} does not exist...creating\n";
+ mkdir -p $conf{job_dir}, 0660
+ or die("Couldn't make $conf{job_dir} w/ perms 0660: $!");
}
run_main();
@@ -35,11 +41,14 @@ run_main();
sub run_main {
#ok folks so here's how this thang goes down.
#1. Connect.
+ create_connection();
+
#2. Register with the DB. (only it knows if you're allowed to be active)
+ register_client();
+
#3. Scan the jobs directory. If there are done/failed jobs, report them. Note jobs in running or queue.
#4. Fetch the jobs list
#5. ?
- create_connection();
run_test();
}
@@ -52,15 +61,28 @@ sub run_test {
}
sub parse_command_line {
- # XXX: Anyone know how to use getopt? I've never bothered figuring it out :P
- while($#ARGV > -1) {
- my $foo = shift @ARGV;
- if($foo eq "-f") {
- $SCIRE_CONFIG_FILE = shift @ARGV;
- } else {
- print "Unrecognized command line option: ${foo}\n";
- }
+ GetOptions(
+ 'verbose|D' => \$conf{debug},
+ 'dry-run' => \$conf{dry_run},
+ 'help|h' => \$conf{help},
+ 'config|c=s' => \$conf{config},
+ 'threads|t=i' => \$conf{max_threads},
+
+ #config overrides.
+ 'host=s' => \$conf{host},
+ 'port=i' => \$conf{port},
+ 'user|u=s' => \$conf{user},
+ 'server_script=s' => \$conf{server_script},
+ 'job_dir' => \$conf{job_dir},
+ );
+ if ($conf{help}) {
+ print "\nusage: scireclient.pl [--verbose or -D]\n\t [--dry-run]"
+ ."\t [--config=CONF or -c] \n\t [--threads=# or -t] \t [--help or -h] \n"
+ ."\t [[--host=HOST] \t [--port=PORT] \t [--user=USER or -u] \n\t"
+ ." [--server_script=foo.pl] \t [--job_dir=/tmp/jobs] \n";
+ exit 0;
}
+
}
sub send_command {
@@ -76,7 +98,7 @@ sub send_command {
$tosend .= " \"${arg}\"";
}
}
- print "Sending: ${tosend}\n";
+ print "Sending: ${tosend}\n" if $conf{debug};
print SERVER_STDIN "${tosend}\n";
}
@@ -92,13 +114,27 @@ sub create_connection {
}
sub read_config {
- open(FH, "< ${SCIRE_CONFIG_FILE}") or die("Couldn't open the config file ${SCIRE_CONFIG_FILE}: $!");
+ my $conf_file = shift;
+ open(FH, "< ${conf_file}") or die("Couldn't open the config file ${conf_file}: $!");
while (<FH>) {
chomp;
next if /^\s*(?:#|$)/;
if(/^\s*(.+?)\s*=\s*(.+?)\s*(?:#.*)?$/) {
- $conf{lc($1)} = $2;
+ unless(defined($conf{lc($1)})) { #Don't overwrite anything specified in cmdline
+ $conf{lc($1)} = $2;
+ }
}
}
- close(FH) or die("Couldn't close the config file ${SCIRE_CONFIG_FILE}: $!");
+ close(FH) or die("Couldn't close the config file ${conf_file}: $!");
+}
+
+sub register_client {
+ my $fingerprint = "AA:BB:CC:DD:EE:FF:GG:HH... this is a digest.";
+ my $cmd = "IDENTIFY $fingerprint";
+ send_command($cmd);
+ my $response = get_response();
+ $response =~ /IDENTIFIED\ CLIENT\ (\d+)/
+ or die("Couldn't register client. Response was $response");
+ $conf{client_id} = $1;
+ print "Registered client $conf{client_id}\n" if $conf{debug};
}