main.c revision 84670
1#ifndef lint 2static const char rcsid[] = 3 "$FreeBSD: head/usr.sbin/pkg_install/create/main.c 84670 2001-10-08 17:01:35Z sobomax $"; 4#endif 5 6/* 7 * FreeBSD install - a package for the installation and maintainance 8 * of non-core utilities. 9 * 10 * Jordan K. Hubbard 11 * 18 July 1993 12 * 13 * This is the create module. 14 * 15 */ 16 17#include <err.h> 18#include "lib.h" 19#include "create.h" 20 21static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:b:"; 22 23char *Prefix = NULL; 24char *Comment = NULL; 25char *Desc = NULL; 26char *SrcDir = 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 *Origin = NULL; 38char *InstalledPkg = NULL; 39char PlayPen[FILENAME_MAX]; 40int Dereference = FALSE; 41int PlistOnly = FALSE; 42int UseBzip2 = FALSE; 43 44static void usage __P((void)); 45 46int 47main(int argc, char **argv) 48{ 49 int ch; 50 char **pkgs, **start, *tmp; 51 52 /*{int barrier = 1; while (barrier); }*/ 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 'f': 81 Contents = optarg; 82 break; 83 84 case 'c': 85 Comment = optarg; 86 break; 87 88 case 'd': 89 Desc = optarg; 90 break; 91 92 case 'i': 93 Install = optarg; 94 break; 95 96 case 'I': 97 PostInstall = optarg; 98 break; 99 100 case 'k': 101 DeInstall = optarg; 102 break; 103 104 case 'K': 105 PostDeInstall = optarg; 106 break; 107 108 case 'r': 109 Require = optarg; 110 break; 111 112 case 't': 113 strcpy(PlayPen, optarg); 114 break; 115 116 case 'X': 117 ExcludeFrom = optarg; 118 break; 119 120 case 'h': 121 Dereference = TRUE; 122 break; 123 124 case 'D': 125 Display = optarg; 126 break; 127 128 case 'm': 129 Mtree = optarg; 130 break; 131 132 case 'P': 133 Pkgdeps = optarg; 134 break; 135 136 case 'o': 137 Origin = optarg; 138 break; 139 140 case 'y': 141 UseBzip2 = TRUE; 142 break; 143 144 case 'b': 145 while ((tmp = strrchr(optarg, (int)'/')) != NULL) { 146 *tmp++ = '\0'; 147 /* 148 * If character after the '/' is alphanumeric, then we've 149 * found the package name. Otherwise we've come across 150 * a trailing '/' and need to continue our quest. 151 */ 152 if (isalpha(*tmp)) { 153 InstalledPkg = tmp; 154 break; 155 } 156 } 157 break; 158 159 case '?': 160 default: 161 usage(); 162 break; 163 } 164 165 argc -= optind; 166 argv += optind; 167 168 /* Get all the remaining package names, if any */ 169 while (*argv) 170 *pkgs++ = *argv++; 171 172 /* If no packages, yelp */ 173 if ((pkgs == start) && (InstalledPkg == NULL)) 174 warnx("missing package name"), usage(); 175 *pkgs = NULL; 176 if ((start[0] != NULL) && (start[1] != NULL)) { 177 warnx("only one package name allowed ('%s' extraneous)", start[1]); 178 usage(); 179 } 180 if (start[0] == NULL) 181 start[0] = InstalledPkg; 182 if (!pkg_perform(start)) { 183 if (Verbose) 184 warnx("package creation failed"); 185 return 1; 186 } 187 else 188 return 0; 189} 190 191static void 192usage() 193{ 194 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", 195"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]", 196" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ", 197" [-t template] [-X excludefile] [-D displayfile] ", 198" [-m mtreefile] [-o origin] -c comment -d description ", 199" -f packlist pkg-filename", 200" pkg_create [-YNhvy] -b pkg-name [pkg-filename]"); 201 exit(1); 202} 203