182 Commits
Author SHA1 Message Date
Colin Percival b669226877 pkg: Enable FreeBSD-base by default
Enable the FreeBSD-base repository in all of the /etc/pkg/FreeBSD.conf
variants, and remove code from various install paths which enabled the
repository via /usr/local/etc/pkg/repos/FreeBSD.conf.

Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D60946
2026-11-01 19:16:23 -07:00
Faraz Vahedi 47f9e66507 pkg(7): Preserve const qualifier on strrchr(3) results
Reviewed by:	fuz
Approved by:	fuz (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59777
2026-09-19 13:45:35 +03:30
Kyle Evans 9dfaf1cb37 Revert "pkg: Add -j and -r options"
This reverts commit d94e034d50 at the
request of des@, as it seems to have broken the pass-through case.
2026-07-13 17:08:58 -05:00
Dag-Erling Smørgrav d94e034d50 pkg: Add -j and -r options
This allows pkg(7) to be used to bootstrap a jail or chroot, and to
recognize the -j and -r options and pass them through to pkg(8) if
already bootstrapped.

Note that this does not address the issue of repository keys.  If using
a signed package repository, you will still need to copy /usr/share/keys
into the target environment before or after bootstrapping, or pkg will
be unable to verify package signatures.

MFC after:	1 week
Reviewed by:	imp, bapt
Differential Revision:	https://reviews.freebsd.org/D58165
2026-07-13 17:32:41 +02:00
Pavel Knoblokh abf911af22 pkg: Fix mirror type parsing and service discovery
Signed-off-by: Pavel Knoblokh <[email protected]>
Reviewed by:	emaste, imp, kevans
Fixes:		dc4581589a ("pkg: clean support for repositories")
Closes:		https://github.com/freebsd/freebsd-src/pull/1989
2026-02-04 21:59:21 -06:00
Guilherme Augusto de Souza Candinho 849c0eb070 Comments: FreeBSD.conf should not be overwritten
The files /usr/sbin/pkg/FreeBSD.conf.* currently set base repo to {enable: no}.
We don't want to overwrite /local/etc/pkg/repos/FreeBSD.conf that already exists
when users choose tech preview in the installation.

Signed-off-by: Guilherme Augusto de Souza Candinho <[email protected]>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1925
2026-01-09 19:41:13 -07:00
Colin Percival a3b0902d73 pkg: Move FreeBSD-base to pkg.freebsd.org
Rather than fetching packages directly from the CDN which currently
backs pkgbase.freebsd.org, requests will go to pkg.freebsd.org mirrors
and be 302ed to the correct servers.  This adds ~70 seconds to the
process of installing or upgrading a pkgbase system; it also orphans
systems with 15.0-{PRERELEASE,ALPHA*,BETA*} installed since they are
expecting to see pkgbase files signed with the pkg keys, not the new
pkgbase signing keys.

Reviewed by:	dch, philip
MFC after:	immediately (for 15.0-RELEASE)
With hat:	re
Requested by:	clusteradm, core
Differential Revision:	https://reviews.freebsd.org/D53964
2025-11-27 14:13:52 -08:00
Colin Percival 8e0b1a1c03 pkg: Add FreeBSD-base to /etc/pkg/FreeBSD.conf
On -CURRENT and -STABLE this gets bits from pkg.freebsd.org; but we get
base system bits from pkgbase.freebsd.org for BETA/RC/RELEASE.

Note that this repository is disabled by default, but can still be used
by explicitly specifying it, e.g. "pkg upgrade -r FreeBSD-base".

With hat:	re
MFC after:	8 hours (needed in 15.0-RC1)
2025-11-14 23:58:41 -08:00
Colin Percival 0837b2ebd5 pkg: Die if make -V BRANCH fails
If build logic breaks such that we can't figure out which branch we're
on, we should error out rather than shipping a default (and probably
wrong) /etc/pkg/FreeBSD.conf

Reviewed by:	ivy
MFC after:	5 minutes
Suggested by:	ivy
Differential Revision:	https://reviews.freebsd.org/D53487
2025-10-30 13:50:45 -07:00
Seyed Pouria Mousavizadeh Tehrani 08b8843137 pkg(7): Add support for pkg+ prefix to bootstrap pubkey
MFC After: 	1 day
Sponsored by:	Amn Afzar Hoopad Inc
Differencial Revision:	https://reviews.freebsd.org/D52418
2025-09-11 09:03:48 +02:00
Colin Percival 579bb6c2cd Update comments to match pkg repo renaming
Reported by:	Ceri Davies
Fixes:		c83705a575 ("Rename FreeBSD* pkg repos to FreeBSD-ports*")
2025-08-27 15:48:46 -07:00
Colin Percival c83705a575 Rename FreeBSD* pkg repos to FreeBSD-ports*
With pkgbase being the New Way Of Doing Things in FreeBSD 15.0, it is
unnecessarily confusing to have a repository called "FreeBSD" which
contains packages built from the FreeBSD ports tree but not from the
FreeBSD src tree.  Bite the bullet and change it now rather than
having an even more painful transition later.

With hat:	re@
Bikeshed on:	freebsd-current, freebsd-ports
Relnotes:	The "FreeBSD" and "FreeBSD-kmods" repositories defined
		in /etc/pkg/FreeBSD.conf have been renamed to
		FreeBSD-ports and FreeBSD-ports-kmods respectively.
		Users who override these in /usr/local/etc/pkg/repos
		will need to adjust their configuration to match the
		new names.
2025-08-27 09:46:36 -07:00
Baptiste Daroussin db6f6cc583 pkg.conf: add valid configurations for kmods for all branches
MFC After:	1 week
Reviewed by:	cperciva
Differential Revision: 	https://reviews.freebsd.org/D50668
2025-06-03 17:48:15 +02:00
Colin Percival 955ab1a8f2 pkg/FreeBSD.conf: Fix comments to reflect -kmods
Now that this file lists two repositories, the text "to disable *this*
repository" no longer makes sense.  Also, expand the example to list
how to disable both FreeBSD and FreeBSD-kmods repositories.

Reported by:	Graham Perrin
MFC after:	3 days
2025-05-29 16:43:46 -07:00
Colin Percival 29f076ae0c pkg.conf: Use kmod repositories
The kmod repositories were added shortly after 14.2-RELEASE.  Point at
them here so that users don't need to manually add the configuration
in order to get e.g. working graphics.

MFC after:	1 minute
Sponsored by:	Amazon
Differential Revision:	https://reviews.freebsd.org/D50583
2025-05-29 12:57:48 -07:00
Isaac Freund 73ba568b1c pkg: suppress error on unknown options
pkg(7) does not understand all the options that pkg(8) understands and
should never log errors about unknown options that it will pass on to
pkg(8) without touching.

PR:		286510
Reviewed by:	bapt
Fixes:		be61deae0a ("pkg: clarify argument parsing")
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50163
2025-05-05 11:52:08 -04:00
Isaac Freund be61deae0a pkg: clarify argument parsing
Currently pkg parses all arguments and subcommands in a single
getopt_long() loop. This results in quite a bit of accidental
complexity, especially around the -r option for the bootstrap and add
subcommands.

This also results in the undocumented behavior of all options understood
by pkg(7) being accepted anywhere in the argument list regardless of
their position. This contradicts the behavior of pkg(8) and I find it
quite unexpected.

This patch splits the argument parsing done by pkg(7) into two phases
for global options and subcommand options. This gives behavior that
matches pkg(8), accepting the subset of pkg(8) options supported by
pkg(7) in the exact same positions that pkg(8) accepts them.

This is however a somewhat breaking change, as options are no longer
accepted by pkg(7) in places they are rejected by pkg(8). For example,
`pkg -f bootstrap` no longer works, only `pkg bootstrap -f`.

The original motivation for writing this patch was investigating support
for --rootdir in pkg(7). Since pkg(8) uses -r as the short form for
both --rootdir and --repository depending on the position, I decided
that pkg(7) needed to be brought inline with pkg(8)'s argument parsing
behavior to avoid confusion.

This patch also gets rid of args_add_message (unused since 40b9f924b1)

Relnotes:	yes
Reviewed by:	bapt
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49977
2025-04-29 21:00:17 -04:00
Isaac Freund 14704a7fdb pkg: update references to pkg.txz in man page
Only pkg.pkg is supported since 0cd9513a5b.

Reviewed by:	emaste, ziaee
Fixes: 0cd9513a5b ("pkg: retire backwards compatibility bootstrap support")
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49994
2025-04-24 11:34:06 -04:00
Christos Margiolis 8900283fa3 pkg.7: Add example for fetching package for different FreeBSD versions
MFC after:	1 week
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D49580
2025-04-01 15:29:50 +02:00
Mark Johnston c1557708f1 pkg: Fix Coverity warnings
- Fix allocation size in config_get_repositories().
- Fix a memory leak in read_conf_file().
- Avoid a null pointer dereference in an error path in
  verify_pubsignature().

Fixes:	e3b4a51580 ("pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME")
Fixes:	dc4581589a ("pkg: clean support for repositories")
2025-01-16 16:45:15 +00:00
Baptiste Daroussin e3b4a51580 pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME
Catchup with pkg(8) by expanding more variable when parsing repositories
The only missing variable now is ARCH, this will have to wait for
pkg 2.0 to be the lowest supported version.
2025-01-16 14:50:42 +01:00
Baptiste Daroussin 5c341fe512 pkg(7): support configuration overwrite like pkg(8)
with pkg(8) it is possible to overwrite a configuration like adding
FreeBSD {
	enabled: false
}

in /usr/local/etc/pkg/repo/overwrite.conf which allows to change any
value which can have been reviously configured in anything in
/etc/pkg/*.conf

now the bootstrap supports the same

MFC After:	3 weeks
2025-01-15 09:21:19 +01:00
Baptiste Daroussin eccf736c3c pkg: make sure the repositories have at least an url
While here, factorize code to free the repository structure
2025-01-15 09:21:19 +01:00
Ed Maste 0cd9513a5b pkg: retire backwards compatibility bootstrap support
pkg.pkg has been available for years and is the default in all supported
releases.  Retire fallback support for pkg.txz.

Reviewed by:	bapt
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46990
2025-01-14 08:42:36 -05:00
Benedict Reuschling 49f4e3d297 pkg: Fix two typos in visible error messages
No functional changes.
2025-01-14 12:58:53 +00:00
Baptiste Daroussin dc4581589a pkg: clean support for repositories
Rework the way the bootstrap fetches pkg, by implementing a full support
for the repositories, the boostrap will now loop over all available repo
and try to fetch the full package from there. It will at the first valid
package found.

Fallback to packagesite (which has been deprecated for a while) if needed, by
transforming it into a repo, if no repo is found.

MFC After:	3 weeks
2025-01-14 12:21:40 +01:00
Kyle Evans b8770ce1df pkg: include missing <string.h>
My local environment seems to be seeing some pollution; we need
<string.h> for strlen.

PR:		284021
Fixes:		2e065d74a5 ("pkg: add a pkgsign_verify_data [...]")
MFC after:	immediately (trivial build fix)
2025-01-12 14:11:22 -06:00
Kyle Evans 3d0a0dda3a pkg: finish adding the ECC signer and signature type bits
Signature types need to be parsed out of the key/signature information
that we are presented with from the files we download.  We use that to
understand whicher signer we need to dispatch to.

The ECC signer is more-or-less lifted from pkg(8), with some changes to
slim it down for pkg(7).

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D48108
2025-01-01 15:11:24 -06:00
Kyle Evans 2e065d74a5 pkg: add a pkgsign_verify_data callback
This will be used to verify raw payloads, as if signed by pkg-key(8).
It will be used specifically in pkg(7) to verify .pubkeysig as published
by poudriere.

Amend verify_pubsignature() now to use it.  For the RSA signer, we need
to verify using a sha256 of the data instead of the data itself.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D48109
2025-01-01 15:11:23 -06:00
Kyle Evans 2ecfc040a0 pkg: refactor out a pkg_read_fd()
We already have to do this for reading the pubkey, just pull it out for
other uses.  The ECC signer will use this to verify the bootstrap if
the PUBKEY mechanism is used.

Reviewed by:	bapt, emaste
Differential Revision:	https://reviews.freebsd.org/D48107
2025-01-01 15:11:23 -06:00
Kyle Evans 5862580ded pkg: abstract rsa out behind a pkgsign API
This mirrors a change we made in pkg(8), and will be used to next add
another signer that does ECC.

Reviewed by:	bapt, emaste
Differential Revision:	https://reviews.freebsd.org/D48106
2025-01-01 15:11:23 -06:00
Kyle Evans 2629e90dd0 pkg: pull rsa bits out of pkg.c
We'll eventually add a pkgsign abstraction over these similar to how we do
in pkg(8), but start by isolating these parts.

Reviewed by:	bapt, emaste
Differential Revision:	https://reviews.freebsd.org/D48105
2025-01-01 15:11:22 -06:00
Ed Maste be9243409d pkg: improve error message
Print the complete list of url that have failed

PR:		281924
Co-authored-by: Baptiste Daroussin <[email protected]>
Differential Revision: https://reviews.freebsd.org/D46983
2024-10-07 13:05:07 -04:00
Ed Maste f5c847ae84 pkg: prefer .pkg extension
.pkg is the default extension as of commit c244b1d8a3, falling back to
.txz if not found.

PR:		281924
Reviewed by:	bapt
Fixes: a2aac2f5e5 ("pkg(7): when bootstrapping first search for pkg.bsd file then pkg.txz")
Fixes: c244b1d8a3 ("pkg: settle the uniq extension to .pkg instead of .bsd")
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46977
2024-10-07 12:01:36 -04:00
Warner Losh e9ac41698b Remove residual blank line at start of Makefile
This is a residual of the $FreeBSD$ removal.

MFC After: 3 days (though I'll just run the command on the branches)
Sponsored by: Netflix
2024-07-15 16:43:39 -06:00
Warner Losh 4d65a7c695 usr.sbin: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
John Baldwin fd9ae9ac04 pkg: Allocate a suitably-sized string for the local ABI
Previously the local ABI string was written to an on-stack buffer and
the pointer to that buffer was saved in a global before the function
returned.  This had two issues: c[ABI].val pointed to a
no-longer-valid on-stack buffer after config_init returned, and the
string could potentially be truncated.  Fix both of those by changing
pkg_get_myabi to return a pointer to a string allocated by asprintf.

Note that the allocated string is left in the global config array
until it is implicitly freed on process exit.

Reported by:	GCC 13 -Wdangling-pointer
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D42623
2023-11-15 16:53:53 -08:00
Baptiste Daroussin d557a86c87 pkg: use https by default
Switch the repository to use https by default, base is providing a CA
root bundle suitable to validate the certificates used by the project.
This can now be activated without requiring another packages to be installed

Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D40473
2023-09-11 17:41:32 +02:00
Warner Losh fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Baptiste Daroussin e5dd5bfa55 pkg(7): now that we do use libmd, use it completly
Use SHA256_Fd and SHA256_Data instead of home made equivalent.
wrap those functions into hash.c to avoid header collition between
openssl and libmd

Suggested by:	kevans
2023-03-09 21:31:30 +01:00
Baptiste Daroussin b2654064c2 pkg(7): use libmd for sha256 instead of openssl
OpenSSL 3.0 has deprecated the sha256 api, let's use libmd which has the
same API instead.

In order to avoid the collision in definitions (sha256.h cannot be
included in the same file as a file where openssl headers has been
included) let's move the sha256 related code in its own file

PR:		270023
Reported by:	ngie
2023-03-09 17:43:01 +01:00
Kyle Evans c816aea7ab Revert "grep: remove tautological condition"
This reverts commit f6d6c66889.

Gremlins snuck into my tree and injected some WIP.
2023-03-08 23:52:23 -06:00
Kyle Evans f6d6c66889 grep: remove tautological condition
st_size is an off_t, it cannot hold values larger than OFF_MAX.

CID:		1008931
2023-03-08 23:34:22 -06:00
Gordon Bergling 990878b07f pkg(8): Remove a double word in a source code comment
- s/that that/that/

MFC after:	3 days
2022-09-04 17:28:16 +02:00
Brooks Davis e9ad2964f5 pkg: Add limited --debug/-d support
Add an internal debug level global:
 - Level 1 (-d) currently does nothing.

 - Level 2 (-d -d) enables libfetch debugging (quite verbose) so it's
   possible to see what pkg is attempting to download without having
   to sniff traffic.

Reviewed by:	debdrup, bapt
Differential Revision:	https://reviews.freebsd.org/D35756
2022-08-24 18:32:09 +01:00