main.c revision 11780
1327Sjkh#ifndef lint 211780Sjkhstatic const char *rcsid = "$Id: main.c,v 1.11.4.1 1995/10/09 11:16:24 jkh Exp $"; 3327Sjkh#endif 4327Sjkh 5327Sjkh/* 6327Sjkh * FreeBSD install - a package for the installation and maintainance 7327Sjkh * of non-core utilities. 8327Sjkh * 9327Sjkh * Jordan K. Hubbard 10327Sjkh * 18 July 1993 11327Sjkh * 12327Sjkh * This is the create module. 13327Sjkh * 14327Sjkh */ 15327Sjkh 16327Sjkh#include "lib.h" 17327Sjkh#include "create.h" 18327Sjkh 197986Sjkhstatic char Options[] = "YNOhvf:p:P:c:d:i:k:r:t:X:D:m:"; 20327Sjkh 21327Sjkhchar *Prefix = NULL; 22327Sjkhchar *Comment = NULL; 23327Sjkhchar *Desc = NULL; 244996Sjkhchar *Display = NULL; 25327Sjkhchar *Install = NULL; 26327Sjkhchar *DeInstall = NULL; 27327Sjkhchar *Contents = NULL; 28327Sjkhchar *Require = NULL; 2911780Sjkhchar PlayPen[FILENAME_MAX]; 30445Sjkhchar *ExcludeFrom = NULL; 314996Sjkhchar *Mtree = NULL; 327713Sjkhchar *Pkgdeps = NULL; 331520Salmint Dereference = 0; 347986Sjkhint PlistOnly = 0; 35327Sjkh 36327Sjkhint 37327Sjkhmain(int argc, char **argv) 38327Sjkh{ 39327Sjkh int ch; 40327Sjkh char **pkgs, **start; 41327Sjkh char *prog_name = argv[0]; 42327Sjkh 43327Sjkh pkgs = start = argv; 44327Sjkh while ((ch = getopt(argc, argv, Options)) != EOF) 45327Sjkh switch(ch) { 46327Sjkh case 'v': 47327Sjkh Verbose = TRUE; 48327Sjkh break; 49327Sjkh 501337Sjkh case 'N': 511337Sjkh AutoAnswer = NO; 521337Sjkh break; 531337Sjkh 541337Sjkh case 'Y': 551337Sjkh AutoAnswer = YES; 561337Sjkh break; 571337Sjkh 587986Sjkh case 'O': 597986Sjkh PlistOnly = YES; 607986Sjkh break; 617986Sjkh 62327Sjkh case 'p': 63327Sjkh Prefix = optarg; 64327Sjkh break; 65327Sjkh 66327Sjkh case 'f': 67327Sjkh Contents = optarg; 68327Sjkh break; 69327Sjkh 70327Sjkh case 'c': 71327Sjkh Comment = optarg; 72327Sjkh break; 73327Sjkh 74327Sjkh case 'd': 75327Sjkh Desc = optarg; 76327Sjkh break; 77327Sjkh 78327Sjkh case 'i': 79327Sjkh Install = optarg; 80327Sjkh break; 81327Sjkh 82327Sjkh case 'k': 83327Sjkh DeInstall = optarg; 84327Sjkh break; 85327Sjkh 86327Sjkh case 'r': 87327Sjkh Require = optarg; 88327Sjkh break; 89327Sjkh 90383Sjkh case 't': 9111780Sjkh strcpy(PlayPen, optarg); 92383Sjkh break; 93383Sjkh 94445Sjkh case 'X': 95445Sjkh ExcludeFrom = optarg; 96445Sjkh break; 97445Sjkh 98327Sjkh case 'h': 991520Salm Dereference = 1; 1001520Salm break; 1011520Salm 1024996Sjkh case 'D': 1034996Sjkh Display = optarg; 1044996Sjkh break; 1054996Sjkh 1064996Sjkh case 'm': 1074996Sjkh Mtree = optarg; 1084996Sjkh break; 1094996Sjkh 1107713Sjkh case 'P': 1117713Sjkh Pkgdeps = optarg; 1127713Sjkh break; 1137713Sjkh 114327Sjkh case '?': 115327Sjkh default: 116327Sjkh usage(prog_name, NULL); 117327Sjkh break; 118327Sjkh } 119327Sjkh 1208857Srgrimes argc -= optind; 121327Sjkh argv += optind; 122327Sjkh 123327Sjkh /* Get all the remaining package names, if any */ 124327Sjkh while (*argv) 125327Sjkh *pkgs++ = *argv++; 126327Sjkh 127327Sjkh /* If no packages, yelp */ 128327Sjkh if (pkgs == start) 129327Sjkh usage(prog_name, "Missing package name"); 130327Sjkh *pkgs = NULL; 131327Sjkh if (start[1]) 132327Sjkh usage(prog_name, "Only one package name allowed\n\t('%s' extraneous)", 133327Sjkh start[1]); 134327Sjkh if (!pkg_perform(start)) { 135327Sjkh if (Verbose) 136327Sjkh fprintf(stderr, "Package creation failed.\n"); 137327Sjkh return 1; 138327Sjkh } 139327Sjkh else 140327Sjkh return 0; 141327Sjkh} 142327Sjkh 143327Sjkhvoid 144327Sjkhusage(const char *name, const char *fmt, ...) 145327Sjkh{ 146327Sjkh va_list args; 147327Sjkh 148327Sjkh va_start(args, fmt); 149327Sjkh if (fmt) { 150327Sjkh fprintf(stderr, "%s: ", name); 151327Sjkh vfprintf(stderr, fmt, args); 152327Sjkh fprintf(stderr, "\n\n"); 153327Sjkh } 154327Sjkh va_end(args); 155327Sjkh fprintf(stderr, "Usage: %s [args] pkg\n\n", name); 156327Sjkh fprintf(stderr, "Where args are one or more of:\n\n"); 157327Sjkh 158327Sjkh fprintf(stderr, "-c [-]file Get one-line comment from file (-or arg)\n"); 159327Sjkh fprintf(stderr, "-d [-]file Get description from file (-or arg)\n"); 160327Sjkh fprintf(stderr, "-f file get list of files from file (- for stdin)\n"); 1611520Salm fprintf(stderr, "-h follow symbolic links\n"); 162327Sjkh fprintf(stderr, "-i script install script\n"); 163327Sjkh fprintf(stderr, "-k script de-install script\n"); 1644996Sjkh fprintf(stderr, "-D file install notice\n"); 1654996Sjkh fprintf(stderr, "-m file mtree spec for directories\n"); 1667713Sjkh fprintf(stderr, "-P pkgs set package dependency list to pkgs\n"); 1674996Sjkh fprintf(stderr, "-p prefix install prefix will be arg\n"); 168327Sjkh fprintf(stderr, "-r script pre/post requirements script\n"); 169383Sjkh fprintf(stderr, "-t temp use temp as template for mktemp()\n"); 170445Sjkh fprintf(stderr, "-X file exclude files listed in file\n"); 171327Sjkh fprintf(stderr, "-v verbose\n"); 1724996Sjkh fprintf(stderr, "-Y assume `yes' answer to all questions\n"); 1734996Sjkh fprintf(stderr, "-N assume `no' answer to all questions\n"); 1747986Sjkh fprintf(stderr, "-O print a revised packing list and exit\n"); 175327Sjkh exit(1); 176327Sjkh} 177