Annotation of coherent/d/etc/build/install.c, revision 1.1

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

unix.superglobalmegacorp.com

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