[BACK]Return to upgrade.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / distrib / utils / sysinst

Annotation of src/distrib/utils/sysinst/upgrade.c, Revision 1.15

1.15    ! mrg         1: /*     $NetBSD: upgrade.c,v 1.14 1998/02/20 00:37:17 jonathan Exp $    */
1.1       phil        2:
                      3: /*
                      4:  * Copyright 1997 Piermont Information Systems Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Written by Philip A. Nelson for Piermont Information Systems Inc.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  * 3. All advertising materials mentioning features or use of this software
                     18:  *    must display the following acknowledgement:
                     19:  *      This product includes software develooped for the NetBSD Project by
                     20:  *      Piermont Information Systems Inc.
                     21:  * 4. The name of Piermont Information Systems Inc. may not be used to endorse
                     22:  *    or promote products derived from this software without specific prior
                     23:  *    written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
                     26:  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
                     29:  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     30:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     31:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     32:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     33:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     34:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
                     35:  * THE POSSIBILITY OF SUCH DAMAGE.
                     36:  *
                     37:  */
                     38:
                     39: /* upgrade.c -- upgrade an installation. */
                     40:
                     41: #include <stdio.h>
                     42: #include <curses.h>
1.9       jonathan   43: #include <errno.h>
1.1       phil       44: #include "defs.h"
                     45: #include "msg_defs.h"
                     46: #include "menu_defs.h"
                     47:
1.9       jonathan   48: /*
                     49:  * local prototypes
                     50:  */
1.10      jonathan   51: void   check_prereqs __P((void));
                     52: int    save_etc __P((void));
                     53: int    merge_etc __P((void));
1.9       jonathan   54:
1.15    ! mrg        55: /*
        !            56:  * Do the system upgrade.
        !            57:  */
        !            58: void
        !            59: do_upgrade()
1.1       phil       60: {
                     61:
1.15    ! mrg        62:        doingwhat = msg_string(MSG_upgrade);
        !            63:
        !            64:        msg_display(MSG_upgradeusure);
        !            65:        process_menu(MENU_noyes);
1.1       phil       66:        if (!yesno)
                     67:                return;
                     68:
1.15    ! mrg        69:        get_ramsize();
1.2       phil       70:
1.15    ! mrg        71:        if (find_disks() < 0)
1.2       phil       72:                return;
1.11      jonathan   73:
                     74:        /* if we need the user to mount root, ask them to. */
                     75:        if (must_mount_root()) {
                     76:                msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
1.15    ! mrg        77:                process_menu(MENU_ok);
1.11      jonathan   78:                return;
                     79:        }
1.2       phil       80:
                     81:        if (!fsck_disks())
1.1       phil       82:                return;
1.5       phil       83:
1.14      jonathan   84:        /*
                     85:         * Move target /etc -> target /etc.old so existing configuration
                     86:         * isn't overwritten by upgrade.
                     87:         */
1.9       jonathan   88:        if (save_etc())
                     89:                return;
                     90:
1.1       phil       91:
1.3       phil       92:        /* Do any md updating of the file systems ... e.g. bootblocks,
                     93:           copy file systems ... */
1.15    ! mrg        94:        if (!md_update())
1.2       phil       95:                return;
1.8       jonathan   96:
                     97:        /* Done with disks. Ready to get and unpack tarballs. */
1.9       jonathan   98:        msg_display(MSG_disksetupdone);
1.15    ! mrg        99:        process_menu(MENU_ok);
1.1       phil      100:
1.6       jonathan  101:        get_and_unpack_sets(MSG_upgrcomplete, MSG_abortupgr);
1.9       jonathan  102:
1.14      jonathan  103:        /* Copy back any files we should restore after the upgrade.*/
1.10      jonathan  104:        merge_etc();
                    105:
1.9       jonathan  106:        sanity_check();
                    107: }
                    108:
                    109: /*
                    110:  * save target /etc files.
                    111:  * if target /etc.old exists, print a warning message and give up.
                    112:  * otherwise move /etc into target /etc.old, and then copy
                    113:  * back files we might want during the installation --  in case
                    114:  * we are upgrading the target root.
                    115:  */
1.15    ! mrg       116: int
        !           117: save_etc()
1.9       jonathan  118: {
                    119:
1.12      jonathan  120:        if (target_dir_exists_p("/etc.old")) {
1.9       jonathan  121:                msg_display(MSG_etc_oldexists);
1.15    ! mrg       122:                process_menu(MENU_ok);
1.9       jonathan  123:                return EEXIST;
                    124:        }
                    125:
                    126: #ifdef DEBUG
                    127:        printf("saving /etc as /etc.old...");
                    128: #endif
                    129:
1.14      jonathan  130:        /* Move target /etc to /etc.old.  Abort on error. */
1.15    ! mrg       131:        mv_within_target_or_die("/etc", "/etc.old");
1.9       jonathan  132:
1.14      jonathan  133:        /* now make an /etc that should let the user reboot. */
1.9       jonathan  134:        make_target_dir("/etc");
                    135:
                    136: #ifdef DEBUG
                    137:        printf("Copying essential files back into new /etc...");
                    138: #endif
                    139:        /* essential stuff */
                    140:        cp_within_target("/etc.old/ld.so.cache", "/etc/");
                    141:        cp_within_target("/etc.old/ld.so.conf", "/etc/");
                    142:        cp_within_target("/etc.old/resolv.conf", "/etc/");
                    143:
                    144:        /*
                    145:         * do NOT create fstab so that restarting an incomplete
                    146:         * upgrade (eg., after power failure) will fail, and
                    147:         * force the user to check and restore their old /etc.
                    148:         */
                    149:
                    150:        /* general config */
                    151:        cp_within_target("/etc.old/rc", "/etc/");
                    152:        cp_within_target("/etc.old/rc.conf", "/etc/");
                    153:        cp_within_target("/etc.old/rc.local", "/etc/");
                    154:
                    155:        /* network config */
                    156:        cp_within_target("/etc.old/ifconfig.*", "/etc/");
                    157:        cp_within_target("/etc.old/myname", "/etc/");
                    158:        cp_within_target("/etc.old/mygate", "/etc/");
                    159:        cp_within_target("/etc.old/defaultdomain", "/etc/");
                    160:
                    161:        /* old-style network config */
                    162:        cp_within_target("/etc.old/hostname.*", "/etc/");
                    163:
                    164:        return 0;
1.10      jonathan  165: }
                    166:
                    167: /*
                    168:  * Merge back saved target /etc files after unpacking the new
                    169:  * sets has completed.
                    170:  */
1.15    ! mrg       171: int
        !           172: merge_etc()
1.10      jonathan  173: {
1.15    ! mrg       174:
1.10      jonathan  175:        /* just move back fstab, so we can boot cleanly.  */
                    176:        cp_within_target("/etc.old/fstab", "/etc/");
                    177:
                    178:        return 0;
1.12      jonathan  179: }
                    180:
                    181: /*
                    182:  * Unpacks sets,  clobbering existintg contents.
                    183:  */
                    184: void
1.15    ! mrg       185: do_reinstall_sets()
1.12      jonathan  186: {
                    187:
                    188:        unwind_mounts();
1.15    ! mrg       189:        msg_display(MSG_reinstallusure);
        !           190:        process_menu(MENU_noyes);
1.12      jonathan  191:        if (!yesno)
                    192:                return;
                    193:
1.15    ! mrg       194:        if (find_disks() < 0)
1.12      jonathan  195:                return;
                    196:
                    197:        /* if we need the user to mount root, ask them to. */
                    198:        if (must_mount_root()) {
                    199:                msg_display(MSG_pleasemountroot, diskdev, diskdev, diskdev);
1.15    ! mrg       200:                process_menu(MENU_ok);
1.12      jonathan  201:                return;
                    202:        }
                    203:
                    204:        if (!fsck_disks())
                    205:                return;
1.13      fvdl      206:
1.15    ! mrg       207:        fflush(stdout);
        !           208:        puts(CL);
        !           209:        wrefresh(stdscr);
1.12      jonathan  210:
                    211:        /* Unpack the distribution. */
                    212:        get_and_unpack_sets(MSG_unpackcomplete, MSG_abortunpack);
                    213:
                    214:        sanity_check();
                    215:
1.1       phil      216: }

CVSweb <webmaster@jp.NetBSD.org>