6aa5647889c9b692e73a10097a1c55d9fbd3537e
[pkgsrc.git] / pkgtools / pkg_install / files / add / pkg_add.1
1 .\" $NetBSD: pkg_add.1,v 1.39 2010/01/20 22:34:47 jmmv Exp $
2 .\"
3 .\" FreeBSD install - a package for the installation and maintenance
4 .\" of non-core utilities.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\"
15 .\" Jordan K. Hubbard
16 .\"
17 .\"
18 .\"     @(#)pkg_add.1
19 .\"
20 .Dd January 20, 2010
21 .Dt PKG_ADD 1
22 .Os
23 .Sh NAME
24 .Nm pkg_add
25 .Nd a utility for installing and upgrading software package distributions
26 .Sh SYNOPSIS
27 .Nm
28 .Op Fl AfILnRuVv
29 .Op Fl K Ar pkg_dbdir
30 .Op Fl m Ar machine
31 .Op Fl P Ar destdir
32 .Op Fl p Ar prefix
33 .Op Fl W Ar viewbase
34 .Op Fl w Ar view
35 .Ar Oo Oo Li ftp|http Oc Ns Li :// Ns Oo Ar user Oc Ns \
36 Oo Li \&: Ns Ar password Oc \
37 Ns Li @ Oc Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns \
38 Oo Li / Ns Ar path/ Oc Ns Ar pkg-name ...
39 .Sh DESCRIPTION
40 The
41 .Nm
42 command is used to extract and upgrade packages that have been
43 previously created with the
44 .Xr pkg_create 1
45 command.
46 Packages are prepared collections of pre-built binaries, documentation,
47 configurations, installation instructions and/or other files.
48 .Nm
49 can recursively install other packages that the current package
50 depends on or requires from both local disk and via FTP or HTTP.
51 .Sh WARNING
52 .Bf -emphasis
53 Since the
54 .Nm
55 command may execute scripts or programs contained within a package file,
56 your system may be susceptible to
57 .Dq Trojan horses
58 or other subtle
59 attacks from miscreants who create dangerous package files.
60 .Pp
61 You are advised to verify the competence and identity of those who
62 provide installable package files.
63 For extra protection, use the digital signatures provided where possible
64 (see the
65 .Xr pkg_install.conf 5 ) ,
66 or, failing that, use
67 .Xr tar 1
68 to extract the package file, and inspect its contents and scripts
69 to ensure it poses no danger to your system's integrity.
70 Pay particular attention to any
71 .Pa +INSTALL
72 or
73 .Pa +DEINSTALL
74 files, and inspect the
75 .Pa +CONTENTS
76 file for
77 .Cm @cwd ,
78 .Cm @mode
79 (check for setuid),
80 .Cm @dirrm ,
81 .Cm @exec ,
82 and
83 .Cm @unexec
84 directives, and/or use the
85 .Xr pkg_info 1
86 command to examine the package file.
87 .Ef
88 .Sh OPTIONS
89 The following command line arguments are supported:
90 .Bl -tag -width indent
91 .It Ar pkg-name [ ... ]
92 The named packages are installed.
93 .Nm
94 will first try to use
95 .Ar pkg-name
96 as full URL or path name without any wildcard processing.
97 If that fails,
98 .Nm
99 will try to match packages using wildcard processing.
100 If that fails as well and
101 .Ar pkg-name
102 does not contain any /, the entries of the
103 .Dv PKG_PATH
104 variable are searched using the wildcard processing rules.
105 .It Fl A
106 Mark package as installed automatically, as dependency of another
107 package.
108 You can use
109 .Dl Ic pkg_admin set automatic=YES
110 to mark packages this way after installation, and
111 .Dl Ic pkg_admin unset automatic
112 to remove the mark.
113 If you
114 .Nm
115 a package without specifying
116 .Fl A
117 after it had already been automatically installed, the mark is
118 removed.
119 .It Fl f
120 Force installation to proceed even if prerequisite packages are not
121 installed or the install script fails.
122 Although
123 .Nm
124 will still try to find and auto-install missing prerequisite packages,
125 a failure to find one will not be fatal.
126 This flag also overrides the fatal error when the operating system or
127 architecture the package was built on differ from that of the host.
128 .It Fl I
129 If an installation script exists for a given package, do not execute it.
130 .It Fl K Ar pkg_dbdir
131 Set
132 .Ar pkg_dbdir
133 as the package database directory.
134 See the
135 .Sx ENVIRONMENT
136 section below for details on how the default value is calculated.
137 .It Fl L
138 Don't add the package to any views after installation.
139 .It Fl m
140 Override the machine architecture returned by uname with
141 .Ar machine .
142 .It Fl n
143 Don't actually install a package, just report the steps that
144 would be taken if it was.
145 .It Fl P Ar destdir
146 Prefix all file and directory names with
147 .Ar destdir .
148 For packages without install scripts this has the same behavior as
149 using chroot.
150 .It Fl p Ar prefix
151 Set
152 .Ar prefix
153 as the directory in which to extract files from a package.
154 If a package has set its default directory, it will be overridden
155 by this flag.
156 Note that only the first
157 .Cm @cwd
158 directive will be replaced, since
159 .Nm
160 has no way of knowing which directory settings are relative and
161 which are absolute.
162 Only one directory transition is supported and the second one is expected to go
163 into
164 .Ar pkgdb .
165 .It Fl R
166 Do not record the installation of a package.
167 This implies
168 .Fl I .
169 This means that you cannot deinstall it later, so only use this option if
170 you know what you are doing!
171 .It Fl u
172 If the package that's being installed is already installed,
173 an update is performed.
174 It is currently not possible to update to an identical version.
175 If this is specified twice, then any dependent packages that are
176 too old will also be updated to fulfill the dependency.
177 See below for a more detailed description of the process.
178 .It Fl V
179 Print version number and exit.
180 .It Fl v
181 Turn on verbose output.
182 .It Fl W Ar viewbase
183 Set
184 .Ar viewbase
185 as the base directory for the managed views.
186 The default
187 .Ar viewbase
188 directory is set by
189 .Xr pkg_view 1 .
190 This value also may be set from the
191 .Ev LOCALBASE
192 environment variable.
193 .It Fl w Ar view
194 Set the
195 .Ar view
196 to which packages should be added after installation.
197 The default
198 .Ar view
199 is set by
200 .Xr pkg_view 1 .
201 This value also may be set from the
202 .Ev PKG_VIEW
203 environment variable.
204 .El
205 .Pp
206 One or more
207 .Ar pkg-name
208 arguments may be specified, each being either a file containing the
209 package (these usually ending with the
210 .Dq .tgz
211 suffix) or a
212 URL pointing at a file available on an ftp or web site.
213 Thus you may extract files directly from their anonymous ftp or WWW
214 locations (e.g.,
215 .Nm
216 ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/i386/3.1_2007Q2/shells/bash-3.2.9.tgz
217 or
218 .Nm
219 http://www.example.org/packages/screen-4.0.tbz).
220 Note:  For ftp transfers, if you wish to use
221 .Bf -emphasis
222 passive mode
223 .Ef
224 ftp in such transfers, set the variable
225 .Bf -emphasis
226 FTP_PASSIVE_MODE
227 .Ef
228 to some value in your environment.
229 Otherwise, the more standard ACTIVE mode may be used.
230 If
231 .Nm
232 consistently fails to fetch a package from a site known to work,
233 it may be because you have a firewall that demands the usage of
234 .Bf -emphasis
235 passive mode
236 .Ef
237 ftp.
238 .Sh TECHNICAL DETAILS
239 .Nm
240 extracts each package's meta data (including the
241 .Dq packing list )
242 to memory and then runs through the following sequence to fully extract
243 the contents of the package:
244 .Bl -enum -offset indent
245 .It
246 A check is made to determine if the package or another version of it
247 is already recorded as installed.
248 If it is,
249 installation is terminated if the
250 .Fl u
251 option is not given.
252 .Pp
253 If the
254 .Fl u
255 option is given, it's assumed the package should be replaced by the
256 new version instead.
257 Before doing so, all packages that depend on the
258 pkg being upgraded are checked if they also work with the new version.
259 If that test is successful, replacing is prepared by moving an existing
260 .Pa +REQUIRED_BY
261 file aside (if it exists), and running
262 .Xr pkg_delete 1
263 on the installed package.
264 Installation then proceeds as if the package
265 was not installed, and restores the
266 .Pa +REQUIRED_BY
267 file afterwards.
268 .It
269 The package build information is extracted from the
270 .Pa +BUILD_INFO
271 file and compared against the result of
272 .Xr uname 3 .
273 If the operating system or architecture of the package differ from
274 that of the host, installation is aborted.
275 This behavior is overridable with the
276 .Fl f
277 flag.
278 .It
279 The package build information from
280 .Pa +BUILD_INFO
281 is then checked for
282 .Ev USE_ABI_DEPENDS=NO
283 (or
284 .Ev IGNORE_RECOMMENDED ) .
285 If the package was built with ABI dependency recommendations ignored,
286 a warning will be issued.
287 .It
288 A check is made to determine if the package conflicts (from
289 .Cm @pkgcfl
290 directives, see
291 .Xr pkg_create 1 )
292 with an already recorded as installed package or if an installed package
293 conflicts with the package.
294 If it is, installation is terminated.
295 .It
296 The file list of the package is compared to the file lists of the
297 installed packages.
298 If there is any overlap, the installation is terminated.
299 .It
300 All package dependencies (from
301 .Cm @pkgdep
302 directives, see
303 .Xr pkg_create 1 )
304 are read from the packing list.
305 If any of these required packages are not currently installed,
306 an attempt is made to find and install it;
307 if the missing package cannot be found or installed,
308 the installation is terminated.
309 If the
310 .Fl u
311 option was specified twice, any required packages that are installed,
312 but which have a version number that is considered to be too old,
313 are also updated.
314 The dependent packages are found according to the normal
315 .Ev PKG_PATH
316 rules.
317 .It
318 If the package contains an
319 .Ar install
320 script, it is executed with the following arguments:
321 .Bl -tag -width indentindent
322 .It Ar pkg-name
323 The name of the package being installed.
324 .It Cm PRE-INSTALL
325 Keyword denoting that the script is to perform any actions needed before
326 the package is installed.
327 .El
328 .Pp
329 If the
330 .Ar install
331 script exits with a non-zero status code, the installation is terminated.
332 .It
333 The files from the file list are extracted to the chosen prefix.
334 .It
335 If an
336 .Ar install
337 script exists for the package, it is executed with the following arguments:
338 .Bl -tag -width indentindent
339 .It Ar pkg_name
340 The name of the package being installed.
341 .It Cm POST-INSTALL
342 Keyword denoting that the script is to perform any actions needed
343 after the package has been installed.
344 .El
345 .It
346 After installation is complete, a copy of the packing list,
347 .Ar deinstall
348 script, description, and display files are copied into
349 .Pa /var/db/pkg/\*[Lt]pkg-name\*[Gt]
350 for subsequent possible use by
351 .Xr pkg_delete 1 .
352 Any package dependencies are recorded in the other packages'
353 .Pa /var/db/pkg/\*[Lt]other-pkg\*[Gt]/+REQUIRED_BY
354 file
355 (if an alternate package database directory is specified, then it
356 overrides the
357 .Pa /var/db/pkg
358 path shown above).
359 .It
360 If the package is a depoted package, then add it to the default view.
361 .It
362 Finally, if we were upgrading a package, any
363 .Pa +REQUIRED_BY
364 file that was moved aside before upgrading was started is now moved
365 back into place.
366 .El
367 .Pp
368 The
369 .Ar install
370 script is called with the environment variable
371 .Ev PKG_PREFIX
372 set to the installation prefix (see the
373 .Fl p
374 option above).
375 This allows a package author to write a script
376 that reliably performs some action on the directory where the package
377 is installed, even if the user might change it with the
378 .Fl p
379 flag to
380 .Cm pkg_add .
381 The scripts are also called with the
382 .Ev PKG_METADATA_DIR
383 environment variable set to the location of the
384 .Pa +*
385 meta-data files, and with the
386 .Ev PKG_REFCOUNT_DBDIR
387 environment variable set to the location of the package reference counts
388 database directory.
389 If the
390 .Fl P
391 flag was given to
392 .Nm ,
393 .Ev PKG_DESTDIR
394 will be set to
395 .Ar destdir .
396 .Sh ENVIRONMENT
397 .Bl -tag -width PKG_TMPDIR
398 .It Ev LOCALBASE
399 This is the location of the
400 .Ar viewbase
401 directory in which all the views are managed.
402 The default
403 .Ar viewbase
404 directory is
405 .Pa /usr/pkg .
406 .It Ev PKG_DBDIR
407 If the
408 .Fl K
409 flag isn't given, then the value of the
410 .Ev PKG_DBDIR
411 variable overrides the
412 .Xr pkg_install.conf 5
413 variable of the same name.
414 If all of this fails to locate a value, then it typically defaults to
415 .Pa /var/db/pkg .
416 .It Ev PKG_PATH
417 The value of the
418 .Ev PKG_PATH
419 variable overrides the
420 .Xr pkg_install.conf 5
421 variable of the same name.
422 It is used if a given package can't be found, it's usually set to
423 .Pa /usr/pkgsrc/packages/All .
424 The environment variable
425 should be a series of entries separated by semicolons.
426 Each entry consists of a directory name or URL.
427 The current directory may be indicated implicitly by an empty directory
428 name, or explicitly by a single period.
429 .It Ev PKG_REFCOUNT_DBDIR
430 Location of the package reference counts database directory.
431 The default location is the path to the package database directory with
432 .Dq .refcount
433 appended to the path, e.g.
434 .Pa /var/db/pkg.refcount .
435 .It Ev PKG_VIEW
436 The default view can be specified in the
437 .Ev PKG_VIEW
438 environment variable.
439 .El
440 .Sh EXAMPLES
441 In all cases,
442 .Nm
443 will try to install binary packages listed in dependencies list.
444 .Pp
445 You can specify a compiled binary package explicitly on the command line.
446 .Bd -literal
447 # pkg_add /usr/pkgsrc/packages/All/tcsh-6.14.00.tgz
448 .Ed
449 .Pp
450 If you omit the version number,
451 .Nm
452 will install the latest version available.
453 With
454 .Fl v ,
455 .Nm
456 emits more messages to terminal.
457 .Bd -literal
458 # pkg_add -v /usr/pkgsrc/packages/All/unzip
459 .Ed
460 .Pp
461 You can grab a compiled binary package from remote location by specifying
462 a URL.
463 The URL can be put into an environment variable,
464 .Ev PKG_PATH .
465 .Bd -literal
466 # pkg_add -v ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/i386/3.1_2007Q2/All/firefox-2.0.0.4.tgz
467
468 # export PKG_PATH=ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/i386/3.1_2007Q2/All
469 # pkg_add -v firefox
470 .Ed
471 .Pp
472 Over time, as problems are found in packages, they will be moved
473 from the
474 .Pa All
475 subdirectory into the
476 .Pa vulnerable
477 subdirectory.
478 If you want to accept vulnerable packages by default
479 (and know what you are doing),
480 you can add the
481 .Pa vulnerable
482 directory to your
483 .Ev PKG_PATH
484 like this:
485 .Bd -literal
486 # export PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/i386/3.1_2007Q2/All/;ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/i386/3.1_2007Q2/vulnerable/"
487 .Ed
488 .Pp
489 (The quotes are needed because semicolon
490 .Pq Sq \&;
491 is a shell meta-character.)
492 If you do this, consider using the audit capabilities in
493 .Xr pkg_admin 1
494 and running it after every
495 .Nm .
496 .Sh CONFIGURATION VARIABLES
497 The following variables change the behavior of
498 .Nm
499 and are described in
500 .Xr pkg_install.conf 5 :
501 .Bl -tag -compact -offset indent -width CERTIFICATE_ANCHOR_PKGS
502 .It Ev CHECK_LICENSE
503 .It Ev CHECK_VULNERABILITIES
504 .It Ev CERTIFICATE_ANCHOR_PKGS
505 .It Ev CERTIFICATE_CHAIN
506 .It Ev VERIFIED_INSTALLATION
507 .El
508 .Sh SEE ALSO
509 .Xr pkg_admin 1 ,
510 .Xr pkg_create 1 ,
511 .Xr pkg_delete 1 ,
512 .Xr pkg_info 1 ,
513 .Xr tar 1 ,
514 .Xr mktemp 3 ,
515 .Xr sysconf 3 ,
516 .Xr pkg_install.conf 5 ,
517 .Xr pkgsrc 7
518 .Sh AUTHORS
519 .Bl -tag -width indent -compact
520 .It "Jordan Hubbard"
521 Initial work and ongoing development.
522 .It "John Kohl"
523 .Nx
524 refinements.
525 .It "Hubert Feyrer"
526 .Nx
527 wildcard dependency processing, pkgdb, upgrading, etc.
528 .It Thomas Klausner
529 HTTP support.
530 .It Joerg Sonnenberger
531 Rewrote most of the code base to work without external commands.
532 .El
533 .Sh BUGS
534 Package upgrading needs a lot more work to be really universal.
535 .Pp
536 Sure to be others.