xref: /minix3/external/bsd/pkg_install/dist/add/main.c (revision a824f5a1008ee67499d167f8c48e64aae26960ca)
1 /*	$NetBSD: main.c,v 1.1.1.10 2011/02/18 22:32:27 aymeric Exp $	*/
2 
3 #if HAVE_CONFIG_H
4 #include "config.h"
5 #endif
6 #include <nbcompat.h>
7 #if HAVE_SYS_CDEFS_H
8 #include <sys/cdefs.h>
9 #endif
10 __RCSID("$NetBSD: main.c,v 1.1.1.10 2011/02/18 22:32:27 aymeric Exp $");
11 
12 /*
13  *
14  * FreeBSD install - a package for the installation and maintainance
15  * of non-core utilities.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  *
26  * Jordan K. Hubbard
27  * 18 July 1993
28  *
29  * This is the add module.
30  *
31  */
32 
33 #if HAVE_ERR_H
34 #include <err.h>
35 #endif
36 #if HAVE_SYS_PARAM_H
37 #include <sys/param.h>
38 #endif
39 #include "lib.h"
40 #include "add.h"
41 
42 static char Options[] = "AC:DIK:LP:RVW:fhm:np:t:Uuvw:";
43 
44 char   *Destdir = NULL;
45 char   *OverrideMachine = NULL;
46 char   *Prefix = NULL;
47 char   *View = NULL;
48 char   *Viewbase = NULL;
49 Boolean NoView = FALSE;
50 Boolean NoInstall = FALSE;
51 Boolean NoRecord = FALSE;
52 Boolean Automatic = FALSE;
53 Boolean ForceDepends = FALSE;
54 /*
55  * Normally, updating fails if the dependencies of a depending package
56  * are not satisfied by the package to be updated.  ForceDepending
57  * turns that failure into a warning.
58  */
59 Boolean ForceDepending = FALSE;
60 
61 int	LicenseCheck = 0;
62 int     Replace = 0;
63 int	ReplaceSame = 0;
64 
65 static void
usage(void)66 usage(void)
67 {
68 	(void) fprintf(stderr, "%s\n%s\n%s\n%s\n",
69 	    "usage: pkg_add [-AfhILnRuVv] [-C config] [-P destdir] [-K pkg_dbdir]",
70 	    "               [-m machine] [-p prefix] [-s verification-type",
71 	    "               [-W viewbase] [-w view]\n",
72 	    "               [[ftp|http]://[user[:password]@]host[:port]][/path/]pkg-name ...");
73 	exit(1);
74 }
75 
76 int
main(int argc,char ** argv)77 main(int argc, char **argv)
78 {
79 	int     ch, error=0;
80 	lpkg_head_t pkgs;
81 
82 	setprogname(argv[0]);
83 	while ((ch = getopt(argc, argv, Options)) != -1) {
84 		switch (ch) {
85 		case 'A':
86 			Automatic = TRUE;
87 			break;
88 
89 		case 'C':
90 			config_file = optarg;
91 			break;
92 
93 		case 'D':
94 			ForceDepending = TRUE;
95 			break;
96 
97 		case 'P':
98 			Destdir = optarg;
99 			break;
100 
101 		case 'f':
102 			Force = TRUE;
103 			ForceDepends = TRUE;
104 			ForceDepending = TRUE;
105 			break;
106 
107 		case 'I':
108 			NoInstall = TRUE;
109 			break;
110 
111 		case 'K':
112 			pkgdb_set_dir(optarg, 3);
113 			break;
114 
115 		case 'L':
116 			NoView = TRUE;
117 			break;
118 
119 		case 'R':
120 			NoRecord = TRUE;
121 			break;
122 
123 		case 'm':
124 			OverrideMachine = optarg;
125 			break;
126 
127 		case 'n':
128 			Fake = TRUE;
129 			Verbose = TRUE;
130 			break;
131 
132 		case 'p':
133 			Prefix = optarg;
134 			break;
135 
136 		case 'U':
137 			ReplaceSame = 1;
138 			Replace = 1;
139 			break;
140 
141 		case 'u':
142 			Replace = 1;
143 			break;
144 
145 		case 'V':
146 			show_version();
147 			/* NOTREACHED */
148 
149 		case 'v':
150 			Verbose = TRUE;
151 			break;
152 
153 		case 'W':
154 			Viewbase = optarg;
155 			break;
156 
157 		case 'w':
158 			View = optarg;
159 			break;
160 
161 		case 'h':
162 		case '?':
163 		default:
164 			usage();
165 			break;
166 		}
167 	}
168 	argc -= optind;
169 	argv += optind;
170 
171 	pkg_install_config();
172 
173 	if (Destdir != NULL) {
174 		char *pkgdbdir;
175 
176 		pkgdbdir = xasprintf("%s/%s", Destdir, config_pkg_dbdir);
177 		pkgdb_set_dir(pkgdbdir, 4);
178 		free(pkgdbdir);
179 	}
180 
181 	process_pkg_path();
182 	TAILQ_INIT(&pkgs);
183 
184 	if (argc == 0) {
185 		/* If no packages, yelp */
186 		warnx("missing package name(s)");
187 		usage();
188 	}
189 
190 	if (strcasecmp(do_license_check, "no") == 0)
191 		LicenseCheck = 0;
192 	else if (strcasecmp(do_license_check, "yes") == 0)
193 		LicenseCheck = 1;
194 	else if (strcasecmp(do_license_check, "always") == 0)
195 		LicenseCheck = 2;
196 	else
197 		errx(1, "Unknown value of the configuration variable"
198 		    "CHECK_LICENSE");
199 
200 	if (LicenseCheck)
201 		load_license_lists();
202 
203 	/* Get all the remaining package names, if any */
204 	for (; argc > 0; --argc, ++argv) {
205 		lpkg_t *lpp;
206 
207 		if (IS_STDIN(*argv))
208 			lpp = alloc_lpkg("-");
209 		else
210 			lpp = alloc_lpkg(*argv);
211 
212 		TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
213 	}
214 
215 	error += pkg_perform(&pkgs);
216 	if (error != 0) {
217 		warnx("%d package addition%s failed", error, error == 1 ? "" : "s");
218 		exit(1);
219 	}
220 	exit(0);
221 }
222