diff --git a/src/server/simpleslave.c b/src/server/simpleslave.c --- a/src/server/simpleslave.c +++ b/src/server/simpleslave.c @@ -63,8 +63,9 @@ int main(int argc, char *argv[]) char curopt; int runBenchmark = 0; + int updateConf = 0; - while(((char)-1) != (curopt = getopt(argc, argv, "u:rh"))) + while(((char)-1) != (curopt = getopt(argc, argv, "u:p:rh"))) { if(curopt == ':') { @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) } else if(curopt == 'h') { - fprintf(stderr, "Usage: distrensimpleslave [option] \nStarts a distren slave\n\t-u\tset username (run after fresh install)\n\t-r\tRecalculate render power (benchmark)\n\t-h\tshow this help\n"); + fprintf(stderr, "Usage: distrensimpleslave [option] \nStarts a distren slave\n\t-u\tset Slave ID/Username (run after fresh install)\n\t-p\tset Slave Passphrase (run after fresh install)\n\t-r\tRecalculate render power (benchmark)\n\t-h\tshow this help\n"); return 2; } else if(curopt == 'r') @@ -86,16 +87,27 @@ int main(int argc, char *argv[]) runBenchmark = 1; break; } - else if(curopt == 'u') + else if(curopt == 'u'){ username = strdup(optarg); - if(DEBUG) - fprintf(stderr, "Putting username \"%s\" in distrenslave.conf\n", username); - - conf_replace("distrenslave.conf", "!username", username); - fprintf(stderr, "Please invoke distrensimpleslave with no arguments to run with the username you just set\n"); - return 0; + updateConf = 1; + } + else if(curopt == 'p'){ + password = strdup(optarg); + updateConf = 1; + } } +if(updateConf){ + if(DEBUG) + fprintf(stderr, "Putting Slave ID \"%s\" and Slave Passphrase \"%s\" in distrenslave.conf\n", username, password); + if(username != NULL) + conf_replace("distrenslave.conf", "!username", username); + if(password != NULL) + conf_replace("distrenslave.conf", "!password", password); + + fprintf(stderr, "Please invoke distrensimpleslave with no arguments to run with the slave ID and/or passphrase you just set\n"); + return 0; +} /* Get conf data */ options_init(argc, argv, &my_cfg, myopts, "slave", &commonopts); @@ -111,12 +123,12 @@ int main(int argc, char *argv[]) } if(!username) { - fprintf(stderr, "username not set\n"); + fprintf(stderr, "username not set, try the -u flag \n"); return 1; } if(!password) { - fprintf(stderr, "password not set\n"); + fprintf(stderr, "password not set, try the -p flag\n"); return 1; } if(!hostname) @@ -131,7 +143,7 @@ int main(int argc, char *argv[]) return 1; if(!strncmp(password, "!password",10)) { - fprintf(stderr, "You haven't specified a password. Please edit distrenslave.conf!\n"); + fprintf(stderr, "You haven't specified a password. Please edit distrenslave.conf or try the -p flag!\n"); return 1; }