1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1997-10-08 07:48:21 +00:00
|
|
|
static const char rcsid[] =
|
1998-09-11 07:26:58 +00:00
|
|
|
"$Id: perform.c,v 1.44 1998/09/08 10:42:24 jkh Exp $";
|
1993-08-26 01:19:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* This is the main body of the create module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib.h"
|
|
|
|
#include "create.h"
|
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
#include <signal.h>
|
1995-04-24 21:50:11 +00:00
|
|
|
#include <sys/syslimits.h>
|
1996-06-20 18:33:55 +00:00
|
|
|
#include <sys/wait.h>
|
1996-02-06 22:49:11 +00:00
|
|
|
#include <unistd.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
static void sanity_check(void);
|
|
|
|
static void make_dist(char *, char *, char *, Package *);
|
|
|
|
|
1995-10-25 15:38:37 +00:00
|
|
|
static char *home;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
int
|
|
|
|
pkg_perform(char **pkgs)
|
|
|
|
{
|
|
|
|
char *pkg = *pkgs; /* Only one arg to create */
|
1995-10-25 15:38:37 +00:00
|
|
|
char *cp;
|
1993-08-26 01:19:55 +00:00
|
|
|
FILE *pkg_in, *fp;
|
|
|
|
Package plist;
|
1998-09-08 03:15:41 +00:00
|
|
|
int len;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Preliminary setup */
|
|
|
|
sanity_check();
|
1995-04-22 00:03:18 +00:00
|
|
|
if (Verbose && !PlistOnly)
|
1993-08-26 01:19:55 +00:00
|
|
|
printf("Creating package %s\n", pkg);
|
|
|
|
get_dash_string(&Comment);
|
|
|
|
get_dash_string(&Desc);
|
|
|
|
if (!strcmp(Contents, "-"))
|
|
|
|
pkg_in = stdin;
|
|
|
|
else {
|
|
|
|
pkg_in = fopen(Contents, "r");
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!pkg_in) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "unable to open contents file '%s' for input", Contents);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
plist.head = plist.tail = NULL;
|
|
|
|
|
1998-09-08 03:15:41 +00:00
|
|
|
/* chop suffix off if already specified */
|
|
|
|
len = strlen(pkg);
|
|
|
|
if (len > 4 && !strcmp(&pkg[len - 4], ".tgz"))
|
|
|
|
pkg[len - 4] = '\0';
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1995-04-09 15:05:01 +00:00
|
|
|
/* Stick the dependencies, if any, at the top */
|
1995-04-10 08:01:52 +00:00
|
|
|
if (Pkgdeps) {
|
1995-04-22 00:59:33 +00:00
|
|
|
if (Verbose && !PlistOnly)
|
1995-04-10 08:01:52 +00:00
|
|
|
printf("Registering depends:");
|
|
|
|
while (Pkgdeps) {
|
|
|
|
cp = strsep(&Pkgdeps, " \t\n");
|
|
|
|
if (*cp) {
|
|
|
|
add_plist(&plist, PLIST_PKGDEP, cp);
|
1995-04-22 01:20:13 +00:00
|
|
|
if (Verbose && !PlistOnly)
|
1995-04-10 08:01:52 +00:00
|
|
|
printf(" %s", cp);
|
|
|
|
}
|
1995-04-09 15:05:01 +00:00
|
|
|
}
|
1995-04-22 00:59:33 +00:00
|
|
|
if (Verbose && !PlistOnly)
|
1995-04-10 08:01:52 +00:00
|
|
|
printf(".\n");
|
1995-04-09 15:05:01 +00:00
|
|
|
}
|
1997-06-06 12:19:11 +00:00
|
|
|
|
|
|
|
/* If a SrcDir override is set, add it now */
|
|
|
|
if (SrcDir) {
|
|
|
|
if (Verbose && !PlistOnly)
|
|
|
|
printf("Using SrcDir value of %s\n", SrcDir);
|
|
|
|
add_plist(&plist, PLIST_SRC, SrcDir);
|
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Slurp in the packing list */
|
|
|
|
read_plist(&plist, pkg_in);
|
|
|
|
|
1997-11-14 01:56:04 +00:00
|
|
|
/* Prefix should add an @cwd to the packing list */
|
|
|
|
if (Prefix)
|
|
|
|
add_plist_top(&plist, PLIST_CWD, Prefix);
|
1993-09-03 23:01:17 +00:00
|
|
|
/*
|
|
|
|
* Run down the list and see if we've named it, if not stick in a name
|
|
|
|
* at the top.
|
|
|
|
*/
|
1994-05-25 06:24:41 +00:00
|
|
|
if (find_plist(&plist, PLIST_NAME) == NULL)
|
1994-11-17 10:54:11 +00:00
|
|
|
add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
|
1993-09-03 23:01:17 +00:00
|
|
|
|
1995-04-22 00:03:18 +00:00
|
|
|
/*
|
|
|
|
* We're just here for to dump out a revised plist for the FreeBSD ports
|
|
|
|
* hack. It's not a real create in progress.
|
|
|
|
*/
|
|
|
|
if (PlistOnly) {
|
1997-07-04 04:48:02 +00:00
|
|
|
check_list(home, &plist);
|
1995-04-22 00:03:18 +00:00
|
|
|
write_plist(&plist, stdout);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Make a directory to stomp around in */
|
1994-10-14 05:55:57 +00:00
|
|
|
home = make_playpen(PlayPen, 0);
|
1993-08-26 01:19:55 +00:00
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
signal(SIGHUP, cleanup);
|
|
|
|
|
|
|
|
/* Make first "real contents" pass over it */
|
|
|
|
check_list(home, &plist);
|
1994-12-06 00:51:50 +00:00
|
|
|
(void) umask(022); /* make sure gen'ed directories, files don't have
|
|
|
|
group or other write bits. */
|
1995-04-22 14:55:07 +00:00
|
|
|
/* copy_plist(home, &plist); */
|
|
|
|
/* mark_plist(&plist); */
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Now put the release specific items in */
|
|
|
|
add_plist(&plist, PLIST_CWD, ".");
|
|
|
|
write_file(COMMENT_FNAME, Comment);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
|
|
|
|
write_file(DESC_FNAME, Desc);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, DESC_FNAME);
|
|
|
|
|
|
|
|
if (Install) {
|
|
|
|
copy_file(home, Install, INSTALL_FNAME);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, INSTALL_FNAME);
|
|
|
|
}
|
|
|
|
if (DeInstall) {
|
|
|
|
copy_file(home, DeInstall, DEINSTALL_FNAME);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME);
|
|
|
|
}
|
|
|
|
if (Require) {
|
|
|
|
copy_file(home, Require, REQUIRE_FNAME);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, REQUIRE_FNAME);
|
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
if (Display) {
|
|
|
|
copy_file(home, Display, DISPLAY_FNAME);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, DISPLAY_FNAME);
|
|
|
|
add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME);
|
|
|
|
}
|
|
|
|
if (Mtree) {
|
|
|
|
copy_file(home, Mtree, MTREE_FNAME);
|
|
|
|
add_plist(&plist, PLIST_IGNORE, NULL);
|
|
|
|
add_plist(&plist, PLIST_FILE, MTREE_FNAME);
|
|
|
|
add_plist(&plist, PLIST_MTREE, MTREE_FNAME);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Finally, write out the packing list */
|
|
|
|
fp = fopen(CONTENTS_FNAME, "w");
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!fp) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "can't open file %s for writing", CONTENTS_FNAME);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
write_plist(&plist, fp);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (fclose(fp)) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "error while closing %s", CONTENTS_FNAME);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* And stick it into a tar ball */
|
1998-09-08 03:15:41 +00:00
|
|
|
make_dist(home, pkg, "tgz", &plist);
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
free(Comment);
|
|
|
|
free(Desc);
|
|
|
|
free_plist(&plist);
|
1998-02-16 17:16:51 +00:00
|
|
|
leave_playpen();
|
1993-08-26 01:19:55 +00:00
|
|
|
return TRUE; /* Success */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
make_dist(char *home, char *pkg, char *suffix, Package *plist)
|
|
|
|
{
|
|
|
|
char tball[FILENAME_MAX];
|
1995-04-22 14:55:07 +00:00
|
|
|
PackingList p;
|
1996-06-20 18:33:55 +00:00
|
|
|
int ret;
|
1996-02-06 22:49:11 +00:00
|
|
|
char *args[50]; /* Much more than enough. */
|
1995-05-10 20:46:06 +00:00
|
|
|
int nargs = 0;
|
1996-02-06 22:49:11 +00:00
|
|
|
int pipefds[2];
|
|
|
|
FILE *totar;
|
|
|
|
pid_t pid;
|
1995-05-10 20:46:06 +00:00
|
|
|
|
|
|
|
args[nargs++] = "tar"; /* argv[0] */
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1994-08-29 16:31:38 +00:00
|
|
|
if (*pkg == '/')
|
1995-05-10 20:46:06 +00:00
|
|
|
snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suffix);
|
1994-08-29 16:31:38 +00:00
|
|
|
else
|
1995-05-10 20:46:06 +00:00
|
|
|
snprintf(tball, FILENAME_MAX, "%s/%s.%s", home, pkg, suffix);
|
|
|
|
|
|
|
|
args[nargs++] = "-c";
|
|
|
|
args[nargs++] = "-f";
|
|
|
|
args[nargs++] = tball;
|
1993-08-26 01:19:55 +00:00
|
|
|
if (index(suffix, 'z')) /* Compress/gzip? */
|
1995-05-10 20:46:06 +00:00
|
|
|
args[nargs++] = "-z";
|
1994-05-19 18:27:41 +00:00
|
|
|
if (Dereference)
|
1995-05-10 20:46:06 +00:00
|
|
|
args[nargs++] = "-h";
|
1995-04-26 15:06:58 +00:00
|
|
|
if (ExcludeFrom) {
|
1995-05-10 20:46:06 +00:00
|
|
|
args[nargs++] = "-X";
|
|
|
|
args[nargs++] = ExcludeFrom;
|
1995-04-26 15:06:58 +00:00
|
|
|
}
|
1996-02-06 22:49:11 +00:00
|
|
|
args[nargs++] = "-T"; /* Take filenames from file instead of args. */
|
|
|
|
args[nargs++] = "-"; /* Use stdin for the file. */
|
|
|
|
args[nargs] = NULL;
|
1995-05-10 20:46:06 +00:00
|
|
|
|
|
|
|
if (Verbose)
|
|
|
|
printf("Creating gzip'd tar ball in '%s'\n", tball);
|
|
|
|
|
1996-02-06 22:49:11 +00:00
|
|
|
/* Set up a pipe for passing the filenames, and fork off a tar process. */
|
1998-09-11 07:26:58 +00:00
|
|
|
if (pipe(pipefds) == -1) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "cannot create pipe");
|
|
|
|
}
|
|
|
|
if ((pid = fork()) == -1) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "cannot fork process for tar");
|
|
|
|
}
|
1996-02-06 22:49:11 +00:00
|
|
|
if (pid == 0) { /* The child */
|
|
|
|
dup2(pipefds[0], 0);
|
1996-03-20 19:05:59 +00:00
|
|
|
close(pipefds[0]);
|
1996-02-06 22:49:11 +00:00
|
|
|
close(pipefds[1]);
|
|
|
|
execv("/usr/bin/tar", args);
|
1997-10-08 07:48:21 +00:00
|
|
|
cleanup(0);
|
|
|
|
errx(2, "failed to execute tar command");
|
1996-02-06 22:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Meanwhile, back in the parent process ... */
|
|
|
|
close(pipefds[0]);
|
1998-09-11 07:26:58 +00:00
|
|
|
if ((totar = fdopen(pipefds[1], "w")) == NULL) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "fdopen failed");
|
|
|
|
}
|
1996-02-06 22:49:11 +00:00
|
|
|
|
|
|
|
fprintf(totar, "%s\n", CONTENTS_FNAME);
|
|
|
|
fprintf(totar, "%s\n", COMMENT_FNAME);
|
|
|
|
fprintf(totar, "%s\n", DESC_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
|
|
|
|
if (Install)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", INSTALL_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
if (DeInstall)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", DEINSTALL_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
if (Require)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", REQUIRE_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
if (Display)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", DISPLAY_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
if (Mtree)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", MTREE_FNAME);
|
1995-05-10 20:46:06 +00:00
|
|
|
|
1995-04-22 14:55:07 +00:00
|
|
|
for (p = plist->head; p; p = p->next) {
|
1995-05-10 20:46:06 +00:00
|
|
|
if (p->type == PLIST_FILE)
|
1996-02-06 22:49:11 +00:00
|
|
|
fprintf(totar, "%s\n", p->name);
|
|
|
|
else if (p->type == PLIST_CWD || p->type == PLIST_SRC)
|
|
|
|
fprintf(totar, "-C\n%s\n", p->name);
|
1995-04-22 14:55:07 +00:00
|
|
|
else if (p->type == PLIST_IGNORE)
|
|
|
|
p = p->next;
|
|
|
|
}
|
1996-02-06 22:49:11 +00:00
|
|
|
|
|
|
|
fclose(totar);
|
|
|
|
wait(&ret);
|
1995-05-10 20:46:06 +00:00
|
|
|
/* assume either signal or bad exit is enough for us */
|
1998-09-11 07:26:58 +00:00
|
|
|
if (ret) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "tar command failed with code %d", ret);
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sanity_check()
|
|
|
|
{
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!Comment) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "required package comment string is missing (-c comment)");
|
|
|
|
}
|
|
|
|
if (!Desc) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "required package description string is missing (-d desc)");
|
|
|
|
}
|
|
|
|
if (!Contents) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "required package contents list is missing (-f [-]file)");
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Clean up those things that would otherwise hang around */
|
|
|
|
void
|
|
|
|
cleanup(int sig)
|
|
|
|
{
|
1998-02-16 17:16:51 +00:00
|
|
|
int in_cleanup = 0;
|
|
|
|
|
|
|
|
if (!in_cleanup) {
|
|
|
|
in_cleanup = 1;
|
|
|
|
leave_playpen();
|
|
|
|
}
|
1998-07-28 11:55:39 +00:00
|
|
|
if (sig)
|
|
|
|
exit(1);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|