home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-05  |  3.8 KB  |  184 lines

  1. #include <alloca.h>
  2. #include <newt.h>
  3. #include <sys/wait.h>
  4. #include <malloc.h>
  5. #include <strings.h>
  6. #include <unistd.h>
  7.  
  8. #include "config.h"
  9. #include "install.h"
  10. #include "kickstart.h"
  11. #include "log.h"
  12.  
  13. static int runConfigTool(char * rootPath,
  14.              char * tool, int argc, char ** inargv) {
  15.     int childpid;
  16.     int status;
  17.     char ** argv = NULL;
  18.  
  19.     if (inargv) {
  20.     argv = alloca(sizeof(*argv) * (argc + 1));
  21.     memcpy(argv, inargv, sizeof(*argv) * argc);
  22.     argv[argc] = NULL;
  23.     argv[0] = tool;
  24.     }
  25.  
  26.     logMessage("running %s", tool);
  27.     newtSuspend();
  28.  
  29.     if (!(childpid = fork())) {
  30.     if (!testing) chroot(rootPath);
  31.     chdir("/");
  32.  
  33.     if (argv)
  34.         execv(argv[0], argv);
  35.     else
  36.         execl(tool, tool, NULL);
  37.     exit(2);
  38.     } 
  39.  
  40.     waitpid(childpid, &status, 0);
  41.     newtResume();
  42.     if (WIFEXITED(status)) {
  43.     if (WEXITSTATUS(status) == 1) {
  44.         logMessage("    tool canceled");
  45.         return INST_CANCEL;
  46.     } else if (WEXITSTATUS(status) == 0) {
  47.         return 0;
  48.     }
  49.     }
  50.  
  51.     logMessage("    tool failed");
  52.  
  53.     return INST_ERROR;
  54. }
  55.  
  56. int timeConfig(char * rootPath) {
  57.     char ** argv; 
  58.     int argc;
  59.     char * otherArgv[] = { "timeconfig", "--back", NULL };
  60.  
  61.     if (kickstart && !ksGetCommand(KS_CMD_TIMEZONE, NULL, &argc, &argv)) {
  62.     return runConfigTool(rootPath, "/usr/sbin/timeconfig", argc, argv);
  63.     }
  64.  
  65.     return runConfigTool(rootPath, "/usr/sbin/timeconfig", 2, otherArgv);
  66. }
  67.  
  68. int servicesConfig(char * rootPath) {
  69.     char * otherArgv[] = { "/usr/sbin/ntsysv", "--back", NULL };
  70.  
  71.     return runConfigTool(rootPath, "/usr/sbin/ntsysv", 2, otherArgv);
  72. }
  73.  
  74. int mouseConfig(char * rootPath) {
  75.     char ** argv, **kargv; 
  76.     int argc;
  77.     int i;
  78.     int shift;
  79.     
  80.     if (!kickstart || ksGetCommand(KS_CMD_MOUSE, NULL, &argc, &argv)) {
  81.     /* no options, or in normal mode */
  82.     argc = 1;
  83.     argv = alloca(sizeof(*argv));
  84.     argv[0] = alloca(sizeof("mouse")+1);
  85.     strcpy(argv[0],"mouse");
  86.     }    
  87.  
  88.     /* add --kickstart and --expert options */
  89.     shift = 0;
  90.     if (kickstart)
  91.     shift++;
  92.     if (expert)
  93.     shift++;
  94.     
  95.     kargv = alloca(sizeof(*argv) * (argc + shift));
  96.     memcpy(kargv, argv, sizeof(*argv) * argc);
  97.     for (i=argc+shift-1; i>shift; i--)
  98.     kargv[i]=kargv[i-shift];
  99.  
  100.     i = 1;
  101.     if (kickstart) {
  102.     kargv[i] = "--kickstart";
  103.     i++;
  104.     }
  105.     if (expert) {
  106.     kargv[i] = "--expert";
  107.     kargv[i] = "--noprobe";
  108.     i++;
  109.     }
  110.  
  111.     argc += shift;
  112.     return runConfigTool(rootPath, "/usr/sbin/mouseconfig", argc, kargv);
  113. }
  114.  
  115. int xfree86Config(char * rootPath, char *mode) {
  116.     char **argv, **kargv;
  117.     int argc;
  118.     int i;
  119.     int shift;
  120.  
  121.     argv  = NULL;
  122.     kargv = NULL;
  123.     if (!kickstart || ksGetCommand(KS_CMD_XCONFIG, argv, &argc, &argv)) {
  124.     /* they didnt specify anything, or in normal mode */
  125.     argc=1;
  126.     argv=alloca(sizeof(*argv));
  127.     argv[0]=alloca(strlen("xconfig"+1));
  128.     strcpy(argv[0],"xconfig");
  129.     }
  130.     
  131.     /* make commandline, add mode and --kickstart, and maybe --expert */
  132.     shift = 1;
  133.     if (expert)
  134.     shift++;
  135.     if (kickstart)
  136.     shift++;
  137.  
  138.     kargv = alloca(sizeof(*argv) * (argc + shift));
  139.     memcpy(kargv, argv, sizeof(*argv) * argc);
  140.     for (i=argc+shift-1; i>shift; i--)
  141.     kargv[i]=kargv[i-shift];
  142.  
  143.     i = 1;
  144.     if (kickstart) {
  145.     kargv[i] = "--kickstart";
  146.     i++;
  147.     }
  148.     if (expert) {
  149.     kargv[i] = "--expert";
  150.     i++;
  151.     }
  152.  
  153.     kargv[i] = alloca(strlen(mode)+1);
  154.     strcpy(kargv[i],mode);
  155.     i++;
  156.     
  157.     argc+=shift;
  158.     
  159.     return runConfigTool(rootPath, "/usr/X11R6/bin/Xconfigurator",argc, kargv);
  160. }
  161.  
  162. void configPCMCIA(char * rootPath, char * pcic) {
  163.     FILE * f;
  164.     char * path;
  165.  
  166.     if (testing) return;
  167.  
  168.     path = alloca(strlen(rootPath) + 30);
  169.     sprintf(path, "%s/etc/sysconfig/pcmcia", rootPath);
  170.  
  171.     f = fopen(path, "w");
  172.     if (pcic) {
  173.     fprintf(f, "PCMCIA=yes\n");
  174.     fprintf(f, "PCIC=%s\n", pcic);
  175.     } else {
  176.     fprintf(f, "PCMCIA=no\n");
  177.     fprintf(f, "PCIC=\n");
  178.     }
  179.  
  180.     fprintf(f, "PCIC_OPTS=\nCORE_OPTS=\n");
  181.  
  182.     fclose(f);
  183. }
  184.