main.c revision 179433
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 179433 2008-05-30 14:26:09Z flz $"); 14 15#include <getopt.h> 16#include <err.h> 17 18#include "lib.h" 19#include "create.h" 20 21match_t MatchType = MATCH_GLOB; 22char *Prefix = NULL; 23char *Comment = NULL; 24char *Desc = NULL; 25char *SrcDir = NULL; 26char *BaseDir = NULL; 27char *Display = NULL; 28char *Install = NULL; 29char *PostInstall = NULL; 30char *DeInstall = NULL; 31char *PostDeInstall = NULL; 32char *Contents = NULL; 33char *Require = NULL; 34char *ExcludeFrom = NULL; 35char *Mtree = NULL; 36char *Pkgdeps = NULL; 37char *Conflicts = NULL; 38char *Origin = NULL; 39char *InstalledPkg = NULL; 40char PlayPen[FILENAME_MAX]; 41int Dereference = FALSE; 42int PlistOnly = FALSE; 43int Recursive = FALSE; 44int Regenerate = TRUE; 45int Help = FALSE; 46#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039 47enum zipper Zipper = BZIP2; 48#else 49enum zipper Zipper = GZIP; 50#endif 51 52 53static void usage(void); 54 55static char opts[] = "EGYNnORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; 56static struct option longopts[] = { 57 { "backup", required_argument, NULL, 'b' }, 58 { "extended", no_argument, NULL, 'E' }, 59 { "help", no_argument, &Help, TRUE }, 60 { "no", no_argument, NULL, 'N' }, 61 { "no-glob", no_argument, NULL, 'G' }, 62 { "origin", required_argument, NULL, 'o' }, 63 { "plist-only", no_argument, NULL, 'O' }, 64 { "prefix", required_argument, NULL, 'p' }, 65 { "recursive", no_argument, NULL, 'R' }, 66 { "regex", no_argument, NULL, 'x' }, 67 { "template", required_argument, NULL, 't' }, 68 { "verbose", no_argument, NULL, 'v' }, 69 { "yes", no_argument, NULL, 'Y' }, 70 { NULL, 0, NULL, 0 }, 71}; 72 73int 74main(int argc, char **argv) 75{ 76 int ch; 77 char **pkgs, **start, *tmp; 78 79 pkgs = start = argv; 80 while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) 81 switch(ch) { 82 case 'v': 83 Verbose++; 84 break; 85 86 case 'x': 87 MatchType = MATCH_REGEX; 88 break; 89 90 case 'E': 91 MatchType = MATCH_EREGEX; 92 break; 93 94 case 'G': 95 MatchType = MATCH_EXACT; 96 break; 97 98 case 'N': 99 AutoAnswer = NO; 100 break; 101 102 case 'Y': 103 AutoAnswer = YES; 104 break; 105 106 case 'O': 107 PlistOnly = TRUE; 108 break; 109 110 case 'p': 111 Prefix = optarg; 112 break; 113 114 case 's': 115 SrcDir = optarg; 116 break; 117 118 case 'S': 119 BaseDir = optarg; 120 break; 121 122 case 'f': 123 Contents = optarg; 124 break; 125 126 case 'C': 127 Conflicts = optarg; 128 break; 129 130 case 'c': 131 Comment = optarg; 132 break; 133 134 case 'd': 135 Desc = optarg; 136 break; 137 138 case 'i': 139 Install = optarg; 140 break; 141 142 case 'I': 143 PostInstall = optarg; 144 break; 145 146 case 'k': 147 DeInstall = optarg; 148 break; 149 150 case 'K': 151 PostDeInstall = optarg; 152 break; 153 154 case 'r': 155 Require = optarg; 156 break; 157 158 case 't': 159 strlcpy(PlayPen, optarg, sizeof(PlayPen)); 160 break; 161 162 case 'X': 163 ExcludeFrom = optarg; 164 break; 165 166 case 'h': 167 Dereference = TRUE; 168 break; 169 170 case 'D': 171 Display = optarg; 172 break; 173 174 case 'm': 175 Mtree = optarg; 176 break; 177 178 case 'P': 179 Pkgdeps = optarg; 180 break; 181 182 case 'o': 183 Origin = optarg; 184 break; 185 186 case 'y': 187 case 'j': 188 Zipper = BZIP2; 189 break; 190 191 case 'z': 192 Zipper = GZIP; 193 break; 194 195 case 'b': 196 InstalledPkg = optarg; 197 while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 198 *tmp++ = '\0'; 199 /* 200 * If character after the '/' is alphanumeric, then we've 201 * found the package name. Otherwise we've come across 202 * a trailing '/' and need to continue our quest. 203 */ 204 if (isalpha(*tmp)) { 205 InstalledPkg = tmp; 206 break; 207 } 208 } 209 break; 210 211 case 'R': 212 Recursive = TRUE; 213 break; 214 215 case 0: 216 if (Help) 217 usage(); 218 break; 219 220 default: 221 usage(); 222 break; 223 } 224 225 argc -= optind; 226 argv += optind; 227 228 /* Get all the remaining package names, if any */ 229 while (*argv) 230 *pkgs++ = *argv++; 231 232 /* If no packages, yelp */ 233 if ((pkgs == start) && (InstalledPkg == NULL)) 234 warnx("missing package name"), usage(); 235 *pkgs = NULL; 236 if ((start[0] != NULL) && (start[1] != NULL)) { 237 warnx("only one package name allowed ('%s' extraneous)", start[1]); 238 usage(); 239 } 240 if (start[0] == NULL) 241 start[0] = InstalledPkg; 242 if (!pkg_perform(start)) { 243 if (Verbose) 244 warnx("package creation failed"); 245 return 1; 246 } 247 else 248 return 0; 249} 250 251static void 252usage() 253{ 254 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 255"usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]", 256" [-i iscript] [-I piscript] [-k dscript] [-K pdscript]", 257" [-r rscript] [-s srcdir] [-S basedir]", 258" [-t template] [-X excludefile]", 259" [-D displayfile] [-m mtreefile] [-o originpath]", 260" -c comment -d description -f packlist pkg-filename", 261" pkg_create [-EGYNRhnvxy] -b pkg-name [pkg-filename]"); 262 exit(1); 263} 264