Index: branches/tap_branches/ippTools/src/pubtool.c
===================================================================
--- branches/tap_branches/ippTools/src/pubtool.c	(revision 25900)
+++ branches/tap_branches/ippTools/src/pubtool.c	(revision 27838)
@@ -32,4 +32,5 @@
 
 static bool defineclientMode(pxConfig *config);
+static bool updateclientMode(pxConfig *config);
 static bool definerunMode(pxConfig *config);
 static bool pendingMode(pxConfig *config);
@@ -57,4 +58,5 @@
     switch (config->mode) {
         MODECASE(PUBTOOL_MODE_DEFINECLIENT, defineclientMode);
+        MODECASE(PUBTOOL_MODE_UPDATECLIENT, updateclientMode);
         MODECASE(PUBTOOL_MODE_DEFINERUN, definerunMode);
         MODECASE(PUBTOOL_MODE_PENDING, pendingMode);
@@ -93,9 +95,52 @@
     // optional
     PXOPT_LOOKUP_STR(comment, config->args, "-comment",  false, false);
-
-    if (!publishClientInsert(config->dbh, 0, product, stage, workdir, comment)) {
-        psError(PS_ERR_UNKNOWN, false, "Database error");
-        return false;
-    }
+    PXOPT_LOOKUP_BOOL(unmagicked, config->args, "-unmagicked",  false);
+
+    if (!publishClientInsert(config->dbh, 0, 0, product, stage, !unmagicked, workdir, comment)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        return false;
+    }
+
+    return true;
+}
+
+static bool updateclientMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psMetadata *where = psMetadataAlloc(); // WHERE conditions
+    PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-product", "product", "==");
+    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
+    PXOPT_COPY_STR(config->args, where, "-comment", "comment", "LIKE");
+
+    PXOPT_LOOKUP_BOOL(active, config->args, "-active",  false);
+    PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive",  false);
+
+    if ((!active && !inactive) || (active && inactive)) {
+        psError(PS_ERR_UNKNOWN, false, "Must specify one, and only one, of -active and -inactive.");
+        psFree(where);
+        return false;
+    }
+
+    psString query = NULL;              // Query to run
+    psStringAppend(&query, "UPDATE publishClient SET active = %d", active ? 1 : 0);
+
+    if (psListLength(where->list)) {
+        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, "\n WHERE %s", clause);
+        psFree(clause);
+    }
+    psFree(where);
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "Database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    long numUpdated = psDBAffectedRows(config->dbh);
+    psLogMsg("pubtool", PS_LOG_INFO, "%ld rows updated.", numUpdated);
 
     return true;
@@ -112,11 +157,9 @@
     // optional
     PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
-
-    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
+    pxAddLabelSearchArgs(config, where, "-label", "label", "=="); // define using newExp label
 
     psString query = pxDataGet("pubtool_definerun.sql"); // Query to run
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "Failed to retreive SQL statement");
         psFree(where);
         return false;
@@ -167,4 +210,5 @@
         psS64 client = psMetadataLookupS64(NULL, row, "client_id"); // Client identifier
         psS64 stage = psMetadataLookupS64(NULL, row, "stage_id");   // Stage identifier
+        char *label = psMetadataLookupStr(NULL, row, "src_label");   // label from correct source
 
         if (!publishRunInsert(config->dbh, 0, client, stage, label, "new")) {
@@ -205,5 +249,5 @@
     psString query = pxDataGet("pubtool_pending.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "Failed to retreive SQL statement");
         psFree(where);
         return false;
@@ -311,9 +355,9 @@
     PXOPT_COPY_STR(config->args, where, "-client_id", "publishClient.client_id", "==");
     PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
-    PXOPT_COPY_STR(config->args, where, "-label", "publishRun.label", "==");
+    pxAddLabelSearchArgs(config, where, "-label", "publishRun.label", "==");
 
     psString query = pxDataGet("pubtool_revert.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "Failed to retreive SQL statement");
         psFree(where);
         return false;
