1995-10-15 12:41:09 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-10-15 12:41:09 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
|
|
|
* point in the file.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``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 JORDAN HUBBARD OR HIS PETS 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, LIFE 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-01-03 06:32:39 +00:00
|
|
|
#include "sysinstall.h"
|
1995-10-15 12:41:09 +00:00
|
|
|
#include <sys/errno.h>
|
1996-05-23 16:34:30 +00:00
|
|
|
#include <sys/time.h>
|
1995-10-15 12:41:09 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1999-09-02 00:51:16 +00:00
|
|
|
static Boolean sigpipe_caught;
|
1997-03-22 15:20:51 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
catch_pipe(int sig)
|
|
|
|
{
|
|
|
|
sigpipe_caught = TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-12 09:02:37 +00:00
|
|
|
extern PkgNode Top;
|
|
|
|
|
|
|
|
/* Like package_extract, but assumes current media device and chases deps */
|
1995-10-22 11:32:58 +00:00
|
|
|
int
|
|
|
|
package_add(char *name)
|
|
|
|
{
|
2002-01-25 05:10:00 +00:00
|
|
|
PkgNodePtr tmp;
|
1999-05-12 09:02:37 +00:00
|
|
|
int i;
|
|
|
|
|
1995-10-22 11:32:58 +00:00
|
|
|
if (!mediaVerify())
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1999-09-02 00:51:16 +00:00
|
|
|
|
2001-07-02 00:18:04 +00:00
|
|
|
if (!DEVICE_INIT(mediaDevice))
|
1999-09-02 00:51:16 +00:00
|
|
|
return DITEM_FAILURE;
|
|
|
|
|
1999-05-12 09:02:37 +00:00
|
|
|
i = index_initialize("packages/INDEX");
|
|
|
|
if (DITEM_STATUS(i) != DITEM_SUCCESS)
|
|
|
|
return i;
|
1999-09-02 00:51:16 +00:00
|
|
|
|
2002-01-25 05:10:00 +00:00
|
|
|
tmp = index_search(&Top, name, &tmp);
|
1999-05-12 09:02:37 +00:00
|
|
|
if (tmp)
|
1999-05-15 14:34:22 +00:00
|
|
|
return index_extract(mediaDevice, &Top, tmp, FALSE);
|
1999-05-12 09:02:37 +00:00
|
|
|
else {
|
|
|
|
msgConfirm("Sorry, package %s was not found in the INDEX.", name);
|
1999-12-14 04:25:29 +00:00
|
|
|
return DITEM_FAILURE;
|
1999-05-12 09:02:37 +00:00
|
|
|
}
|
1995-10-22 11:32:58 +00:00
|
|
|
}
|
|
|
|
|
1997-06-13 17:55:32 +00:00
|
|
|
/* For use by dispatch */
|
|
|
|
int
|
|
|
|
packageAdd(dialogMenuItem *self)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
1997-09-17 16:18:22 +00:00
|
|
|
cp = variable_get(VAR_PACKAGE);
|
1997-06-13 17:55:32 +00:00
|
|
|
if (!cp) {
|
|
|
|
msgDebug("packageAdd: No package name passed in package variable\n");
|
|
|
|
return DITEM_FAILURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return package_add(cp);
|
|
|
|
}
|
|
|
|
|
1996-05-16 11:47:46 +00:00
|
|
|
Boolean
|
|
|
|
package_exists(char *name)
|
|
|
|
{
|
1996-06-25 04:28:23 +00:00
|
|
|
char fname[FILENAME_MAX];
|
|
|
|
int status /* = vsystem("pkg_info -e %s", name) */;
|
1996-05-16 11:47:46 +00:00
|
|
|
|
1996-06-25 04:28:23 +00:00
|
|
|
/* XXX KLUDGE ALERT! This makes evil assumptions about how XXX
|
|
|
|
* packages register themselves and should *really be done with
|
|
|
|
* `pkg_info -e <name>' except that this it's too slow for an
|
|
|
|
* item check routine.. :-(
|
|
|
|
*/
|
|
|
|
snprintf(fname, FILENAME_MAX, "/var/db/pkg/%s", name);
|
|
|
|
status = access(fname, R_OK);
|
1997-01-29 21:45:30 +00:00
|
|
|
if (isDebug())
|
|
|
|
msgDebug("package check for %s returns %s.\n", name, status ? "failure" : "success");
|
1996-05-16 11:47:46 +00:00
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
1995-10-15 12:41:09 +00:00
|
|
|
/* Extract a package based on a namespec and a media device */
|
|
|
|
int
|
1996-03-21 09:30:18 +00:00
|
|
|
package_extract(Device *dev, char *name, Boolean depended)
|
1995-10-15 12:41:09 +00:00
|
|
|
{
|
1999-05-12 07:12:01 +00:00
|
|
|
char path[511];
|
1997-09-16 10:14:23 +00:00
|
|
|
int ret, last_msg = 0;
|
1996-12-11 09:35:06 +00:00
|
|
|
FILE *fp;
|
1995-10-15 12:41:09 +00:00
|
|
|
|
1995-10-16 15:14:28 +00:00
|
|
|
/* Check to make sure it's not already there */
|
1996-05-16 11:47:46 +00:00
|
|
|
if (package_exists(name))
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_SUCCESS;
|
1995-10-16 15:14:28 +00:00
|
|
|
|
2001-07-02 00:18:04 +00:00
|
|
|
if (!DEVICE_INIT(dev)) {
|
1995-10-22 17:18:36 +00:00
|
|
|
msgConfirm("Unable to initialize media type for package extract.");
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-10-18 00:12:55 +00:00
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
|
1999-05-14 12:15:34 +00:00
|
|
|
/* If necessary, initialize the ldconfig hints */
|
2001-05-12 19:39:13 +00:00
|
|
|
if (!file_readable("/var/run/ld-elf.so.hints"))
|
1999-12-19 19:42:02 +00:00
|
|
|
vsystem("ldconfig /usr/lib /usr/lib/compat /usr/local/lib /usr/X11R6/lib");
|
2001-05-12 19:39:13 +00:00
|
|
|
if (!file_readable("/var/run/ld.so.hints"))
|
|
|
|
vsystem("ldconfig -aout /usr/lib/aout /usr/lib/compat/aout /usr/local/lib/aout /usr/X11R6/lib/aout");
|
1999-05-14 12:15:34 +00:00
|
|
|
|
1996-03-21 09:30:18 +00:00
|
|
|
/* Be initially optimistic */
|
1999-12-14 04:25:29 +00:00
|
|
|
ret = DITEM_SUCCESS;
|
1995-11-06 12:49:27 +00:00
|
|
|
/* Make a couple of paranoid locations for temp files to live if user specified none */
|
1997-10-15 04:37:26 +00:00
|
|
|
if (!variable_get(VAR_PKG_TMPDIR)) {
|
1996-03-18 15:28:10 +00:00
|
|
|
/* Set it to a location with as much space as possible */
|
2002-04-01 21:35:24 +00:00
|
|
|
variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0);
|
1995-11-06 12:49:27 +00:00
|
|
|
}
|
1997-10-15 04:37:26 +00:00
|
|
|
Mkdir(variable_get(VAR_PKG_TMPDIR));
|
|
|
|
vsystem("chmod 1777 %s", variable_get(VAR_PKG_TMPDIR));
|
1995-11-06 12:49:27 +00:00
|
|
|
|
1999-05-14 12:15:34 +00:00
|
|
|
if (!index(name, '/')) {
|
|
|
|
if (!strpbrk(name, "-_"))
|
|
|
|
sprintf(path, "packages/Latest/%s.tgz", name);
|
|
|
|
else
|
|
|
|
sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
|
|
|
|
}
|
1996-06-29 02:22:48 +00:00
|
|
|
else
|
|
|
|
sprintf(path, "%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
|
1999-05-12 06:11:32 +00:00
|
|
|
|
1999-05-12 07:12:01 +00:00
|
|
|
/* We have a path, call the device strategy routine to get the file */
|
2001-07-02 00:18:04 +00:00
|
|
|
fp = DEVICE_GET(dev, path, TRUE);
|
1996-12-11 09:35:06 +00:00
|
|
|
if (fp) {
|
1997-03-22 15:20:51 +00:00
|
|
|
int i = 0, tot, pfd[2];
|
1996-03-18 15:28:10 +00:00
|
|
|
pid_t pid;
|
1999-12-17 02:46:04 +00:00
|
|
|
WINDOW *w = savescr();
|
1996-03-18 15:28:10 +00:00
|
|
|
|
1999-05-15 14:34:22 +00:00
|
|
|
sigpipe_caught = FALSE;
|
1997-03-22 15:20:51 +00:00
|
|
|
signal(SIGPIPE, catch_pipe);
|
1999-05-15 14:34:22 +00:00
|
|
|
|
1999-12-18 03:13:19 +00:00
|
|
|
dialog_clear_norefresh();
|
1996-03-21 09:30:18 +00:00
|
|
|
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
|
1996-03-18 15:28:10 +00:00
|
|
|
pipe(pfd);
|
|
|
|
pid = fork();
|
|
|
|
if (!pid) {
|
|
|
|
dup2(pfd[0], 0); close(pfd[0]);
|
2002-04-07 10:08:55 +00:00
|
|
|
dup2(DebugFD, 1); dup2(1, 2);
|
1996-03-18 15:28:10 +00:00
|
|
|
close(pfd[1]);
|
2000-11-10 09:34:06 +00:00
|
|
|
|
|
|
|
/* Prevent pkg_add from wanting to interact in bad ways */
|
|
|
|
setenv("PACKAGE_BUILDING", "t", 1);
|
|
|
|
setenv("BATCH", "t", 1);
|
|
|
|
|
1999-05-14 14:29:50 +00:00
|
|
|
if (isDebug())
|
2001-07-09 09:24:06 +00:00
|
|
|
i = execl("/usr/sbin/pkg_add", "/usr/sbin/pkg_add", "-v", "-",
|
|
|
|
(char *)0);
|
1999-05-14 14:29:50 +00:00
|
|
|
else
|
2001-07-09 09:24:06 +00:00
|
|
|
i = execl("/usr/sbin/pkg_add", "/usr/sbin/pkg_add", "-",
|
|
|
|
(char *)0);
|
1995-10-15 12:41:09 +00:00
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
1996-03-18 15:28:10 +00:00
|
|
|
char buf[BUFSIZ];
|
1996-05-23 16:34:30 +00:00
|
|
|
struct timeval start, stop;
|
1996-03-18 15:28:10 +00:00
|
|
|
|
1996-04-30 06:13:50 +00:00
|
|
|
close(pfd[0]);
|
1996-03-18 15:28:10 +00:00
|
|
|
tot = 0;
|
1996-05-23 16:34:30 +00:00
|
|
|
(void)gettimeofday(&start, (struct timezone *)0);
|
|
|
|
|
1997-03-22 15:20:51 +00:00
|
|
|
while (!sigpipe_caught && (i = fread(buf, 1, BUFSIZ, fp)) > 0) {
|
1996-05-23 16:34:30 +00:00
|
|
|
int seconds;
|
1996-04-13 13:32:15 +00:00
|
|
|
|
1996-03-18 15:28:10 +00:00
|
|
|
tot += i;
|
1996-05-23 16:34:30 +00:00
|
|
|
/* Print statistics about how we're doing */
|
|
|
|
(void) gettimeofday(&stop, (struct timezone *)0);
|
|
|
|
stop.tv_sec = stop.tv_sec - start.tv_sec;
|
|
|
|
stop.tv_usec = stop.tv_usec - start.tv_usec;
|
|
|
|
if (stop.tv_usec < 0)
|
|
|
|
stop.tv_sec--, stop.tv_usec += 1000000;
|
|
|
|
seconds = stop.tv_sec + (stop.tv_usec / 1000000.0);
|
|
|
|
if (!seconds)
|
|
|
|
seconds = 1;
|
1997-09-16 10:14:23 +00:00
|
|
|
if (seconds != last_msg) {
|
|
|
|
last_msg = seconds;
|
2001-04-08 20:42:52 +00:00
|
|
|
msgInfo("%10d bytes read from package %s @ %4.1f KBytes/second", tot, name, (tot / seconds) / 1000.0);
|
1997-09-16 10:14:23 +00:00
|
|
|
}
|
1996-05-23 16:34:30 +00:00
|
|
|
/* Write it out */
|
1997-03-22 15:20:51 +00:00
|
|
|
if (sigpipe_caught || write(pfd[1], buf, i) != i) {
|
1996-05-23 16:34:30 +00:00
|
|
|
msgInfo("Write failure to pkg_add! Package may be corrupt.");
|
|
|
|
break;
|
|
|
|
}
|
1996-03-18 15:28:10 +00:00
|
|
|
}
|
|
|
|
close(pfd[1]);
|
1996-12-11 09:35:06 +00:00
|
|
|
fclose(fp);
|
1997-03-22 15:20:51 +00:00
|
|
|
if (sigpipe_caught)
|
|
|
|
msgInfo("pkg_add(1) apparently did not like the %s package.", name);
|
|
|
|
else if (i == -1)
|
|
|
|
msgInfo("I/O error while reading in the %s package.", name);
|
1996-05-27 22:12:05 +00:00
|
|
|
else
|
1997-03-22 15:20:51 +00:00
|
|
|
msgInfo("Package %s read successfully - waiting for pkg_add(1)", name);
|
1996-03-21 09:30:18 +00:00
|
|
|
refresh();
|
1996-03-18 15:28:10 +00:00
|
|
|
i = waitpid(pid, &tot, 0);
|
1999-12-19 06:34:22 +00:00
|
|
|
dialog_clear_norefresh();
|
1997-03-22 15:20:51 +00:00
|
|
|
if (sigpipe_caught || i < 0 || WEXITSTATUS(tot)) {
|
1999-12-14 04:25:29 +00:00
|
|
|
ret = DITEM_FAILURE;
|
1999-07-02 22:36:14 +00:00
|
|
|
if (variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgNotify("Add of package %s aborted, error code %d -\n"
|
|
|
|
"Please check the debug screen for more info.", name, WEXITSTATUS(tot));
|
|
|
|
else
|
|
|
|
msgConfirm("Add of package %s aborted, error code %d -\n"
|
|
|
|
"Please check the debug screen for more info.", name, WEXITSTATUS(tot));
|
1996-03-18 15:28:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
msgNotify("Package %s was added successfully", name);
|
1996-10-05 12:28:36 +00:00
|
|
|
|
|
|
|
/* Now catch any stragglers */
|
1996-10-12 19:30:26 +00:00
|
|
|
while (wait3(&tot, WNOHANG, NULL) > 0);
|
1996-10-05 12:28:36 +00:00
|
|
|
|
1996-04-28 03:27:26 +00:00
|
|
|
sleep(1);
|
|
|
|
restorescr(w);
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
1999-12-19 06:34:22 +00:00
|
|
|
dialog_clear_norefresh();
|
1999-07-02 22:36:14 +00:00
|
|
|
if (variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgNotify("Unable to fetch package %s from selected media.\n"
|
|
|
|
"No package add will be done.", name);
|
|
|
|
else
|
|
|
|
msgConfirm("Unable to fetch package %s from selected media.\n"
|
|
|
|
"No package add will be done.", name);
|
1999-12-14 04:25:29 +00:00
|
|
|
ret = DITEM_FAILURE;
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1999-05-15 14:34:22 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
1999-12-20 00:16:10 +00:00
|
|
|
return ret;
|
1995-10-15 12:41:09 +00:00
|
|
|
}
|