main.c revision 95161
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 95161 2002-04-20 21:20:58Z obrien $"); 1493520Sobrien 1530221Scharnier#include <err.h> 16327Sjkh#include "lib.h" 17327Sjkh#include "create.h" 18327Sjkh 1995161Sobrienstatic char Options[] = "YNOhjvyzf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:"; 20327Sjkh 21327Sjkhchar *Prefix = NULL; 22327Sjkhchar *Comment = NULL; 23327Sjkhchar *Desc = NULL; 2426473Sjkhchar *SrcDir = NULL; 254996Sjkhchar *Display = NULL; 26327Sjkhchar *Install = NULL; 2741866Sjkhchar *PostInstall = NULL; 28327Sjkhchar *DeInstall = NULL; 2941866Sjkhchar *PostDeInstall = NULL; 30327Sjkhchar *Contents = NULL; 31327Sjkhchar *Require = NULL; 32445Sjkhchar *ExcludeFrom = NULL; 334996Sjkhchar *Mtree = NULL; 347713Sjkhchar *Pkgdeps = NULL; 3567454Ssobomaxchar *Origin = NULL; 3684670Ssobomaxchar *InstalledPkg = NULL; 3726473Sjkhchar PlayPen[FILENAME_MAX]; 3871095Ssobomaxint Dereference = FALSE; 3971095Ssobomaxint PlistOnly = FALSE; 4095161Sobrienenum zipper Zipper = GZIP; 41327Sjkh 4230221Scharnierstatic void usage __P((void)); 4330221Scharnier 44327Sjkhint 45327Sjkhmain(int argc, char **argv) 46327Sjkh{ 47327Sjkh int ch; 4884670Ssobomax char **pkgs, **start, *tmp; 49327Sjkh 50327Sjkh pkgs = start = argv; 5124428Simp while ((ch = getopt(argc, argv, Options)) != -1) 52327Sjkh switch(ch) { 53327Sjkh case 'v': 54327Sjkh Verbose = TRUE; 55327Sjkh break; 56327Sjkh 571337Sjkh case 'N': 581337Sjkh AutoAnswer = NO; 591337Sjkh break; 601337Sjkh 611337Sjkh case 'Y': 621337Sjkh AutoAnswer = YES; 631337Sjkh break; 641337Sjkh 657986Sjkh case 'O': 6671095Ssobomax PlistOnly = TRUE; 677986Sjkh break; 687986Sjkh 69327Sjkh case 'p': 70327Sjkh Prefix = optarg; 71327Sjkh break; 72327Sjkh 7326473Sjkh case 's': 7426473Sjkh SrcDir = optarg; 7526473Sjkh break; 7626473Sjkh 77327Sjkh case 'f': 78327Sjkh Contents = optarg; 79327Sjkh break; 80327Sjkh 81327Sjkh case 'c': 82327Sjkh Comment = optarg; 83327Sjkh break; 84327Sjkh 85327Sjkh case 'd': 86327Sjkh Desc = optarg; 87327Sjkh break; 88327Sjkh 89327Sjkh case 'i': 90327Sjkh Install = optarg; 91327Sjkh break; 92327Sjkh 9341866Sjkh case 'I': 9441866Sjkh PostInstall = optarg; 9541866Sjkh break; 9641866Sjkh 97327Sjkh case 'k': 98327Sjkh DeInstall = optarg; 99327Sjkh break; 100327Sjkh 10141866Sjkh case 'K': 10241866Sjkh PostDeInstall = optarg; 10341866Sjkh break; 10441866Sjkh 105327Sjkh case 'r': 106327Sjkh Require = optarg; 107327Sjkh break; 108327Sjkh 109383Sjkh case 't': 11085019Ssobomax strlcpy(PlayPen, optarg, sizeof(PlayPen)); 111383Sjkh break; 112383Sjkh 113445Sjkh case 'X': 114445Sjkh ExcludeFrom = optarg; 115445Sjkh break; 116445Sjkh 117327Sjkh case 'h': 11871095Ssobomax Dereference = TRUE; 1191520Salm break; 1201520Salm 1214996Sjkh case 'D': 1224996Sjkh Display = optarg; 1234996Sjkh break; 1244996Sjkh 1254996Sjkh case 'm': 1264996Sjkh Mtree = optarg; 1274996Sjkh break; 1284996Sjkh 1297713Sjkh case 'P': 1307713Sjkh Pkgdeps = optarg; 1317713Sjkh break; 1327713Sjkh 13367454Ssobomax case 'o': 13467454Ssobomax Origin = optarg; 13567454Ssobomax break; 13667454Ssobomax 13771373Ssobomax case 'y': 13895161Sobrien case 'j': 13995161Sobrien Zipper = BZIP2; 14071373Ssobomax break; 14171373Ssobomax 14295161Sobrien case 'z': 14395161Sobrien Zipper = GZIP; 14495161Sobrien break; 14595161Sobrien 14684670Ssobomax case 'b': 14785470Ssobomax InstalledPkg = optarg; 14884670Ssobomax while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 14984670Ssobomax *tmp++ = '\0'; 15084670Ssobomax /* 15184670Ssobomax * If character after the '/' is alphanumeric, then we've 15284670Ssobomax * found the package name. Otherwise we've come across 15384670Ssobomax * a trailing '/' and need to continue our quest. 15484670Ssobomax */ 15584670Ssobomax if (isalpha(*tmp)) { 15684670Ssobomax InstalledPkg = tmp; 15784670Ssobomax break; 15884670Ssobomax } 15984670Ssobomax } 16084670Ssobomax break; 16184670Ssobomax 162327Sjkh case '?': 163327Sjkh default: 16430221Scharnier usage(); 165327Sjkh break; 166327Sjkh } 167327Sjkh 1688857Srgrimes argc -= optind; 169327Sjkh argv += optind; 170327Sjkh 171327Sjkh /* Get all the remaining package names, if any */ 172327Sjkh while (*argv) 173327Sjkh *pkgs++ = *argv++; 174327Sjkh 175327Sjkh /* If no packages, yelp */ 17684670Ssobomax if ((pkgs == start) && (InstalledPkg == NULL)) 17730221Scharnier warnx("missing package name"), usage(); 178327Sjkh *pkgs = NULL; 17984670Ssobomax if ((start[0] != NULL) && (start[1] != NULL)) { 18084670Ssobomax warnx("only one package name allowed ('%s' extraneous)", start[1]); 18130221Scharnier usage(); 18284670Ssobomax } 18384670Ssobomax if (start[0] == NULL) 18484670Ssobomax start[0] = InstalledPkg; 185327Sjkh if (!pkg_perform(start)) { 186327Sjkh if (Verbose) 18730221Scharnier warnx("package creation failed"); 188327Sjkh return 1; 189327Sjkh } 190327Sjkh else 191327Sjkh return 0; 192327Sjkh} 193327Sjkh 19430221Scharnierstatic void 19530221Scharnierusage() 196327Sjkh{ 19784670Ssobomax fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", 19871373Ssobomax"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]", 19941866Sjkh" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ", 20041866Sjkh" [-t template] [-X excludefile] [-D displayfile] ", 20167454Ssobomax" [-m mtreefile] [-o origin] -c comment -d description ", 20284670Ssobomax" -f packlist pkg-filename", 20384670Ssobomax" pkg_create [-YNhvy] -b pkg-name [pkg-filename]"); 204327Sjkh exit(1); 205327Sjkh} 206