1.\" $OpenBSD: pkg_add.1,v 1.163 2020/01/24 21:10:46 schwarze Exp $ 2.\" 3.\" Documentation and design originally from FreeBSD. All the code has 4.\" been rewritten since. We keep the documentation's notice: 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.Dd $Mdocdate: January 24 2020 $ 19.Dt PKG_ADD 1 20.Os 21.Sh NAME 22.Nm pkg_add 23.Nd install or update software packages 24.Sh SYNOPSIS 25.Nm pkg_add 26.Bk -words 27.Op Fl acIimnqrsUuVvxz 28.Op Fl A Ar arch 29.Op Fl B Ar pkg-destdir 30.Op Fl D Ar name Ns Op = Ns Ar value 31.Op Fl L Ar localbase 32.Op Fl l Ar file 33.Op Fl P Ar type 34.Op Ar pkg-name ... 35.Ek 36.Sh DESCRIPTION 37The 38.Nm 39command is used to install or update packages created 40from the 41.Xr ports 7 42tree. 43.Bd -filled -offset indent 44.Em Note : 45System distribution files, e.g., base58.tgz, comp58.tgz, are 46.Em not 47packages and may not be installed using 48.Nm . 49.Ed 50.Pp 51By default, 52.Nm 53rejects unsigned packages unless they come from a trusted source 54.Po 55.Ev TRUSTED_PKG_PATH 56.Pc 57or option 58.Fl D Cm unsigned 59is used. 60.Pp 61If a package is digitally signed: 62.Bl -bullet 63.It 64.Nm 65checks that its signature is valid and that the signature was 66emitted by a valid signing key, as stored in 67.Pa /etc/signify/*-pkg.pub , 68.It 69.Nm 70verifies that the compressed package data matches the signature, before 71it decompresses and unpacks files. 72.El 73.Pp 74.Nm 75can be used to 76.Bl -bullet 77.It 78Install new packages. 79This is the normal mode. 80The 81.Ar pkg-name ... 82specified on the command line are new package names to install. 83.It 84Update installed packages, using option 85.Fl u . 86Optional 87.Ar pkg-name ... 88may be specified on the command line, as names of packages already installed 89on the machine, to be updated to new versions along with their dependencies. 90If no name is specified, all the packages will be updated. 91.It 92Install new packages in a hurry, updating their dependencies first, 93using option 94.Fl U . 95The 96.Ar pkg-name ... 97specified on the command line are new packages that may require updating 98dependencies first. 99It is recommended to keep all packages in-synch 100with 101.Fl u 102whenever possible, but 103.Fl U 104can be much faster. 105.It 106Replace existing packages with explicit other versions, using option 107.Fl r . 108The 109.Ar pkg-name ... 110specified on the command line are new packages that should replace 111already installed packages, with other versions or flavors. 112.El 113.Pp 114.Nm 115relies on the file system information being consistent. 116In case of a system crash, 117.Pa /var/db/pkg 118may become corrupted. 119Use 120.Xr pkg_check 8 121to repair things. 122.Pp 123Details of packing-list internals are documented in 124.Xr pkg_create 1 . 125.Pp 126.Nm 127will 128.Xr syslog 3 129installations and updates by default. 130.Pp 131Each package name may be specified as a filename (which normally consists of the 132package name itself plus the 133.Dq .tgz 134suffix) or a URL referring to FTP, HTTP, HTTPS, or SCP locations. 135If the given package names are not found in the current working directory, 136.Nm 137will search for them in each directory (local or remote) named by the 138.Ev TRUSTED_PKG_PATH 139environment variable, 140then the 141.Ev PKG_PATH 142environment variable. 143The special url 144.Sq installpath 145refers to the contents of 146.Xr installurl 5 . 147If neither 148.Ev TRUSTED_PKG_PATH 149nor 150.Ev PKG_PATH 151are defined, 152.Nm 153will use 154.Sq ./:installpath 155as a default. 156Specifying 157.Ql - 158as a package name causes 159.Nm 160to read from the standard input. 161.Pp 162.Nm 163also understands 164.Sq stems , 165that is, package names without any version specification. 166For instance, with 167.Sq Nm Ar kdelibs , 168.Nm 169will look in the current directory 170.Po 171or the 172.Ev PKG_PATH 173.Pc 174for a 175.Ar kdelibs 176package. 177.Pp 178.Nm 179may ask questions in interactive mode, or error out otherwise. 180Interactive mode is the default on a tty, see 181options 182.Fl I/i . 183.Pp 184For instance 185.Sq Nm Ar screen 186is ambiguous as it matches 187.Ar screen-4.03p6 188and 189.Ar screen-4.03p6-shm . 190.Pp 191To avoid ambiguities, 192.Nm 193supports 194.Sq stems with flavors , 195that is, a stem separated from flavors with a double dash. 196For instance, the previous ambiguity could be resolved by using 197.Sq Nm Ar screen-- 198(matches only the empty flavor) 199or 200.Sq Nm Ar screen--shm 201(matches only the shm flavor). 202.Pp 203There is also an ambiguity related to ports with multiple branches. 204For instance 205.Sq Nm Ar python 206is ambiguous, as there are several versions of python in the ports tree. 207So is 208.Sq Nm Ar postfix . 209The special form 210.Sq Ar pkgname Ns % Ns Ar branch 211can be used to restrict matches to a branch matching the 212.Xr pkgpath 7 . 213.Pp 214The above ambiguities can be resolved using 215.Sq Nm Ar postfix Ns % Ns Ar stable 216and 217.Sq Nm Ar python Ns % Ns Ar 3.4 , 218respectively. 219.Pp 220All paths recognize certain special sequences, 221which are expanded as follows: 222.Bl -tag -width "%m" 223.It %a 224The package architecture as returned by 225.Xr arch 1 226.Fl s . 227.It %v 228The operating system version in the format 229.Dq digit dot digit . 230.It %c 231Expands to the string 232.Qq snapshots 233when running a -current or -beta kernel, or if the command line option 234.Fl D Cm snap | Fl D Cm snapshot 235is specified. 236Otherwise, %c expands to %v, which selects a release version. 237.It %m 238The full mirror path, 239.Qq /pub/OpenBSD/%c/packages/%a/ . 240.El 241.Pp 242If the resulting path contains 243.Qq %c/packages 244and %c is not 245.Qq snapshots , 246then a second directory is also searched, which is constructed by replacing 247.Qq packages 248with 249.Qq packages-stable . 250.Pp 251The following examples are valid: 252.Bd -literal -offset indent 253pkg_add -v http://ftp.openbsd.org/%m/rsync-- 254pkg_add -v http://ftp.openbsd.org/%m/m4 255pkg_add -v scp://login@host/usr/ports/packages/%a/all/tcl%8.5 256.Ed 257.Pp 258If the environment variable 259.Ev PKG_CACHE 260is set to a directory name, every package retrieved from a distant location 261will also be copied here. 262.Pp 263If the environment variable 264.Ev DEBUG_PKG_CACHE 265is set to a directory name, debug packages matching installed/updated packages 266will be downloaded to that directory 267.Po 268this is to avoid 269.Sq shearing , 270as later on, you might wish to debug software, but the snapshots will have 271moved on and the debug packages no longer match your installation 272.Pc . 273This only applies to debug packages that are not currently installed/updated. 274.Pp 275Some packages may depend on other packages. 276When resolving dependencies 277.Nm 278will first look at already installed packages, then match 279dependencies with the list of packages left to install, then ask the 280user's opinion in interactive mode, 281then install default packages that satisfy the dependencies. 282.Pp 283.Sy Warning: 284Since the 285.Nm 286command may execute scripts or programs contained within a package file, 287your system may be susceptible to 288.Dq trojan horses 289or other subtle attacks from miscreants who create dangerous packages. 290Be sure the specified package(s) are from trusted sources. 291.Pp 292The options are as follows: 293.Bl -tag -width keyword 294.It Fl A Ar arch 295Assume 296.Ar arch 297as current machine architecture for any package tests. 298.It Fl a 299Automated package installation; do not record packages as installed manually. 300.It Fl aa 301Force already installed packages to be tagged as installed automatically. 302.It Fl B Ar pkg-destdir 303Set 304.Ar pkg-destdir 305as the prefix to prepend to any object extracted from the package. 306.It Fl c 307While replacing packages, delete extra configuration file in the old package, 308mentioned as 309.Dl @extra file 310in the packing-list. 311.It Fl D Ar name Ns Op = Ns Ar value 312Force installation of the package. 313.Ar name 314is a keyword that states what failsafe 315should be waived. 316Recognized keywords include: 317.Pp 318.Bl -tag -width "updatedependsXX" -compact 319.It Cm allversions 320Do not trim older p* variants of packages for updates. 321.It Cm arch 322Architecture recorded in package may not match. 323.It Cm checksum 324Verify checksums before deleting or tying old files. 325.It Cm dontmerge 326By default, if dependencies are too strict, 327.Nm 328will merge updates together to make sure everything stays in sync. 329.Fl D Ns Cm dontmerge 330disables that behavior. 331.It Cm donttie 332By default, 333.Nm 334will try to find new files in old packages by comparing the stored sha256, 335and tie the entries together to avoid extracting files needlessly. 336.Fl D Ns Cm donttie 337disables that behavior. 338.It Cm downgrade 339Don't filter out package versions older than what's currently installed. 340.It Cm installed 341In update mode, reinstall an existing package with the same update signature. 342.It Cm nonroot 343Install even if not running as root. 344.It Cm paranoid 345Very safe update: don't run any @exec/@unexec. 346This may break some packages that will need manual intervention. 347.It Cm repair 348Attempt to repair installed packages with missing registration data. 349.It Cm scripts 350External scripts may fail. 351.It Cm SIGNER 352List of trusted signers, separated by commas. 353Corresponds to list of public keys under 354.Pa /etc/signify 355we want to trust. 356Defaults to any key matching 357.Sq *pkg 358for packages, and any key matching 359.Sq *fw 360for firmware. 361.It Cm snap | Cm snapshot 362Force 363.Sq %c 364and 365.Sq %m 366to expand to 367.Sq snapshots , 368even on a release kernel. 369.It Cm unsigned 370Allow the installation of unsigned packages without warnings/errors. 371But see 372.Ev TRUSTED_PKG_PATH , 373which is more discriminating. 374.It Cm updatedepends 375Force update even if forward dependencies no longer match. 376.El 377.It Fl I 378Force non-interactive mode. 379Default is to be interactive when run from a tty. 380.It Fl i 381Force interactive mode, even if not run from a tty. 382.Nm 383may ask questions to the user if faced with difficult decisions. 384.It Fl L Ar localbase 385Install a package under 386.Ar localbase . 387By default, 388.Ar localbase 389equals 390.Pa /usr/local , 391and specifying it is not necessary. 392However, packages can be created using a different 393.Ar localbase 394.Po 395see 396.Xr pkg_create 1 397.Pc , 398and those packages can only be installed by using the same 399.Ar localbase . 400See 401.Xr bsd.port.mk 5 402for a description of 403.Ev LOCALBASE . 404.It Fl l Ar file 405Installs packages from the raw output of 406.Xr pkg_info 1 , 407as saved in 408.Ar file . 409Generally, use with 410.Li pkg_info -mz \*(Gtfile , 411to reproduce an installation from machine to machine. 412With 413.Fl l 414.Nm 415will try its best to reproduce the installation. 416.It Fl m 417Causes 418.Nm 419to always display the progress meter in cases it would not do so by default. 420.It Fl n 421Don't actually install a package, just report the steps that 422would be taken if it was. 423Will still copy packages to 424.Ev PKG_CACHE 425if applicable. 426.It Fl P Ar ftp 427Check that package can be distributed on ftp. 428.It Fl qq 429Do not bother with checksums for configuration files. 430.It Fl r 431Replace existing packages. 432.Nm 433will try to take every precaution to make sure the replacement can 434proceed before removing the old package and adding the new one, and it 435should also handle shared libraries correctly. 436Among other things, 437.Nm 438will refuse to replace packages as soon as it needs to run scripts that 439might fail 440.Po 441use 442.Fl D Cm update 443to force the replacement 444.Pc ; 445.Nm 446will also refuse to replace packages when the dependencies don't quite 447match 448.Po 449use 450.Fl D Cm updatedepends 451to force the replacement 452.Pc . 453.It Fl s 454Don't actually install packages, skip as many steps as needed and report 455only the disk size changes that would happen. 456Similar to 457.Fl n , 458except it also skips fetching full packages and stops at getting the 459information it needs. 460.It Fl U 461Update dependencies if required before installing the new package(s). 462.It Fl u 463Update the given installed 464.Ar pkgname(s) , 465and anything it depends upon. 466If no 467.Ar pkgname 468is given, 469.Nm 470will update all installed packages. 471This relies on 472.Ev PKG_PATH 473to figure out the new package names. 474.It Fl V 475Turn on statistics output. 476For now, only displays the number of packages done/total number of packages. 477Several 478.Fl V 479will turn on more statistics in the future. 480.It Fl v 481Turn on verbose output. 482Several 483.Fl v 484turn on more verbose output. 485By default, 486.Nm 487is almost completely silent, but it reacts to keyboard status requests 488.Po 489see 490.Xr stty 1 491.Pc . 492.Fl v 493turns on basic messages, 494.Fl vv 495adds relevant system operations, 496.Fl vvv 497shows most internal computations apart from individual file/directory 498additions, 499.Fl vvvv 500also shows dependencies adjustments, and 501.Fl vvvvv 502shows everything. 503.It Fl x 504Disable progress meter. 505.It Fl z 506Fuzzy package addition: 507.Nm 508should do its best to match package names passed on the command line, 509even if the versions don't match and it will proceed even if 510some packages can't be found. 511.El 512.Pp 513By default, when adding packages via FTP, the 514.Xr ftp 1 515program operates in 516.Dq passive 517mode. 518If you wish to use active mode instead, set the 519.Ev FTPMODE 520environment variable to 521.Dq active . 522If 523.Nm 524consistently fails to fetch a package from a site known to work, 525it may be because the site does not support 526passive mode FTP correctly. 527This is very rare since 528.Nm 529will try active mode FTP if the server refuses a passive mode 530connection. 531.Ss Manual installation 532.Nm 533differentiates between packages specified on the command line, and packages 534installed automatically because of inter-dependencies: 535the first kind will be tagged as 536.Sq installed manually . 537The 538.Fl a 539option is used internally by the 540.Xr ports 7 541infrastructure 542and 543.Xr dpb 1 544to handle dependencies. 545.Pp 546It is also possible to tweak the 547.Sq installed manually 548status of a package after the fact. 549Running 550.Nm 551on an already installed package will tag it as 552.Sq installed manually , 553even if it was already there as a dependency of something else, 554and doubling the 555.Fl a 556option will remove the 557.Sq installed manually 558tag from installed packages. 559.Pp 560.Xr pkg_info 1 561can be used to show only manually-installed packages, and 562.Xr pkg_delete 1 563can be used to remove dependencies when they are no longer needed. 564.Ss Technical details 565.Nm 566deals with 567.Sq updatesets 568internally. 569An updateset is a collection of old package(s) to delete, and new package(s) 570to install, as an atomic operation. 571Under normal circumstances, an updateset contains at most one old package 572and one new package, but some situations may require 573.Nm 574to perform several installations/deletions at once. 575.Pp 576For each new package in an updateset, 577.Nm 578extracts the package's 579.Dq packing information 580(the packing-list, description, and installation/deinstallation scripts) 581into a special staging directory in 582.Pa /tmp 583(or 584.Ev PKG_TMPDIR 585if set) 586and then runs through the following sequence to fully extract the contents 587of the package: 588.Bl -enum 589.It 590A check is made to determine if the package is already recorded as installed. 591If it is, 592the installation is terminated. 593.It 594A check is made to determine if the package conflicts (from 595.Cm @conflict 596directives; see 597.Xr pkg_create 1 ) 598with a package already recorded as installed. 599In non-replacement mode, its installation is terminated. 600.It 601For packages tagged with architecture constraints, 602.Nm 603verifies that the current machine architecture agrees with the constraints. 604.It 605All package dependencies (from 606.Cm @depend 607and 608.Cm @wantlib 609directives; see 610.Xr pkg_create 1 ) 611are read from the packing-list. 612If any of these dependencies are not currently fulfilled, 613an attempt is made to find a package that meets them and install it, 614looking first in the current updateset, then in the list of packages 615to install passed to 616.Nm ; 617if no adequate package can be found and installed, 618the installation is terminated. 619.It 620.Nm 621checks for collisions with installed file names, read-only file systems, 622and enough space to store files. 623.It 624The packing-list is used as a guide for extracting 625files from the package into their final locations. 626.It 627After installation is complete, a copy of all package files 628such as the packing-list, extra messages, or 629the description file is made into 630.Pa /var/db/pkg/<pkg-name> 631for subsequent possible use by 632.Xr pkg_delete 1 633and 634.Xr pkg_info 1 . 635Any package dependencies are recorded in the other packages' 636.Pa /var/db/pkg/<other-pkg>/+REQUIRED_BY 637file 638(if the environment variable 639.Ev PKG_DBDIR 640is set, this overrides the 641.Pa /var/db/pkg/ 642path shown above). 643.It 644Finally, the staging area is deleted and the program terminates. 645.El 646.Pp 647Note that it is safe to interrupt 648.Nm pkg_add 649through 650.Dv SIGINT , 651.Dv SIGHUP , 652and other signals, as it will safely record an interrupted install as 653.Pa partial-<pkgname>[.n] . 654.Pp 655When replacing packages, the procedure is slightly different. 656.Bl -enum 657.It 658A check is made to determine if a similar package is already installed. 659If so, its full update signature is computed, which contains all the 660necessary dependency information along with the actual package version. 661If that signature is identical to that of the new package, no replacement 662is performed (unless 663.Fl D Cm installed 664is specified). 665.It 666A check is made to determine what old package(s) the new package(s) should 667replace, using conflicts. 668.Nm 669will attempt to update those packages. 670If they update to the new package(s), nothing needs to be done. 671If they're part of the list of updatesets to install, the corresponding 672updatesets will be merged. 673Otherwise, 674.Nm 675will add them to the current updateset, and rerun update to find suitable 676update to those packages. 677.It 678A check is made to determine whether the old packages will be deleted without 679issue, and whether the new packages will install correctly. 680This includes refusing to run any code (unless 681.Fl D Cm update ) , 682and verifying 683that the new package still matches dependencies (unless 684.Fl D Cm updatedepends ) . 685.It 686Shared libraries deserve special treatment: each shared library from the old 687packages that does no longer exist in the new packages, but that is required 688from a wantlib of another package is kept along in a stub package named 689.Pa \&.libs-<pkgname> . 690.It 691The new packages are extracted to the filesystem, using temporary filenames 692of the form 693.Pa pkg.XXXXXXX 694since the old packages are still there. 695The packing-list is amended to record these names as @temp annotations, 696in cases the installation fails. 697.It 698The old packages are deleted as usual, except that some packages may still 699depend on them. 700Note also that 701.Cm @unexec-delete 702commands are not executed. 703.It 704The new packages are installed as usual, except that the files are already 705present and only need to be renamed. 706Note also that 707.Cm @exec-add 708commands are not executed. 709.It 710Dependencies from the old packages are adjusted to point to the correct new 711package. 712.El 713.Pp 714To update packages in -u mode, 715.Nm 716performs the following steps. 717.Bl -enum 718.It 719Each package name is reduced to its stem, and every package name with matching 720stem available through 721.Ev PKG_PATH 722is considered as an update candidate. 723.It 724.Nm 725searches for a 726.Sq quirks 727package first, which may contain exceptions to these rules. 728This special package contains global information, such as packages that 729can be deleted because they're now part of base, or stem changes. 730.It 731Version matching occurs: unless 732.Fl D Cm downgrade , 733only packages with newer 734versions will be considered as update candidates. 735Note that version matching is costly, thus 736.Ev PKG_PATH 737should point to a snapshot of packages for a given version of 738.Ox , 739similar to the organization on the FTP sites. 740.It 741Candidates are then matched according to their pkgpaths 742.Po 743see 744.Xr pkgpath 7 745and 746.Xr pkg_create 1 747.Pc 748in order to weed out similar packages with distinct options. 749.It 750The update signature of the candidate is compared to the signature of the 751already installed package: identical signatures mean no update needed. 752.It 753If several candidates are left, 754.Nm 755will ask the user in interactive mode, and not perform the update in 756non-interactive mode. 757.It 758Once a suitable update candidate has been found, 759.Nm 760checks the package dependencies. 761If necessary, it will install or update them first. 762Once all dependencies are up to date, 763.Nm 764will update the package. 765.El 766.Sh ENVIRONMENT 767.Bl -tag -width PKG_CHECKSUM 768.It Ev DEBUG_PKG_CACHE 769If set, debug packages matching installed/updated packages will be downloaded 770to that directory as well. 771.It Ev FTPMODE 772Specifies whether 773.Xr ftp 1 774should operate in 775.Dq active 776or 777.Dq passive 778mode. 779The default is 780.Dq passive . 781.It Ev FETCH_CMD 782Override use of 783.Xr ftp 1 . 784Must point to a command that understands 785.Li ${FETCH_CMD} -o - url . 786.It Ev PKG_CACHE 787If set, any package retrieved from a distant location will be copied to 788that directory as well. 789.It Ev PKG_CHECKSUM 790If set, verify files checksums during deletion, exactly like 791.Fl D Ns Cm checksum . 792.It Ev PKG_DBDIR 793Where to register packages instead of 794.Pa /var/db/pkg . 795.It Ev PKG_PATH 796If a given package name cannot be found, 797the directories named by 798.Ev PKG_PATH 799are searched. 800It should contain a series of entries separated by colons. 801Each entry consists of a directory name. 802URL schemes such as FTP, HTTP, HTTPS, or SCP are also appropriate. 803The current directory may be indicated 804implicitly by an empty directory name, or explicitly by a single 805period 806.Pq Ql \&./ . 807Special sequences 808.Sq %a , 809.Sq %c , 810.Sq %m , 811.Sq %v 812will be expanded. 813.It Ev PKG_TMPDIR 814Temporary area where package information files will be extracted, instead of 815.Pa /tmp . 816.It Ev TRUSTED_PKG_PATH 817Same semantics as 818.Ev PKG_PATH , 819but it is searched before 820.Ev PKG_PATH 821and waives any kind of signature checking. 822.El 823.Sh FILES 824.Bl -tag -width /etc/installurl 825.It Pa /etc/installurl 826default mirror server for package download 827.It Pa /etc/signify/*-pkg.pub 828public keys for package verification with 829.Xr signify 1 830.It Pa /usr/local/ 831default file system to install packages in 832.It Pa /usr/local/share/doc/pkg-readmes/ 833.Ox Ns -specific 834information about individual packages 835.It Pa /var/db/pkg/ 836database of installed 837.Xr packages 7 838.El 839.Sh SEE ALSO 840.Xr ftp 1 , 841.Xr pkg_create 1 , 842.Xr pkg_delete 1 , 843.Xr pkg_info 1 , 844.Xr OpenBSD::Intro 3p , 845.Xr bsd.port.mk 5 , 846.Xr installurl 5 , 847.Xr package 5 , 848.Xr pkg_check 8 849.Sh AUTHORS 850.Bl -tag -width indent -compact 851.It An Jordan Hubbard 852Initial design. 853.It An Marc Espie 854Complete rewrite. 855.El 856