main.c revision 147043
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 147043 2005-06-06 03:24:14Z sobomax $");
1493520Sobrien
1530221Scharnier#include <err.h>
16327Sjkh#include "lib.h"
17327Sjkh#include "create.h"
18327Sjkh
19147043Ssobomaxstatic char Options[] = "YNORhjvyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
20327Sjkh
21327Sjkhchar	*Prefix		= NULL;
22327Sjkhchar	*Comment        = NULL;
23327Sjkhchar	*Desc		= NULL;
2426473Sjkhchar	*SrcDir		= NULL;
25131277Seikchar	*BaseDir	= NULL;
264996Sjkhchar	*Display	= NULL;
27327Sjkhchar	*Install	= NULL;
2841866Sjkhchar	*PostInstall	= NULL;
29327Sjkhchar	*DeInstall	= NULL;
3041866Sjkhchar	*PostDeInstall	= NULL;
31327Sjkhchar	*Contents	= NULL;
32327Sjkhchar	*Require	= NULL;
33445Sjkhchar	*ExcludeFrom	= NULL;
344996Sjkhchar	*Mtree		= NULL;
357713Sjkhchar	*Pkgdeps	= NULL;
36113594Skrischar	*Conflicts	= NULL;
3767454Ssobomaxchar	*Origin		= NULL;
3884670Ssobomaxchar	*InstalledPkg	= NULL;
3926473Sjkhchar	PlayPen[FILENAME_MAX];
4071095Ssobomaxint	Dereference	= FALSE;
4171095Ssobomaxint	PlistOnly	= FALSE;
42147043Ssobomaxint	Recursive	= FALSE;
4395161Sobrienenum zipper	Zipper	= GZIP;
44327Sjkh
4530221Scharnierstatic void usage __P((void));
4630221Scharnier
47327Sjkhint
48327Sjkhmain(int argc, char **argv)
49327Sjkh{
50327Sjkh    int ch;
5184670Ssobomax    char **pkgs, **start, *tmp;
52327Sjkh
53327Sjkh    pkgs = start = argv;
5424428Simp    while ((ch = getopt(argc, argv, Options)) != -1)
55327Sjkh	switch(ch) {
56327Sjkh	case 'v':
57327Sjkh	    Verbose = TRUE;
58327Sjkh	    break;
59327Sjkh
601337Sjkh	case 'N':
611337Sjkh	    AutoAnswer = NO;
621337Sjkh	    break;
631337Sjkh
641337Sjkh	case 'Y':
651337Sjkh	    AutoAnswer = YES;
661337Sjkh	    break;
671337Sjkh
687986Sjkh	case 'O':
6971095Ssobomax	    PlistOnly = TRUE;
707986Sjkh	    break;
717986Sjkh
72327Sjkh	case 'p':
73327Sjkh	    Prefix = optarg;
74327Sjkh	    break;
75327Sjkh
7626473Sjkh	case 's':
7726473Sjkh	    SrcDir = optarg;
7826473Sjkh	    break;
7926473Sjkh
80131277Seik	case 'S':
81131277Seik	    BaseDir = optarg;
82131277Seik	    break;
83131277Seik
84327Sjkh	case 'f':
85327Sjkh	    Contents = optarg;
86327Sjkh	    break;
87327Sjkh
88113594Skris	case 'C':
89113594Skris	    Conflicts = optarg;
90113594Skris	    break;
91113594Skris
92327Sjkh	case 'c':
93327Sjkh	    Comment = optarg;
94327Sjkh	    break;
95327Sjkh
96327Sjkh	case 'd':
97327Sjkh	    Desc = optarg;
98327Sjkh	    break;
99327Sjkh
100327Sjkh	case 'i':
101327Sjkh	    Install = optarg;
102327Sjkh	    break;
103327Sjkh
10441866Sjkh	case 'I':
10541866Sjkh	    PostInstall = optarg;
10641866Sjkh	    break;
10741866Sjkh
108327Sjkh	case 'k':
109327Sjkh	    DeInstall = optarg;
110327Sjkh	    break;
111327Sjkh
11241866Sjkh	case 'K':
11341866Sjkh	    PostDeInstall = optarg;
11441866Sjkh	    break;
11541866Sjkh
116327Sjkh	case 'r':
117327Sjkh	    Require = optarg;
118327Sjkh	    break;
119327Sjkh
120383Sjkh	case 't':
12185019Ssobomax	    strlcpy(PlayPen, optarg, sizeof(PlayPen));
122383Sjkh	    break;
123383Sjkh
124445Sjkh	case 'X':
125445Sjkh	    ExcludeFrom = optarg;
126445Sjkh	    break;
127445Sjkh
128327Sjkh	case 'h':
12971095Ssobomax	    Dereference = TRUE;
1301520Salm	    break;
1311520Salm
1324996Sjkh	case 'D':
1334996Sjkh	    Display = optarg;
1344996Sjkh	    break;
1354996Sjkh
1364996Sjkh	case 'm':
1374996Sjkh	    Mtree = optarg;
1384996Sjkh	    break;
1394996Sjkh
1407713Sjkh	case 'P':
1417713Sjkh	    Pkgdeps = optarg;
1427713Sjkh	    break;
1437713Sjkh
14467454Ssobomax	case 'o':
14567454Ssobomax	    Origin = optarg;
14667454Ssobomax	    break;
14767454Ssobomax
14871373Ssobomax	case 'y':
14995161Sobrien	case 'j':
15095161Sobrien	    Zipper = BZIP2;
15171373Ssobomax	    break;
15271373Ssobomax
15395161Sobrien	case 'z':
15495161Sobrien	    Zipper = GZIP;
15595161Sobrien	    break;
15695161Sobrien
15784670Ssobomax	case 'b':
15885470Ssobomax	    InstalledPkg = optarg;
15984670Ssobomax	    while ((tmp = strrchr(optarg, (int)'/')) != NULL) {
16084670Ssobomax		*tmp++ = '\0';
16184670Ssobomax		/*
16284670Ssobomax		 * If character after the '/' is alphanumeric, then we've
16384670Ssobomax		 * found the package name.  Otherwise we've come across
16484670Ssobomax		 * a trailing '/' and need to continue our quest.
16584670Ssobomax		 */
16684670Ssobomax		if (isalpha(*tmp)) {
16784670Ssobomax		    InstalledPkg = tmp;
16884670Ssobomax		    break;
16984670Ssobomax		}
17084670Ssobomax	    }
17184670Ssobomax	    break;
17284670Ssobomax
173147043Ssobomax	case 'R':
174147043Ssobomax	    Recursive = TRUE;
175147043Ssobomax	    break;
176147043Ssobomax
177327Sjkh	case '?':
178327Sjkh	default:
17930221Scharnier	    usage();
180327Sjkh	    break;
181327Sjkh	}
182327Sjkh
1838857Srgrimes    argc -= optind;
184327Sjkh    argv += optind;
185327Sjkh
186327Sjkh    /* Get all the remaining package names, if any */
187327Sjkh    while (*argv)
188327Sjkh	*pkgs++ = *argv++;
189327Sjkh
190327Sjkh    /* If no packages, yelp */
19184670Ssobomax    if ((pkgs == start) && (InstalledPkg == NULL))
19230221Scharnier	warnx("missing package name"), usage();
193327Sjkh    *pkgs = NULL;
19484670Ssobomax    if ((start[0] != NULL) && (start[1] != NULL)) {
19584670Ssobomax	warnx("only one package name allowed ('%s' extraneous)", start[1]);
19630221Scharnier	usage();
19784670Ssobomax    }
19884670Ssobomax    if (start[0] == NULL)
19984670Ssobomax	start[0] = InstalledPkg;
200327Sjkh    if (!pkg_perform(start)) {
201327Sjkh	if (Verbose)
20230221Scharnier	    warnx("package creation failed");
203327Sjkh	return 1;
204327Sjkh    }
205327Sjkh    else
206327Sjkh	return 0;
207327Sjkh}
208327Sjkh
20930221Scharnierstatic void
21030221Scharnierusage()
211327Sjkh{
212131277Seik    fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
213131277Seik"usage: pkg_create [-YNOhvyz] [-P pkgs] [-C conflicts] [-p prefix] ",
214113594Skris"                  [-i iscript] [-I piscript] [-k dscript] [-K pdscript] ",
215113594Skris"                  [-r rscript] [-t template] [-X excludefile] ",
216113594Skris"                  [-D displayfile] [-m mtreefile] [-o origin] ",
217131277Seik"                  [-s srcdir] [-S basedir] ",
218113594Skris"                  -c comment -d description -f packlist pkg-filename",
219147043Ssobomax"       pkg_create [-YNhvyzR] -b pkg-name [pkg-filename]");
220327Sjkh    exit(1);
221327Sjkh}
222