1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1996-03-20 19:05:59 +00:00
|
|
|
static const char *rcsid = "$Id: perform.c,v 1.29 1996/02/06 22:49:11 jdp 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"
|
|
|
|
|
1996-02-06 22:49:11 +00:00
|
|
|
#include <errno.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-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;
|
|
|
|
char *suffix; /* What we tack on to the end of the finished package */
|
|
|
|
|
|
|
|
/* 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");
|
|
|
|
if (!pkg_in)
|
|
|
|
barf("Unable to open contents file '%s' for input.", Contents);
|
|
|
|
}
|
|
|
|
plist.head = plist.tail = NULL;
|
|
|
|
|
|
|
|
/* Break the package name into base and desired suffix (if any) */
|
1994-08-29 16:31:38 +00:00
|
|
|
if ((cp = rindex(pkg, '.')) != NULL) {
|
1993-08-26 01:19:55 +00:00
|
|
|
suffix = cp + 1;
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
suffix = "tgz";
|
|
|
|
|
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
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Slurp in the packing list */
|
|
|
|
read_plist(&plist, pkg_in);
|
|
|
|
|
1994-10-04 15:54:39 +00:00
|
|
|
/* Prefix should override the packing list */
|
|
|
|
if (Prefix) {
|
|
|
|
delete_plist(&plist, FALSE, PLIST_CWD, NULL);
|
|
|
|
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) {
|
|
|
|
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
|
|
|
|
|
|
|
/* Run through the list again, picking up extra "local" items */
|
1995-04-22 14:55:07 +00:00
|
|
|
/* check_list(".", &plist); */
|
|
|
|
/* copy_plist(".", &plist); */
|
|
|
|
/* mark_plist(&plist); */
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Finally, write out the packing list */
|
|
|
|
fp = fopen(CONTENTS_FNAME, "w");
|
|
|
|
if (!fp)
|
|
|
|
barf("Can't open file %s for writing.", CONTENTS_FNAME);
|
|
|
|
write_plist(&plist, fp);
|
|
|
|
if (fclose(fp))
|
|
|
|
barf("Error while closing %s.", CONTENTS_FNAME);
|
|
|
|
|
|
|
|
/* And stick it into a tar ball */
|
|
|
|
make_dist(home, pkg, suffix, &plist);
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
free(Comment);
|
|
|
|
free(Desc);
|
|
|
|
free_plist(&plist);
|
|
|
|
cleanup(0);
|
|
|
|
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;
|
1995-05-10 20:46:06 +00:00
|
|
|
int ret, max, len;
|
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. */
|
|
|
|
if (pipe(pipefds) == -1)
|
|
|
|
barf("Cannot create pipe: %s", strerror(errno));
|
|
|
|
if ((pid = fork()) == -1)
|
|
|
|
barf("Cannot fork process for tar: %s", strerror(errno));
|
|
|
|
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);
|
|
|
|
barf("Failed to execute tar command: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Meanwhile, back in the parent process ... */
|
|
|
|
close(pipefds[0]);
|
|
|
|
if ((totar = fdopen(pipefds[1], "w")) == NULL)
|
|
|
|
barf("fdopen failed: %s", strerror(errno));
|
|
|
|
|
|
|
|
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 */
|
1993-09-12 20:56:40 +00:00
|
|
|
if (ret)
|
1995-05-10 20:46:06 +00:00
|
|
|
barf("tar command failed with code %d", ret);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sanity_check()
|
|
|
|
{
|
|
|
|
if (!Comment)
|
|
|
|
barf("Required package comment string is missing (-c comment).");
|
|
|
|
if (!Desc)
|
|
|
|
barf("Required package description string is missing (-d desc).");
|
|
|
|
if (!Contents)
|
|
|
|
barf("Required package contents list is missing (-f [-]file).");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Clean up those things that would otherwise hang around */
|
|
|
|
void
|
|
|
|
cleanup(int sig)
|
|
|
|
{
|
1995-10-25 15:38:37 +00:00
|
|
|
leave_playpen(home);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|