main.c revision 93520
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 93520 2002-04-01 09:39:07Z obrien $"); 1493520Sobrien 1530221Scharnier#include <err.h> 16327Sjkh#include "lib.h" 17327Sjkh#include "create.h" 18327Sjkh 1984670Ssobomaxstatic char Options[] = "YNOhvyf: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; 4071373Ssobomaxint UseBzip2 = FALSE; 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': 13871513Ssobomax UseBzip2 = TRUE; 13971373Ssobomax break; 14071373Ssobomax 14184670Ssobomax case 'b': 14285470Ssobomax InstalledPkg = optarg; 14384670Ssobomax while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 14484670Ssobomax *tmp++ = '\0'; 14584670Ssobomax /* 14684670Ssobomax * If character after the '/' is alphanumeric, then we've 14784670Ssobomax * found the package name. Otherwise we've come across 14884670Ssobomax * a trailing '/' and need to continue our quest. 14984670Ssobomax */ 15084670Ssobomax if (isalpha(*tmp)) { 15184670Ssobomax InstalledPkg = tmp; 15284670Ssobomax break; 15384670Ssobomax } 15484670Ssobomax } 15584670Ssobomax break; 15684670Ssobomax 157327Sjkh case '?': 158327Sjkh default: 15930221Scharnier usage(); 160327Sjkh break; 161327Sjkh } 162327Sjkh 1638857Srgrimes argc -= optind; 164327Sjkh argv += optind; 165327Sjkh 166327Sjkh /* Get all the remaining package names, if any */ 167327Sjkh while (*argv) 168327Sjkh *pkgs++ = *argv++; 169327Sjkh 170327Sjkh /* If no packages, yelp */ 17184670Ssobomax if ((pkgs == start) && (InstalledPkg == NULL)) 17230221Scharnier warnx("missing package name"), usage(); 173327Sjkh *pkgs = NULL; 17484670Ssobomax if ((start[0] != NULL) && (start[1] != NULL)) { 17584670Ssobomax warnx("only one package name allowed ('%s' extraneous)", start[1]); 17630221Scharnier usage(); 17784670Ssobomax } 17884670Ssobomax if (start[0] == NULL) 17984670Ssobomax start[0] = InstalledPkg; 180327Sjkh if (!pkg_perform(start)) { 181327Sjkh if (Verbose) 18230221Scharnier warnx("package creation failed"); 183327Sjkh return 1; 184327Sjkh } 185327Sjkh else 186327Sjkh return 0; 187327Sjkh} 188327Sjkh 18930221Scharnierstatic void 19030221Scharnierusage() 191327Sjkh{ 19284670Ssobomax fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", 19371373Ssobomax"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]", 19441866Sjkh" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ", 19541866Sjkh" [-t template] [-X excludefile] [-D displayfile] ", 19667454Ssobomax" [-m mtreefile] [-o origin] -c comment -d description ", 19784670Ssobomax" -f packlist pkg-filename", 19884670Ssobomax" pkg_create [-YNhvy] -b pkg-name [pkg-filename]"); 199327Sjkh exit(1); 200327Sjkh} 201