main.c revision 147043
1/* 2 * FreeBSD install - a package for the installation and maintainance 3 * of non-core utilities. 4 * 5 * Jordan K. Hubbard 6 * 18 July 1993 7 * 8 * This is the create module. 9 * 10 */ 11 12#include <sys/cdefs.h> 13__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/main.c 147043 2005-06-06 03:24:14Z sobomax $"); 14 15#include <err.h> 16#include "lib.h" 17#include "create.h" 18 19static char Options[] = "YNORhjvyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; 20 21char *Prefix = NULL; 22char *Comment = NULL; 23char *Desc = NULL; 24char *SrcDir = NULL; 25char *BaseDir = NULL; 26char *Display = NULL; 27char *Install = NULL; 28char *PostInstall = NULL; 29char *DeInstall = NULL; 30char *PostDeInstall = NULL; 31char *Contents = NULL; 32char *Require = NULL; 33char *ExcludeFrom = NULL; 34char *Mtree = NULL; 35char *Pkgdeps = NULL; 36char *Conflicts = NULL; 37char *Origin = NULL; 38char *InstalledPkg = NULL; 39char PlayPen[FILENAME_MAX]; 40int Dereference = FALSE; 41int PlistOnly = FALSE; 42int Recursive = FALSE; 43enum zipper Zipper = GZIP; 44 45static void usage __P((void)); 46 47int 48main(int argc, char **argv) 49{ 50 int ch; 51 char **pkgs, **start, *tmp; 52 53 pkgs = start = argv; 54 while ((ch = getopt(argc, argv, Options)) != -1) 55 switch(ch) { 56 case 'v': 57 Verbose = TRUE; 58 break; 59 60 case 'N': 61 AutoAnswer = NO; 62 break; 63 64 case 'Y': 65 AutoAnswer = YES; 66 break; 67 68 case 'O': 69 PlistOnly = TRUE; 70 break; 71 72 case 'p': 73 Prefix = optarg; 74 break; 75 76 case 's': 77 SrcDir = optarg; 78 break; 79 80 case 'S': 81 BaseDir = optarg; 82 break; 83 84 case 'f': 85 Contents = optarg; 86 break; 87 88 case 'C': 89 Conflicts = optarg; 90 break; 91 92 case 'c': 93 Comment = optarg; 94 break; 95 96 case 'd': 97 Desc = optarg; 98 break; 99 100 case 'i': 101 Install = optarg; 102 break; 103 104 case 'I': 105 PostInstall = optarg; 106 break; 107 108 case 'k': 109 DeInstall = optarg; 110 break; 111 112 case 'K': 113 PostDeInstall = optarg; 114 break; 115 116 case 'r': 117 Require = optarg; 118 break; 119 120 case 't': 121 strlcpy(PlayPen, optarg, sizeof(PlayPen)); 122 break; 123 124 case 'X': 125 ExcludeFrom = optarg; 126 break; 127 128 case 'h': 129 Dereference = TRUE; 130 break; 131 132 case 'D': 133 Display = optarg; 134 break; 135 136 case 'm': 137 Mtree = optarg; 138 break; 139 140 case 'P': 141 Pkgdeps = optarg; 142 break; 143 144 case 'o': 145 Origin = optarg; 146 break; 147 148 case 'y': 149 case 'j': 150 Zipper = BZIP2; 151 break; 152 153 case 'z': 154 Zipper = GZIP; 155 break; 156 157 case 'b': 158 InstalledPkg = optarg; 159 while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 160 *tmp++ = '\0'; 161 /* 162 * If character after the '/' is alphanumeric, then we've 163 * found the package name. Otherwise we've come across 164 * a trailing '/' and need to continue our quest. 165 */ 166 if (isalpha(*tmp)) { 167 InstalledPkg = tmp; 168 break; 169 } 170 } 171 break; 172 173 case 'R': 174 Recursive = TRUE; 175 break; 176 177 case '?': 178 default: 179 usage(); 180 break; 181 } 182 183 argc -= optind; 184 argv += optind; 185 186 /* Get all the remaining package names, if any */ 187 while (*argv) 188 *pkgs++ = *argv++; 189 190 /* If no packages, yelp */ 191 if ((pkgs == start) && (InstalledPkg == NULL)) 192 warnx("missing package name"), usage(); 193 *pkgs = NULL; 194 if ((start[0] != NULL) && (start[1] != NULL)) { 195 warnx("only one package name allowed ('%s' extraneous)", start[1]); 196 usage(); 197 } 198 if (start[0] == NULL) 199 start[0] = InstalledPkg; 200 if (!pkg_perform(start)) { 201 if (Verbose) 202 warnx("package creation failed"); 203 return 1; 204 } 205 else 206 return 0; 207} 208 209static void 210usage() 211{ 212 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 213"usage: pkg_create [-YNOhvyz] [-P pkgs] [-C conflicts] [-p prefix] ", 214" [-i iscript] [-I piscript] [-k dscript] [-K pdscript] ", 215" [-r rscript] [-t template] [-X excludefile] ", 216" [-D displayfile] [-m mtreefile] [-o origin] ", 217" [-s srcdir] [-S basedir] ", 218" -c comment -d description -f packlist pkg-filename", 219" pkg_create [-YNhvyzR] -b pkg-name [pkg-filename]"); 220 exit(1); 221} 222