main.c revision 7713
1#ifndef lint
2static char *rcsid = "$Id: main.c,v 1.5 1994/12/06 00:51:33 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
29static char Options[] = "hvIRfnp:SMt:";
30
31char	*Prefix		= NULL;
32Boolean	NoInstall	= FALSE;
33Boolean	NoRecord	= FALSE;
34Boolean	Force		= FALSE;
35
36char	*Mode		= NULL;
37char	*Owner		= NULL;
38char	*Group		= NULL;
39char	*PkgName	= NULL;
40char	*Directory	= NULL;
41char	*PlayPen	= NULL;
42char	*Home		= NULL;
43add_mode_t AddMode	= NORMAL;
44
45int
46main(int argc, char **argv)
47{
48    int ch, err;
49    char **pkgs, **start;
50    char *prog_name = argv[0];
51
52    pkgs = start = argv;
53    while ((ch = getopt(argc, argv, Options)) != EOF)
54	switch(ch) {
55	case 'v':
56	    Verbose = TRUE;
57	    break;
58
59	case 'p':
60	    Prefix = optarg;
61	    break;
62
63	case 'I':
64	    NoInstall = TRUE;
65	    break;
66
67	case 'R':
68	    NoRecord = TRUE;
69	    break;
70
71	case 'f':
72	    Force = TRUE;
73	    break;
74
75	case 'n':
76	    Fake = TRUE;
77	    Verbose = TRUE;
78	    break;
79
80	case 't':
81	    PlayPen = optarg;
82	    break;
83
84	case 'S':
85	    AddMode = SLAVE;
86	    break;
87
88	case 'M':
89	    AddMode = MASTER;
90	    break;
91
92	case 'h':
93	case '?':
94	default:
95	    usage(prog_name, NULL);
96	    break;
97	}
98
99    argc -= optind;
100    argv += optind;
101
102    /* Get all the remaining package names, if any */
103    while (*argv)
104	*pkgs++ = *argv++;
105
106    /* If no packages, yelp */
107    *pkgs = NULL;
108    if (pkgs == start && AddMode != SLAVE)
109	usage(prog_name, "Missing package name(s)");
110    else if (start[1] && AddMode == MASTER)
111	usage(prog_name, "Only one package name may be specified with master mode");
112    else if (pkgs != start && AddMode == SLAVE)
113	whinge("Package names ignored in slave mode.");
114    if ((err = pkg_perform(start)) != NULL) {
115	if (Verbose)
116	    fprintf(stderr, "%d package addition(s) failed.\n", err);
117	return err;
118    }
119    else
120	return 0;
121}
122
123void
124usage(const char *name, const char *fmt, ...)
125{
126    va_list args;
127
128    va_start(args, fmt);
129    if (fmt) {
130	fprintf(stderr, "%s: ", name);
131	vfprintf(stderr, fmt, args);
132	fprintf(stderr, "\n\n");
133    }
134    va_end(args);
135    fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name);
136    fprintf(stderr, "Where args are one or more of:\n\n");
137    fprintf(stderr, "-v         verbose\n");
138    fprintf(stderr, "-p arg     override prefix with arg\n");
139    fprintf(stderr, "-I         don't execute pkg install script, if any\n");
140    fprintf(stderr, "-R         don't record installation (can't delete!)\n");
141    fprintf(stderr, "-n         don't actually install, just show steps\n");
142    fprintf(stderr, "-t temp    use temp as template for mktemp()\n");
143    fprintf(stderr, "-S         run in SLAVE mode\n");
144    fprintf(stderr, "-M         run in MASTER mode\n");
145    exit(1);
146}
147