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