main.c revision 179366
1327Sjkh/*
2327Sjkh * FreeBSD install - a package for the installation and maintainance
3327Sjkh * of non-core utilities.
4327Sjkh *
5327Sjkh * Jordan K. Hubbard
6327Sjkh * 18 July 1993
7327Sjkh *
8327Sjkh * This is the create module.
9327Sjkh *
10327Sjkh */
11327Sjkh
1293520Sobrien#include <sys/cdefs.h>
1393520Sobrien__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/main.c 179366 2008-05-27 19:06:45Z keramida $");
1493520Sobrien
1530221Scharnier#include <err.h>
16327Sjkh#include "lib.h"
17327Sjkh#include "create.h"
18327Sjkh
19179352Skeramidastatic char Options[] = "EGYNnORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
20327Sjkh
21152210Skrionmatch_t	MatchType	= MATCH_GLOB;
22327Sjkhchar	*Prefix		= NULL;
23327Sjkhchar	*Comment        = NULL;
24327Sjkhchar	*Desc		= NULL;
2526473Sjkhchar	*SrcDir		= NULL;
26131277Seikchar	*BaseDir	= NULL;
274996Sjkhchar	*Display	= NULL;
28327Sjkhchar	*Install	= NULL;
2941866Sjkhchar	*PostInstall	= NULL;
30327Sjkhchar	*DeInstall	= NULL;
3141866Sjkhchar	*PostDeInstall	= NULL;
32327Sjkhchar	*Contents	= NULL;
33327Sjkhchar	*Require	= NULL;
34445Sjkhchar	*ExcludeFrom	= NULL;
354996Sjkhchar	*Mtree		= NULL;
367713Sjkhchar	*Pkgdeps	= NULL;
37113594Skrischar	*Conflicts	= NULL;
3867454Ssobomaxchar	*Origin		= NULL;
3984670Ssobomaxchar	*InstalledPkg	= NULL;
4026473Sjkhchar	PlayPen[FILENAME_MAX];
4171095Ssobomaxint	Dereference	= FALSE;
4271095Ssobomaxint	PlistOnly	= FALSE;
43147043Ssobomaxint	Recursive	= FALSE;
44179352Skeramidaint	Regenerate	= TRUE;
45157808Skrion#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
46157808Skrionenum zipper	Zipper  = BZIP2;
47157808Skrion#else
48157808Skrionenum zipper	Zipper  = GZIP;
49157808Skrion#endif
50327Sjkh
51157808Skrion
52173412Skevlostatic void usage(void);
5330221Scharnier
54327Sjkhint
55327Sjkhmain(int argc, char **argv)
56327Sjkh{
57327Sjkh    int ch;
5884670Ssobomax    char **pkgs, **start, *tmp;
59327Sjkh
60327Sjkh    pkgs = start = argv;
6124428Simp    while ((ch = getopt(argc, argv, Options)) != -1)
62327Sjkh	switch(ch) {
63327Sjkh	case 'v':
64159554Sobrien	    Verbose++;
65327Sjkh	    break;
66327Sjkh
67152210Skrion	case 'x':
68152210Skrion	    MatchType = MATCH_REGEX;
69152210Skrion	    break;
70152210Skrion
71152210Skrion	case 'E':
72152210Skrion	    MatchType = MATCH_EREGEX;
73152210Skrion	    break;
74152210Skrion
75152210Skrion	case 'G':
76152210Skrion	    MatchType = MATCH_EXACT;
77152210Skrion	    break;
78152210Skrion
791337Sjkh	case 'N':
801337Sjkh	    AutoAnswer = NO;
811337Sjkh	    break;
821337Sjkh
831337Sjkh	case 'Y':
841337Sjkh	    AutoAnswer = YES;
851337Sjkh	    break;
861337Sjkh
877986Sjkh	case 'O':
8871095Ssobomax	    PlistOnly = TRUE;
897986Sjkh	    break;
907986Sjkh
91327Sjkh	case 'p':
92327Sjkh	    Prefix = optarg;
93327Sjkh	    break;
94327Sjkh
9526473Sjkh	case 's':
9626473Sjkh	    SrcDir = optarg;
9726473Sjkh	    break;
9826473Sjkh
99131277Seik	case 'S':
100131277Seik	    BaseDir = optarg;
101131277Seik	    break;
102131277Seik
103327Sjkh	case 'f':
104327Sjkh	    Contents = optarg;
105327Sjkh	    break;
106327Sjkh
107113594Skris	case 'C':
108113594Skris	    Conflicts = optarg;
109113594Skris	    break;
110113594Skris
111327Sjkh	case 'c':
112327Sjkh	    Comment = optarg;
113327Sjkh	    break;
114327Sjkh
115327Sjkh	case 'd':
116327Sjkh	    Desc = optarg;
117327Sjkh	    break;
118327Sjkh
119327Sjkh	case 'i':
120327Sjkh	    Install = optarg;
121327Sjkh	    break;
122327Sjkh
12341866Sjkh	case 'I':
12441866Sjkh	    PostInstall = optarg;
12541866Sjkh	    break;
12641866Sjkh
127327Sjkh	case 'k':
128327Sjkh	    DeInstall = optarg;
129327Sjkh	    break;
130327Sjkh
13141866Sjkh	case 'K':
13241866Sjkh	    PostDeInstall = optarg;
13341866Sjkh	    break;
13441866Sjkh
135327Sjkh	case 'r':
136327Sjkh	    Require = optarg;
137327Sjkh	    break;
138327Sjkh
139383Sjkh	case 't':
14085019Ssobomax	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
141383Sjkh	    break;
142383Sjkh
143445Sjkh	case 'X':
144445Sjkh	    ExcludeFrom = optarg;
145445Sjkh	    break;
146445Sjkh
147327Sjkh	case 'h':
14871095Ssobomax	    Dereference = TRUE;
1491520Salm	    break;
1501520Salm
1514996Sjkh	case 'D':
1524996Sjkh	    Display = optarg;
1534996Sjkh	    break;
1544996Sjkh
1554996Sjkh	case 'm':
1564996Sjkh	    Mtree = optarg;
1574996Sjkh	    break;
1584996Sjkh
1597713Sjkh	case 'P':
1607713Sjkh	    Pkgdeps = optarg;
1617713Sjkh	    break;
1627713Sjkh
16367454Ssobomax	case 'o':
16467454Ssobomax	    Origin = optarg;
16567454Ssobomax	    break;
16667454Ssobomax
16771373Ssobomax	case 'y':
16895161Sobrien	case 'j':
16995161Sobrien	    Zipper = BZIP2;
17071373Ssobomax	    break;
17171373Ssobomax
17295161Sobrien	case 'z':
17395161Sobrien	    Zipper = GZIP;
17495161Sobrien	    break;
17595161Sobrien
17684670Ssobomax	case 'b':
17785470Ssobomax	    InstalledPkg = optarg;
17884670Ssobomax	    while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
17984670Ssobomax		*tmp++ = '\0';
18084670Ssobomax		/*
18184670Ssobomax		 * If character after the '/' is alphanumeric, then we've
18284670Ssobomax		 * found the package name.  Otherwise we've come across
18384670Ssobomax		 * a trailing '/' and need to continue our quest.
18484670Ssobomax		 */
18584670Ssobomax		if (isalpha(*tmp)) {
18684670Ssobomax		    InstalledPkg = tmp;
18784670Ssobomax		    break;
18884670Ssobomax		}
18984670Ssobomax	    }
19084670Ssobomax	    break;
19184670Ssobomax
192147043Ssobomax	case 'R':
193147043Ssobomax	    Recursive = TRUE;
194147043Ssobomax	    break;
195147043Ssobomax
196179352Skeramida	case 'n':
197179352Skeramida		Regenerate = FALSE;
198179352Skeramida		break;
199179352Skeramida
200327Sjkh	case '?':
201327Sjkh	default:
20230221Scharnier	    usage();
203327Sjkh	    break;
204327Sjkh	}
205327Sjkh
2068857Srgrimes    argc -= optind;
207327Sjkh    argv += optind;
208327Sjkh
209327Sjkh    /* Get all the remaining package names, if any */
210327Sjkh    while (*argv)
211327Sjkh	*pkgs++ = *argv++;
212327Sjkh
213327Sjkh    /* If no packages, yelp */
21484670Ssobomax    if ((pkgs == start) && (InstalledPkg == NULL))
21530221Scharnier	warnx("missing package name"), usage();
216327Sjkh    *pkgs = NULL;
21784670Ssobomax    if ((start[0] != NULL) && (start[1] != NULL)) {
21884670Ssobomax	warnx("only one package name allowed ('%s' extraneous)", start[1]);
21930221Scharnier	usage();
22084670Ssobomax    }
22184670Ssobomax    if (start[0] == NULL)
22284670Ssobomax	start[0] = InstalledPkg;
223327Sjkh    if (!pkg_perform(start)) {
224327Sjkh	if (Verbose)
22530221Scharnier	    warnx("package creation failed");
226327Sjkh	return 1;
227327Sjkh    }
228327Sjkh    else
229327Sjkh	return 0;
230327Sjkh}
231327Sjkh
23230221Scharnierstatic void
23330221Scharnierusage()
234327Sjkh{
235131277Seik    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
236179352Skeramida"usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]",
237162803Sru"                  [-i iscript] [-I piscript] [-k dscript] [-K pdscript]",
238162803Sru"                  [-r rscript] [-s srcdir] [-S basedir]",
239162803Sru"                  [-t template] [-X excludefile]",
240162803Sru"                  [-D displayfile] [-m mtreefile] [-o originpath]",
241113594Skris"                  -c comment -d description -f packlist pkg-filename",
242179366Skeramida"       pkg_create [-EGYNRhnvxy] -b pkg-name [pkg-filename]");
243327Sjkh    exit(1);
244327Sjkh}
245