]> git.defcon.no Git - hermes/blobdiff - guc-clients/assignphone
Added auto-location of config file to scripts tool-scripts
[hermes] / guc-clients / assignphone
index 074ab1fd8b32853453e6e17a898d7d0d4d68235e..4b06f66eb6f56678e798d87c598d1825c0961d65 100755 (executable)
@@ -13,7 +13,8 @@ my $api_key;
 
 my $help;
 my $username;
-my $configfile;
+my $configfile = undef;
+my $dryrun = 0;
 my ($g_ua, $session, $api_key, $auth_key, $data, $domain);
 my ($user, $sipuser, $mac);
 
@@ -22,11 +23,20 @@ my $config = AppConfig->new({ CREATE => 1 });
 $config->define("api_url=s");
 $config->define("api_keyfile=s");
 
+foreach ( 
+       "/usr/local/etc/hermes/hermes_config",
+       "/usr/local/etc/hermes/config",
+       "/etc/hermes/config",
+       $ENV{"HOME"} . "/.hermes/config",
+       $ENV{"HOME"} . "/.hermes_config",
+) { $configfile = $_ if ( -f $_ ); }
+
 GetOptions(
        "help"          => \$help,
        "macaddress=s"  => \$mac,
        "username=s"    => \$username,
        "configfile=s"  => \$configfile,
+       "dryrun"        => \$dryrun,
 );
 
 if (
@@ -57,6 +67,7 @@ Verify that the following options are set:
        --configfile=s|--config|-c
        --username=s|--user|-u
        --macaddress=s|--mac|-m
+       --dryrun|--dry|-d
 
 Verify the contents of the configuration file.
 Verify that the key-file exists.
@@ -106,6 +117,12 @@ if ( not $data->{'response'} eq 'ok' )
        exit;
 }
 
+if ( $dryrun ) {
+       print("Dryrun specified. All OK so far, stopping before add.\n");
+       logout();
+       exit;
+}
+
 $data = exec_apinode("phone/add", { 'user' => $sipuser, 'mac' => $mac });
 
 printf("Failed to add phone+user, cause given: '%s'\n", $data->{'cause'})