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

Annotation of src/usr.sbin/sysinst/upgrade.c, Revision 1.16

1.16    ! martin      1: /*     $NetBSD: upgrade.c,v 1.15 2020/02/06 19:08:38 martin Exp $      */
1.1       dholland    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. The name of Piermont Information Systems Inc. may not be used to endorse
                     18:  *    or promote products derived from this software without specific prior
                     19:  *    written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
                     22:  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
                     25:  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     26:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     27:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     28:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     29:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     30:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
                     31:  * THE POSSIBILITY OF SUCH DAMAGE.
                     32:  *
                     33:  */
                     34:
                     35: /* upgrade.c -- upgrade an installation. */
                     36:
                     37: #include <sys/param.h>
                     38: #include <stdio.h>
                     39: #include <curses.h>
                     40: #include <errno.h>
                     41: #include "defs.h"
                     42: #include "msg_defs.h"
                     43: #include "menu_defs.h"
                     44:
                     45: /*
                     46:  * local prototypes
                     47:  */
                     48: static int save_X(const char *);
                     49: static int merge_X(const char *);
                     50:
                     51: /*
                     52:  * Do the system upgrade.
                     53:  */
                     54: void
                     55: do_upgrade(void)
                     56: {
1.12      martin     57:        struct install_partition_desc install = {};
1.2       martin     58:        int retcode = 0;
                     59:        partman_go = 0;
1.1       dholland   60:
                     61:        msg_display(MSG_upgradeusure);
1.4       martin     62:        if (!ask_noyes(NULL))
1.1       dholland   63:                return;
                     64:
1.13      martin     65:        if (find_disks(msg_string(MSG_upgrade), !root_is_read_only()) < 0)
1.1       dholland   66:                return;
                     67:
1.15      martin     68:        if (pm->parts == NULL && !pm->cur_system && !pm->no_part) {
1.10      martin     69:                hit_enter_to_continue(MSG_noroot, NULL);
                     70:                return;
                     71:        }
                     72:
1.15      martin     73:        if (!pm->cur_system && pm->parts != NULL) {
1.12      martin     74:                if (pm->parts->pscheme->pre_update_verify) {
                     75:                        if (pm->parts->pscheme->pre_update_verify(pm->parts))
                     76:                                pm->parts->pscheme->write_to_disk(pm->parts);
                     77:                }
                     78:
                     79:                install_desc_from_parts(&install, pm->parts);
1.15      martin     80:        } else if (pm->cur_system) {
1.12      martin     81:                install.cur_system = true;
1.7       martin     82:        }
                     83:
1.9       martin     84:        if (set_swap_if_low_ram(&install) < 0)
                     85:                return;
                     86:
1.7       martin     87:        if (md_pre_update(&install) < 0)
                     88:                goto free_install;
1.1       dholland   89:
1.7       martin     90:        if (mount_disks(&install) != 0)
                     91:                goto free_install;
1.1       dholland   92:
                     93:
                     94:        /*
                     95:         * Save X symlink, ...
                     96:         */
                     97:        if (save_X("/usr/X11R6"))
1.7       martin     98:                goto free_install;
1.1       dholland   99:        if (save_X("/usr/X11R7"))
1.7       martin    100:                goto free_install;
1.1       dholland  101:
                    102: #ifdef AOUT2ELF
                    103:        move_aout_libs();
                    104: #endif
                    105:        /* Do any md updating of the file systems ... e.g. bootblocks,
                    106:           copy file systems ... */
1.7       martin    107:        /* XXX pass install here too */
                    108:        if (!md_update(&install))
                    109:                goto free_install;
1.1       dholland  110:
                    111:        wrefresh(curscr);
                    112:        wmove(stdscr, 0, 0);
                    113:        wclear(stdscr);
                    114:        wrefresh(stdscr);
                    115:
                    116:        /* Done with disks. Ready to get and unpack tarballs. */
1.2       martin    117:        process_menu(MENU_distset, &retcode);
                    118:        if (retcode == 0)
1.7       martin    119:                goto free_install;
1.1       dholland  120:        if (get_and_unpack_sets(1, MSG_disksetupdoneupdate,
                    121:            MSG_upgrcomplete, MSG_abortupgr) != 0)
1.7       martin    122:                goto free_install;
1.1       dholland  123:
1.7       martin    124:        if (md_post_extract(&install))
                    125:                goto free_install;
1.1       dholland  126:
                    127:        merge_X("/usr/X11R6");
                    128:        merge_X("/usr/X11R7");
                    129:
                    130:        sanity_check();
1.7       martin    131:
                    132: free_install:
                    133:        free_install_desc(&install);
1.1       dholland  134: }
                    135:
                    136: /*
                    137:  * Save X symlink to X.old so it can be recovered later
                    138:  */
                    139: static int
                    140: save_X(const char *xroot)
                    141: {
                    142:        char newx[MAXPATHLEN], oldx[MAXPATHLEN];
                    143:
                    144:        strlcpy(newx, xroot, sizeof(newx));
                    145:        strlcat(newx, "/bin/X", sizeof(newx));
                    146:        strlcpy(oldx, newx, sizeof(oldx));
                    147:        strlcat(oldx, ".old", sizeof(oldx));
                    148:
                    149:        /* Only care for X if it's a symlink */
                    150:        if (target_symlink_exists_p(newx)) {
                    151:                if (target_symlink_exists_p(oldx)) {
1.8       christos  152:                        msg_fmt_display(MSG_X_oldexists,
                    153:                            "%s%s%s%s%s%s%s%s%s%s%s",
1.1       dholland  154:                            xroot, xroot, xroot, xroot, xroot, xroot, xroot,
1.8       christos  155:                            xroot, xroot, xroot, xroot);
1.7       martin    156:                        hit_enter_to_continue(NULL, NULL);
1.1       dholland  157:                        return EEXIST;
                    158:                }
                    159:
                    160: #ifdef DEBUG
                    161:                printf("saving %s as %s ...", newx, oldx);
                    162: #endif
                    163:
                    164:                /* Move target .../X to .../X.old.  Abort on error. */
                    165:                mv_within_target_or_die(newx, oldx);
                    166:        }
                    167:
                    168:        return 0;
                    169: }
                    170:
                    171: /*
                    172:  * Merge back saved target X files after unpacking the new
                    173:  * sets has completed.
                    174:  */
                    175: static int
                    176: merge_X(const char *xroot)
                    177: {
                    178:        char newx[MAXPATHLEN], oldx[MAXPATHLEN];
                    179:
                    180:        strlcpy(newx, xroot, sizeof(newx));
                    181:        strlcat(newx, "/bin/X", sizeof(newx));
                    182:        strlcpy(oldx, newx, sizeof(oldx));
                    183:        strlcat(oldx, ".old", sizeof(oldx));
                    184:
                    185:        if (target_symlink_exists_p(oldx)) {
                    186:                /* Only move back X if it's a symlink - we don't want
                    187:                 * to restore old binaries */
                    188:                mv_within_target_or_die(oldx, newx);
                    189:        }
                    190:
                    191:        return 0;
                    192: }
                    193:
                    194: /*
                    195:  * Unpacks sets,  clobbering existing contents.
                    196:  */
                    197: void
1.11      martin    198: do_reinstall_sets()
1.1       dholland  199: {
1.12      martin    200:        struct install_partition_desc install = {};
1.2       martin    201:        int retcode = 0;
1.11      martin    202:        partman_go = 0;
1.1       dholland  203:
                    204:        unwind_mounts();
                    205:        msg_display(MSG_reinstallusure);
1.4       martin    206:        if (!ask_noyes(NULL))
1.1       dholland  207:                return;
                    208:
1.13      martin    209:        if (find_disks(msg_string(MSG_reinstall), !root_is_read_only()) < 0)
1.1       dholland  210:                return;
                    211:
1.16    ! martin    212:        if (!pm->cur_system && pm->parts != NULL) {
1.12      martin    213:                install_desc_from_parts(&install, pm->parts);
1.16    ! martin    214:        } else if (pm->cur_system) {
1.12      martin    215:                install.cur_system = true;
1.11      martin    216:        }
                    217:
                    218:        if (mount_disks(&install) != 0)
                    219:                goto free_install;
1.1       dholland  220:
                    221:        /* Unpack the distribution. */
1.2       martin    222:        process_menu(MENU_distset, &retcode);
                    223:        if (retcode == 0)
1.11      martin    224:                goto free_install;
1.1       dholland  225:        if (get_and_unpack_sets(0, NULL, MSG_unpackcomplete, MSG_abortunpack) != 0)
1.11      martin    226:                goto free_install;
1.1       dholland  227:
                    228:        sanity_check();
1.11      martin    229:
                    230: free_install:
                    231:        free_install_desc(&install);
1.1       dholland  232: }

CVSweb <webmaster@jp.NetBSD.org>