Annotation of coherent/b/etc/Build_401/install.c, revision 1.1

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

unix.superglobalmegacorp.com

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