Back to index

webcit  8.12-dfsg
setup.c
Go to the documentation of this file.
00001 /*
00002  * WebCit setup utility
00003  * 
00004  * (This is basically just an install wizard.  It's not required.)
00005  */
00006 
00007 #include "sysdep.h"
00008 #include "webcit.h"
00009 #include "webserver.h"
00010 
00011 
00012 #define UI_TEXT             0      /* Default setup type -- text only */
00013 #define UI_DIALOG    2      /* Use the 'dialog' program */
00014 #define UI_SILENT    3      /* Silent running, for use in scripts */
00015 
00016 int setup_type;
00017 char setup_directory[SIZ];
00018 int using_web_installer = 0;
00019 char suggested_url[SIZ];
00020 
00021 /* some copies... 
00022 int syslog(int loglevel, const char *format, ...){return 0;} */
00023 void wc_printf(const char *format,...){}
00024 
00025 void RegisterNS(const char *NSName, long len, 
00026               int nMinArgs, 
00027               int nMaxArgs, 
00028               WCHandlerFunc HandlerFunc,
00029               WCPreevalFunc PreEvalFunc,
00030               int ContextRequired){}
00031 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F){}
00032 pthread_key_t MyConKey;
00033 
00034 #ifdef ENABLE_NLS
00035 
00036 #ifdef HAVE_USELOCALE 
00037 int localeoffset = 1;
00038 #else
00039 int localeoffset = 0;
00040 #endif
00041 
00042 #endif
00043 /*
00044  * Delete an entry from /etc/inittab
00045  */
00046 void delete_init_entry(char *which_entry)
00047 {
00048        char *inittab = NULL;
00049        FILE *fp;
00050        char buf[SIZ];
00051        char entry[SIZ];
00052        char levels[SIZ];
00053        char state[SIZ];
00054        char prog[SIZ];
00055 
00056        inittab = strdup("");
00057        if (inittab == NULL) return;
00058 
00059        fp = fopen("/etc/inittab", "r");
00060        if (fp == NULL) return;
00061 
00062        while(fgets(buf, sizeof buf, fp) != NULL) {
00063 
00064               if (num_tokens(buf, ':') == 4) {
00065                      extract_token(entry, buf, 0, ':', sizeof entry);
00066                      extract_token(levels, buf, 1, ':', sizeof levels);
00067                      extract_token(state, buf, 2, ':', sizeof state);
00068                      extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
00069 
00070                      if (!strcmp(entry, which_entry)) {
00071                             strcpy(state, "off");       /* disable it */
00072                      }
00073               }
00074 
00075               inittab = realloc(inittab, strlen(inittab) + strlen(buf) + 2);
00076               if (inittab == NULL) {
00077                      fclose(fp);
00078                      return;
00079               }
00080               
00081               strcat(inittab, buf);
00082        }
00083        fclose(fp);
00084        fp = fopen("/etc/inittab", "w");
00085        if (fp != NULL) {
00086               fwrite(inittab, strlen(inittab), 1, fp);
00087               fclose(fp);
00088               kill(1, SIGHUP);     /* Tell init to re-read /etc/inittab */
00089        }
00090        free(inittab);
00091 }
00092 
00093 
00094 
00095 
00096 /* 
00097  * Remove any /etc/inittab entries for webcit, because we don't
00098  * start it that way anymore.
00099  */
00100 void delete_the_old_way(void) {
00101        FILE *infp;
00102        char buf[1024];
00103        char looking_for[1024];
00104        int have_entry = 0;
00105        char entry[1024];
00106        char prog[1024];
00107        char init_entry[1024];
00108 
00109 
00110        strcpy(init_entry, "");
00111 
00112        /* Determine the fully qualified path name of webcit */
00113        snprintf(looking_for, sizeof looking_for, "%s/webcit ", setup_directory);
00114 
00115        /* Pound through /etc/inittab line by line.  Set have_entry to 1 if
00116         * an entry is found which we believe starts webcit.
00117         */
00118        infp = fopen("/etc/inittab", "r");
00119        if (infp == NULL) {
00120               return;
00121        } else {
00122               while (fgets(buf, sizeof buf, infp) != NULL) {
00123                      buf[strlen(buf) - 1] = 0;
00124                      extract_token(entry, buf, 0, ':', sizeof entry);
00125                      extract_token(prog, buf, 3, ':', sizeof prog);
00126                      if (!strncasecmp(prog, looking_for,
00127                         strlen(looking_for))) {
00128                             ++have_entry;
00129                             strcpy(init_entry, entry);
00130                      }
00131               }
00132               fclose(infp);
00133        }
00134 
00135        /* Bail out if there's nothing to do. */
00136        if (!have_entry) return;
00137 
00138        delete_init_entry(init_entry);
00139 }
00140 
00141 
00142 
00143 void cleanup(int exitcode)
00144 {
00145        exit(exitcode);
00146 }
00147 
00148 
00149 
00150 void title(char *text)
00151 {
00152        if (setup_type == UI_TEXT) {
00153               printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
00154        }
00155 }
00156 
00157 
00158 
00159 
00160 int yesno(char *question, int default_value)
00161 {
00162        int i = 0;
00163        int answer = 0;
00164        char buf[SIZ] = "";
00165 
00166        switch (setup_type) {
00167 
00168        case UI_TEXT:
00169               do {
00170                      printf("%s\nYes/No [%s] --> ",
00171                             question,
00172                             ( default_value ? "Yes" : "No" )
00173                      );
00174                      if (fgets(buf, sizeof buf, stdin))
00175                      {
00176                             answer = tolower(buf[0]);
00177                             if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
00178                                    answer = default_value;
00179                             else if (answer == 'y')
00180                                    answer = 1;
00181                             else if (answer == 'n')
00182                                    answer = 0;
00183                      }
00184 
00185               } while ((answer < 0) || (answer > 1));
00186               break;
00187 
00188        case UI_DIALOG:
00189               sprintf(buf, "exec %s %s --yesno '%s' 15 75",
00190                      getenv("CTDL_DIALOG"),
00191                      ( default_value ? "" : "--defaultno" ),
00192                      question);
00193               i = system(buf);
00194               if (i == 0) {
00195                      answer = 1;
00196               }
00197               else {
00198                      answer = 0;
00199               }
00200               break;
00201 
00202        }
00203        return (answer);
00204 }
00205 
00206 
00207 
00208 
00209 void set_value(char *prompt, char str[])
00210 {
00211        char buf[SIZ] = "";
00212        char dialog_result[PATH_MAX];
00213        char setupmsg[SIZ];
00214        FILE *fp;
00215 
00216        strcpy(setupmsg, "");
00217 
00218        switch (setup_type) {
00219        case UI_TEXT:
00220               title("WebCit setup");
00221               printf("\n%s\n", prompt);
00222               printf("This is currently set to:\n%s\n", str);
00223               printf("Enter new value or press return to leave unchanged:\n");
00224               if (fgets(buf, sizeof buf, stdin)) {
00225                      buf[strlen(buf) - 1] = 0;
00226               }
00227               if (strlen(buf) != 0)
00228                      strcpy(str, buf);
00229               break;
00230        case UI_DIALOG:
00231               CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
00232               sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
00233                      getenv("CTDL_DIALOG"),
00234                      prompt,
00235                      str,
00236                      dialog_result);
00237               system(buf);
00238               fp = fopen(dialog_result, "r");
00239               if (fp != NULL) {
00240                      if (fgets(str, sizeof buf, fp)){
00241                             if (str[strlen(str)-1] == 10) {
00242                                    str[strlen(str)-1] = 0;
00243                             }
00244                      }
00245                      fclose(fp);
00246                      unlink(dialog_result);
00247               }
00248               break;
00249 
00250        }
00251 }
00252 
00253 
00254 extern const char *AvailLang[];
00255 int GetLocalePrefs(void)
00256 {
00257        int nLocales;
00258        StrBuf *Buf;
00259        char buf[SIZ];
00260        char dialog_result[PATH_MAX];
00261        FILE *fp;
00262        int i = 0;
00263        int offs = 0;
00264 
00265        nLocales = 0; 
00266        while (!IsEmptyStr(AvailLang[nLocales]))
00267               nLocales++;
00268 
00269        Buf = NewStrBuf();
00270 
00271        StrBufAppendBufPlain(Buf, HKEY("Select the locale webcit should use : \n"), 0);
00272 #ifdef HAVE_USELOCALE 
00273        StrBufAppendBufPlain(Buf, HKEY(" 0 Let the user select it at the login prompt (default)\n"), 0);
00274        offs ++;
00275 #endif
00276        for (i = 0; i < nLocales; i++) {
00277               StrBufAppendPrintf(Buf, " %ld: %s\n", i + offs, AvailLang[i]);
00278 
00279        }
00280 
00281        switch (setup_type) {
00282        case UI_TEXT:
00283               title("WebCit setup");
00284               printf("\n%s\n", ChrPtr(Buf));
00285               printf("This is currently set to:\n%ld\n", 0L);
00286               printf("Enter new value or press return to leave unchanged:\n");
00287               if (fgets(buf, sizeof buf, stdin))
00288                      return atoi(buf);
00289               break;
00290 
00291        case UI_DIALOG:
00292               CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
00293               sprintf(buf, "exec %s --inputbox '%s' 19 72 '%ld' 2>%s",
00294                      getenv("CTDL_DIALOG"),
00295                      ChrPtr(Buf),
00296                      0L,
00297                      dialog_result);
00298               system(buf);
00299               fp = fopen(dialog_result, "r");
00300               if (fp != NULL) {
00301                      char *str = &buf[0];
00302                      if (fgets(str, sizeof buf, fp)){
00303                             if (str[strlen(str)-1] == 10) {
00304                                    str[strlen(str)-1] = 0;
00305                             }
00306                      }
00307                      fclose(fp);
00308                      unlink(dialog_result);
00309                      return atoi(buf);
00310               }
00311               break;
00312 
00313        }
00314        return 0;
00315 }
00316 
00317 void important_message(char *title, char *msgtext)
00318 {
00319        char buf[SIZ];
00320 
00321        switch (setup_type) {
00322 
00323        case UI_TEXT:
00324               printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
00325               printf("       %s \n\n%s\n\n", title, msgtext);
00326               printf("Press return to continue...");
00327               if (fgets(buf, sizeof buf, stdin));
00328               break;
00329 
00330        case UI_DIALOG:
00331               sprintf(buf, "exec %s --msgbox '%s' 19 72",
00332                      getenv("CTDL_DIALOG"),
00333                      msgtext);
00334               system(buf);
00335               break;
00336        }
00337 }
00338 
00339 
00340 void display_error(char *error_message)
00341 {
00342        important_message("Error", error_message);
00343 }
00344 
00345 void progress(char *text, long int curr, long int cmax)
00346 {
00347        static long dots_printed = 0L;
00348        long a = 0;
00349        char buf[SIZ];
00350        static FILE *fp = NULL;
00351 
00352        switch (setup_type) {
00353 
00354        case UI_TEXT:
00355               if (curr == 0) {
00356                      printf("%s\n", text);
00357                      printf("..........................");
00358                      printf("..........................");
00359                      printf("..........................\r");
00360                      fflush(stdout);
00361                      dots_printed = 0;
00362               } else if (curr == cmax) {
00363                      printf("\r%79s\n", "");
00364               } else {
00365                      a = (curr * 100) / cmax;
00366                      a = a * 78;
00367                      a = a / 100;
00368                      while (dots_printed < a) {
00369                             printf("*");
00370                             ++dots_printed;
00371                             fflush(stdout);
00372                      }
00373               }
00374               break;
00375 
00376        case UI_DIALOG:
00377               if (curr == 0) {
00378                      sprintf(buf, "exec %s --gauge '%s' 7 72 0",
00379                             getenv("CTDL_DIALOG"),
00380                             text);
00381                      fp = popen(buf, "w");
00382                      if (fp != NULL) {
00383                             fprintf(fp, "0\n");
00384                             fflush(fp);
00385                      }
00386               } 
00387               else if (curr == cmax) {
00388                      if (fp != NULL) {
00389                             fprintf(fp, "100\n");
00390                             pclose(fp);
00391                             fp = NULL;
00392                      }
00393               }
00394               else {
00395                      a = (curr * 100) / cmax;
00396                      if (fp != NULL) {
00397                             fprintf(fp, "%ld\n", a);
00398                             fflush(fp);
00399                      }
00400               }
00401               break;
00402        }
00403 }
00404 
00405 
00406 
00407 
00408 /*
00409  * install_init_scripts()  -- Create and deploy SysV init scripts.
00410  *
00411  */
00412 void install_init_scripts(void)
00413 {
00414 #ifdef ENABLE_NLS
00415        int localechoice;
00416 #endif
00417        char question[1024];
00418        char buf[256];
00419        char http_port[128];
00420 #ifdef HAVE_OPENSSL
00421        char https_port[128];
00422 #endif
00423        char hostname[128];
00424        char portname[128];
00425        char command[SIZ];
00426        struct utsname my_utsname;
00427        struct stat etcinitd;
00428        FILE *fp;
00429        char *initfile = "/etc/init.d/webcit";
00430 
00431        fp = fopen(initfile, "r");
00432        if (fp != NULL) {
00433               if (yesno("WebCit already appears to be configured to start at boot.\n"
00434                        "Would you like to keep your boot configuration as is?\n", 1) == 1) {
00435                      return;
00436               }
00437               fclose(fp);
00438               
00439        }
00440 
00441        /* Otherwise, prompt the user to create an entry. */
00442        snprintf(question, sizeof question,
00443                "Would you like to automatically start WebCit at boot?"
00444               );
00445        if (yesno(question, 1) == 0)
00446               return;
00447 
00448 
00449 #ifdef ENABLE_NLS
00450 
00451        localechoice = GetLocalePrefs();
00452 
00453 #endif
00454        /* Defaults */
00455        sprintf(http_port, "2000");
00456 #ifdef HAVE_OPENSSL
00457        sprintf(https_port, "443");
00458 #endif
00459        sprintf(hostname, "uds");
00460        sprintf(portname, "/usr/local/citadel");
00461 
00462        /* This is a very hackish way of learning the port numbers used
00463         * in a previous install, if we are upgrading: read them out of
00464         * the existing init script.
00465         */
00466        if ((stat("/etc/init.d/", &etcinitd) == -1) && 
00467            (errno == ENOENT))
00468        {
00469               if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
00470                   (errno == ENOENT))
00471                      initfile = WEBCITDIR"/webcit.init";
00472               else
00473                      initfile = "/etc/rc.d/init.d/webcit";
00474        }
00475 
00476        fp = fopen(initfile, "r");
00477        if (fp != NULL) {
00478               while (fgets(buf, sizeof buf, fp) != NULL) {
00479                      if (strlen(buf) > 0) {
00480                             buf[strlen(buf)-1] = 0;     /* strip trailing cr */
00481                      }
00482                      if (!strncasecmp(buf, "HTTP_PORT=", 10)) {
00483                             safestrncpy(http_port, &buf[10], sizeof http_port);
00484                      }
00485 #ifdef HAVE_OPENSSL
00486                      if (!strncasecmp(buf, "HTTPS_PORT=", 11)) {
00487                             safestrncpy(https_port, &buf[11], sizeof https_port);
00488                      }
00489 #endif
00490                      if (!strncasecmp(buf, "CTDL_HOSTNAME=", 14)) {
00491                             safestrncpy(hostname, &buf[14], sizeof hostname);
00492                      }
00493                      if (!strncasecmp(buf, "CTDL_PORTNAME=", 14)) {
00494                             safestrncpy(portname, &buf[14], sizeof portname);
00495                      }
00496               }
00497               fclose(fp);
00498        }
00499 
00500        /* Now ask for the port numbers */
00501        snprintf(question, sizeof question,
00502                "On which port do you want WebCit to listen for HTTP "
00503                "requests?\n\nYou can use the standard port (80) if you are "
00504                "not running another\nweb server (such as Apache), otherwise "
00505                "select another port.");
00506        set_value(question, http_port);
00507        uname(&my_utsname);
00508        sprintf(suggested_url, "http://%s:%s/", my_utsname.nodename, http_port);
00509 
00510 #ifdef HAVE_OPENSSL
00511        snprintf(question, sizeof question,
00512                "On which port do you want WebCit to listen for HTTPS "
00513                "requests?\n\nYou can use the standard port (443) if you are "
00514                "not running another\nweb server (such as Apache), otherwise "
00515                "select another port.");
00516        set_value(question, https_port);
00517 #endif
00518 
00519        /* Find out where Citadel is. */
00520        if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
00521               strcpy(hostname, "uds");
00522               strcpy(portname, getenv("CITADEL"));
00523        }
00524        else {
00525               snprintf(question, sizeof question,
00526                       "Is the Citadel service running on the same host as WebCit?");
00527               if (yesno(question, ((!strcasecmp(hostname, "uds")) ? 1 : 0))) {
00528                      strcpy(hostname, "uds");
00529                      if (atoi(portname) != 0) strcpy(portname, "/usr/local/citadel");
00530                      set_value("In what directory is Citadel installed?", portname);
00531               }
00532               else {
00533                      if (!strcasecmp(hostname, "uds")) strcpy(hostname, "127.0.0.1");
00534                      if (atoi(portname) == 0) strcpy(portname, "504");
00535                      set_value("Enter the host name or IP address of your "
00536                               "Citadel server.", hostname);
00537                      set_value("Enter the port number on which Citadel is "
00538                               "running (usually 504)", portname);
00539               }
00540        }
00541 
00542 
00543        fp = fopen(initfile, "w");
00544 
00545        fprintf(fp,   "#!/bin/sh\n"
00546               "\n"
00547               "# uncomment this to create coredumps as described in\n"
00548               "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
00549               "# ulimit -c unlimited\n"
00550                      "WEBCIT_DIR=%s\n", setup_directory);
00551        fprintf(fp,   "HTTP_PORT=%s\n", http_port);
00552 #ifdef HAVE_OPENSSL
00553        fprintf(fp,   "HTTPS_PORT=%s\n", https_port);
00554 #endif
00555        fprintf(fp,   "CTDL_HOSTNAME=%s\n", hostname);
00556        fprintf(fp,   "CTDL_PORTNAME=%s\n", portname);
00557 
00558 #ifdef ENABLE_NLS
00559        
00560        if (localechoice == 0) {
00561 #ifdef HAVE_USELOCALE 
00562               fprintf(fp, "unset LANG\n");
00563 #else
00564               fprintf(fp, "export WEBCIT_LANG=c\n");
00565 #endif
00566        }
00567        else {
00568               fprintf(fp, "export WEBCIT_LANG=%s\n", AvailLang[localechoice - localeoffset]);
00569 
00570        }
00571 #else
00572        fprintf(fp,     "# your system doesn't support locales\n");
00573 #endif
00574        fprintf(fp,   "\n"
00575                      "\n"
00576                      "case \"$1\" in\n"
00577                      "\n"
00578                      "start)              echo -n \"Starting WebCit... \"\n"
00579                      "             if   $WEBCIT_DIR/webcit "
00580                                                       "-D/var/run/webcit.pid "
00581                                                  "-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
00582                      "             then\n"
00583                      "                    echo \"ok\"\n"
00584                      "             else\n"
00585                      "                    echo \"failed\"\n"
00586                      "             fi\n");
00587 #ifdef HAVE_OPENSSL
00588        fprintf(fp,   "             echo -n \"Starting WebCit SSL... \"\n"
00589                      "             if  $WEBCIT_DIR/webcit "
00590                                                       "-D/var/run/webcit-ssl.pid "
00591                                                  "-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
00592                      "             then\n"
00593                      "                    echo \"ok\"\n"
00594                      "             else\n"
00595                      "                    echo \"failed\"\n"
00596                      "             fi\n");
00597 #endif
00598        fprintf(fp,   "             ;;\n"
00599                      "stop)        echo -n \"Stopping WebCit... \"\n"
00600                      "             if kill `cat /var/run/webcit.pid 2>/dev/null` 2>/dev/null\n"
00601                      "             then\n"
00602                      "                    echo \"ok\"\n"
00603                      "             else\n"
00604                      "                    echo \"failed\"\n"
00605                      "             fi\n"
00606                      "             rm -f /var/run/webcit.pid 2>/dev/null\n");
00607 #ifdef HAVE_OPENSSL
00608        fprintf(fp,   "             echo -n \"Stopping WebCit SSL... \"\n"
00609                      "             if kill `cat /var/run/webcit-ssl.pid 2>/dev/null` 2>/dev/null\n"
00610                      "             then\n"
00611                      "                    echo \"ok\"\n"
00612                      "             else\n"
00613                      "                    echo \"failed\"\n"
00614                      "             fi\n"
00615                      "             rm -f /var/run/webcit-ssl.pid 2>/dev/null\n");
00616 #endif
00617        fprintf(fp,   "             ;;\n"
00618                      "restart)     $0 stop\n"
00619                      "             $0 start\n"
00620                      "             ;;\n"
00621                      "*)           echo \"Usage: $0 {start|stop|restart}\"\n"
00622                      "             exit 1\n"
00623                      "             ;;\n"
00624                      "esac\n"
00625        );
00626 
00627        fclose(fp);
00628        chmod(initfile, 0755);
00629 
00630        /* Set up the run levels. */
00631        system("/bin/rm -f /etc/rc?.d/[SK]??webcit 2>/dev/null");
00632        snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S84webcit ; done 2>/dev/null", initfile);
00633        system(command);
00634        snprintf(command, sizeof(command), "for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K15webcit ; done 2>/dev/null", initfile);
00635        system(command);
00636 
00637 }
00638 
00639 
00640 
00641 
00642 /*
00643  * Figure out what type of user interface we're going to use
00644  */
00645 int discover_ui(void)
00646 {
00647 
00648        /* Use "dialog" if we have it */
00649        if (getenv("CTDL_DIALOG") != NULL) {
00650               return UI_DIALOG;
00651        }
00652               
00653        return UI_TEXT;
00654 }
00655 
00656 
00657 
00658 
00659 
00660 int main(int argc, char *argv[])
00661 {
00662        int a;
00663        char aaa[256];
00664        int info_only = 0;
00665 
00666        strcpy(suggested_url, "http://<your_host_name>:<port>/");
00667 
00668        /* set an invalid setup type */
00669        setup_type = (-1);
00670 
00671        /* Check to see if we're running the web installer */
00672        if (getenv("CITADEL_INSTALLER") != NULL) {
00673               using_web_installer = 1;
00674        }
00675 
00676        /* parse command line args */
00677        for (a = 0; a < argc; ++a) {
00678               if (!strncmp(argv[a], "-u", 2)) {
00679                      strcpy(aaa, argv[a]);
00680                      strcpy(aaa, &aaa[2]);
00681                      setup_type = atoi(aaa);
00682               }
00683               if (!strcmp(argv[a], "-i")) {
00684                      info_only = 1;
00685               }
00686               if (!strcmp(argv[a], "-q")) {
00687                      setup_type = UI_SILENT;
00688               }
00689        }
00690 
00691 
00692        /* If a setup type was not specified, try to determine automatically
00693         * the best one to use out of all available types.
00694         */
00695        if (setup_type < 0) {
00696               setup_type = discover_ui();
00697        }
00698        if (info_only == 1) {
00699               important_message("WebCit Setup", "Welcome to WebCit setup");
00700               cleanup(0);
00701        }
00702 
00703        /* Get started in a valid setup directory. */
00704        strcpy(setup_directory, WEBCITDIR);
00705        if ( (using_web_installer) && (getenv("WEBCIT") != NULL) ) {
00706               strcpy(setup_directory, getenv("WEBCIT"));
00707        }
00708        else {
00709               set_value("In what directory is WebCit installed?",
00710                      setup_directory);
00711        }
00712        if (chdir(setup_directory) != 0) {
00713               important_message("WebCit Setup",
00714                        "The directory you specified does not exist.");
00715               cleanup(errno);
00716        }
00717 
00718        /*
00719         * We used to start WebCit by putting it directly into /etc/inittab.
00720         * Since some systems are moving away from init, we can't do this anymore.
00721         */
00722        progress("Removing obsolete /etc/inittab entries...", 0, 1);
00723        delete_the_old_way();
00724        progress("Removing obsolete /etc/inittab entries...", 1, 1);
00725 
00726        /* Now begin. */
00727        switch (setup_type) {
00728 
00729        case UI_TEXT:
00730               printf("\n\n\n"
00731                      "               *** WebCit setup program ***\n\n");
00732               break;
00733 
00734        }
00735 
00736        /* 
00737         * If we're running on SysV, install init scripts.
00738         */
00739        if (!access("/var/run", W_OK)) {
00740               install_init_scripts();
00741 
00742               if (!access("/etc/init.d/webcit", X_OK)) {
00743                      system("/etc/init.d/webcit stop");
00744                      system("/etc/init.d/webcit start");
00745               }
00746 
00747               sprintf(aaa,
00748                      "Setup is finished.  You may now log in.\n"
00749                      "Point your web browser at %s\n", suggested_url
00750               );
00751               important_message("Setup finished", aaa);
00752        }
00753 
00754        else {
00755               important_message("Setup finished",
00756                      "Setup is finished.  You may now start the server.");
00757        }
00758 
00759        cleanup(0);
00760        return 0;
00761 }