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