1995-10-15 13:41:09 +01:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1996-05-16 13:47:46 +02:00
|
|
|
* $Id: package.c,v 1.35 1996/04/30 06:13:50 jkh Exp $
|
1995-10-15 13:41:09 +01: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "sysinstall.h"
|
|
|
|
|
1995-10-22 12:32:58 +01:00
|
|
|
/* Like package_extract, but assumes current media device */
|
|
|
|
int
|
|
|
|
package_add(char *name)
|
|
|
|
{
|
|
|
|
if (!mediaVerify())
|
1996-04-13 15:32:15 +02:00
|
|
|
return DITEM_FAILURE;
|
1996-03-21 10:30:18 +01:00
|
|
|
return package_extract(mediaDevice, name, FALSE);
|
1995-10-22 12:32:58 +01:00
|
|
|
}
|
|
|
|
|
1996-05-16 13:47:46 +02:00
|
|
|
Boolean
|
|
|
|
package_exists(char *name)
|
|
|
|
{
|
|
|
|
int status = vsystem("pkg_info -e %s", name);
|
|
|
|
|
|
|
|
msgDebug("package check for %s returns %s.\n", name,
|
|
|
|
status ? "failure" : "success");
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
1995-10-15 13:41:09 +01:00
|
|
|
/* Extract a package based on a namespec and a media device */
|
|
|
|
int
|
1996-03-21 10:30:18 +01:00
|
|
|
package_extract(Device *dev, char *name, Boolean depended)
|
1995-10-15 13:41:09 +01:00
|
|
|
{
|
|
|
|
char path[511];
|
1995-10-23 14:19:51 +01:00
|
|
|
int fd, ret;
|
1995-10-15 13:41:09 +01:00
|
|
|
|
1995-11-12 12:02:43 +01:00
|
|
|
/* If necessary, initialize the ldconfig hints */
|
|
|
|
if (!file_readable("/var/run/ld.so.hints"))
|
|
|
|
vsystem("ldconfig /usr/lib /usr/local/lib /usr/X11R6/lib");
|
|
|
|
|
1995-10-16 16:14:28 +01:00
|
|
|
/* Check to make sure it's not already there */
|
1996-05-16 13:47:46 +02:00
|
|
|
msgNotify("Checking for existence of %s package", name);
|
|
|
|
if (package_exists(name))
|
1996-04-13 15:32:15 +02:00
|
|
|
return DITEM_SUCCESS;
|
1995-10-16 16:14:28 +01:00
|
|
|
|
1995-10-18 01:12:55 +01:00
|
|
|
if (!dev->init(dev)) {
|
1995-10-22 18:18:36 +01:00
|
|
|
msgConfirm("Unable to initialize media type for package extract.");
|
1996-04-13 15:32:15 +02:00
|
|
|
return DITEM_FAILURE;
|
1995-10-18 01:12:55 +01:00
|
|
|
}
|
1995-10-15 13:41:09 +01:00
|
|
|
|
1996-03-21 10:30:18 +01:00
|
|
|
/* Be initially optimistic */
|
1996-04-30 07:40:15 +02:00
|
|
|
ret = DITEM_SUCCESS | DITEM_RESTORE;
|
1995-11-06 13:49:27 +01:00
|
|
|
/* Make a couple of paranoid locations for temp files to live if user specified none */
|
|
|
|
if (!variable_get("PKG_TMPDIR")) {
|
|
|
|
Mkdir("/usr/tmp", NULL);
|
|
|
|
Mkdir("/var/tmp", NULL);
|
1996-03-18 16:28:10 +01:00
|
|
|
/* Set it to a location with as much space as possible */
|
|
|
|
variable_set2("PKG_TMPDIR", "/usr/tmp");
|
1995-11-06 13:49:27 +01:00
|
|
|
}
|
|
|
|
|
1995-10-18 01:12:55 +01:00
|
|
|
sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
|
|
|
|
fd = dev->get(dev, path, TRUE);
|
1995-10-15 13:41:09 +01:00
|
|
|
if (fd >= 0) {
|
1996-03-18 16:28:10 +01:00
|
|
|
int i, tot, pfd[2];
|
|
|
|
pid_t pid;
|
|
|
|
|
1996-03-21 10:30:18 +01:00
|
|
|
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
|
1996-03-18 16:28:10 +01:00
|
|
|
pipe(pfd);
|
|
|
|
pid = fork();
|
|
|
|
if (!pid) {
|
|
|
|
dup2(pfd[0], 0); close(pfd[0]);
|
|
|
|
dup2(DebugFD, 1);
|
1996-04-28 05:27:26 +02:00
|
|
|
close(2);
|
1996-03-18 16:28:10 +01:00
|
|
|
close(pfd[1]);
|
|
|
|
i = execl("/usr/sbin/pkg_add", "/usr/sbin/pkg_add", "-", 0);
|
1995-10-15 13:41:09 +01:00
|
|
|
if (isDebug())
|
1996-03-18 16:28:10 +01:00
|
|
|
msgDebug("pkg_add returns %d status\n", i);
|
1995-10-15 13:41:09 +01:00
|
|
|
}
|
1995-10-22 18:18:36 +01:00
|
|
|
else {
|
1996-03-18 16:28:10 +01:00
|
|
|
char buf[BUFSIZ];
|
1996-04-28 05:27:26 +02:00
|
|
|
WINDOW *w = savescr();
|
1996-03-18 16:28:10 +01:00
|
|
|
|
1996-04-30 08:13:50 +02:00
|
|
|
close(pfd[0]);
|
1996-03-18 16:28:10 +01:00
|
|
|
tot = 0;
|
|
|
|
while ((i = read(fd, buf, BUFSIZ)) > 0) {
|
1996-04-13 15:32:15 +02:00
|
|
|
char line[80];
|
|
|
|
int x, len;
|
|
|
|
|
1996-03-18 16:28:10 +01:00
|
|
|
write(pfd[1], buf, i);
|
|
|
|
tot += i;
|
1996-04-13 15:32:15 +02:00
|
|
|
sprintf(line, "%d bytes read from package %s", tot, name);
|
|
|
|
len = strlen(line);
|
|
|
|
for (x = len; x < 79; x++)
|
|
|
|
line[x] = ' ';
|
|
|
|
line[79] = '\0';
|
|
|
|
mvprintw(0, 0, line);
|
1996-03-18 16:28:10 +01:00
|
|
|
clrtoeol();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
close(pfd[1]);
|
1996-04-30 08:13:50 +02:00
|
|
|
dev->close(dev, fd);
|
1996-03-21 10:30:18 +01:00
|
|
|
mvprintw(0, 0, "Package %s read successfully - waiting for pkg_add", name);
|
|
|
|
refresh();
|
1996-03-18 16:28:10 +01:00
|
|
|
i = waitpid(pid, &tot, 0);
|
|
|
|
if (i < 0 || WEXITSTATUS(tot)) {
|
|
|
|
msgNotify("Add of package %s aborted due to some error -\n"
|
|
|
|
"Please check the debug screen for more info.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
msgNotify("Package %s was added successfully", name);
|
1996-04-28 05:27:26 +02:00
|
|
|
sleep(1);
|
|
|
|
restorescr(w);
|
1995-10-22 18:18:36 +01:00
|
|
|
}
|
1995-10-15 13:41:09 +01:00
|
|
|
}
|
1995-10-22 18:18:36 +01:00
|
|
|
else {
|
1995-10-18 01:12:55 +01:00
|
|
|
msgDebug("pkg_extract: get operation returned %d\n", fd);
|
1995-10-22 18:18:36 +01:00
|
|
|
if (variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgNotify("Unable to fetch package %s from selected media.\n"
|
1995-10-26 09:11:24 +01:00
|
|
|
"No package add will be done.", name);
|
1995-10-22 18:18:36 +01:00
|
|
|
else {
|
|
|
|
msgConfirm("Unable to fetch package %s from selected media.\n"
|
1995-10-26 09:11:24 +01:00
|
|
|
"No package add will be done.", name);
|
1995-10-22 18:18:36 +01:00
|
|
|
}
|
1996-04-30 07:40:15 +02:00
|
|
|
ret = DITEM_FAILURE | DITEM_RESTORE;
|
1995-10-22 18:18:36 +01:00
|
|
|
}
|
1996-04-28 05:27:26 +02:00
|
|
|
return ret;
|
1995-10-15 13:41:09 +01:00
|
|
|
}
|