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