main.c revision 22997
11556Srgrimes#ifndef lint 21556Srgrimesstatic const char *rcsid = "$Id$"; 31556Srgrimes#endif 41556Srgrimes 51556Srgrimes/* 61556Srgrimes * FreeBSD install - a package for the installation and maintainance 71556Srgrimes * of non-core utilities. 81556Srgrimes * 91556Srgrimes * Jordan K. Hubbard 101556Srgrimes * 18 July 1993 111556Srgrimes * 121556Srgrimes * This is the create module. 131556Srgrimes * 141556Srgrimes */ 151556Srgrimes 161556Srgrimes#include "lib.h" 171556Srgrimes#include "create.h" 181556Srgrimes 191556Srgrimesstatic char Options[] = "YNOhvf:p:P:c:d:i:k:r:t:X:D:m:"; 201556Srgrimes 211556Srgrimeschar *Prefix = NULL; 221556Srgrimeschar *Comment = NULL; 231556Srgrimeschar *Desc = NULL; 241556Srgrimeschar *Display = NULL; 251556Srgrimeschar *Install = NULL; 261556Srgrimeschar *DeInstall = NULL; 271556Srgrimeschar *Contents = NULL; 281556Srgrimeschar *Require = NULL; 291556Srgrimeschar PlayPen[FILENAME_MAX]; 301556Srgrimeschar *ExcludeFrom = NULL; 311556Srgrimeschar *Mtree = NULL; 321556Srgrimeschar *Pkgdeps = NULL; 331556Srgrimesint Dereference = 0; 3436150Scharnierint PlistOnly = 0; 3536150Scharnier 3636150Scharnierint 371556Srgrimesmain(int argc, char **argv) 3899110Sobrien{ 3999110Sobrien int ch; 401556Srgrimes char **pkgs, **start; 411556Srgrimes char *prog_name = argv[0]; 421556Srgrimes 431556Srgrimes pkgs = start = argv; 441556Srgrimes while ((ch = getopt(argc, argv, Options)) != EOF) 451556Srgrimes switch(ch) { 461556Srgrimes case 'v': 471556Srgrimes Verbose = TRUE; 481556Srgrimes break; 491556Srgrimes 5053891Scracauer case 'N': 5117987Speter AutoAnswer = NO; 5238521Scracauer break; 531556Srgrimes 5478732Sdd case 'Y': 5517987Speter AutoAnswer = YES; 561556Srgrimes break; 571556Srgrimes 581556Srgrimes case 'O': 591556Srgrimes PlistOnly = YES; 601556Srgrimes break; 611556Srgrimes 621556Srgrimes case 'p': 631556Srgrimes Prefix = optarg; 6438521Scracauer break; 6538530Scracauer 6638521Scracauer case 'f': 671556Srgrimes Contents = optarg; 681556Srgrimes break; 691556Srgrimes 70213811Sobrien case 'c': 7120425Ssteve Comment = optarg; 721556Srgrimes break; 731556Srgrimes 741556Srgrimes case 'd': 751556Srgrimes Desc = optarg; 76199660Sjilles break; 77199660Sjilles 78199660Sjilles case 'i': 791556Srgrimes Install = optarg; 801556Srgrimes break; 811556Srgrimes 8290111Simp case 'k': 8317987Speter DeInstall = optarg; 84199660Sjilles break; 851556Srgrimes 861556Srgrimes case 'r': 871556Srgrimes Require = optarg; 881556Srgrimes break; 891556Srgrimes 901556Srgrimes case 't': 911556Srgrimes strcpy(PlayPen, optarg); 921556Srgrimes break; 93276038Sjilles 94276038Sjilles case 'X': 95276038Sjilles ExcludeFrom = optarg; 96276038Sjilles break; 97276038Sjilles 98276038Sjilles case 'h': 99276038Sjilles Dereference = 1; 100276038Sjilles break; 1011556Srgrimes 1021556Srgrimes case 'D': 1031556Srgrimes Display = optarg; 10490111Simp break; 10590111Simp 106211281Sjilles case 'm': 10717987Speter Mtree = optarg; 1081556Srgrimes break; 109211281Sjilles 110211281Sjilles case 'P': 11138521Scracauer Pkgdeps = optarg; 11238536Scracauer break; 11338536Scracauer 11438536Scracauer case '?': 11538521Scracauer default: 116155301Sschweikh usage(prog_name, NULL); 11738521Scracauer break; 11838521Scracauer } 1191556Srgrimes 1201556Srgrimes argc -= optind; 12138521Scracauer argv += optind; 12238521Scracauer 12338521Scracauer /* Get all the remaining package names, if any */ 124276038Sjilles while (*argv) 12538521Scracauer *pkgs++ = *argv++; 1261556Srgrimes 1271556Srgrimes /* If no packages, yelp */ 1281556Srgrimes if (pkgs == start) 129216622Sjilles usage(prog_name, "Missing package name"); 130216622Sjilles *pkgs = NULL; 131216622Sjilles if (start[1]) 132216622Sjilles usage(prog_name, "Only one package name allowed\n\t('%s' extraneous)", 133216622Sjilles start[1]); 134274899Sjilles if (!pkg_perform(start)) { 135274899Sjilles if (Verbose) 136216622Sjilles fprintf(stderr, "Package creation failed.\n"); 137216622Sjilles return 1; 138216622Sjilles } 139216622Sjilles else 140216622Sjilles return 0; 141216622Sjilles} 142216622Sjilles 143216622Sjillesvoid 144216622Sjillesusage(const char *name, const char *fmt, ...) 145216622Sjilles{ 146216622Sjilles va_list args; 147216622Sjilles 148216622Sjilles va_start(args, fmt); 149216622Sjilles if (fmt) { 150216622Sjilles fprintf(stderr, "%s: ", name); 1511556Srgrimes vfprintf(stderr, fmt, args); 15220425Ssteve fprintf(stderr, "\n\n"); 1531556Srgrimes } 1541556Srgrimes va_end(args); 1551556Srgrimes fprintf(stderr, "Usage: %s [args] pkg\n\n", name); 156213811Sobrien fprintf(stderr, "Where args are one or more of:\n\n"); 15790111Simp 15820425Ssteve fprintf(stderr, "-c [-]file Get one-line comment from file (-or arg)\n"); 159199660Sjilles fprintf(stderr, "-d [-]file Get description from file (-or arg)\n"); 160199660Sjilles fprintf(stderr, "-f file get list of files from file (- for stdin)\n"); 161199660Sjilles fprintf(stderr, "-h follow symbolic links\n"); 162199660Sjilles fprintf(stderr, "-i script install script\n"); 163199660Sjilles fprintf(stderr, "-k script de-install script\n"); 164199660Sjilles fprintf(stderr, "-D file install notice\n"); 165199660Sjilles fprintf(stderr, "-m file mtree spec for directories\n"); 166199660Sjilles fprintf(stderr, "-P pkgs set package dependency list to pkgs\n"); 167199660Sjilles fprintf(stderr, "-p prefix install prefix will be arg\n"); 1681556Srgrimes fprintf(stderr, "-r script pre/post requirements script\n"); 16920425Ssteve fprintf(stderr, "-t temp use temp as template for mktemp()\n"); 17020425Ssteve fprintf(stderr, "-X file exclude files listed in file\n"); 17120425Ssteve fprintf(stderr, "-v verbose\n"); 17220425Ssteve fprintf(stderr, "-Y assume `yes' answer to all questions\n"); 17320425Ssteve fprintf(stderr, "-N assume `no' answer to all questions\n"); 17420425Ssteve fprintf(stderr, "-O print a revised packing list and exit\n"); 175216622Sjilles exit(1); 176216622Sjilles} 17720425Ssteve