1999-03-08 22:42:30 +03:00
|
|
|
/* $NetBSD: util.c,v 1.34 1999/03/08 19:42:30 garbled Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software develooped for the NetBSD Project by
|
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* util.c -- routines that don't really fit anywhere else... */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1997-11-02 11:20:40 +03:00
|
|
|
#include <stdarg.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <unistd.h>
|
1997-10-18 01:10:39 +04:00
|
|
|
#include <sys/types.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/sysctl.h>
|
1997-10-18 01:10:39 +04:00
|
|
|
#include <sys/stat.h>
|
1997-09-27 04:09:22 +04:00
|
|
|
#include <curses.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "defs.h"
|
1997-10-18 01:10:39 +04:00
|
|
|
#include "md.h"
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* local prototypes
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
struct tarstats {
|
1997-12-05 17:00:59 +03:00
|
|
|
int nselected;
|
|
|
|
int nfound;
|
|
|
|
int nnotfound;
|
|
|
|
int nerror;
|
|
|
|
int nsuccess;
|
|
|
|
} tarstats;
|
|
|
|
|
|
|
|
void extract_file __P((char *path));
|
|
|
|
int extract_dist __P((void));
|
|
|
|
int distribution_sets_exist_p __P((const char *path));
|
1997-11-05 10:28:20 +03:00
|
|
|
static int check_for __P((const char *type, const char *pathname));
|
1997-10-07 08:01:29 +04:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* XXX these are WAY bogus!
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dir_exists_p(path)
|
|
|
|
const char *path;
|
1997-12-05 17:00:59 +03:00
|
|
|
{
|
|
|
|
register int result;
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
result = (run_prog(0, 0, "test -d %s", path) == 0);
|
1997-12-05 17:00:59 +03:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
|
|
|
file_exists_p(path)
|
|
|
|
const char *path;
|
1997-12-05 17:00:59 +03:00
|
|
|
{
|
|
|
|
register int result;
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
result = (run_prog(0, 0, "test -f %s", path) == 0);
|
1997-12-05 17:00:59 +03:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
|
|
|
distribution_sets_exist_p(path)
|
|
|
|
const char *path;
|
1997-12-05 17:00:59 +03:00
|
|
|
{
|
|
|
|
char buf[STRSIZE];
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
snprintf(buf, STRSIZE, "%s/%s", path, "kern.tgz");
|
|
|
|
result = result && file_exists_p(buf);
|
|
|
|
|
|
|
|
snprintf(buf, STRSIZE, "%s/%s", path, "etc.tgz");
|
|
|
|
result = result && file_exists_p(buf);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
get_ramsize()
|
1997-10-07 08:01:29 +04:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
long len = sizeof(long);
|
1997-10-07 08:01:29 +04:00
|
|
|
int mib[2] = {CTL_HW, HW_PHYSMEM};
|
|
|
|
|
|
|
|
sysctl(mib, 2, (void *)&ramsize, (size_t *)&len, NULL, 0);
|
|
|
|
|
|
|
|
/* Find out how many Megs ... round up. */
|
|
|
|
rammb = (ramsize + MEG - 1) / MEG;
|
|
|
|
}
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
static int asked = 0;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
ask_sizemult()
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (!asked) {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_sizechoice, dlcylsize);
|
|
|
|
process_menu(MENU_sizechoice);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
asked = 1;
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
reask_sizemult()
|
1997-11-01 02:00:32 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-01 02:00:32 +03:00
|
|
|
asked = 0;
|
1998-06-20 17:05:48 +04:00
|
|
|
ask_sizemult();
|
1997-11-01 02:00:32 +03:00
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Returns 1 for "y" or "Y" and "n" otherwise. CR => default.
|
|
|
|
*/
|
1997-09-27 03:02:53 +04:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
ask_ynquestion(char *quest, char def, ...)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
char line[STRSIZE];
|
|
|
|
va_list ap;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
va_start(ap, def);
|
1998-06-20 17:05:48 +04:00
|
|
|
vsnprintf(line, STRSIZE, quest, ap);
|
1997-09-27 03:02:53 +04:00
|
|
|
va_end(ap);
|
|
|
|
|
1997-11-06 02:32:44 +03:00
|
|
|
if (def)
|
1998-06-20 17:05:48 +04:00
|
|
|
printf("%s [%c]: ", line, def);
|
1997-11-06 02:32:44 +03:00
|
|
|
else
|
1998-06-20 17:05:48 +04:00
|
|
|
printf("%s: ", line);
|
1997-09-27 03:02:53 +04:00
|
|
|
c = getchar();
|
|
|
|
if (c == '\n')
|
|
|
|
return def == 'y';
|
|
|
|
|
|
|
|
while (getchar() != '\n') /* eat characters */;
|
|
|
|
|
|
|
|
return c == 'y' || c == 'Y';
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
run_makedev()
|
1997-10-01 09:04:24 +04:00
|
|
|
{
|
1997-12-05 17:00:59 +03:00
|
|
|
char *owd;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_makedev);
|
1997-10-18 01:10:39 +04:00
|
|
|
sleep (1);
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
owd = getcwd(NULL,0);
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* make /dev, in case the user didn't extract it. */
|
|
|
|
make_target_dir("/dev");
|
1997-11-02 11:20:40 +03:00
|
|
|
target_chdir_or_die("/dev");
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/bin/sh MAKEDEV all");
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
chdir(owd);
|
|
|
|
free(owd);
|
1997-10-18 01:10:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Load files from floppy. Requires a /mnt2 directory for mounting them.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
get_via_floppy()
|
1997-10-18 01:10:39 +04:00
|
|
|
{
|
|
|
|
char distname[STRSIZE];
|
|
|
|
char fddev[STRSIZE] = "/dev/fd0a";
|
|
|
|
char fname[STRSIZE];
|
|
|
|
char fullname[STRSIZE];
|
1999-03-08 22:42:30 +03:00
|
|
|
char catcmd[STRSIZE];
|
1997-10-29 04:06:42 +03:00
|
|
|
distinfo *list;
|
1997-10-18 01:10:39 +04:00
|
|
|
char post[4];
|
|
|
|
int mounted = 0;
|
1997-10-30 03:03:32 +03:00
|
|
|
int first;
|
1997-10-18 01:10:39 +04:00
|
|
|
struct stat sb;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
cd_dist_dir("unloading from floppy");
|
1997-10-29 04:06:42 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt_add(MSG_fddev, fddev, fddev, STRSIZE);
|
1997-10-18 01:10:39 +04:00
|
|
|
|
|
|
|
list = dist_list;
|
1997-10-29 04:06:42 +03:00
|
|
|
while (list->name) {
|
1998-06-20 17:05:48 +04:00
|
|
|
strcpy(post, ".aa");
|
|
|
|
snprintf(distname, STRSIZE, "%s%s", list->name, dist_postfix);
|
1997-10-30 03:03:32 +03:00
|
|
|
while (list->getit && strcmp(&post[1],list->fdlast) <= 0) {
|
1998-06-20 17:05:48 +04:00
|
|
|
snprintf(fname, STRSIZE, "%s%s", list->name, post);
|
|
|
|
snprintf(fullname, STRSIZE, "/mnt2/%s", fname);
|
1997-10-30 03:03:32 +03:00
|
|
|
first = 1;
|
1997-10-18 01:10:39 +04:00
|
|
|
while (!mounted || stat(fullname, &sb)) {
|
1997-10-30 03:03:32 +03:00
|
|
|
if (mounted)
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0,"/sbin/umount /mnt2");
|
1997-10-30 03:03:32 +03:00
|
|
|
if (first)
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_fdmount, fname);
|
1997-10-30 03:03:32 +03:00
|
|
|
else
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_fdnotfound, fname);
|
|
|
|
process_menu(MENU_fdok);
|
1997-10-30 03:03:32 +03:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
1999-01-21 11:02:17 +03:00
|
|
|
while (run_prog(0, 0, "/sbin/mount -r -t %s %s /mnt2",
|
1998-06-20 17:05:48 +04:00
|
|
|
fdtype, fddev)) {
|
|
|
|
msg_display(MSG_fdremount, fname);
|
|
|
|
process_menu(MENU_fdremount);
|
1997-10-18 01:10:39 +04:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mounted = 1;
|
1997-10-30 03:03:32 +03:00
|
|
|
first = 0;
|
1997-10-18 01:10:39 +04:00
|
|
|
}
|
1999-03-08 22:42:30 +03:00
|
|
|
sprintf(catcmd, "/bin/cat %s >> %s",
|
|
|
|
fullname, distname);
|
|
|
|
if (logging)
|
|
|
|
(void)fprintf(log, "%s\n", catcmd);
|
|
|
|
if (scripting)
|
|
|
|
(void)fprintf(script, "%s\n", catcmd);
|
|
|
|
do_system(catcmd);
|
1997-10-30 03:03:32 +03:00
|
|
|
if (post[2] < 'z')
|
|
|
|
post[2]++;
|
1997-10-18 01:10:39 +04:00
|
|
|
else
|
1998-06-20 17:05:48 +04:00
|
|
|
post[2] = 'a', post[1]++;
|
1997-10-18 01:10:39 +04:00
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/sbin/umount /mnt2");
|
1997-10-18 01:10:39 +04:00
|
|
|
mounted = 0;
|
|
|
|
list++;
|
|
|
|
}
|
|
|
|
#ifndef DEBUG
|
1997-11-02 11:20:40 +03:00
|
|
|
chdir("/"); /* back to current real root */
|
1997-10-18 01:10:39 +04:00
|
|
|
#endif
|
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
1997-10-20 10:13:25 +04:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Get from a CDROM distribution.
|
|
|
|
*/
|
1997-10-20 10:13:25 +04:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
get_via_cdrom()
|
1997-10-20 10:13:25 +04:00
|
|
|
{
|
1997-12-05 17:00:59 +03:00
|
|
|
char tmpdir[STRSIZE];
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Fill in final default path, similar to ftp path
|
|
|
|
* because we expect the CDROM structure to be the
|
|
|
|
* same as the ftp site.
|
|
|
|
*/
|
|
|
|
strncat(cdrom_dir, machine, STRSIZE - strlen(cdrom_dir));
|
|
|
|
strncat(cdrom_dir, ftp_prefix, STRSIZE - strlen(cdrom_dir));
|
1997-11-05 04:23:06 +03:00
|
|
|
|
1998-05-15 19:12:29 +04:00
|
|
|
/* Get CD-rom device name and path within CD-rom */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_cdromsource);
|
1998-05-15 19:12:29 +04:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
again:
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/sbin/umount /mnt2");
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-10-20 10:13:25 +04:00
|
|
|
/* Mount it */
|
1999-01-21 11:02:17 +03:00
|
|
|
if (run_prog(0, 0, "/sbin/mount -rt cd9660 /dev/%sa /mnt2", cdrom_dev)) {
|
1997-12-05 17:00:59 +03:00
|
|
|
msg_display(MSG_badsetdir, cdrom_dev);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_cdrombadmount);
|
1997-10-20 10:13:25 +04:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(tmpdir, STRSIZE, "%s/%s", "/mnt2", cdrom_dir);
|
|
|
|
|
|
|
|
/* Verify distribution files exist. */
|
|
|
|
if (distribution_sets_exist_p(tmpdir) == 0) {
|
|
|
|
msg_display(MSG_badsetdir, tmpdir);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_cdrombadmount);
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!yesno)
|
|
|
|
return (0);
|
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
1997-10-20 10:13:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return location, don't clean... */
|
1997-12-05 17:00:59 +03:00
|
|
|
strncpy(ext_dir, tmpdir, STRSIZE);
|
1997-10-20 10:13:25 +04:00
|
|
|
clean_dist_dir = 0;
|
|
|
|
mnt2_mounted = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
1997-10-29 04:06:42 +03:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get from a pathname inside an unmounted local filesystem
|
|
|
|
* (e.g., where sets were preloaded onto a local DOS partition)
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
int
|
|
|
|
get_via_localfs()
|
1997-11-06 01:45:53 +03:00
|
|
|
{
|
1997-12-05 17:00:59 +03:00
|
|
|
char tmpdir[STRSIZE];
|
|
|
|
|
1997-11-06 01:45:53 +03:00
|
|
|
/* Get device, filesystem, and filepath */
|
|
|
|
process_menu (MENU_localfssource);
|
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
again:
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/sbin/umount /mnt2");
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-11-06 01:45:53 +03:00
|
|
|
/* Mount it */
|
1999-01-21 11:02:17 +03:00
|
|
|
if (run_prog(0, 0, "/sbin/mount -rt %s /dev/%s /mnt2", localfs_fs,
|
1997-11-06 01:45:53 +03:00
|
|
|
localfs_dev)) {
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_localfsbadmount, localfs_dir, localfs_dev);
|
|
|
|
process_menu(MENU_localfsbadmount);
|
1997-11-06 01:45:53 +03:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!ignorerror)
|
1998-06-20 17:05:48 +04:00
|
|
|
goto again;
|
1997-12-05 17:00:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(tmpdir, STRSIZE, "%s/%s", "/mnt2", localfs_dir);
|
|
|
|
|
|
|
|
/* Verify distribution files exist. */
|
|
|
|
if (distribution_sets_exist_p(tmpdir) == 0) {
|
|
|
|
msg_display(MSG_badsetdir, tmpdir);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_localfsbadmount);
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!yesno)
|
|
|
|
return 0;
|
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
1997-11-06 01:45:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return location, don't clean... */
|
1997-12-05 17:00:59 +03:00
|
|
|
strncpy(ext_dir, tmpdir, STRSIZE);
|
1997-11-06 01:45:53 +03:00
|
|
|
clean_dist_dir = 0;
|
|
|
|
mnt2_mounted = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
1997-10-29 04:06:42 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Get from an already-mounted pathname.
|
|
|
|
*/
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
int get_via_localdir(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Get device, filesystem, and filepath */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_localdirsource);
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
again:
|
|
|
|
/* Complain if not a directory */
|
|
|
|
if (dir_exists_p(localfs_dir) == 0) {
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_badlocalsetdir, localfs_dir);
|
|
|
|
process_menu(MENU_localdirbad);
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!yesno)
|
|
|
|
return (0);
|
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify distribution files exist. */
|
|
|
|
if (distribution_sets_exist_p(localfs_dir) == 0) {
|
|
|
|
msg_display(MSG_badsetdir, localfs_dir);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_localdirbad);
|
1997-12-05 17:00:59 +03:00
|
|
|
if (!yesno)
|
|
|
|
return (0);
|
|
|
|
if (!ignorerror)
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return location, don't clean... */
|
1998-06-20 17:05:48 +04:00
|
|
|
strncpy(ext_dir, localfs_dir, STRSIZE);
|
1997-12-05 17:00:59 +03:00
|
|
|
clean_dist_dir = 0;
|
|
|
|
mnt2_mounted = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
cd_dist_dir(forwhat)
|
|
|
|
char *forwhat;
|
1997-10-29 04:06:42 +03:00
|
|
|
{
|
1997-11-11 03:43:31 +03:00
|
|
|
char *cwd;
|
|
|
|
|
1997-11-02 11:20:40 +03:00
|
|
|
/* ask user for the mountpoint. */
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_prompt(MSG_distdir, dist_dir, dist_dir, STRSIZE, forwhat);
|
1997-11-02 11:20:40 +03:00
|
|
|
|
|
|
|
/* make sure the directory exists. */
|
|
|
|
make_target_dir(dist_dir);
|
|
|
|
|
1997-10-29 04:06:42 +03:00
|
|
|
clean_dist_dir = 1;
|
1997-11-02 11:20:40 +03:00
|
|
|
target_chdir_or_die(dist_dir);
|
1997-11-11 03:43:31 +03:00
|
|
|
|
|
|
|
/* Set ext_dir for absolute path. */
|
1998-06-20 17:05:48 +04:00
|
|
|
cwd = getcwd(NULL,0);
|
|
|
|
strncpy(ext_dir, cwd, STRSIZE);
|
1997-11-11 03:43:31 +03:00
|
|
|
free (cwd);
|
1997-10-29 04:06:42 +03:00
|
|
|
}
|
|
|
|
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Support for custom distribution fetches / unpacks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
toggle_getit(num)
|
|
|
|
int num;
|
1997-10-29 04:06:42 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-10-29 04:06:42 +03:00
|
|
|
dist_list[num].getit ^= 1;
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
show_cur_distsets()
|
1997-10-29 04:06:42 +03:00
|
|
|
{
|
|
|
|
distinfo *list;
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_cur_distsets);
|
1997-10-29 04:06:42 +03:00
|
|
|
list = dist_list;
|
|
|
|
while (list->name) {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_printf_add("%s%s\n", list->desc,
|
|
|
|
list->getit ? msg_string(MSG_yes) : msg_string(MSG_no));
|
1997-10-29 04:06:42 +03:00
|
|
|
list++;
|
|
|
|
}
|
|
|
|
}
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1997-11-04 04:39:03 +03:00
|
|
|
/* Do we want a verbose extract? */
|
|
|
|
static int verbose = -1;
|
|
|
|
|
|
|
|
void
|
1998-06-20 17:05:48 +04:00
|
|
|
ask_verbose_dist()
|
1997-11-04 04:39:03 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-04 04:39:03 +03:00
|
|
|
if (verbose < 0) {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_verboseextract);
|
|
|
|
process_menu(MENU_noyes);
|
1997-11-04 04:39:03 +03:00
|
|
|
verbose = yesno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-06-20 17:05:48 +04:00
|
|
|
extract_file(path)
|
|
|
|
char *path;
|
1997-11-04 04:39:03 +03:00
|
|
|
{
|
|
|
|
char *owd;
|
|
|
|
int tarexit;
|
|
|
|
|
|
|
|
owd = getcwd (NULL,0);
|
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
/* check tarfile exists */
|
|
|
|
if (!file_exists_p(path)) {
|
|
|
|
tarstats.nnotfound++;
|
|
|
|
ask_ynquestion(msg_string(MSG_notarfile), 0, path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tarstats.nfound++;
|
1997-11-05 10:28:20 +03:00
|
|
|
/* cd to the target root. */
|
1997-11-04 04:39:03 +03:00
|
|
|
target_chdir_or_die("/");
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* now extract set files files into "./". */
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)printf(msg_string(MSG_extracting), path);
|
1999-01-21 11:02:17 +03:00
|
|
|
tarexit = run_prog(0, 1, "pax -zr%spe -f %s", verbose ? "v" : "", path);
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-11-06 02:32:44 +03:00
|
|
|
/* Check tarexit for errors and give warning. */
|
1997-12-05 17:00:59 +03:00
|
|
|
if (tarexit) {
|
|
|
|
tarstats.nerror++;
|
1998-06-20 17:05:48 +04:00
|
|
|
ask_ynquestion(msg_string(MSG_tarerror), 0, path);
|
1997-12-05 17:00:59 +03:00
|
|
|
sleep(3);
|
|
|
|
} else {
|
|
|
|
tarstats.nsuccess++;
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
chdir(owd);
|
|
|
|
free(owd);
|
1997-11-04 04:39:03 +03:00
|
|
|
}
|
|
|
|
|
1997-11-11 03:43:31 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/*
|
|
|
|
* Extract_dist **REQUIRES** an absolute path in ext_dir. Any code
|
1997-11-11 03:43:31 +03:00
|
|
|
* that sets up dist_dir for use by extract_dist needs to put in the
|
|
|
|
* full path name to the directory.
|
|
|
|
*/
|
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
int
|
1998-06-20 17:05:48 +04:00
|
|
|
extract_dist()
|
1997-11-04 04:39:03 +03:00
|
|
|
{
|
|
|
|
char distname[STRSIZE];
|
|
|
|
char fname[STRSIZE];
|
|
|
|
distinfo *list;
|
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
/* reset failure/success counters */
|
1998-08-10 06:23:45 +04:00
|
|
|
memset(&tarstats, 0, sizeof(tarstats));
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/*endwin();*/
|
1997-11-04 04:39:03 +03:00
|
|
|
list = dist_list;
|
|
|
|
while (list->name) {
|
1997-11-05 10:48:52 +03:00
|
|
|
if (list->getit) {
|
1997-12-05 17:00:59 +03:00
|
|
|
tarstats.nselected++;
|
1998-06-20 17:05:48 +04:00
|
|
|
(void)snprintf(distname, STRSIZE, "%s%s", list->name,
|
|
|
|
dist_postfix);
|
|
|
|
(void)snprintf(fname, STRSIZE, "%s/%s", ext_dir,
|
|
|
|
distname);
|
|
|
|
extract_file(fname);
|
1997-11-05 10:48:52 +03:00
|
|
|
}
|
1997-11-04 04:39:03 +03:00
|
|
|
list++;
|
|
|
|
}
|
1997-12-05 17:00:59 +03:00
|
|
|
|
1997-11-06 02:32:44 +03:00
|
|
|
puts(CL);
|
|
|
|
wrefresh(stdscr);
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
if (tarstats.nerror == 0 && tarstats.nsuccess == tarstats.nselected) {
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(MSG_endtarok);
|
|
|
|
process_menu(MENU_ok);
|
1997-12-05 17:00:59 +03:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* We encountered errors. Let the user know. */
|
|
|
|
msg_display(MSG_endtar,
|
|
|
|
tarstats.nselected, tarstats.nnotfound,
|
|
|
|
tarstats.nfound, tarstats.nsuccess, tarstats.nerror);
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_ok);
|
1997-12-05 17:00:59 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1997-11-04 04:39:03 +03:00
|
|
|
}
|
|
|
|
|
1997-11-02 12:41:57 +03:00
|
|
|
/*
|
1998-06-20 17:05:48 +04:00
|
|
|
* Get and unpack the distribution.
|
|
|
|
* show success_msg if installation completes. Otherwise,,
|
|
|
|
* show failure_msg and wait for the user to ack it before continuing.
|
1997-11-02 12:41:57 +03:00
|
|
|
* success_msg and failure_msg must both be 0-adic messages.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
void
|
|
|
|
get_and_unpack_sets(success_msg, failure_msg)
|
|
|
|
int success_msg;
|
|
|
|
int failure_msg;
|
1997-11-02 12:41:57 +03:00
|
|
|
{
|
1998-06-20 17:05:48 +04:00
|
|
|
|
1997-11-13 06:06:44 +03:00
|
|
|
/* Ensure mountpoint for distribution files exists in current root. */
|
1999-01-21 11:02:17 +03:00
|
|
|
(void) mkdir("/mnt2", S_IRWXU| S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH);
|
|
|
|
if (scripting)
|
|
|
|
(void)fprintf(script, "mkdir /mnt2\nchmod 755 /mnt2\n");
|
1997-11-13 06:06:44 +03:00
|
|
|
|
1998-02-09 09:55:27 +03:00
|
|
|
/* Find out which files to "get" if we get files. */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_distset);
|
1998-02-09 09:55:27 +03:00
|
|
|
|
1997-11-02 12:41:57 +03:00
|
|
|
/* Get the distribution files */
|
1998-06-20 17:05:48 +04:00
|
|
|
process_menu(MENU_distmedium);
|
1998-02-09 09:55:27 +03:00
|
|
|
|
1997-11-02 12:41:57 +03:00
|
|
|
if (nodist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (got_dist) {
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
/* ask user whether to do normal or verbose extraction */
|
1998-06-20 17:05:48 +04:00
|
|
|
ask_verbose_dist();
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
/* Extract the distribution, abort on errors. */
|
1998-06-20 17:05:48 +04:00
|
|
|
if (extract_dist()) {
|
1997-12-05 17:00:59 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
1997-11-02 12:41:57 +03:00
|
|
|
|
|
|
|
/* Configure the system */
|
1998-06-20 17:05:48 +04:00
|
|
|
run_makedev();
|
1997-11-02 12:41:57 +03:00
|
|
|
|
|
|
|
/* Other configuration. */
|
|
|
|
mnt_net_config();
|
|
|
|
|
1997-11-11 03:43:31 +03:00
|
|
|
/* Clean up dist dir (use absolute path name) */
|
1997-11-02 12:41:57 +03:00
|
|
|
if (clean_dist_dir)
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/bin/rm -rf %s", ext_dir);
|
1997-11-02 12:41:57 +03:00
|
|
|
|
|
|
|
/* Mounted dist dir? */
|
|
|
|
if (mnt2_mounted)
|
1999-01-21 11:02:17 +03:00
|
|
|
run_prog(0, 0, "/sbin/umount /mnt2");
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1998-06-20 17:05:48 +04:00
|
|
|
/* Install/Upgrade complete ... reboot or exit to script */
|
|
|
|
msg_display(success_msg);
|
|
|
|
process_menu(MENU_ok);
|
1997-12-05 17:00:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bad:
|
1998-06-20 17:05:48 +04:00
|
|
|
msg_display(failure_msg);
|
|
|
|
process_menu(MENU_ok);
|
1997-11-02 12:41:57 +03:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1997-12-05 17:00:59 +03:00
|
|
|
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* Do a quick sanity check that the target can reboot.
|
|
|
|
* return 1 if everything OK, 0 if there is a problem.
|
|
|
|
* Uses a table of files we expect to find after a base install/upgrade.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* test flag and pathname to check for after unpacking. */
|
|
|
|
struct check_table { const char *testarg; const char *path;} checks[] = {
|
|
|
|
{ "-f", "/netbsd" },
|
1998-02-07 12:32:32 +03:00
|
|
|
{ "-d", "/etc" },
|
1997-11-05 10:28:20 +03:00
|
|
|
{ "-f", "/etc/fstab" },
|
|
|
|
{ "-f", "/sbin/init" },
|
|
|
|
{ "-f", "/bin/sh" },
|
1997-11-13 06:06:44 +03:00
|
|
|
{ "-f", "/etc/rc" },
|
|
|
|
{ "-f", "/etc/rc.subr" },
|
|
|
|
{ "-f", "/etc/rc.conf" },
|
1997-11-05 10:28:20 +03:00
|
|
|
{ "-d" "/dev" },
|
|
|
|
{ "-c", "/dev/console" },
|
|
|
|
/* XXX check for rootdev in target /dev? */
|
|
|
|
{ "-f", "/etc/fstab" },
|
|
|
|
{ "-f", "/sbin/fsck" },
|
|
|
|
{ "-f", "/sbin/fsck_ffs" },
|
|
|
|
{ "-f", "/sbin/mount" },
|
|
|
|
{ "-f", "/sbin/mount_ffs" },
|
|
|
|
{ "-f", "/sbin/mount_nfs" },
|
1997-11-13 06:06:44 +03:00
|
|
|
#if defined(DEBUG) || defined(DEBUG_CHECK)
|
|
|
|
{ "-f", "/foo/bar" }, /* bad entry to exercise warning */
|
1997-11-05 10:28:20 +03:00
|
|
|
#endif
|
|
|
|
{ 0, 0 }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check target for a single file.
|
|
|
|
*/
|
1998-06-20 17:05:48 +04:00
|
|
|
static int
|
|
|
|
check_for(type, pathname)
|
|
|
|
const char *type;
|
|
|
|
const char *pathname;
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
1997-11-06 12:02:36 +03:00
|
|
|
int found;
|
1997-11-05 10:28:20 +03:00
|
|
|
|
1997-11-06 12:02:36 +03:00
|
|
|
found = (target_test(type, pathname) == 0);
|
|
|
|
if (found == 0)
|
1997-11-05 10:28:20 +03:00
|
|
|
msg_display(MSG_rootmissing, pathname);
|
1997-11-06 12:02:36 +03:00
|
|
|
return found;
|
1997-11-05 10:28:20 +03:00
|
|
|
}
|
|
|
|
|
1998-02-07 12:32:32 +03:00
|
|
|
/*
|
|
|
|
* Check that all the files in check_table are present in the
|
|
|
|
* target root. Warn if not found.
|
|
|
|
*/
|
1997-11-05 10:28:20 +03:00
|
|
|
int
|
|
|
|
sanity_check()
|
|
|
|
{
|
|
|
|
int target_ok = 1;
|
|
|
|
struct check_table *p;
|
|
|
|
|
|
|
|
for (p = checks; p->path; p++) {
|
|
|
|
target_ok = target_ok && check_for(p->testarg, p->path);
|
|
|
|
}
|
|
|
|
if (target_ok)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Uh, oh. Something's missing. */
|
|
|
|
msg_display(MSG_badroot);
|
|
|
|
process_menu(MENU_ok);
|
|
|
|
return 1;
|
|
|
|
}
|
1999-01-21 11:02:17 +03:00
|
|
|
|
|
|
|
/* set reverse to 1 to default to no */
|
|
|
|
int askyesno(int reverse)
|
|
|
|
{
|
|
|
|
WINDOW *yesnowin;
|
|
|
|
int c, found;
|
|
|
|
|
|
|
|
yesnowin = subwin(stdscr, 5, 20, stdscr->maxy/2 - 2, stdscr->maxx/2 - 10);
|
|
|
|
|
|
|
|
box(yesnowin, '*', '*');
|
|
|
|
wmove(yesnowin, 2,2);
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
waddstr(yesnowin, "Yes or No: [N]");
|
|
|
|
else
|
|
|
|
waddstr(yesnowin, "Yes or No: [Y]");
|
|
|
|
|
|
|
|
wrefresh(yesnowin);
|
|
|
|
while ((c = getchar())) {
|
|
|
|
if (c == 'y' || c == 'Y') {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
} else if (c == 'n' || c == 'N' ) {
|
|
|
|
found = 0;
|
|
|
|
break;
|
|
|
|
} else if (c == '\n' || c == '\r') {
|
|
|
|
if (reverse)
|
|
|
|
found = 0;
|
|
|
|
else
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wclear(yesnowin);
|
|
|
|
wrefresh(yesnowin);
|
|
|
|
delwin(yesnowin);
|
|
|
|
refresh();
|
|
|
|
return(found);
|
|
|
|
}
|
|
|
|
|