main.c revision 39185
1#ifndef lint 2static const char rcsid[] = 3 "$Id: main.c,v 1.17 1998/09/08 10:42:19 jkh Exp $"; 4#endif 5 6/* 7 * 8 * FreeBSD install - a package for the installation and maintainance 9 * of non-core utilities. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * Jordan K. Hubbard 21 * 18 July 1993 22 * 23 * This is the add module. 24 * 25 */ 26 27#include <err.h> 28#include <sys/param.h> 29#include "lib.h" 30#include "add.h" 31 32static char Options[] = "hvIRfnp:SMt:"; 33 34char *Prefix = NULL; 35Boolean NoInstall = FALSE; 36Boolean NoRecord = FALSE; 37 38char *Mode = NULL; 39char *Owner = NULL; 40char *Group = NULL; 41char *PkgName = NULL; 42char *Directory = NULL; 43char FirstPen[FILENAME_MAX]; 44add_mode_t AddMode = NORMAL; 45 46#define MAX_PKGS 20 47char pkgnames[MAX_PKGS][MAXPATHLEN]; 48char *pkgs[MAX_PKGS]; 49 50static void usage __P((void)); 51 52int 53main(int argc, char **argv) 54{ 55 int ch, err; 56 char **start; 57 char *cp; 58 59 start = argv; 60 while ((ch = getopt(argc, argv, Options)) != -1) { 61 switch(ch) { 62 case 'v': 63 Verbose = TRUE; 64 break; 65 66 case 'p': 67 Prefix = optarg; 68 break; 69 70 case 'I': 71 NoInstall = TRUE; 72 break; 73 74 case 'R': 75 NoRecord = TRUE; 76 break; 77 78 case 'f': 79 Force = TRUE; 80 break; 81 82 case 'n': 83 Fake = TRUE; 84 Verbose = TRUE; 85 break; 86 87 case 't': 88 strcpy(FirstPen, optarg); 89 break; 90 91 case 'S': 92 AddMode = SLAVE; 93 break; 94 95 case 'M': 96 AddMode = MASTER; 97 break; 98 99 case 'h': 100 case '?': 101 default: 102 usage(); 103 break; 104 } 105 } 106 argc -= optind; 107 argv += optind; 108 109 if (argc > MAX_PKGS) { 110 warnx("too many packages (max %d)", MAX_PKGS); 111 return(1); 112 } 113 114 if (AddMode != SLAVE) { 115 for (ch = 0; ch < MAX_PKGS; pkgs[ch++] = NULL) ; 116 117 /* Get all the remaining package names, if any */ 118 for (ch = 0; *argv; ch++, argv++) { 119 if (!strcmp(*argv, "-")) /* stdin? */ 120 pkgs[ch] = "-"; 121 else if (isURL(*argv)) /* preserve URLs */ 122 pkgs[ch] = strcpy(pkgnames[ch], *argv); 123 else { /* expand all pathnames to fullnames */ 124 if (fexists(*argv)) /* refers to a file directly */ 125 pkgs[ch] = realpath(*argv, pkgnames[ch]); 126 else { /* look for the file in the expected places */ 127 if (!(cp = fileFindByPath(NULL, *argv))) 128 warnx("can't find package '%s'", *argv); 129 else 130 pkgs[ch] = strcpy(pkgnames[ch], cp); 131 } 132 } 133 } 134 } 135 /* If no packages, yelp */ 136 else if (!ch) { 137 warnx("missing package name(s)"); 138 usage(); 139 } 140 else if (ch > 1 && AddMode == MASTER) { 141 warnx("only one package name may be specified with master mode"); 142 usage(); 143 } 144 /* Make sure the sub-execs we invoke get found */ 145 setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1); 146 147 /* Set a reasonable umask */ 148 umask(022); 149 150 if ((err = pkg_perform(pkgs)) != 0) { 151 if (Verbose) 152 warnx("%d package addition(s) failed", err); 153 return err; 154 } 155 else 156 return 0; 157} 158 159static void 160usage() 161{ 162 fprintf(stderr, "%s\n%s\n", 163 "usage: pkg_add [-vInfRMS] [-t template] [-p prefix]", 164 " pkg-name [pkg-name ...]"); 165 exit(1); 166} 167