+ask_netname:
+ if(ask_netname && tty) {
+ fprintf(stderr, "Enter a new netname: ");
+ if(!fgets(line, sizeof line, stdin)) {
+ fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
+ return false;
+ }
+ if(!*line || *line == '\n')
+ goto ask_netname;
+
+ line[strlen(line) - 1] = 0;
+
+ char newbase[PATH_MAX];
+ snprintf(newbase, sizeof newbase, CONFDIR SLASH "tinc" SLASH "%s", line);
+ if(rename(confbase, newbase)) {
+ fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
+ goto ask_netname;
+ }
+
+ netname = line;
+ make_names(false);
+ }
+
+ char filename2[PATH_MAX];
+ snprintf(filename, sizeof filename, "%s" SLASH "tinc-up.invitation", confbase);
+ snprintf(filename2, sizeof filename2, "%s" SLASH "tinc-up", confbase);
+
+ if(valid_tinc_up) {
+ if(tty) {
+ FILE *fup = fopen(filename, "r");
+ if(fup) {
+ fprintf(stderr, "\nPlease review the following tinc-up script:\n\n");
+
+ char buf[MAXSIZE];
+ while(fgets(buf, sizeof buf, fup))
+ fputs(buf, stderr);
+ fclose(fup);
+
+ int response = 0;
+ do {
+ fprintf(stderr, "\nDo you want to use this script [y]es/[n]o/[e]dit? ");
+ response = tolower(getchar());
+ } while(!strchr("yne", response));
+
+ fprintf(stderr, "\n");
+
+ if(response == 'e') {
+ char *command;
+#ifndef HAVE_MINGW
+ xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ?: getenv("EDITOR") ?: "vi", filename);
+#else
+ xasprintf(&command, "edit \"%s\"", filename);
+#endif
+ if(system(command))
+ response = 'n';
+ else
+ response = 'y';
+ free(command);
+ }
+
+ if(response == 'y') {
+ rename(filename, filename2);
+ chmod(filename2, 0755);
+ fprintf(stderr, "tinc-up enabled.\n");
+ } else {
+ fprintf(stderr, "tinc-up has been left disabled.\n");
+ }
+ }
+ } else {
+ fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n");
+ }
+ } else {
+ // A placeholder was generated.
+ rename(filename, filename2);
+ chmod(filename2, 0755);
+ }
+
+ fprintf(stderr, "Configuration stored in: %s\n", confbase);