Index: branches/eam_branches/ipp-20140206/dbconfig/README
===================================================================
--- branches/eam_branches/ipp-20140206/dbconfig/README	(revision 36535)
+++ branches/eam_branches/ipp-20140206/dbconfig/README	(revision 36536)
@@ -10,7 +10,10 @@
    edit the oldtable.md
 
-2. figure out what changes are needed to get the gpc1/isp up to the current
-schema.  Add those changes at the bottom of changes.txt, and modify gpc1/isp.
+2. figure out what changes are needed to get the gpc1/isp/uip/ssp up
+   to the current schema.  Add those changes at the bottom of
+   changes.txt, and modify gpc1/isp/uip/ssp.
 
 3. edit ippTools/share/pxadmin_create_tables.sql.  This is the sql that creates
-an empty database.
+   an empty database.
+
+
Index: branches/eam_branches/ipp-20140206/dbconfig/changes.txt
===================================================================
--- branches/eam_branches/ipp-20140206/dbconfig/changes.txt	(revision 36535)
+++ branches/eam_branches/ipp-20140206/dbconfig/changes.txt	(revision 36536)
@@ -2392,5 +2392,5 @@
     state   VARCHAR(16),
     label   VARCHAR(654),
-    registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+    registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
     fault   SMALLINT,
     PRIMARY KEY(seq_id, projection_cell),
@@ -2412,5 +2412,5 @@
 -- unique keys for the release tables
 
-alter table relStack  add unique key (rel_id, tess_id, skycell_id, filter, stack_type, mjd_obs)
+alter table relStack  add unique key (rel_id, tess_id, skycell_id, filter, stack_type, mjd_obs);
 alter table relExp add UNIQUE KEY(rel_id, exp_id);
 alter table ippRelease add unique key (surveyID, release_name);
@@ -2494,2 +2494,30 @@
 UPDATE dbversion set schema_version = '1.1.78', updated= CURRENT_TIMESTAMP();
 
+--
+
+CREATE TABLE remoteRun (
+    remote_id BIGINT NOT NULL AUTO_INCREMENT,
+    state     VARCHAR(64) NOT NULL,
+    stage     VARCHAR(64) NOT NULL,
+    label     VARCHAR(64) NOT NULL,
+    path_base VARCHAR(255) NOT NULL,
+    job_id    BIGINT,
+    last_poll TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    fault     SMALLINT NOT NULL,
+    PRIMARY KEY (remote_id),
+    KEY (state),
+    KEY (stage),
+    KEY (label),
+    KEY (job_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;    
+
+CREATE TABLE remoteComponent (
+    remote_id BIGINT,
+    stage_id  BIGINT,
+    KEY (stage_id),
+    FOREIGN KEY (remote_id) REFERENCES remoteRun(remote_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;    
+
+UPDATE dbversion set schema_version = '1.1.79', updated= CURRENT_TIMESTAMP();
+
+
Index: branches/eam_branches/ipp-20140206/dbconfig/ipp.m4
===================================================================
--- branches/eam_branches/ipp-20140206/dbconfig/ipp.m4	(revision 36535)
+++ branches/eam_branches/ipp-20140206/dbconfig/ipp.m4	(revision 36536)
@@ -41,2 +41,3 @@
 include(release.md)
 include(ff.md)
+include(remote.md)
Index: branches/eam_branches/ipp-20140206/dbconfig/remote.md
===================================================================
--- branches/eam_branches/ipp-20140206/dbconfig/remote.md	(revision 36536)
+++ branches/eam_branches/ipp-20140206/dbconfig/remote.md	(revision 36536)
@@ -0,0 +1,15 @@
+remoteRun METADATA
+    remote_id      S64         0    # Primary Key AUTO_INCREMENT
+    state          STR         64
+    stage          STR         64
+    label          STR         64
+    path_base      STR         255
+    job_id         S64         0
+    last_poll      TAI         NULL # DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+    fault          S16         0    # Key
+END
+
+remoteComponent METADATA
+    remote_id      S64         0    # Primary Key fkey (remote_id) ref remoteRun(remote_id)
+    stage_id       S64         0    # Key
+END
Index: branches/eam_branches/ipp-20140206/ippScripts/scripts/ipp_apply_burntool_single.pl
===================================================================
--- branches/eam_branches/ipp-20140206/ippScripts/scripts/ipp_apply_burntool_single.pl	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippScripts/scripts/ipp_apply_burntool_single.pl	(revision 36536)
@@ -197,5 +197,5 @@
     my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
     if ($status) {
-	&my_die("failed to update imfile");
+	&my_die("failed to update imfile",$exp_id,$class_id);
     }
     $burntool_state = 1;
Index: branches/eam_branches/ipp-20140206/ippScripts/scripts/register_imfile.pl
===================================================================
--- branches/eam_branches/ipp-20140206/ippScripts/scripts/register_imfile.pl	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippScripts/scripts/register_imfile.pl	(revision 36536)
@@ -330,6 +330,9 @@
             unless ($success) {
                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                warn ("Unable to perform regtool -addprocessedimfile: $error_code");
-                exit($error_code);
+                warn ("Unable to perform regtool -updateprocessedimfile: $error_code");
+#                exit($error_code);
+            &my_die_for_update("Unable to perform updateprocessedimfile",
+                               $exp_id, $class_id, $error_code);
+
             }
         } else {
@@ -522,4 +525,5 @@
     carp($msg);
     if (defined $exp_id && defined $class_id and not $no_update) {
+	sleep(5);
         my $command = "$regtool -updateprocessedimfile";
         $command .= " -exp_id $exp_id";
Index: branches/eam_branches/ipp-20140206/ippTasks/pantasks.pro
===================================================================
--- branches/eam_branches/ipp-20140206/ippTasks/pantasks.pro	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippTasks/pantasks.pro	(revision 36536)
@@ -490,4 +490,6 @@
     book delpage $1 -key pantaskState UNKNOWN_ERR
     book delpage $1 -key pantaskState CRASH_ERR
+    book delpage $1 -key pantaskState CRASH
+    book delpage $1 -key pantaskState TIMEOUT
   end
 end
Index: branches/eam_branches/ipp-20140206/ippTasks/summit.copy.pro
===================================================================
--- branches/eam_branches/ipp-20140206/ippTasks/summit.copy.pro	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippTasks/summit.copy.pro	(revision 36536)
@@ -34,4 +34,19 @@
 macro copy.status
     book listbook pzPendingImfile
+end
+
+macro copy.reset
+    book init pzPendingExp
+    book init pzPendingImfile
+    book init pzPendingAdvance
+end
+
+# aliases because copy.* isn't intuitive
+macro pztool.reset
+    copy.reset
+end
+
+macro summitcopy.reset
+    summitcopy.reset
 end
 
Index: branches/eam_branches/ipp-20140206/ippTools/share/Makefile.am
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/Makefile.am	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippTools/share/Makefile.am	(revision 36536)
@@ -496,4 +496,11 @@
 	fftool_summary.sql \
 	fftool_todo.sql \
-	fftool_toadvance.sql
+	fftool_toadvance.sql \
+	remotetool_definebyquery_chip.sql \
+	remotetool_definebyquery_cam.sql \
+	remotetool_definebyquery_warp.sql \
+	remotetool_definebyquery_stack.sql \
+	remotetool_updatepoll.sql
 
+
+
Index: branches/eam_branches/ipp-20140206/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/pxadmin_create_tables.sql	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippTools/share/pxadmin_create_tables.sql	(revision 36536)
@@ -2365,4 +2365,26 @@
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
+CREATE TABLE remoteRun (
+    remote_id BIGINT NOT NULL AUTO_INCREMENT,
+    state     VARCHAR(64) NOT NULL,
+    stage     VARCHAR(64) NOT NULL,
+    label     VARCHAR(64) NOT NULL,
+    path_base VARCHAR(255) NOT NULL,
+    job_id    BIGINT,
+    last_poll TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    fault     SMALLINT NOT NULL,
+    PRIMARY KEY (remote_id),
+    KEY (state),
+    KEY (stage),
+    KEY (label),
+    KEY (job_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE remoteComponent (
+    remote_id BIGINT,
+    stage_id  BIGINT,
+    KEY (stage_id),
+    FOREIGN KEY (remote_id) REFERENCES remoteRun(remote_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 -- These comment lines are here to avoid an empty query error.
Index: branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_cam.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36536)
@@ -0,0 +1,12 @@
+SELECT 
+       cam_id AS stage_id
+FROM camRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = camRun.cam_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = camRun.label
+	    )
+WHERE
+camRun.state = 'new' AND
+remoteRun.stage = 'camera' AND
+remote_id IS NULL
Index: branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_chip.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_chip.sql	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_chip.sql	(revision 36536)
@@ -0,0 +1,16 @@
+SELECT 
+       chip_id AS stage_id
+FROM chipRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = chipRun.chip_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = chipRun.label
+	    )
+WHERE
+chipRun.state = 'new' AND
+(remoteRun.stage = 'chip' OR remoteRun.stage IS NULL) AND
+remoteComponent.remote_id IS NULL
+
+
+
+       
Index: branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_stack.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36536)
@@ -0,0 +1,12 @@
+SELECT 
+       stack_id AS stage_id
+FROM stackRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = stackRun.stack_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = stackRun.label
+	    )
+WHERE
+stackRun.state = 'new' AND
+remoteRun.stage = 'stack' AND
+remote_id IS NULL
Index: branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_warp.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36536)
@@ -0,0 +1,12 @@
+SELECT 
+       warp_id AS stage_id
+FROM warpRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = warpRun.warp_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = warpRun.label
+	    )
+WHERE
+warpRun.state = 'new' AND
+remoteRun.stage = 'warp' AND
+remote_id IS NULL
Index: branches/eam_branches/ipp-20140206/ippTools/share/remotetool_updatepoll.sql
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/share/remotetool_updatepoll.sql	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/share/remotetool_updatepoll.sql	(revision 36536)
@@ -0,0 +1,3 @@
+UPDATE remoteRun SET last_poll = CURRENT_TIMESTAMP 
+WHERE
+%s
Index: branches/eam_branches/ipp-20140206/ippTools/src/Makefile.am
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/src/Makefile.am	(revision 36535)
+++ branches/eam_branches/ipp-20140206/ippTools/src/Makefile.am	(revision 36536)
@@ -34,5 +34,6 @@
 	sctool \
 	releasetool \
-	fftool
+	fftool \
+	remotetool
 
 pkginclude_HEADERS = \
@@ -89,5 +90,6 @@
 	sctool.h \
 	releasetool.h \
-	fftool.h
+	fftool.h \
+	remotetool.h 
 
 lib_LTLIBRARIES = libpxtools.la
@@ -340,4 +342,10 @@
     fftoolConfig.c
 
+remotetool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
+remotetool_LDADD  = $(PSLIB_LIBS)   $(PSMODULES_LIBS)   $(IPPDB_LIBS)   libpxtools.la
+remotetool_SOURCES = \
+    remotetool.c \
+    remotetoolConfig.c
+
 clean-local:
 	-rm -f TAGS
Index: branches/eam_branches/ipp-20140206/ippTools/src/remotetool.c
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/src/remotetool.c	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/src/remotetool.c	(revision 36536)
@@ -0,0 +1,423 @@
+/*
+ * remotetool.c
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <math.h>
+
+#include "pxtools.h"
+#include "pxdata.h"
+#include "remotetool.h"
+
+// Create
+static bool definebyqueryMode(pxConfig *config);
+
+// List
+static bool listrunMode(pxConfig *config);
+static bool listcomponentMode(pxConfig *config);
+
+// Update
+static bool updaterunMode(pxConfig *config);
+static bool updatepollMode(pxConfig *config);
+static bool revertrunMode(pxConfig *config);
+static bool revertauthMode(pxConfig *config);
+
+# define MODECASE(caseName, func) \
+  case caseName: \
+  if (!func(config)) { \
+  goto FAIL; \
+  } \
+  break;
+
+int main(int argc, char **argv)
+{
+  psLibInit(NULL);
+
+  pxConfig *config = remotetoolConfig(NULL, argc, argv);
+  if (!config) {
+    psError(PXTOOLS_ERR_CONFIG, false, "failed to configure");
+    goto FAIL;
+  }
+
+  switch (config->mode) {
+    MODECASE(REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryMode);
+    MODECASE(REMOTETOOL_MODE_LISTRUN,       listrunMode);
+    MODECASE(REMOTETOOL_MODE_LISTCOMPONENT, listcomponentMode);
+    MODECASE(REMOTETOOL_MODE_UPDATERUN,     updaterunMode);
+    MODECASE(REMOTETOOL_MODE_UPDATEPOLL,    updatepollMode);
+    MODECASE(REMOTETOOL_MODE_REVERTRUN,     revertrunMode);
+    MODECASE(REMOTETOOL_MODE_REVERTAUTH,    revertauthMode);
+
+  default:
+    psAbort("invalid option (this should not happen)");
+  }
+  psTrace("remotetool", 9, "Attempting to free config\n");
+  psFree(config);
+  pmConfigDone();
+  psLibFinalize();
+  exit(EXIT_SUCCESS);
+
+ FAIL:
+  psErrorStackPrint(stderr, "\n");
+  int exit_status = pxerrorGetExitStatus();
+
+  psFree(config);
+  pmConfigDone();
+  psLibFinalize();
+
+  exit(exit_status);
+}
+
+// Create
+
+static bool definebyqueryMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+  // These are required
+  PXOPT_LOOKUP_STR(label,      config->args, "-label",        true, false);
+  PXOPT_LOOKUP_STR(stage,      config->args, "-stage",        true, false);
+  PXOPT_LOOKUP_STR(path_base,  config->args, "-path_base",    true, false);
+
+  // These are not
+  PXOPT_LOOKUP_STR(set_label,  config->args, "-set_label",    false, false);
+  PXOPT_LOOKUP_S16(limit,      config->args, "-limit",        false, false);
+
+  PXOPT_LOOKUP_BOOL(simple,    config->args, "-simple",       false);
+  PXOPT_LOOKUP_BOOL(pretend,   config->args, "-pretend",      false);
+  
+  set_label = set_label ? set_label : label;
+
+  // Get a list of the things we can insert into a new component
+  psString query = NULL;
+  if (!strcmp(stage,"chip")) {
+    query = pxDataGet("remotetool_definebyquery_chip.sql");
+    if (!query) {
+      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
+      return(false);
+    }
+    
+    if (label) {
+      psStringAppend(&query, " AND (chipRun.label = '%s')", label);
+    }
+  }
+  else if (!strcmp(stage,"camera")) {
+    query = pxDataGet("remotetool_definebyquery_cam.sql");
+    if (!query) {
+      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
+      return(false);
+    }
+    
+    if (label) {
+      psStringAppend(&query, " AND (camRun.label = '%s')", label);
+    }
+  }    
+  else if (!strcmp(stage,"warp")) {
+    query = pxDataGet("remotetool_definebyquery_warp.sql");
+    if (!query) {
+      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
+      return(false);
+    }
+    
+    if (label) {
+      psStringAppend(&query, " AND (warpRun.label = '%s')", label);
+    }
+  }    
+  else if (!strcmp(stage,"stack")) {
+    query = pxDataGet("remotetool_definebyquery_stack.sql");
+    if (!query) {
+      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
+      return(false);
+    }
+    
+    if (label) {
+      psStringAppend(&query, " AND (stackRun.label = '%s')", label);
+    }
+  }    
+  else {
+    psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage);
+    return false;
+  }
+
+  if (limit) {
+    psString limitString = psDBGenerateLimitSQL(limit);
+    psStringAppend(&query, " %s", limitString);
+    psFree(limitString);
+  }
+  if (!p_psDBRunQueryF(config->dbh, query)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    psFree(query);
+    return false;
+  }
+  psFree(query);
+
+  psArray *output = p_psDBFetchResult(config->dbh);
+  if (!output) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return false;
+  }
+  if (!psArrayLength(output)) {
+    psTrace("remotetool", PS_LOG_INFO, "no rows found");
+    psFree(output);
+    return true;
+  }
+
+  if (pretend) {
+    if (!ippdbPrintMetadatas(stdout, output, "newremoteComponents", !simple)) {
+      psError(PS_ERR_UNKNOWN, false, "failed to print array");
+      psFree(output);
+      return false;
+    }
+    psFree(output);
+    return true;
+  }
+
+  if (!psDBTransaction(config->dbh)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return false;
+  }
+
+
+  // Insert the top level run object
+  remoteRunRow *run = remoteRunRowAlloc(0, // remote_id
+					"new", // state
+					stage,
+					set_label,
+					path_base,
+					-1, // job_id
+					NULL, // last_poll
+					0   // fault
+					  );
+  if (!run) {
+    psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
+    return(true);
+  }
+  
+  if (!remoteRunInsertObject(config->dbh, run)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    psFree(run);
+    return(true);
+  }
+  psS64 remote_id = psDBLastInsertID(config->dbh);
+  
+  psArray *list = psArrayAllocEmpty(limit);
+  for (long i=0; i < psArrayLength(output); i++) {
+    psMetadata *md = output->data[i];
+    psS64 stage_id = psMetadataLookupS64(NULL, md, "stage_id");
+
+    remoteComponentRow *comp = remoteComponentRowAlloc(remote_id,
+						       stage_id);
+    if (!comp) {
+      psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
+      return(true);
+    }
+    
+    if (!remoteComponentInsertObject(config->dbh, comp)) {
+      if (!psDBRollback(config->dbh)) {
+	psError(PS_ERR_UNKNOWN, false, "database error");
+      }
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(run);
+      return(true);
+    }
+
+    psArrayAdd(list, list->n, comp);
+    psFree(comp);
+    
+  }
+  psFree(run);
+  // point of no return
+  if (!psDBCommit(config->dbh)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    return false;
+  }
+  
+  if (!remoteComponentPrintObjects(stdout, list, !simple)) {
+    if (!psDBRollback(config->dbh)) {
+      psError(PS_ERR_UNKNOWN, false, "database error");
+    }
+    psError(PS_ERR_UNKNOWN, false, "failed to print object");
+    psFree(run);
+    return false;
+  }
+  
+  psFree(list);
+  psFree(output);
+					
+  return true;
+}
+
+// List
+static bool listrunMode(pxConfig *config)
+{
+  psMetadata *where = psMetadataAlloc();
+  
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
+  PXOPT_COPY_STR(config->args, where, "-stage",  "stage",  "==");
+  PXOPT_COPY_STR(config->args, where, "-label",  "label",  "==");
+
+  PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
+  PXOPT_COPY_TIME(config->args, where, "-poll_begin", "last_poll", ">=");
+  PXOPT_COPY_TIME(config->args, where, "-poll_end", "last_poll", "<=");
+  
+  PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
+
+  PXOPT_LOOKUP_S16(limit,   config->args, "-limit",  false, false);
+  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+  
+
+  psArray *remRuns = NULL;
+  remRuns = psDBSelectRows(config->dbh, "remoteRun", where, limit);
+  
+  if (!ippdbPrintMetadatas(stdout, remRuns, "remoteRun", !simple)) {
+    psError(PS_ERR_UNKNOWN, false, "failed to print array");
+    psFree(remRuns);
+    return false;
+  }
+  psFree(remRuns);
+
+  return true;
+}
+
+static bool listcomponentMode(pxConfig *config)
+{
+  psMetadata *where = psMetadataAlloc();
+
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+  
+  psArray *remComps = NULL;
+  remComps = psDBSelectRows(config->dbh, "remoteComponent", where, 0);
+  
+  if (!ippdbPrintMetadatas(stdout, remComps, "remoteComponent", !simple)) {
+    psError(PS_ERR_UNKNOWN, false, "failed to print array");
+    psFree(remComps);
+    return false;
+  }
+  psFree(remComps);
+
+  return true;
+}
+
+// Update
+
+static bool updaterunMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+  PXOPT_LOOKUP_S64(remote_id,  config->args, "-remote_id",    true, false);
+  
+  psMetadata *where = psMetadataAlloc();
+  psMetadata *values = psMetadataAlloc();
+
+  // Wheres
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  
+  // Values to set
+  PXOPT_COPY_STR(config->args, values, "-set_label", "label", "==");
+  PXOPT_COPY_STR(config->args, values, "-set_state", "state", "==");
+  PXOPT_COPY_S16(config->args, values, "-fault",     "fault", "==");
+  PXOPT_COPY_S64(config->args, values, "-job_id",    "job_id", "==");
+
+  long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
+  psFree(values);
+
+  if (rows < 1) {
+    psError(PS_ERR_UNKNOWN,false, "no rows affected");
+    return(false);
+  }
+  
+  return(true);
+}
+
+static bool updatepollMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+  PXOPT_LOOKUP_S64(remote_id,  config->args, "-remote_id",    true, false);
+  
+  psMetadata *where = psMetadataAlloc();
+  // Wheres
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+  psFree(where);
+  
+  psString query = NULL;
+  query = pxDataGet("remotetool_updatepoll.sql");
+  if (!query) {
+    psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
+    psFree(whereClause);
+    return(false);
+  }
+
+  if (!p_psDBRunQueryF(config->dbh, query,whereClause)) {
+    psError(PS_ERR_UNKNOWN, false, "database error");
+    psFree(query);
+    psFree(whereClause);
+    return false;
+  }
+  psFree(query);
+  psFree(whereClause);
+  return(true);
+}
+  
+
+  
+
+static bool revertrunMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+
+  psMetadata *where = psMetadataAlloc();
+  psMetadata *values = psMetadataAlloc();
+
+  // required
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+  
+  // Value to set
+  PXOPT_COPY_S16(config->args, values, "-fault", "fault", "==");
+  long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
+  psFree(values);
+  psFree(where);
+  if (rows < 1) {
+    psError(PS_ERR_UNKNOWN,false, "no rows affected");
+    return(false);
+  }
+
+  return(true);
+}
+
+static bool revertauthMode(pxConfig *config)
+{
+  PS_ASSERT_PTR_NON_NULL(config, false);
+
+  psMetadata *where = psMetadataAlloc();
+  psMetadata *values = psMetadataAlloc();
+
+  // required
+  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
+  PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+
+  psMetadataAddStr(where, PS_LIST_TAIL, "state", 0, "==", "auth"); 
+
+  // Value to set
+  psMetadataAddStr(values, PS_LIST_TAIL, "state", 0, "==", "run");
+  
+  long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
+  psFree(values);
+  psFree(where);
+  if (rows < 1) {
+    psError(PS_ERR_UNKNOWN,false, "no rows affected");
+    return(false);
+  }
+
+  return(true);
+}
+    
Index: branches/eam_branches/ipp-20140206/ippTools/src/remotetool.h
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/src/remotetool.h	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/src/remotetool.h	(revision 36536)
@@ -0,0 +1,23 @@
+/*
+ * remotetool.h
+ */
+
+#ifndef REMOTETOOL_H
+#define REMOTETOOL_H 1
+
+#include "pxtools.h"
+
+typedef enum {
+  REMOTETOOL_MODE_NONE          = 0x0,
+  REMOTETOOL_MODE_DEFINEBYQUERY,
+  REMOTETOOL_MODE_LISTRUN,
+  REMOTETOOL_MODE_LISTCOMPONENT,
+  REMOTETOOL_MODE_UPDATERUN,
+  REMOTETOOL_MODE_UPDATEPOLL,
+  REMOTETOOL_MODE_REVERTRUN,    
+  REMOTETOOL_MODE_REVERTAUTH,   
+} remotetoolMode;
+
+pxConfig *remotetoolConfig(pxConfig *config, int argc, char **argv);
+
+#endif // REMOTETOOL_H
Index: branches/eam_branches/ipp-20140206/ippTools/src/remotetoolConfig.c
===================================================================
--- branches/eam_branches/ipp-20140206/ippTools/src/remotetoolConfig.c	(revision 36536)
+++ branches/eam_branches/ipp-20140206/ippTools/src/remotetoolConfig.c	(revision 36536)
@@ -0,0 +1,124 @@
+/*
+ * remotetoolConfig.c
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+#include <stdint.h>
+#include <psmodules.h>
+#include "pxtools.h"
+#include "remotetool.h"
+
+#define ADD_OPT(TYPE,TARG,NAME,COMMENT,DEFAULT) psMetadataAdd##TYPE(TARG, PS_LIST_TAIL, NAME, 0, COMMENT, DEFAULT)
+
+pxConfig *remotetoolConfig(pxConfig *config, int argc, char **argv)
+{
+  if (!config) {
+    config = pxConfigAlloc();
+  }
+
+  pmConfigReadParamsSet(false);
+
+  // setup site config
+  config->modules = pmConfigRead(&argc, argv, NULL);
+  if (!config->modules) {
+    psError(psErrorCodeLast(), false, "Can't find site configuration");
+    psFree(config);
+    return NULL;
+  }
+
+  // -definebyquery
+  psMetadata *definebyqueryArgs = psMetadataAlloc();
+  ADD_OPT(Str, definebyqueryArgs, "-label",          "stage label to query", NULL);
+  ADD_OPT(Str, definebyqueryArgs, "-set_label",      "remRun label to use", NULL);
+  ADD_OPT(Str, definebyqueryArgs, "-stage",          "stage to query", NULL);
+  ADD_OPT(Str, definebyqueryArgs, "-path_base",      "define base output location", NULL);
+  ADD_OPT(S16, definebyqueryArgs, "-limit",          "limit to number of jobs to bundle",0);
+  ADD_OPT(Bool, definebyqueryArgs, "-pretend",       "pretend to do this.", 0);
+  ADD_OPT(Bool, definebyqueryArgs,"-simple",         "simple print format",0);
+  
+  // -listrun
+  psMetadata *listrunArgs = psMetadataAlloc();
+  ADD_OPT(S64, listrunArgs, "-remote_id",             "run to list", 0);
+  ADD_OPT(Str, listrunArgs, "-state",              "run state", NULL);
+  ADD_OPT(Str, listrunArgs, "-stage",              "stage to return", NULL);
+  ADD_OPT(Str, listrunArgs, "-label",              "remRun label to use", NULL);
+
+  ADD_OPT(S64, listrunArgs, "-job_id",             "job_id", 0);
+  //  ADD_OPT(Str, listrunArgs, "-poll_begin",         "last polled time begin", NULL);
+  //  ADD_OPT(Str, listrunArgs, "-poll_end",           "last polled time begin", NULL);
+  psMetadataAddTime(listrunArgs, PS_LIST_TAIL, "-poll_begin", 0, "last polled time begin", NULL);
+  psMetadataAddTime(listrunArgs, PS_LIST_TAIL, "-poll_end", 0, "last polled time end", NULL);
+
+  ADD_OPT(S16, listrunArgs, "-fault",              "fault code", 0);
+
+  ADD_OPT(Bool, listrunArgs, "-simple",            "simple print format", false);
+  ADD_OPT(S16, listrunArgs,  "-limit",             "limit to number of runs to display", 0);
+
+  // -listcomponents
+  psMetadata *listcomponentArgs = psMetadataAlloc();
+  ADD_OPT(S64, listcomponentArgs, "-remote_id",             "run to list", 0);
+  ADD_OPT(S16, listcomponentArgs, "-limit",              "limit to number of runs to display", 0);
+  ADD_OPT(Bool, listcomponentArgs, "-simple",            "simple print format", false);
+  // -updaterun
+  psMetadata *updaterunArgs = psMetadataAlloc();
+  ADD_OPT(S64, updaterunArgs, "-remote_id",             "run to update", 0);
+  //  ADD_OPT(Str, updaterunArgs, "-label",                  "label to update", NULL);
+  ADD_OPT(Str, updaterunArgs, "-set_label",          "remRun label to use", NULL);
+  ADD_OPT(Str, updaterunArgs, "-set_state",          "remoteRun state to assign", NULL);
+  ADD_OPT(S64, updaterunArgs, "-job_id",             "job_id to set", 0);
+  ADD_OPT(S16, updaterunArgs, "-fault",              "fault code", 0);
+  //  ADD_OPT(Bool, updaterunArgs, "-poll",              "set poll date", NULL);
+
+  // -updatepoll
+  psMetadata *updatepollArgs = psMetadataAlloc();
+  ADD_OPT(S64, updatepollArgs, "-remote_id",            "run to update", 0);
+  
+  // -revertrun
+  psMetadata *revertrunArgs = psMetadataAlloc();
+  ADD_OPT(S64, revertrunArgs, "-remote_id",             "run to revert", 0);
+  ADD_OPT(Str, revertrunArgs, "-label",      "remRun label to use", NULL);
+  ADD_OPT(S16, revertrunArgs, "-fault",              "fault code", 0);
+  
+  // -revertauth
+  psMetadata *revertauthArgs = psMetadataAlloc();
+  ADD_OPT(S64, revertauthArgs, "-remote_id",             "run to revert", 0);
+  ADD_OPT(Str, revertauthArgs, "-label",      "remRun label to use", NULL);
+
+  psMetadata *argSets = psMetadataAlloc();
+  psMetadata *modes   = psMetadataAlloc();
+
+  PXOPT_ADD_MODE("-definebyquery",     "", REMOTETOOL_MODE_DEFINEBYQUERY,  definebyqueryArgs);
+  PXOPT_ADD_MODE("-listrun",           "", REMOTETOOL_MODE_LISTRUN,        listrunArgs);
+  PXOPT_ADD_MODE("-listcomponent",     "", REMOTETOOL_MODE_LISTCOMPONENT,  listcomponentArgs);
+  PXOPT_ADD_MODE("-updaterun",         "", REMOTETOOL_MODE_UPDATERUN,      updaterunArgs);
+  PXOPT_ADD_MODE("-updatepoll",        "", REMOTETOOL_MODE_UPDATEPOLL,     updatepollArgs);
+  PXOPT_ADD_MODE("-revertrun",         "", REMOTETOOL_MODE_REVERTRUN,      revertrunArgs);
+  PXOPT_ADD_MODE("-revertauth",        "", REMOTETOOL_MODE_REVERTAUTH,     revertauthArgs);
+
+
+  if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
+    psError(PS_ERR_UNKNOWN, true, "option parsing failed");
+    psFree(argSets);
+    psFree(modes);
+    psFree(config);
+    return NULL;
+  }
+
+  psFree(argSets);
+  psFree(modes);
+
+  // define Database handle, if used
+  config->dbh = psMemIncrRefCounter(pmConfigDB(config->modules));
+  if (!config->dbh) {
+    psError(PXTOOLS_ERR_SYS, false, "Can't configure database");
+    psFree(config);
+    return NULL;
+  }
+
+  return config;
+}
+
