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.
|
|
|
|
*
|
1995-11-10 06:49:03 +00:00
|
|
|
* $Id: package.c,v 1.23 1995/11/06 12:49:27 jkh Exp $
|
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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Jordan Hubbard
|
|
|
|
* for the FreeBSD Project.
|
|
|
|
* 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
static char *make_playpen(char *pen, size_t sz);
|
|
|
|
|
1995-10-22 11:32:58 +00:00
|
|
|
/* Like package_extract, but assumes current media device */
|
|
|
|
int
|
|
|
|
package_add(char *name)
|
|
|
|
{
|
|
|
|
if (!mediaVerify())
|
|
|
|
return RET_FAIL;
|
|
|
|
return package_extract(mediaDevice, name);
|
|
|
|
}
|
|
|
|
|
1995-10-15 12:41:09 +00:00
|
|
|
/* Extract a package based on a namespec and a media device */
|
|
|
|
int
|
|
|
|
package_extract(Device *dev, char *name)
|
|
|
|
{
|
|
|
|
char path[511];
|
|
|
|
char pen[FILENAME_MAX];
|
|
|
|
char *where;
|
1995-10-23 13:19:51 +00:00
|
|
|
int fd, ret;
|
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 */
|
1995-10-22 17:18:36 +00:00
|
|
|
if (!vsystem("pkg_info -e %s", name)) {
|
1995-10-27 02:12:58 +00:00
|
|
|
msgDebug("package %s marked as already installed - return SUCCESS.\n", name);
|
1995-10-16 15:14:28 +00:00
|
|
|
return RET_SUCCESS;
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1995-10-16 15:14:28 +00:00
|
|
|
|
1995-10-18 00:12:55 +00:00
|
|
|
if (!dev->init(dev)) {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
|
|
|
msgConfirm("Unable to initialize media type for package extract.");
|
1995-10-15 12:41:09 +00:00
|
|
|
return RET_FAIL;
|
1995-10-18 00:12:55 +00:00
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
|
|
|
|
ret = RET_FAIL;
|
1995-11-06 12:49:27 +00: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);
|
|
|
|
}
|
|
|
|
|
1995-10-18 00:12:55 +00:00
|
|
|
sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
|
1995-10-27 03:07:14 +00:00
|
|
|
msgNotify("Adding %s\nfrom %s", path, dev->name);
|
1995-10-18 00:12:55 +00:00
|
|
|
fd = dev->get(dev, path, TRUE);
|
1995-10-15 12:41:09 +00:00
|
|
|
if (fd >= 0) {
|
|
|
|
pen[0] = '\0';
|
|
|
|
if ((where = make_playpen(pen, 0)) != NULL) {
|
1995-10-22 23:20:45 +00:00
|
|
|
if (mediaExtractDist(pen, fd)) {
|
|
|
|
if (file_readable("+CONTENTS")) {
|
1995-11-10 06:49:03 +00:00
|
|
|
if (mediaDevice->type == DEVICE_TYPE_FTP && variable_get(VAR_FTP_PATH)) {
|
|
|
|
char ftppath[512];
|
|
|
|
|
|
|
|
/* Special case to leave hint for pkg_add that this is an FTP install */
|
|
|
|
sprintf(ftppath, "%spackages/All/", variable_get(VAR_FTP_PATH));
|
|
|
|
variable_set2("PKG_ADD_BASE", ftppath);
|
|
|
|
}
|
1995-10-22 20:15:07 +00:00
|
|
|
if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S",
|
|
|
|
!strcmp(variable_get(VAR_CPIO_VERBOSITY), "high") ? "-v " : "")) {
|
|
|
|
dialog_clear();
|
1995-11-06 12:49:27 +00:00
|
|
|
if (!variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgConfirm("An error occurred while trying to pkg_add %s.\n"
|
|
|
|
"Please check debugging screen for possible further details.", name);
|
|
|
|
else
|
|
|
|
msgNotify("An error occurred while trying to pkg_add %s.", name);
|
1995-10-22 20:15:07 +00:00
|
|
|
}
|
1995-10-23 13:19:51 +00:00
|
|
|
else {
|
|
|
|
msgNotify("Package %s added successfully!", name);
|
1995-10-22 20:15:07 +00:00
|
|
|
ret = RET_SUCCESS;
|
1995-10-23 13:19:51 +00:00
|
|
|
}
|
1995-10-22 20:15:07 +00:00
|
|
|
}
|
|
|
|
else {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-11-06 12:49:27 +00:00
|
|
|
if (!variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgConfirm("The package specified (%s) has no CONTENTS file. This means\n"
|
|
|
|
"that there was either a media error of some sort or the package\n"
|
|
|
|
"file itself is corrupted.\n"
|
|
|
|
"You may wish to look into this and try again.", name);
|
|
|
|
else
|
|
|
|
msgNotify("The package specified (%s) has no CONTENTS file. Skipping.", name);
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1995-10-22 23:20:45 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = RET_FAIL;
|
1995-11-06 12:49:27 +00:00
|
|
|
if (!variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgConfirm("Unable to extract the contents of package %s. This means\n"
|
|
|
|
"that there was either a media error of some sort or the package\n"
|
|
|
|
"file itself is corrupted.\n"
|
|
|
|
"You may wish to look into this and try again.", name);
|
|
|
|
else
|
|
|
|
msgNotify("Unable to extract the contents of package %s. Skipping.", name);
|
1995-10-15 12:41:09 +00:00
|
|
|
}
|
|
|
|
if (chdir(where) == -1)
|
1995-10-21 20:03:07 +00:00
|
|
|
msgFatal("Unable to get back to where I was before, Jojo! (That was: %s)", where);
|
1995-10-15 12:41:09 +00:00
|
|
|
vsystem("rm -rf %s", pen);
|
|
|
|
if (isDebug())
|
|
|
|
msgDebug("Nuked pen: %s\n", pen);
|
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Unable to find a temporary location to unpack this stuff in.\n"
|
|
|
|
"You must simply not have enough space or you've configured your\n"
|
|
|
|
"system oddly. Sorry!");
|
1995-10-22 17:18:36 +00:00
|
|
|
ret = RET_FAIL;
|
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
dev->close(dev, fd);
|
|
|
|
if (dev->type == DEVICE_TYPE_TAPE)
|
|
|
|
unlink(path);
|
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
1995-10-18 00:12:55 +00:00
|
|
|
msgDebug("pkg_extract: get operation returned %d\n", fd);
|
1995-10-22 17:18:36 +00:00
|
|
|
if (variable_get(VAR_NO_CONFIRM))
|
|
|
|
msgNotify("Unable to fetch package %s from selected media.\n"
|
1995-10-26 08:11:24 +00:00
|
|
|
"No package add will be done.", name);
|
1995-10-22 17:18:36 +00:00
|
|
|
else {
|
|
|
|
dialog_clear();
|
|
|
|
msgConfirm("Unable to fetch package %s from selected media.\n"
|
1995-10-26 08:11:24 +00:00
|
|
|
"No package add will be done.", name);
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
min_free(char *tmpdir)
|
|
|
|
{
|
|
|
|
struct statfs buf;
|
|
|
|
|
|
|
|
if (statfs(tmpdir, &buf) != 0) {
|
|
|
|
msgDebug("Error in statfs, errno = %d\n", errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return buf.f_bavail * buf.f_bsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a good place to play. */
|
|
|
|
static char *
|
|
|
|
find_play_pen(char *pen, size_t sz)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (pen[0] && stat(pen, &sb) != RET_FAIL && (min_free(pen) >= sz))
|
|
|
|
return pen;
|
|
|
|
else if (stat("/var/tmp", &sb) != RET_FAIL && min_free("/var/tmp") >= sz)
|
|
|
|
strcpy(pen, "/var/tmp/instmp.XXXXXX");
|
|
|
|
else if (stat("/tmp", &sb) != RET_FAIL && min_free("/tmp") >= sz)
|
|
|
|
strcpy(pen, "/tmp/instmp.XXXXXX");
|
|
|
|
else if ((stat("/usr/tmp", &sb) == RET_SUCCESS || mkdir("/usr/tmp", 01777) == RET_SUCCESS) &&
|
|
|
|
min_free("/usr/tmp") >= sz)
|
|
|
|
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
|
|
|
|
else {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Can't find enough temporary space to extract the files, please try\n"
|
|
|
|
"This again after your system is up (you can run /stand/sysinstall\n"
|
|
|
|
"directly) and you've had a chance to point /var/tmp somewhere with\n"
|
|
|
|
"sufficient temporary space available.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return pen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a temporary directory to play in and chdir() to it, returning
|
|
|
|
* pathname of previous working directory.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
make_playpen(char *pen, size_t sz)
|
|
|
|
{
|
|
|
|
static char Previous[FILENAME_MAX];
|
|
|
|
|
|
|
|
if (!find_play_pen(pen, sz))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!mktemp(pen)) {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Can't mktemp '%s'.", pen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (mkdir(pen, 0755) == RET_FAIL) {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Can't mkdir '%s'.", pen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (isDebug()) {
|
|
|
|
if (sz)
|
|
|
|
msgDebug("Requested space: %d bytes, free space: %d bytes in %s\n", (int)sz, min_free(pen), pen);
|
|
|
|
}
|
|
|
|
if (min_free(pen) < sz) {
|
|
|
|
rmdir(pen);
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Not enough free space to create: `%s'\n"
|
|
|
|
"Please try this again after your system is up (you can run\n"
|
|
|
|
"/stand/sysinstall directly) and you've had a chance to point\n"
|
|
|
|
"/var/tmp somewhere with sufficient temporary space available.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!getcwd(Previous, FILENAME_MAX)) {
|
1995-10-22 17:18:36 +00:00
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("getcwd");
|
|
|
|
return NULL;
|
|
|
|
}
|
1995-10-22 17:18:36 +00:00
|
|
|
if (chdir(pen) == RET_FAIL) {
|
|
|
|
dialog_clear();
|
1995-10-15 12:41:09 +00:00
|
|
|
msgConfirm("Can't chdir to '%s'.", pen);
|
1995-10-22 17:18:36 +00:00
|
|
|
}
|
1995-10-15 12:41:09 +00:00
|
|
|
return Previous;
|
|
|
|
}
|