* due to demand of debian, we rename the webcit binary from webserver to webcit.
[citadel.git] / webcit / setup.c
index 27176e961d47d67c92fd8954709afaf1b3ad66cb..25690cee12f21c00b65167f6dbc61deef9739b2d 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 
-#include "config.h"
+#include "sysdep.h"
 #include "webcit.h"
 #include "webserver.h"
 
@@ -90,11 +90,11 @@ void delete_the_old_way(void) {
 
        strcpy(init_entry, "");
 
-       /* Determine the fully qualified path name of webserver */
-       snprintf(looking_for, sizeof looking_for, "%s/webserver ", setup_directory);
+       /* Determine the fully qualified path name of webcit */
+       snprintf(looking_for, sizeof looking_for, "%s/webcit ", setup_directory);
 
        /* Pound through /etc/inittab line by line.  Set have_entry to 1 if
-        * an entry is found which we believe starts webserver.
+        * an entry is found which we believe starts webcit.
         */
        infp = fopen("/etc/inittab", "r");
        if (infp == NULL) {
@@ -333,11 +333,22 @@ void install_init_scripts(void)
 #endif
        char hostname[128];
        char portname[128];
+       char command[SIZ];
        struct utsname my_utsname;
        struct stat etcinitd;
        FILE *fp;
        char *initfile = "/etc/init.d/webcit";
 
+       fp = fopen(initfile, "r");
+       if (fp != NULL) {
+               if (yesno("WebCit already appears to be configured to start at boot.\n"
+                  "Would you like to keep your boot configuration as is?\n", 1) == 1) {
+                       return;
+               }
+               fclose(fp);
+               
+       }
+
        /* Otherwise, prompt the user to create an entry. */
        snprintf(question, sizeof question,
                "Would you like to automatically start WebCit at boot?"
@@ -357,10 +368,15 @@ void install_init_scripts(void)
         * in a previous install, if we are upgrading: read them out of
         * the existing init script.
         */
-
-       if ((stat("/etc/init.d/",&etcinitd) == -1) && 
+       if ((stat("/etc/init.d/", &etcinitd) == -1) && 
            (errno == ENOENT))
-               initfile = PREFIX"/webcit.init";
+       {
+               if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
+                   (errno == ENOENT))
+                       initfile = WEBCITDIR"/webcit.init";
+               else
+                       initfile = "/etc/rc.d/init.d/webcit";
+       }
 
        fp = fopen(initfile, "r");
        if (fp != NULL) {
@@ -429,11 +445,7 @@ void install_init_scripts(void)
        }
 
 
-       fp = fopen("/etc/init.d/webcit", "w");
-       if (fp == NULL) {
-               display_error("Cannot create /etc/init.d/webcit");
-               return;
-       }
+       fp = fopen(initfile, "w");
 
        fprintf(fp,     "#!/bin/sh\n"
                        "\n"
@@ -449,7 +461,7 @@ void install_init_scripts(void)
                        "case \"$1\" in\n"
                        "\n"
                        "start)         echo -n \"Starting WebCit... \"\n"
-                       "               if   $WEBCIT_DIR/webserver "
+                       "               if   $WEBCIT_DIR/webcit "
                                                        "-D/var/run/webcit.pid "
                                                        "-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
@@ -459,7 +471,7 @@ void install_init_scripts(void)
                        "               fi\n");
 #ifdef HAVE_OPENSSL
        fprintf(fp,     "               echo -n \"Starting WebCit SSL... \"\n"
-                       "               if  $WEBCIT_DIR/webserver "
+                       "               if  $WEBCIT_DIR/webcit "
                                                        "-D/var/run/webcit-ssl.pid "
                                                        "-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
                        "               then\n"
@@ -498,12 +510,14 @@ void install_init_scripts(void)
        );
 
        fclose(fp);
-       chmod("/etc/init.d/webcit", 0755);
+       chmod(initfile, 0755);
 
        /* Set up the run levels. */
        system("/bin/rm -f /etc/rc?.d/[SK]??webcit 2>/dev/null");
-       system("for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/webcit /etc/rc$x.d/S84webcit ; done 2>/dev/null");
-       system("for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s /etc/init.d/webcit /etc/rc$x.d/K15webcit ; done 2>/dev/null");
+       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);
+       system(command);
+       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);
+       system(command);
 
 }
 
@@ -571,7 +585,7 @@ int main(int argc, char *argv[])
        }
 
        /* Get started in a valid setup directory. */
-       strcpy(setup_directory, PREFIX);
+       strcpy(setup_directory, WEBCITDIR);
        if ( (using_web_installer) && (getenv("WEBCIT") != NULL) ) {
                strcpy(setup_directory, getenv("WEBCIT"));
        }