Annotation of coherent/f/tmp/inst2/install.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * install.c
                      3:  *
                      4:  * Last hacked 07/01/93, COH 4.2-Alpha
                      5:  *
                      6:  * Install COHERENT disks on a system.
                      7:  * This is the back end of the initial COHERENT installation procedure;
                      8:  * the first part is in build.c.
                      9:  * Without the -b option, it installs an update to an existing COH system.
                     10:  * If -b or -u selected, suppress copying of files from /compressed directory
                     11:  * on floppies and actually uncompress and unarchive them into place.
                     12:  * Uses common routines in build0.o: cc install.c build0.c
                     13:  * Usage: install [ -bdv ] id device ndisks
                     14:  * Options:
                     15:  *     -b      Build: special processing for build, part 2.
                     16:  *     -d      Debug, echo commands without executing
                     17:  *     -u      Update: special processing for build, part 2.
                     18:  *     -v      Verbose
                     19:  */
                     20: 
                     21: #include <stdio.h>
                     22: #include "build0.h"
                     23: 
                     24: #define        VERSION         "3.1"
                     25: #define        USAGE           "Usage: /etc/install [ -bduv ] id device ndisks\n"
                     26: 
                     27: /* Forward. */
                     28: void   config();
                     29: void   done();
                     30: void   install();
                     31: int    newdisk();
                     32: void   newusr();
                     33: void   setbaud();
                     34: 
                     35: /* Globals. */
                     36: int    bflag;                          /* build flag           */
                     37: char   *device;                        /* special device name  */
                     38: char   *id;                            /* disk id              */
                     39: int    ndisks;                         /* number of disks      */
                     40: int    update;                         /* perform update install */
                     41: 
                     42: /*
                     43:  * Baud rate table for serial port initialization.
                     44:  * The index in the table gives the baud rate value from <sgtty.h>.
                     45:  */
                     46: #if !_I386
                     47: #define        MAXBAUD 17
                     48: int    baudrate[MAXBAUD+1] = {
                     49:        0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2000,
                     50:        2400, 3600, 4800, 7200, 9600, 19200
                     51: };
                     52: #endif
                     53: 
                     54: main(argc, argv) int argc; char *argv[];
                     55: {
                     56:        register char *s;
                     57:        register int i;
                     58: 
                     59:        argv0 = argv[0];
                     60:        abortmsg = 1;
                     61:        usagemsg = USAGE;
                     62:        if (argc > 1 && argv[1][0] == '-') {
                     63:                for (s = &argv[1][1]; *s; ++s) {
                     64:                        switch(*s) {
                     65:                        case 'b':       ++bflag;        break;
                     66:                        case 'd':       ++dflag;        break;
                     67:                        case 'u':       ++update;       break;
                     68:                        case 'v':       ++vflag;        break;
                     69:                        case 'V':
                     70:                                fprintf(stderr, "%s: V%s\n", argv0, VERSION);
                     71:                                break;
                     72:                        default:        usage();        break;
                     73:                        }
                     74:                }
                     75:                --argc;
                     76:                ++argv;
                     77:        }
                     78:        if (argc != 4)
                     79:                usage();
                     80:        id = argv[1];
                     81:        device = argv[2];
                     82:        ndisks = atoi(argv[3]);
                     83: 
                     84:        /* Add line to /etc/install.log. */
                     85:        sprintf(cmd, "/bin/echo /etc/install: %s %s %s >>/etc/install.log",
                     86:                argv[1], argv[2], argv[3]);
                     87:        sys(cmd, S_NONFATAL);
                     88:        sys("/bin/date >>/etc/install.log", S_NONFATAL);
                     89: 
                     90: #if 0
                     91:        /* Remove old ids and postfile if present. */
                     92:        if (bflag || update)    /* Leave disk 1 marker on /. */
                     93:                sprintf(cmd, "/bin/rm -f /%s.[023456789]* /conf/%s.post", id, id);
                     94:        else
                     95:                sprintf(cmd, "/bin/rm -f /%s.* /conf/%s.post", id, id);
                     96:        sys(cmd, S_IGNORE);
                     97: #endif /* bob h proposed removal of code */
                     98: 
                     99:        if (bflag || update)
                    100:                sys("/etc/mount.all", S_NONFATAL);
                    101:        cls(0);
                    102: 
                    103: #if    0
                    104:        /* Execute prefile.  Not required for the moment. */
                    105:        sprintf(cmd, "/conf/%s.pre", id);
                    106:        if (exists(cmd)) {
                    107:                cls(0);
                    108:                sys(cmd, S_NONFATAL);
                    109:        }
                    110: #endif
                    111: 
                    112:        /*
                    113:         * Install disks.
                    114:         * Disk numbers are 2 to ndisks for build, 1 to ndisks otherwise.
                    115:         */
                    116:        for (i = ((bflag || update) ? 2 : 1); i <= ndisks; ++i)
                    117:                install(i);
                    118:        if (bflag)
                    119:                newusr();
                    120:        if (bflag || update) {
                    121:                config();
                    122:                done();
                    123:        }
                    124: 
                    125:        /* Delete ids and execute postfile if present. */
                    126:        sprintf(cmd, "/bin/rm -f /%s.*", id);
                    127:        sys(cmd, S_NONFATAL);
                    128:        sprintf(cmd, "/conf/%s.post", id);
                    129:        if (exists(cmd)) {
                    130:                cls(0);
                    131:                if (update)
                    132:                        strcat(cmd, " -u");
                    133:                sys(cmd, S_NONFATAL);
                    134:        }
                    135:        sys("/bin/echo /etc/install: success >>/etc/install.log", S_NONFATAL);
                    136:        sys("/bin/date >>/etc/install.log", S_NONFATAL);
                    137:        sys("/bin/echo >>/etc/install.log", S_NONFATAL);
                    138:        if (bflag || update)
                    139:                sys("/etc/umount.all", S_NONFATAL);
                    140:        cls(0);
                    141:        printf("You have completed the %s procedure successfully.\n",
                    142:                (update) ? "update" : "installation");
                    143:        printf("Don't forget to remove the last diskette from the disk drive.\n");
                    144:        sync();
                    145:        exit(0);
                    146: }
                    147: 
                    148: /*
                    149:  * System-specific configuration.  A lot of grunge.
                    150:  */
                    151: void
                    152: config()
                    153: {
                    154:        register int port, i, polled, parallel;
                    155:        char device[6+1];               /* e.g. "com1pr" */
                    156:        char rdevice[7+1];
                    157:        char backend[15];
                    158:        char spool_dev[29];
                    159: 
                    160:        cls(1);
                    161: 
                    162: #if 0  /* well, waddayaknow... Norm finally added but we've switched to Taylor
                    163:         * UUCP. Oh well...
                    164:         */
                    165:        if (bflag) {
                    166:                /*
                    167:                 * graft customer's serial number into /usr/lib/uucp/L.sys to
                    168:                 * reduce tech calls.
                    169:                 */
                    170:                sprintf(cmd, "/bin/sed -e s/SERIALNUM/`cat /etc/serialno`/g "
                    171:                        "</usr/lib/uucp/L.sys >/tmp/L.sys ; "
                    172:                        "/bin/cp /tmp/L.sys /usr/lib/uucp/L.sys ; /bin/rm /tmp/L.sys");
                    173:                sys(cmd, S_NONFATAL);
                    174:        }
                    175: # endif
                    176:        if (yes_no("Does your computer system have a modem")) {
                    177:                printf(
                    178: "You must specify which asychronous serial line your modem will use.\n"
                    179: "See the article \"%s\" in the COHERENT documentation for details.\n",
                    180: #if _I386
                    181:                "asy");
                    182: #else
                    183:                "com");
                    184: #endif
                    185:                port = get_int(1, 4, "Enter 1 to 4 for COM1 through COM4:");
                    186:                i = (port > 2) ? port - 2 : port;       /* 1 or 2 */
                    187:                printf(
                    188: "If your computer system uses both ports COM%d and COM%d,\n"
                    189: "one must be run in polled mode rather than interrupt-driven.\n",
                    190:                        i, i+2);
                    191:                polled = yes_no("Do you want to run COM%d in polled mode", port);
                    192:                sprintf(cmd, "/bin/ln -f /dev/com%d%sl /dev/modem",
                    193:                        port, (polled) ? "p" : "");
                    194:                if (sys(cmd, S_NONFATAL) == 0)
                    195:                        printf("/dev/modem is now linked to /dev/com%d%sl.\n",
                    196:                                port, (polled) ? "p" : "");
                    197:                printf("\n");
                    198:        }
                    199:        if (bflag && yes_no("Does your computer system have a printer")) {
                    200:                printf(
                    201: "Your printer is connected to your computer system either through a\n"
                    202: "parallel port or through a serial port; most printers are connected\n"
                    203: "through parallel port LPT1.\n"
                    204:                        );
                    205: again:
                    206:                parallel = yes_no("Is your printer connected through a parallel port");
                    207:                if (parallel) {
                    208:                        strcpy(backend,"default");
                    209:                        port = get_int(1, 3, "Enter 1, 2 or 3 for port LPT1, LPT2 or LPT3:");
                    210:                        sprintf(device, "lpt%d", port);
                    211:                } else {
                    212:                        strcpy(backend,"hpserial");
                    213:                        port = get_int(1, 4, "Enter 1 to 4 for COM1 through COM4:");
                    214:                        i = (port > 2) ? port - 2 : port;
                    215:                        printf(
                    216: "If your computer system uses both ports COM%d and COM%d,\n"
                    217: "one must be run in polled mode rather than interrupt-driven.\n",
                    218:                                i, i+2);
                    219:                        polled = yes_no("Do you want to run COM%d in polled mode", port);
                    220:                        sprintf(device, "com%d%sl", port, (polled) ? "p" : "");
                    221:                        printf("By default, COM%d runs at 9600 baud.\n", port);
                    222: #if _I386
                    223:                        printf(
                    224: "If you need a different speed, refer to lexicon article \"asy\" after\n"
                    225: "the installation procedure completes.\n");
                    226: #else
                    227:                        if (yes_no("Does your device use a different baud rate"))
                    228:                                setbaud(port);
                    229: #endif
                    230:                }
                    231:                printf(
                    232: "Even if you know which port your printer uses under your existing operating\n"
                    233: "system, under COHERENT the port name may be different. For this reason,\n"
                    234: "we strongly recommend that you test your printer configuration.\n"
                    235: "If you test your printer configuration and see no output on your printer,\n"
                    236: "you can try a different configuration until you find the one which works.\n"
                    237:                        );
                    238:                if (yes_no("Do you want to test whether your printer configuration is correct")) {
                    239:                        /* The command below is backgrounded in case it hangs. */
                    240:                        if (yes_no("Is your printer a PostScript language printer"))
                    241:                                sprintf(cmd,
                    242: "/bin/echo 'PostScript\ndevice\n/dev/%s.' | prps -p10 >/dev/%s&",
                    243:                                device, device);
                    244:                        else    /* non-PS printer */
                    245:                                sprintf(cmd,
                    246: "/bin/echo -n 'This is printing on device /dev/%s.\r\n\014' >/dev/%s&",
                    247:                                device, device);        /* 014 is formfeed */
                    248:                        printf("Testing /dev/%s: process ", device);
                    249:                        fflush(stdout);
                    250:                        sys(cmd, S_IGNORE);
                    251:                        if (!yes_no("\nDid output appear on your printer")) {
                    252:                                printf(
                    253: "Now try again, specifying a different port for your printer.\n"
                    254:                                        );
                    255:                                goto again;
                    256:                        }
                    257:                }
                    258:                sprintf(cmd, "/bin/ln -f /dev/%s /dev/lp", device);
                    259:                if (sys(cmd, S_NONFATAL) == 0){
                    260:                        printf("/dev/lp is now linked to /dev/%s.\n", device);
                    261:                        strcpy(spool_dev,"/dev/lp");
                    262:                }
                    263:                if (yes_no("Is your printer an HP LaserJet compatible laser printer")) {
                    264:                        sprintf(cmd, "/bin/ln -f /dev/%s /dev/hp", device);
                    265:                        if (sys(cmd, S_NONFATAL) == 0){
                    266:                                printf("/dev/hp is now linked to /dev/%s.\n", device);
                    267:                                strcpy(spool_dev,"/dev/hp");
                    268:                        }                       
                    269:                        sprintf(rdevice, "%s%s", (parallel) ? "r" : "", device);
                    270:                        sprintf(cmd, "/bin/ln -f /dev/%s /dev/rhp", rdevice);
                    271:                        if (sys(cmd, S_NONFATAL) == 0)
                    272:                                printf("/dev/rhp is now linked to /dev/%s.\n", rdevice);
                    273:                }
                    274:                printf("\n");
                    275:                sprintf(cmd,"echo \"printer=main,%s,%s\" >> /usr/spool/mlp/controls",
                    276:                        spool_dev, backend);
                    277:                if (sys(cmd, S_NONFATAL) == 0){
                    278:                        printf("Print spooler controls file configured.\n");
                    279:                }
                    280:        }
                    281: }
                    282: 
                    283: /*
                    284:  * Finish up.
                    285:  */
                    286: void
                    287: done()
                    288: {
                    289:        cls(1);
                    290: 
                    291:        /* Replace the install version of /etc/brc with the normal one. */
                    292:        sys("/bin/rm /etc/brc", S_NONFATAL);
                    293:        sys("/bin/ln -f /etc/brc.coh /etc/brc", S_NONFATAL);
                    294: }
                    295: 
                    296: /*
                    297:  * Install disk n.
                    298:  */
                    299: void
                    300: install(n) int n;
                    301: {
                    302:        register int i;
                    303: 
                    304: again:
                    305:        get_line("Insert a disk from the installation kit into the drive and hit <Enter>.",
                    306:                n);
                    307:        sprintf(cmd, "/etc/mount %s /mnt -r", device);
                    308:        if (sys(cmd, S_NONFATAL))
                    309:                goto again;
                    310:        if ((i = newdisk()) == 0) {
                    311:                sprintf(cmd, "/etc/umount %s", device);
                    312:                sys(cmd, S_NONFATAL);
                    313:                goto again;
                    314:        }
                    315:        printf("Copying disk %d.  This will take a few minutes...\n", i);
                    316:        sprintf(cmd, "/bin/cpdir -ad%s -smnt %s %s /mnt /",
                    317:                (vflag) ? "v" : "",
                    318:                (bflag || update) ? "-scompressed" : "",
                    319:                (update) ? "`cat /conf/upd_suppress`" : "");
                    320:        sys(cmd, S_FATAL);
                    321:        /*
                    322:         * If called from /etc/build as part of the COHERENT install/update,
                    323:         * suppress any files in directory "compressed" and then go install
                    324:         * those files individually while uncompressing and unarchiving.
                    325:         */
                    326:        if ((bflag || update) && is_dir("/mnt/compressed")) {
                    327:                sys(
                    328: "cd / \n"
                    329: "for Archive in /mnt/compressed/* \n"
                    330: "do \n"
                    331: "      case $Archive in \n"
                    332: "      *tar*)  \n"
                    333: "              /usr/bin/gunzip -c $Archive | /usr/bin/ustar xf - ;;\n"
                    334: "      *cpio*) \n"
                    335: "              /usr/bin/gunzip -c $Archive | /usr/bin/cpio -icdmu ;;\n"
                    336: "      /mnt/compressed/\\*) \n"
                    337: "              exit 0 ;;\n"
                    338: "      *) echo Unknown archive type in file $Archive ;;\n"
                    339: "      esac \n"
                    340: "done \n",
                    341:                    S_NONFATAL);
                    342:        }
                    343:        sprintf(cmd, "/etc/umount %s", device);
                    344:        sys(cmd, S_NONFATAL);
                    345:        sprintf(cmd, "/bin/echo /etc/install: disk %d installed >>/etc/install.log",
                    346:                i);
                    347:        sys(cmd, S_NONFATAL);
                    348:        sync();
                    349: }
                    350: 
                    351: /*
                    352:  * Check for an appropriate id on the disk on /mnt.
                    353:  * Return 0 if not found, disk number otherwise.
                    354:  */
                    355: int
                    356: newdisk()
                    357: {
                    358:        register int i;
                    359:        static int n;
                    360: 
                    361:        if (dflag)
                    362:                return (n >= ndisks) ? 0 : ++n;
                    363:        for (i = 1; i <= ndisks; i++) {
                    364:                sprintf(buf, "/mnt/%s.%d", id, i);
                    365:                if (!exists(buf))
                    366:                        continue;                       /* not disk i */
                    367:                sprintf(buf, "/%s.%d", id, i);
                    368:                if (exists(buf)) {                      /* exists on root */
                    369:                        printf(
                    370:                                "The disk you inserted is disk %d of the kit;\n"
                    371:                                "it has already been copied to the hard disk.\n"
                    372:                                "Please try again.\n",
                    373:                                i);
                    374:                        return 0;                       /* wrong disk */
                    375:                }
                    376:                return i;                               /* ok */
                    377:        }
                    378:        printf(
                    379:                "The disk you inserted is not part of the kit.\n"
                    380:                "Please try again.\n"
                    381:                );
                    382:        return 0;                                       /* no id found */
                    383: }
                    384: 
                    385: /*
                    386:  * Install new users.
                    387:  */
                    388: void
                    389: newusr()
                    390: {
                    391:        static int flag = 0;
                    392:        register int n, status, passwd;
                    393:        register char *s;
                    394:        char homeparent[80], user[80];
                    395: 
                    396:        cls(0);
                    397:        printf(
                    398: "Your COHERENT system initially allows logins by users \"root\" (superuser)\n"
                    399: "and \"bin\" (system administrator).  In addition, the password file contains\n"
                    400: "special entries for \"remacc\" (to control remote access, e.g. via modem),\n"
                    401: "\"daemon\" (the spooler), \"sys\" (to access system information), and\n"
                    402: "\"uucp\" (for communication with other COHERENT systems).\n"
                    403: "\n"
                    404: "If your system has multiple users or allows remote logins, you should assign\n"
                    405: "a password to each user.\n"
                    406: "\n"
                    407:        );
                    408:        passwd = yes_no("Do you want to assign passwords to users");
                    409:        if (passwd) {
                    410:                printf("You must enter each password twice.\n");
                    411:                if (yes_no("Do you want to assign a password for user \"root\""))
                    412:                        sys("passwd root", S_NONFATAL);
                    413:                if (yes_no("Do you want to assign a remote access password"))
                    414:                        sys("passwd remacc", S_NONFATAL);
                    415:                if (yes_no("Do you want to assign a password for user \"bin\""))
                    416:                        sys("passwd bin", S_NONFATAL);
                    417:                if (yes_no("Do you want to assign a password for user \"uucp\""))
                    418:                        sys("passwd uucp", S_NONFATAL);
                    419:        }
                    420:        printf(
                    421: "\nYou should create a login for each additional user of your system.\n"
                    422:                );
                    423:        for (n = 0; ;) {
                    424:                if (!yes_no("Do you want to create another login"))
                    425:                        break;
                    426:                if (++n == 1) {
                    427:                        printf(
                    428: "You must specify a login name, a full name and a shell for each user.\n"
                    429: "Joe Smith might have login name \"joe\" and full name \"Joseph H. Smith.\"\n"
                    430: "His home directory would be in \"/usr\" by default, namely \"/usr/joe\".\n"
                    431: "Do not type quotation marks around the names you enter.\n"
                    432:                                );
                    433:                        if (yes_no("Do you want home directories in \"/usr\"")) 
                    434:                                strcpy(homeparent, "/usr");
                    435:                        else {
                    436: again:
                    437:                                s = get_line("Where do you want home directories?");
                    438:                                if (*s != '/') {
                    439:                                        printf(
                    440: "Please enter a name beginning with '/', such as \"/u\".\n"
                    441:                                                );
                    442:                                        goto again;
                    443:                                } else
                    444:                                        strcpy(homeparent, s);
                    445:                        }
                    446:                        if ((status = is_dir(homeparent)) == -1) {
                    447:                                printf("%s is not a directory, try again.\n",
                    448:                                        homeparent);
                    449:                                goto again;
                    450:                        } else if (status == 0) {
                    451:                                sprintf(cmd, "/bin/mkdir -r %s", homeparent);
                    452:                                if (sys(cmd, S_NONFATAL) != 0)
                    453:                                        goto again;
                    454:                        }
                    455:                }
                    456:                s = get_line("Login name:");
                    457:                strcpy(user, s);
                    458:                sprintf(cmd, "/etc/newusr %s ", s);
                    459:                s = get_line("Full name:");
                    460:                sprintf(&cmd[strlen(cmd)], "\"%s\" %s", s, homeparent);
                    461:                if (flag == 0) {
                    462:                        ++flag;         /* print only first time through */
                    463:                        printf(
                    464: "COHERENT includes three different command line interpreters, or shells.\n"
                    465: "A command line interpreter is a program which reads and executes each\n"
                    466: "command which the user types.  The available command line interpreters\n"
                    467: "are the Bourne shell (/bin/sh), the Korn shell (/usr/bin/ksh) and the\n"
                    468: "visual (full screen) shell (/usr/bin/vsh).\n\n"
                    469: "Use the visual shell if you prefer a menu-driven interface.  Use the\n"
                    470: "Bourne shell if you are not sure which shell to use.\n\n"
                    471: "After you have finished installing COHERENT, you can change the shell\n"
                    472: "for any user by editing the password file /etc/passwd.\n"
                    473:                                );
                    474:                }
                    475:                for (s = NULL; s == NULL; ) {
                    476:                        if (yes_no("Do you want to user %s to use the Bourne shell (/bin/sh)",
                    477:                                        user))
                    478:                                s = "/bin/sh";
                    479:                        else if (yes_no("Do you want to user %s to use the visual shell (/usr/bin/vsh)",
                    480:                                        user))
                    481:                                s = "/usr/bin/vsh";
                    482:                        else if (yes_no("Do you want to user %s to use the Korn shell (/usr/bin/ksh)",
                    483:                                        user))
                    484:                                s = "/usr/bin/ksh";
                    485:                        else
                    486:                                printf("You must specify either the Bourne, visual or Korn shell.\n");
                    487:                }
                    488:                sprintf(&cmd[strlen(cmd)], " %s", s);
                    489:                sys(cmd, S_NONFATAL);
                    490:                if (passwd && yes_no("Do you want to assign a password for user \"%s\"", user)) {
                    491:                        sprintf(cmd, "passwd %s", user);
                    492:                        sys(cmd, S_NONFATAL);
                    493:                }
                    494:        }
                    495:        printf("\n");
                    496: }
                    497: 
                    498: #if !_I386
                    499: /*
                    500:  * Set a serial port baud rate.
                    501:  * Patch the running COHERENT image and /coherent accordingly.
                    502:  */
                    503: void
                    504: setbaud(port) int port;
                    505: {
                    506:        register int i, baud;
                    507: 
                    508: again:
                    509:        printf(
                    510: "The COHERENT serial port driver supports the following baud rates:\n"
                    511: "      50, 75, 110, 134, 150, 200, 300, 600, 1200,\n"
                    512: "      1800, 2000, 2400, 3600, 4800, 7200, 9600, 19200\n"
                    513: "Enter the baud rate of your device (or 0 if your baud rate"
                    514:                );
                    515:        baud = get_int(0, 19200, "is not listed):");
                    516:        if (baud == 0)
                    517:                return;
                    518:        for (i = 1; i <= MAXBAUD; i++)
                    519:                if (baudrate[i] == baud)
                    520:                        break;
                    521:        if (i > MAXBAUD) {
                    522:                printf("COHERENT does not support baud rate %d.\n", baud);
                    523:                goto again;
                    524:        }
                    525: 
                    526:        /* Patch the running COHERENT for possible subsequent test. */
                    527:        sprintf(cmd, "/conf/patch -K /coherent C%dBAUD_=%d", port, i);
                    528:        sys(cmd, S_NONFATAL);
                    529: 
                    530:        /* Patch /coherent for specified baudrate. */
                    531:        sprintf(cmd, "/conf/patch /coherent C%dBAUD_=%d", port, i);
                    532:        sys(cmd, S_NONFATAL);
                    533: }
                    534: #endif /* !_I386 */
                    535: /* end of install.c */
                    536: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.