]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pkg_install/add/main.c
This is the Linux generic soundcard driver, version 1.0c. Supports
[FreeBSD/FreeBSD.git] / usr.sbin / pkg_install / add / main.c
1 #ifndef lint
2 static char *rcsid = "$Id: main.c,v 1.3 1993/09/05 04:53:49 jkh Exp $";
3 #endif
4
5 /*
6  *
7  * FreeBSD install - a package for the installation and maintainance
8  * of non-core utilities.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * Jordan K. Hubbard
20  * 18 July 1993
21  *
22  * This is the add module.
23  *
24  */
25
26 #include "lib.h"
27 #include "add.h"
28
29 static char Options[] = "hvIRnp:SMt:";
30
31 char    *Prefix         = NULL;
32 Boolean NoInstall       = FALSE;
33 Boolean NoRecord        = FALSE;
34
35 char    *Mode           = NULL;
36 char    *Owner          = NULL;
37 char    *Group          = NULL;
38 char    *PkgName        = NULL;
39 char    *Directory      = NULL;
40 char    *PlayPen        = NULL;
41 add_mode_t AddMode      = NORMAL;
42
43 int
44 main(int argc, char **argv)
45 {
46     int ch, err;
47     char **pkgs, **start;
48     char *prog_name = argv[0];
49
50     pkgs = start = argv;
51     while ((ch = getopt(argc, argv, Options)) != EOF)
52         switch(ch) {
53         case 'v':
54             Verbose = TRUE;
55             break;
56
57         case 'p':
58             Prefix = optarg;
59             break;
60
61         case 'I':
62             NoInstall = TRUE;
63             break;
64
65         case 'R':
66             NoRecord = TRUE;
67             break;
68
69         case 'n':
70             Fake = TRUE;
71             Verbose = TRUE;
72             break;
73
74         case 't':
75             PlayPen = optarg;
76             break;
77
78         case 'S':
79             AddMode = SLAVE;
80             break;
81
82         case 'M':
83             AddMode = MASTER;
84             break;
85
86         case 'h':
87         case '?':
88         default:
89             usage(prog_name, NULL);
90             break;
91         }
92
93     argc -= optind;     
94     argv += optind;
95
96     /* Get all the remaining package names, if any */
97     while (*argv)
98         *pkgs++ = *argv++;
99
100     /* If no packages, yelp */
101     *pkgs = NULL;
102     if (pkgs == start && AddMode != SLAVE)
103         usage(prog_name, "Missing package name(s)");
104     else if (start[1] && AddMode == MASTER)
105         usage(prog_name, "Only one package name may be specified with master mode");
106     else if (pkgs != start && AddMode == SLAVE)
107         whinge("Package names ignored in slave mode.");
108     if ((err = pkg_perform(start)) != NULL) {
109         if (Verbose)
110             fprintf(stderr, "%d package addition(s) failed.\n", err);
111         return err;
112     }
113     else
114         return 0;
115 }
116
117 void
118 usage(const char *name, const char *fmt, ...)
119 {
120     va_list args;
121
122     va_start(args, fmt);
123     if (fmt) {
124         fprintf(stderr, "%s: ", name);
125         vfprintf(stderr, fmt, args);
126         fprintf(stderr, "\n\n");
127     }
128     va_end(args);
129     fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
130     fprintf(stderr, "Where args are one or more of:\n\n");
131     fprintf(stderr, "-v         verbose\n");
132     fprintf(stderr, "-p arg     override prefix with arg\n");
133     fprintf(stderr, "-I         don't execute pkg install script, if any\n");
134     fprintf(stderr, "-R         don't record installation (can't delete!)\n");
135     fprintf(stderr, "-n         don't actually install, just show steps\n");
136     fprintf(stderr, "-t temp    use temp as template for mktemp()\n");
137     fprintf(stderr, "-S         run in SLAVE mode\n");
138     fprintf(stderr, "-M         run in MASTER mode\n");
139     exit(1);
140 }