1.\"
2.\" FreeBSD install - a package for the installation and maintainance
3.\" of non-core utilities.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" Jordan K. Hubbard
15.\"
16.\" $FreeBSD: stable/9/usr.sbin/pkg_install/add/pkg_add.1 236462 2012-06-02 18:28:34Z jpaetzel $
17.\"
18.Dd January 4, 2009
19.Dt PKG_ADD 1
20.Os
21.Sh NAME
22.Nm pkg_add
23.Nd a utility for installing software package distributions
24.Sh SYNOPSIS
25.Nm
26.Op Fl viInfFrRMSK
27.Op Fl t Ar template
28.Op Fl p Ar prefix
29.Op Fl P Ar prefix
30.Op Fl C Ar chrootdir
31.Ar pkg-name Op Ar pkg-name ...
32.Sh DESCRIPTION
33The
34.Nm
35command is used to extract packages that have been previously created
36with the
37.Xr pkg_create 1
38command.
39.Sh WARNING
40.Bf -emphasis
41Since the
42.Nm
43command may execute scripts or programs contained within a package file,
44your system may be susceptible to
45.Dq Em trojan horses
46or other subtle
47attacks from miscreants who create dangerous package files.
48.Pp
49You are advised to verify the competence and identity of those who
50provide installable package files.
51For extra protection, use the
52.Fl M
53flag to extract the package file, and inspect its contents and scripts to
54ensure it poses no danger to your system's integrity.
55Pay particular
56attention to any +INSTALL, +POST-INSTALL, +DEINSTALL, +POST-DEINSTALL,
57+REQUIRE or +MTREE_DIRS files, and inspect the +CONTENTS file for
58.Cm @cwd ,
59.Cm @mode
60(check for setuid),
61.Cm @dirrm ,
62.Cm @exec ,
63and
64.Cm @unexec
65directives, and/or use the
66.Xr pkg_info 1
67command to examine the package file.
68.Ef
69.Sh OPTIONS
70The following command line arguments are supported:
71.Bl -tag -width indent
72.It Ar pkg-name Op Ar pkg-name ...
73The named packages are installed.
74A package name of
75.Fl
76will cause
77.Nm
78to read from stdin.
79If the packages are not found in the current
80working directory,
81.Nm
82will search them in each directory named by
83.Ev PKG_PATH .
84.It Fl v , -verbose
85Turn on verbose output.
86.It Fl K , -keep
87Keep any downloaded package in
88.Ev PKGDIR
89if it is defined or in current directory by default.
90.It Fl i , -no-deps
91Install the package without fetching and installing
92dependencies.
93.It Fl I , -no-script
94If any installation scripts (pre-install or post-install) exist for a given
95package, do not execute them.
96.It Fl n , -dry-run
97Do not actually install a package, just report the steps that
98would be taken if it was.
99.It Fl R , -no-record
100Do not record the installation of a package.
101This means
102that you cannot deinstall it later, so only use this option if
103you know what you are doing!
104.It Fl r , -remote
105Use the remote fetching feature.
106This will determine the appropriate
107objformat and release and then fetch and install the package.
108.It Fl f , -force
109Force installation to proceed even if prerequisite packages are not
110installed or the requirements script fails.
111Although
112.Nm
113will still try to find and auto-install missing prerequisite packages,
114a failure to find one will not be fatal.
115.It Fl F
116Already installed packages are not an error.
117.It Fl p , -prefix Ar prefix
118Set
119.Ar prefix
120as the directory in which to extract files from a package.
121If a package has set its default directory, it will be overridden
122by this flag.
123Note that only the first
124.Cm @cwd
125directive will be replaced, since
126.Nm
127has no way of knowing which directory settings are relative and
128which are absolute.
129It is rare in any case to see more than one
130directory transition made, but when such does happen and you wish
131to have control over *all* directory transitions, then you
132may then wish to look into the use of
133.Cm MASTER
134and
135.Cm SLAVE
136modes (see the
137.Fl M
138and
139.Fl S
140options).
141If the
142.Fl p
143flag appears after any
144.Fl P
145flag on the command line, it overrides its effect, causing
146.Nm
147not to use the given
148.Ar prefix
149recursively.
150.It Fl P Ar prefix
151Does the same as the
152.Fl p
153option, except that the given
154.Ar prefix
155is also used recursively for the dependency packages, if any.
156If the
157.Fl P
158flag appears after any
159.Fl p
160flag on the command line, it overrides its effect, causing
161.Nm
162to use the given
163.Ar prefix
164recursively.
165.It Fl t , -template Ar template
166Use
167.Ar template
168as the input to
169.Xr mktemp 3
170when creating a
171.Dq staging area .
172By default, this is the string
173.Pa /var/tmp/instmp.XXXXXX ,
174but it may be necessary to override it in the situation where
175space in your
176.Pa /var/tmp
177directory is limited.
178Be sure to leave some number of `X' characters
179for
180.Xr mktemp 3
181to fill in with a unique ID.
182.Pp
183You can get a performance boost by setting the staging area
184.Ar template
185to reside on the same disk partition as target directories for package
186file installation; often this is
187.Pa /usr .
188.It Fl M , -master
189Run in
190.Cm MASTER
191mode.
192This is a very specialized mode for running
193.Nm
194and is meant to be run in conjunction with
195.Cm SLAVE
196mode.
197When run in this mode,
198.Nm
199does no work beyond extracting the package into a temporary staging
200area (see the
201.Fl t
202option), reading in the packing list, and then dumping it (prefaced by
203the current staging area) to stdout where it may be filtered by a
204program such as
205.Xr sed 1 .
206When used in conjunction with
207.Cm SLAVE
208mode, it allows you to make radical changes to the package structure
209before acting on its contents.
210.It Fl S , -slave
211Run in
212.Cm SLAVE
213mode.
214This is a very specialized mode for running
215.Nm
216and is meant to be run in conjunction with
217.Cm MASTER
218mode.
219When run in this mode,
220.Nm
221expects the release contents to be already extracted and waiting
222in the staging area, the location of which is read as a string
223from stdin.
224The complete packing list is also read from stdin,
225and the contents then acted on as normal.
226.It Fl C , -chroot Ar chrootdir
227Before doing any operations,
228.Xr chroot 2
229to the
230.Ar chrootdir
231directory so that all package files, and the package database, are
232installed to
233.Ar chrootdir .
234Note that
235.Ar chrootdir
236needs to be a fairly complete file system, including everything normally
237needed by
238.Nm
239to run.
240This flag was added to help support operations done by
241.Xr sysinstall 8
242and is not expected to be useful for much else.
243Be careful that
244.Ar chrootdir
245is properly configured and cannot be modified by normal users,
246versions of commands like
247.Xr fetch 1
248may be run inside
249.Ar chrootdir
250as a side effect.
251.El
252.Pp
253One or more
254.Ar pkg-name
255arguments may be specified, each being either a file containing the
256package (these usually end with a
257.Dq .tbz
258suffix) or a
259URL pointing at a file available on an ftp site.
260Thus you may
261extract files directly from their anonymous ftp locations (e.g.\&
262.Nm
263.Li ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/packages/shells/bash-1.14.7.tbz ) .
264Note: If you wish to use
265.Bf -emphasis
266passive mode
267.Ef
268ftp in such transfers, set
269the variable
270.Bf -emphasis
271FTP_PASSIVE_MODE
272.Ef
273to some value in your environment.
274Otherwise, the more standard
275ACTIVE mode may be used.
276If
277.Nm
278consistently fails to fetch a package from a site known to work,
279it may be because you have a firewall that demands the usage of
280.Bf -emphasis
281passive mode
282.Ef
283ftp.
284.Sh TECHNICAL DETAILS
285The
286.Nm
287utility extracts each package's
288.Dq "packing list"
289into a special staging directory (see
290.Sx ENVIRONMENT ) ,
291parses it, and then runs
292through the following sequence to fully extract the contents of the package:
293.Bl -enum
294.It
295A check is made to determine if the package is already recorded as installed.
296If it is, installation is terminated.
297.It
298A check is made to determine if the package conflicts (from
299.Ic @conflicts
300directives, see
301.Xr pkg_create 1 )
302with an already installed package.
303If it is, installation is terminated.
304.It
305Scan all the package dependencies (from
306.Ic @pkgdep
307directives, see
308.Xr pkg_create 1 )
309are read from the packing list.
310If any of these required packages is not currently installed,
311an attempt is made to find and install it;
312if the missing package cannot be found or installed,
313the installation is terminated.
314.It
315Search for any
316.Ic @option
317directives which control how the package is added to the system.
318At the time of this writing, the only currently implemented option is
319.Ic @option Cm extract-in-place
320which will cause the package to be extracted directly into its
321prefix directory without moving through a staging area.
322.It
323If
324.Ic @option Cm extract-in-place
325is enabled, the package is now extracted directly into its
326final location, otherwise it is extracted into the staging area.
327.It
328If a requirements script
329.Pa +REQUIRE
330exists for the package (see the
331.Fl r
332flag of
333.Xr pkg_create 1 ) ,
334then execute it with the following arguments:
335.Pp
336.D1 Ar pkg-name Li INSTALL
337.Pp
338where
339.Ar pkg-name
340is the name of the package in question and the
341.Dq Li INSTALL
342keyword denotes this as an installation requirements check (useful if
343you want to have one script serving multiple functions).
344.It
345If a pre-install script
346.Pa +INSTALL
347exists for the package,
348it is then executed with the following arguments:
349.Pp
350.D1 Ar pkg-name Li PRE-INSTALL
351.Pp
352where
353.Ar pkg-name
354is the name of the package in question and
355.Dq Li PRE-INSTALL
356is a keyword denoting this as the preinstallation phase.
357.Pp
358.Sy Note :
359The
360.Dq Li PRE-INSTALL
361keyword will not appear if separate scripts for pre-install and post-install
362are given during package creation time (using the
363.Fl i
364and
365.Fl I
366flags to
367.Xr pkg_create 1 ) .
368.It
369If
370.Cm @option Cm extract-in-place
371is not used, then the packing list (this is the
372.Pa +CONTENTS
373file) is now used as a guide for moving (or copying, as necessary) files from
374the staging area into their final locations.
375.It
376If an mtree file
377.Pa +MTREE_DIRS
378exists for the package (see the
379.Fl m
380flag of
381.Xr pkg_create 1 ) ,
382then
383.Xr mtree 8
384is invoked as:
385.Pp
386.D1 Nm mtree Fl U f Pa +MTREE_DIRS Fl d e p Ar prefix
387.Pp
388where
389.Ar prefix
390is either the prefix specified with the
391.Fl p
392or
393.Fl P
394flag or,
395if neither flag was specified, the name of the first directory named by a
396.Ic @cwd
397directive within this package.
398.It
399If a post-install script
400.Pa +POST-INSTALL
401exists for the package,
402it is then executed with the following arguments:
403.Pp
404.D1 Ar pkg-name Li POST-INSTALL
405.Pp
406where
407.Ar pkg-name
408is the name of the package in question and
409.Dq Li POST-INSTALL
410is a keyword denoting this as the post-installation phase.
411.Pp
412.Sy Note :
413The
414.Dq Li POST-INSTALL
415keyword will not appear if separate scripts for pre-install and post-install
416are given during package creation time (using the
417.Fl i
418and
419.Fl I
420flags to
421.Xr pkg_create 1 ) .
422.Pp
423Reasoning behind passing keywords such as
424.Dq Li POST-INSTALL
425and
426.Dq Li PRE-INSTALL
427is that this allows you to write a single
428install
429script that does both
430.Dq before
431and
432.Dq after
433actions.
434But, separating the
435functionality is more advantageous and easier from a maintenance viewpoint.
436.It
437After installation is complete, a copy of the
438description
439.Pq Pa +DESC ,
440comment
441.Pq Pa +COMMENT ,
442pre-install script
443.Pq Pa +INSTALL ,
444post-install script
445.Pq Pa +POST-INSTALL ,
446deinstall script
447.Pq Pa +DEINSTALL ,
448post-deinstall script
449.Pq Pa +POST-DEINSTALL ,
450requirements script
451.Pq Pa +REQUIRE ,
452display
453.Pq Pa +DISPLAY ,
454mtree
455.Pq Pa +MTREE_DIRS ,
456and packing list
457.Pq Pa +CONTENTS
458files are copied into
459.Pa /var/db/pkg/ Ns Aq Ar pkg-name
460for subsequent possible use by
461.Xr pkg_delete 1 .
462Any package dependencies are recorded in the other packages'
463.Pa /var/db/pkg/ Ns Ao Ar other-pkg Ac Ns Pa /+REQUIRED_BY
464file
465(if the environment variable
466.Ev PKG_DBDIR
467is set, this overrides the
468.Pa /var/db/pkg/
469path shown above).
470.It
471Finally, the staging area is deleted and the program terminates.
472.El
473.Pp
474All the scripts are called with the environment variable
475.Ev PKG_PREFIX
476set to the installation prefix (see the
477.Fl p
478and
479.Fl P
480options above).
481This allows a package author to write a script
482that reliably performs some action on the directory where the package
483is installed, even if the user might change it with the
484.Fl p
485or
486.Fl P
487flags to
488.Nm .
489.Sh ENVIRONMENT
490The value of the
491.Ev PKG_PATH
492is used if a given package cannot be found.
493The environment variable
494should be a series of entries separated by colons.
495Each entry
496consists of a directory name.
497The current directory may be indicated
498implicitly by an empty directory name, or explicitly by a single
499period.
500.Pp
501The environment variable
502.Ev PKG_DBDIR
503specifies an alternative location for the installed package database,
504default location is
505.Pa /var/db/pkg .
506.Pp
507The environment variables
508.Ev PKG_TMPDIR
509and
510.Ev TMPDIR ,
511in that order, are taken to name temporary directories where
512.Nm
513will attempt to create its staging area in.
514If these variables are not present or if the directories named lack
515sufficient space, then
516.Nm
517will use the first of
518.Pa /var/tmp ,
519.Pa /tmp
520or
521.Pa /usr/tmp
522with sufficient space.
523.Pp
524The environment variable
525.Ev PACKAGEROOT
526specifies an alternate location for
527.Nm
528to fetch from.
529The fetch URL is built using this environment variable and the automatic
530directory logic that
531.Nm
532uses when the
533.Fl r
534option is invoked.
535An example setting would be
536.Qq Li ftp://ftp3.FreeBSD.org .
537.Pp
538The environment variable
539.Ev PACKAGESITE
540specifies an alternate location for
541.Nm
542to fetch from.
543This variable subverts the automatic directory logic
544that
545.Nm
546uses when the
547.Fl r
548option is invoked.
549Thus it should be a complete URL to the remote package file(s).
550.Pp
551The environment variable
552.Ev PKGDIR
553specifies an alternative location to save downloaded packages to when
554.Fl K
555option is used.
556.Pp
557The environment variable
558.Ev PACKAGESUFFIX
559specifies an alternative file extension to use when fetching remote
560packages. Default is .tbz
561.Sh FILES
562.Bl -tag -width /var/db/pkg -compact
563.It Pa /var/tmp
564Temporary directory for creating the staging area, if environmental variables
565.Ev PKG_TMPDIR
566or
567.Ev TMPDIR
568do not point to a suitable directory.
569.It Pa /tmp
570Next choice if
571.Pa /var/tmp
572does not exist or has insufficient space.
573.It Pa /usr/tmp
574Last choice if
575.Pa /var/tmp
576and
577.Pa /tmp
578are not suitable for creating the staging area.
579.It Pa /var/db/pkg
580Default location of the installed package database.
581.El
582.Sh SEE ALSO
583.Xr pkg_create 1 ,
584.Xr pkg_delete 1 ,
585.Xr pkg_info 1 ,
586.Xr pkg_version 1 ,
587.Xr mktemp 3 ,
588.Xr sysconf 3 ,
589.Xr mtree 8
590.Sh AUTHORS
591.An Jordan Hubbard
592.Sh CONTRIBUTORS
593.An John Kohl Aq jtk@rational.com
594.Sh BUGS
595Hard links between files in a distribution are only preserved if either
596(1) the staging area is on the same file system as the target directory of
597all the links to the file, or (2) all the links to the file are bracketed by
598.Cm @cwd
599directives in the contents file,
600.Em and
601the link names are extracted with a single
602.Cm tar
603command (not split between
604invocations due to exec argument-space limitations--this depends on the
605value returned by
606.Fn sysconf _SC_ARG_MAX ) .
607.Pp
608Sure to be others.
609