diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1993-08-26 01:19:55 +0000 |
| commit | 6d946b2e52275a56dd775436f4c6b6a4c65915c8 (patch) | |
| tree | b3cb91ab036ba2deccf4af07caf09c2bf6b4b88e /usr.sbin/pkg_install/create | |
| parent | 24a82630a20b64577bcc7454bec7288b1dbdb37a (diff) | |
Notes
Diffstat (limited to 'usr.sbin/pkg_install/create')
| -rw-r--r-- | usr.sbin/pkg_install/create/Makefile | 8 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/create.h | 39 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/main.c | 125 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 165 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/pkg_create.1 | 185 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/pl.c | 104 |
6 files changed, 626 insertions, 0 deletions
diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile new file mode 100644 index 000000000000..01e6b20c2c56 --- /dev/null +++ b/usr.sbin/pkg_install/create/Makefile @@ -0,0 +1,8 @@ +PROG= pkg_create + +CFLAGS+= -I${.CURDIR}/../lib +LDADD+= -L${.CURDIR}/../lib -linstall + +SRCS= main.c perform.c pl.c + +.include <bsd.prog.mk> diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h new file mode 100644 index 000000000000..2e1e73c3644d --- /dev/null +++ b/usr.sbin/pkg_install/create/create.h @@ -0,0 +1,39 @@ +/* $Id: create.h,v 1.3 1993/08/24 09:23:32 jkh Exp $ */ + +/* + * 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 + * + * Include and define various things wanted by the create command. + * + */ + +#ifndef _INST_CREATE_H_INCLUDE +#define _INST_CREATE_H_INCLUDE + +extern char *Prefix; +extern char *Comment; +extern char *Desc; +extern char *Install; +extern char *DeInstall; +extern char *Contents; +extern char *Require; + +void check_list(char *, Package *); +void usage(const char *, const char *, ...); +int pkg_perform(char **); +void copy_plist(char *, Package *); + +#endif /* _INST_CREATE_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c new file mode 100644 index 000000000000..63f669939678 --- /dev/null +++ b/usr.sbin/pkg_install/create/main.c @@ -0,0 +1,125 @@ +#ifndef lint +static const char *rcsid = "$Id: main.c,v 1.3 1993/08/20 08:52:39 jkh Exp $"; +#endif + +/* + * FreeBSD install - a package for the installation and maintainance + * of non-core utilities. + * + * Jordan K. Hubbard + * 18 July 1993 + * + * This is the create module. + * + */ + +#include "lib.h" +#include "create.h" + +static char Options[] = "hvf:p:c:d:i:k:r:"; + +char *Prefix = NULL; +char *Comment = NULL; +char *Desc = NULL; +char *Install = NULL; +char *DeInstall = NULL; +char *Contents = NULL; +char *Require = NULL; + +int +main(int argc, char **argv) +{ + int ch; + char **pkgs, **start; + char *prog_name = argv[0]; + + pkgs = start = argv; + while ((ch = getopt(argc, argv, Options)) != EOF) + switch(ch) { + case 'v': + Verbose = TRUE; + break; + + case 'p': + Prefix = optarg; + break; + + case 'f': + Contents = optarg; + break; + + case 'c': + Comment = optarg; + break; + + case 'd': + Desc = optarg; + break; + + case 'i': + Install = optarg; + break; + + case 'k': + DeInstall = optarg; + break; + + case 'r': + Require = optarg; + break; + + case 'h': + case '?': + default: + usage(prog_name, NULL); + break; + } + + argc -= optind; + argv += optind; + + /* Get all the remaining package names, if any */ + while (*argv) + *pkgs++ = *argv++; + + /* If no packages, yelp */ + if (pkgs == start) + usage(prog_name, "Missing package name"); + *pkgs = NULL; + if (start[1]) + usage(prog_name, "Only one package name allowed\n\t('%s' extraneous)", + start[1]); + if (!pkg_perform(start)) { + if (Verbose) + fprintf(stderr, "Package creation failed.\n"); + return 1; + } + else + return 0; +} + +void +usage(const char *name, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (fmt) { + fprintf(stderr, "%s: ", name); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n\n"); + } + va_end(args); + fprintf(stderr, "Usage: %s [args] pkg\n\n", name); + fprintf(stderr, "Where args are one or more of:\n\n"); + + fprintf(stderr, "-c [-]file Get one-line comment from file (-or arg)\n"); + fprintf(stderr, "-d [-]file Get description from file (-or arg)\n"); + fprintf(stderr, "-f file get list of files from file (- for stdin)\n"); + fprintf(stderr, "-i script install script\n"); + fprintf(stderr, "-p arg install prefix will be arg\n"); + fprintf(stderr, "-k script de-install script\n"); + fprintf(stderr, "-r script pre/post requirements script\n"); + fprintf(stderr, "-v verbose\n"); + exit(1); +} diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c new file mode 100644 index 000000000000..634188b00b61 --- /dev/null +++ b/usr.sbin/pkg_install/create/perform.c @@ -0,0 +1,165 @@ +#ifndef lint +static const char *rcsid = "$Id: perform.c,v 1.4 1993/08/26 08:12:52 jkh Exp $"; +#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" + +#include <signal.h> + +static void sanity_check(void); +static void make_dist(char *, char *, char *, Package *); + +int +pkg_perform(char **pkgs) +{ + char *pkg = *pkgs; /* Only one arg to create */ + char *home, *cp; + FILE *pkg_in, *fp; + Package plist; + char *suffix; /* What we tack on to the end of the finished package */ + + /* Preliminary setup */ + sanity_check(); + if (Verbose) + 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) */ + if ((cp = index(pkg, '.')) != NULL) { + suffix = cp + 1; + *cp = '\0'; + } + else + suffix = "tgz"; + + /* Register the package name (base part) */ + add_plist(&plist, PLIST_NAME, pkg); + if (Prefix) + add_plist(&plist, PLIST_CWD, Prefix); + + /* Slurp in the packing list */ + read_plist(&plist, pkg_in); + + /* Make a directory to stomp around in */ + home = make_playpen(); + signal(SIGINT, cleanup); + signal(SIGHUP, cleanup); + + /* Make first "real contents" pass over it */ + check_list(home, &plist); + copy_plist(home, &plist); + mark_plist(&plist); + + /* 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); + } + + /* Run through the list again, picking up extra "local" items */ + check_list(".", &plist); + copy_plist(".", &plist); + mark_plist(&plist); + + /* 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]; + char args[10]; + + sprintf(tball, "%s/%s.%s", home, pkg, suffix); + if (index(suffix, 'z')) /* Compress/gzip? */ + strcpy(args, "z"); + if (Verbose) + printf("Creating gzip'd tar ball in '%s', contents:\n", tball); + strcat(args, "cf"); + if (vsystem("tar %s %s .", args, tball)) + barf("tar command failed!"); +} + +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) +{ + leave_playpen(); +} diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 new file mode 100644 index 000000000000..dd0e967714a4 --- /dev/null +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -0,0 +1,185 @@ +.\" +.\" 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 +.\" +.\" +.\" @(#)pkg_create.1 +.\" +.TH pkg_create 1 "July 18, 1993" "" "FreeBSD" + +.SH NAME +pkg_create - a utility for creating software package distributions. +.SH SYNOPSIS +.na +.B pkg_create +.RB [options] +.RB pkg-name + +.SH DESCRIPTION +The +.B pkg_create +command is used to create packages that will subsequently be fed to +one of the package extraction/info utilities. The input description +and command line arguments for the creation of a package are not +really meant to be human-generated, though it is easy enough to +do so. It is more expected that you will use a front-end tool for +the job rather than muddling through it yourself. Nonetheless, a short +description of the input syntax is included in this document. + +.SH OPTIONS +.TP +The following command line options are supported. +.TP +.B \-v +Turns on verbose output. +.B "Optional." +.TP +.BI "\-c\ " [-]desc +Fetch package "one line description" from file +.I desc +or, if preceeded by +.B - +, the argument itself. This string should also +give some idea of which version of the product (if any) the package +represents. +.B "Mandatory." +.TP +.BI "\-d\ " [-]desc +Fetch long description for package from file +.I desc +or, if preceeded by +.B - +, the argument itself. +.B "Mandatory." +.TP +.BI "\-f\ " file +Fetch "packing list" for package from +.I file +or +.B stdin +if +.I file +is a +.B - +(dash). +.B "Mandatory." +.TP +.BI "\-i\ " script +Sets +.I script +to be the install procedure for the package. This can be any +executable program (or shell script). It will be invoked automatically +when the package is later installed. +.B "Optional." +.TP +.BI "\-p\ " prefix +Sets +.I prefix +As the initial directory "base" to start from in selecting files for +the package. +.B "Optional." +.TP +.BI "\-k\ " script +Sets +.I script +to be the de-install procedure for the package. This can be any +executable program (or shell script). It will be invoked automatically +when the package is later (if ever) de-installed. +.B "Optional." +.TP +.BI "\-r\ " script +Sets +.I script +to be the "requirements" procedure for the package. This can be any +executable program (or shell script). It will be invoked automatically +at installation/deinstallation time to determine whether or not +installation/deinstallation should proceed. +.B "Optional." +.PP +.SH "TECHNICAL DETAILS" +The "packing list" format (see \fB-f\fR) is fairly simple, being +nothing more than a single column of filenames to include in the +package. However, since absolute pathnames are generally a bad idea +for a package that could be installed potentially anywhere, there is +another method of specifying where things are supposed to go +and, optionally, what ownership and mode information they should be +installed with. This is done by imbeding specialized command sequences +in the packing list. Briefly described, these sequences are: +.TP +.BI "@cwd\ " directory +Sets the internal directory pointer to point to +.I directory. +All subsequent filenames will be assumed relative to this directory. +.TP +.BI "@exec\ " command +Execute +.I command +as part of the unpacking process. If +.I command +contains a `%s' sequence somewhere in it, it will be expanded to +the name of the last filename extracted. In practice, such +weird things should be unnecessary in all but the most extenuating +circumstances, but it's there should you need it nonetheless. +.TP +.BI "@mode\ " mode +Sets default permission for all subsequently extracted files to +.I mode. +Format is the same as that used by the +.B chmod +command (well, considering that it's later handed off to it, that's +no surprise). Use without an arg to set back to default (extraction) +permissions. +.TP +.BI "@owner\ " user +Sets default ownership for all subsequently extracted files to +.I user. +Use without an arg to set back to default (extraction) +ownership. +.TP +.BI "@group\ " group +Sets default group ownership for all subsequently extracted files to +.I group. +Use without an arg to set back to default (extraction) +group ownership. +.TP +.BI "@comment\ " string +Imbed a comment in the packing list. Useful in +trying to document some particularly hairy sequence that +may trip someone up later. +.TP +.BI "@ignore\ " file +Used internally to tell extraction to ignore the next file (don't +copy it anywhere), as it's used for some special purpose. Also useful +if you want to pack some specialized datafiles in with a distribution +for your install script (or something) and want to have the installer +ignore it. +.TP +.BI "@name\ " name +Sets the name of the package. This is mandatory and is usually +put at the top. This name is potentially different than the name of +the file it came in, and is used when keeping track of the package +for later deinstallation. Note that +.B pkg_create +currently derives this field from the package name and adds it +automatically. + +.SH BUGS +Sure to be some. +.SH "SEE ALSO" +.BR pkg_add "(" 1 ")," +.BR pkg_info "(" 1 ")," +.BR pkg_delete "(" 1 ")," +.SH AUTHORS +Jordan Hubbard + diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c new file mode 100644 index 000000000000..3b9a2d048388 --- /dev/null +++ b/usr.sbin/pkg_install/create/pl.c @@ -0,0 +1,104 @@ +#ifndef lint +static const char *rcsid = "$Id: pl.c,v 1.4 1993/08/26 08:12:53 jkh Exp $"; +#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 + * + * Routines for dealing with the packing list. + * + */ + +#include "lib.h" +#include "create.h" + +#define QUERY_GZIP \ +"File '%s' appears to be gzip'd.\nWould you like to unpack it first" +#define UNZIP "gzip -d %s" + +#define QUERY_COMPRESS \ +"File '%s' appears to be compressed.\nWould you like to unpack it first" +#define UNCOMPRESS "compress -d %s" + +/* Check a list for files that require preconversion */ +void +check_list(char *home, Package *pkg) +{ + char cmd[FILENAME_MAX]; + char name[FILENAME_MAX]; + char *where = home; + PackingList p = pkg->head; + + while (p) { + if (p->type == PLIST_CWD) + where = p->name; + else if (p->type == PLIST_IGNORE) + p = p->next; + else if (p->type == PLIST_FILE) { + cmd[0] = '\0'; + sprintf(name, "%s/%s", where, p->name); + /* gzip? */ + if ((suffix(name, "gz") || suffix(name, "z")) && + y_or_n(TRUE, QUERY_GZIP, name)) + sprintf(cmd, UNZIP, name); + + /* Compress? */ + else if (suffix(name, "Z") && y_or_n(TRUE, QUERY_COMPRESS, name)) + sprintf(cmd, UNCOMPRESS, name); + + if (*cmd) { + if (Verbose) + printf("Uncompressing-> %s\n", cmd); + if (system(cmd)) + barf("%s failed!", cmd); + nuke_suffix(p->name); + } + } + p = p->next; + } +} + +/* + * Copy unmarked files in packing list to playpen - marked files + * have already been copied in an earlier pass through the list. + */ +void +copy_plist(char *home, Package *plist) +{ + PackingList p = plist->head; + char *where = home; + + while (p) { + if (p->type == PLIST_CWD) + where = p->name; + else if (p->type == PLIST_IGNORE) + p = p->next; + else if (p->type == PLIST_FILE && !p->marked) { + char fn[FILENAME_MAX]; + + /* First, look for it in the "home" dir */ + sprintf(fn, "%s/%s", home, p->name); + if (fexists(fn)) + copy_hierarchy(home, p->name, FALSE); + /* + * Otherwise, try along the actual extraction path.. + */ + else + copy_hierarchy(where, p->name, FALSE); + } + p = p->next; + } +} |
