main.c revision 159554
1351280Sdim/* 2351280Sdim * FreeBSD install - a package for the installation and maintainance 3351280Sdim * of non-core utilities. 4351280Sdim * 5351280Sdim * Jordan K. Hubbard 6351280Sdim * 18 July 1993 7351280Sdim * 8351280Sdim * This is the create module. 9351280Sdim * 10351280Sdim */ 11351280Sdim 12351280Sdim#include <sys/cdefs.h> 13351280Sdim__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/main.c 159554 2006-06-12 22:39:32Z obrien $"); 14351280Sdim 15351280Sdim#include <err.h> 16351280Sdim#include "lib.h" 17351280Sdim#include "create.h" 18351280Sdim 19351280Sdimstatic char Options[] = "EGYNORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:"; 20351280Sdim 21351280Sdimmatch_t MatchType = MATCH_GLOB; 22351280Sdimchar *Prefix = NULL; 23351280Sdimchar *Comment = NULL; 24351280Sdimchar *Desc = NULL; 25351280Sdimchar *SrcDir = NULL; 26351280Sdimchar *BaseDir = NULL; 27351280Sdimchar *Display = NULL; 28351280Sdimchar *Install = NULL; 29351280Sdimchar *PostInstall = NULL; 30351280Sdimchar *DeInstall = NULL; 31351280Sdimchar *PostDeInstall = NULL; 32351280Sdimchar *Contents = NULL; 33351280Sdimchar *Require = NULL; 34351280Sdimchar *ExcludeFrom = NULL; 35351280Sdimchar *Mtree = NULL; 36351280Sdimchar *Pkgdeps = NULL; 37351280Sdimchar *Conflicts = NULL; 38351280Sdimchar *Origin = NULL; 39351280Sdimchar *InstalledPkg = NULL; 40351280Sdimchar PlayPen[FILENAME_MAX]; 41351280Sdimint Dereference = FALSE; 42351280Sdimint PlistOnly = FALSE; 43351280Sdimint Recursive = FALSE; 44351280Sdim#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039 45351280Sdimenum zipper Zipper = BZIP2; 46351280Sdim#else 47351280Sdimenum zipper Zipper = GZIP; 48351280Sdim#endif 49351280Sdim 50351280Sdim 51351280Sdimstatic void usage __P((void)); 52351280Sdim 53351280Sdimint 54351280Sdimmain(int argc, char **argv) 55351280Sdim{ 56351280Sdim int ch; 57351280Sdim char **pkgs, **start, *tmp; 58351280Sdim 59 pkgs = start = argv; 60 while ((ch = getopt(argc, argv, Options)) != -1) 61 switch(ch) { 62 case 'v': 63 Verbose++; 64 break; 65 66 case 'x': 67 MatchType = MATCH_REGEX; 68 break; 69 70 case 'E': 71 MatchType = MATCH_EREGEX; 72 break; 73 74 case 'G': 75 MatchType = MATCH_EXACT; 76 break; 77 78 case 'N': 79 AutoAnswer = NO; 80 break; 81 82 case 'Y': 83 AutoAnswer = YES; 84 break; 85 86 case 'O': 87 PlistOnly = TRUE; 88 break; 89 90 case 'p': 91 Prefix = optarg; 92 break; 93 94 case 's': 95 SrcDir = optarg; 96 break; 97 98 case 'S': 99 BaseDir = optarg; 100 break; 101 102 case 'f': 103 Contents = optarg; 104 break; 105 106 case 'C': 107 Conflicts = optarg; 108 break; 109 110 case 'c': 111 Comment = optarg; 112 break; 113 114 case 'd': 115 Desc = optarg; 116 break; 117 118 case 'i': 119 Install = optarg; 120 break; 121 122 case 'I': 123 PostInstall = optarg; 124 break; 125 126 case 'k': 127 DeInstall = optarg; 128 break; 129 130 case 'K': 131 PostDeInstall = optarg; 132 break; 133 134 case 'r': 135 Require = optarg; 136 break; 137 138 case 't': 139 strlcpy(PlayPen, optarg, sizeof(PlayPen)); 140 break; 141 142 case 'X': 143 ExcludeFrom = optarg; 144 break; 145 146 case 'h': 147 Dereference = TRUE; 148 break; 149 150 case 'D': 151 Display = optarg; 152 break; 153 154 case 'm': 155 Mtree = optarg; 156 break; 157 158 case 'P': 159 Pkgdeps = optarg; 160 break; 161 162 case 'o': 163 Origin = optarg; 164 break; 165 166 case 'y': 167 case 'j': 168 Zipper = BZIP2; 169 break; 170 171 case 'z': 172 Zipper = GZIP; 173 break; 174 175 case 'b': 176 InstalledPkg = optarg; 177 while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 178 *tmp++ = '\0'; 179 /* 180 * If character after the '/' is alphanumeric, then we've 181 * found the package name. Otherwise we've come across 182 * a trailing '/' and need to continue our quest. 183 */ 184 if (isalpha(*tmp)) { 185 InstalledPkg = tmp; 186 break; 187 } 188 } 189 break; 190 191 case 'R': 192 Recursive = TRUE; 193 break; 194 195 case '?': 196 default: 197 usage(); 198 break; 199 } 200 201 argc -= optind; 202 argv += optind; 203 204 /* Get all the remaining package names, if any */ 205 while (*argv) 206 *pkgs++ = *argv++; 207 208 /* If no packages, yelp */ 209 if ((pkgs == start) && (InstalledPkg == NULL)) 210 warnx("missing package name"), usage(); 211 *pkgs = NULL; 212 if ((start[0] != NULL) && (start[1] != NULL)) { 213 warnx("only one package name allowed ('%s' extraneous)", start[1]); 214 usage(); 215 } 216 if (start[0] == NULL) 217 start[0] = InstalledPkg; 218 if (!pkg_perform(start)) { 219 if (Verbose) 220 warnx("package creation failed"); 221 return 1; 222 } 223 else 224 return 0; 225} 226 227static void 228usage() 229{ 230 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 231"usage: pkg_create [-YNOhvyz] [-P pkgs] [-C conflicts] [-p prefix] ", 232" [-i iscript] [-I piscript] [-k dscript] [-K pdscript] ", 233" [-r rscript] [-t template] [-X excludefile] ", 234" [-D displayfile] [-m mtreefile] [-o origin] ", 235" [-s srcdir] [-S basedir] ", 236" -c comment -d description -f packlist pkg-filename", 237" pkg_create [-EGYNhvxyzR] -b pkg-name [pkg-filename]"); 238 exit(1); 239} 240