Drop the cross-build leftovers, pilot and migrate-device.sh
The build runs natively on arm64 since 2026-11-18: setup no longer installs qemu-user-static and aarch64-binutils (and refuses a non-aarch64 host), GATEWAY.conf drops PRODUCT_WANTS_CROSS, build no longer asks tools for an xtools set, finish no longer moves one aside, and mk-image.sh no longer sets up xtools or removes qemu. The pilot command, which timed ports before the first full build, goes too. Gateways are migrated with the shell commands in RELEASE.md, as ApolloGuardian was, instead of migrate-device.sh; that includes the custom mirror for a proxy that is not on 443 inside the LAN, and the major upgrade's UPGRADE_RELEASE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5f4afd0155
commit
e1b9aa77fd
6 changed files with 139 additions and 581 deletions
203
RELEASE.md
203
RELEASE.md
|
|
@ -211,8 +211,8 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
|
|||
of hanging.
|
||||
2. Applies `patches/<series>/*.patch` to core with `git am`. Core's version
|
||||
becomes `<release>_<patches>`.
|
||||
3. Builds base, kernel and xtools, then this repository's kernel modules, as
|
||||
an early check against the new kernel.
|
||||
3. Builds base and kernel, then this repository's kernel modules, as an
|
||||
early check against the new kernel.
|
||||
4. Builds the ports in one tools ports step over the whole list, tools'
|
||||
`ports.conf`. Tools caches the build-only dependencies it builds (cmake,
|
||||
autoconf, the Rust and Go compilers) for the rest of a step only, and the
|
||||
|
|
@ -308,9 +308,7 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
|
|||
with the key. So `finish` first unpacks the aux set, signs its catalogue
|
||||
with `pkg repo` and repacks it. `gwmirror verify` found the aux catalogue
|
||||
unsigned on 2026-11-22.
|
||||
3. Builds the 5 GB ZFS eMMC image (`mk-image.sh`). On a cross-building
|
||||
host the xtools set is moved aside first, because tools would otherwise
|
||||
overlay amd64 toolchain files onto the image.
|
||||
3. Builds the 5 GB ZFS eMMC image (`mk-image.sh`).
|
||||
4. Imports the image's pool read-only, without mounting it, and mounts each
|
||||
dataset read-only by itself. Mounting them all at import does not work:
|
||||
the pool's own dataset needs a mountpoint inside the read-only root, and
|
||||
|
|
@ -320,18 +318,6 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
|
|||
cannot pass.
|
||||
5. Compresses and signs the image.
|
||||
|
||||
**To time a few ports** before a first full build of a series:
|
||||
|
||||
```sh
|
||||
release/vm.sh run 14.3 pilot 26.1 26.1.11 security/suricata databases/py-duckdb@py313
|
||||
```
|
||||
|
||||
The pilot builds base, kernel and xtools, then the given ports with their
|
||||
dependencies (fetching and repairing distfiles as the build does), timing
|
||||
each. It then removes its partial packages set (tools would otherwise
|
||||
consider the ports built); base, kernel, xtools and distfiles are kept for
|
||||
the full build.
|
||||
|
||||
### Board package version
|
||||
|
||||
`mono-gateway` is versioned `<release>_<commit count of this repository>`,
|
||||
|
|
@ -427,68 +413,124 @@ python3 mirror/gwmirror.py verify --url http://127.0.0.1:18080 --allow-http --se
|
|||
|
||||
## Migrating a gateway from opnsense.mono.si
|
||||
|
||||
Shell commands, run on the gateway over ssh as root. Root's shell there is
|
||||
csh, which does not take `#` comments typed at the prompt: start `sh` first.
|
||||
ApolloGuardian was migrated this way on 2026-11-23.
|
||||
|
||||
**Before you start:**
|
||||
- Download a configuration backup (System > Configuration > Backups).
|
||||
- Set System > Firmware > Settings > Mirror to "(default)".
|
||||
- Have the serial console (115200 baud) at hand for the first kernel update.
|
||||
- Have the serial console (115200 baud), or Recovery Linux and the image in
|
||||
`releases/26.1/`, at hand for the first kernel update.
|
||||
- `opnsense.karsttech.com` resolves to the public address, which is the
|
||||
gateway's own WAN address: without an Unbound host override to the
|
||||
proxy's LAN IP, the gateway connects to its own web GUI. With the
|
||||
override, the URL depends on the proxy's LAN port (step 4).
|
||||
|
||||
**Steps:**
|
||||
|
||||
1. Copy the script and the fingerprint to the gateway, then do a dry run:
|
||||
|
||||
```sh
|
||||
scp release/migrate-device.sh keys/fingerprints/trusted/opnsense.karsttech.com.20261117 root@gw:/root/
|
||||
ssh root@gw sh /root/migrate-device.sh repoint --mirror https://opnsense.karsttech.com \
|
||||
--fingerprint /root/opnsense.karsttech.com.20261117 --dry-run
|
||||
```
|
||||
|
||||
2. Run the same command without `--dry-run`. `repoint` does the following;
|
||||
every file it changes is backed up to `/root/gwmirror-backup-<time>/`.
|
||||
1. Checks that the gateway reaches `/healthz` and its repository.
|
||||
2. Creates a boot environment.
|
||||
3. Installs the fingerprint.
|
||||
4. Rewrites the URL in `OPNsense.conf` and `OPNsense-aux.conf` and their
|
||||
`.sample` files.
|
||||
5. Removes `MonoGateway.conf`.
|
||||
6. Re-annotates `mono-gateway` to the OPNsense repository.
|
||||
7. Runs `configctl firmware reload` and `pkg update -f`.
|
||||
|
||||
3. System > Firmware > Updates > Check for updates, then update. This installs
|
||||
our core `26.1.11_2` (which makes the repoint permanent), the packages,
|
||||
base and kernel, then reboots.
|
||||
|
||||
4. Reinstall everything once, so no vendor-built binary remains:
|
||||
`opnsense-update -pf` (packages) and `opnsense-update -bkf` (base,
|
||||
kernel), then reboot.
|
||||
|
||||
5. Check:
|
||||
- `opnsense-version` and `uname -v` show the new release;
|
||||
- `kldstat` lists cdx, fci, ...;
|
||||
- System > Firmware > Status > Audit > Health is clean.
|
||||
|
||||
**When the gateway reaches the proxy only on another port.** At home, the
|
||||
router forwards WAN 443 to Traefik's port 444, so inside the LAN the mirror
|
||||
is `https://opnsense.karsttech.com:444` (with the Unbound host override to
|
||||
Traefik's LAN IP). pf cannot redirect connections the firewall makes
|
||||
itself, so set System > Firmware > Settings > Mirror to "(custom)" with that
|
||||
URL instead of rewriting the repository files. The setting is kept in
|
||||
`config.xml`, and core applies it on every firmware reload
|
||||
(`opnsense-update -sd -m`), so it survives core updates. On the vendor's
|
||||
26.1.9 the GUI did not save it (2026-11-23); this did, keeping the previous
|
||||
version in System > Configuration > History:
|
||||
**1. Checks.** `opnsense-verify -a` must print `FreeBSD:14:aarch64`,
|
||||
`opnsense-version -a` `26.1`, and the fetches `ok` and `repo-ok` (add the
|
||||
proxy's port to the URLs if it is not 443 inside the LAN):
|
||||
|
||||
```sh
|
||||
/usr/local/bin/php -r 'require_once("config.inc"); require_once("util.inc"); global $config;
|
||||
$config["system"]["firmware"]["mirror"] = "https://opnsense.karsttech.com:444";
|
||||
write_config("custom mirror opnsense.karsttech.com:444");'
|
||||
configctl firmware reload
|
||||
opnsense-update -M # https://opnsense.karsttech.com:444/FreeBSD:14:aarch64/26.1
|
||||
sh
|
||||
opnsense-verify -a
|
||||
opnsense-version -a
|
||||
fetch -qo - https://opnsense.karsttech.com/healthz
|
||||
fetch -qo /dev/null https://opnsense.karsttech.com/FreeBSD:14:aarch64/26.1/latest/meta.conf && echo repo-ok
|
||||
```
|
||||
The changelog and
|
||||
bogons downloads do not follow it: `opnsense-update -X` reads core's
|
||||
`OPNsense.conf.sample`, which names the mirror without a port. On such a
|
||||
gateway the GUI changelog is unavailable, and the bogons list keeps the
|
||||
version it has. Serving Traefik on 443 inside the LAN avoids both.
|
||||
|
||||
**2. Backup and boot environment:**
|
||||
|
||||
```sh
|
||||
B=/root/gwmirror-backup-$(date +%Y%m%d%H%M%S)
|
||||
mkdir -p $B
|
||||
cp -p /usr/local/etc/pkg/repos/* $B/
|
||||
bectl create pre-gwmirror
|
||||
```
|
||||
|
||||
**3. Trust the signing key** (keys/fingerprints/trusted):
|
||||
|
||||
```sh
|
||||
printf 'function: "sha256"\nfingerprint: "5fc1e2bf74e0386a2ea1ee60d085d683735a9d7cd8090647be0f476c779c0dc3"\n' > /usr/local/etc/pkg/fingerprints/OPNsense/trusted/opnsense.karsttech.com.20261117
|
||||
```
|
||||
|
||||
**4. Point the repositories at the mirror.** If the proxy answers on 443
|
||||
inside the LAN, rewrite the URLs in the repository files and their
|
||||
`.sample` files (`${ABI}` stays literal):
|
||||
|
||||
```sh
|
||||
cd /usr/local/etc/pkg/repos
|
||||
for f in OPNsense.conf.sample OPNsense-aux.conf.sample OPNsense.conf OPNsense-aux.conf; do
|
||||
[ -f $f ] && sed -i '' 's|^\([[:space:]]*url:[[:space:]]*"\)[^"]*\(/${ABI}/\)|\1https://opnsense.karsttech.com\2|' $f
|
||||
done
|
||||
cd
|
||||
```
|
||||
|
||||
If the gateway reaches the proxy only on another port (at home Traefik
|
||||
listens on 444 and the router forwards WAN 443 to it; pf cannot redirect
|
||||
connections the firewall makes itself), set a custom mirror instead. It is
|
||||
kept in `config.xml`, and core applies it at every firmware reload
|
||||
(`opnsense-update -sd -m`), so it survives core updates. The GUI (System >
|
||||
Firmware > Settings, Mirror "(custom)") did not store it on the vendor's
|
||||
26.1.9; this did, keeping the previous version in System > Configuration >
|
||||
History:
|
||||
|
||||
```sh
|
||||
/usr/local/bin/php -r 'require_once("config.inc"); require_once("util.inc"); global $config; $config["system"]["firmware"]["mirror"] = "https://opnsense.karsttech.com:444"; write_config("custom mirror opnsense.karsttech.com:444");'
|
||||
pluginctl -g system.firmware.mirror
|
||||
```
|
||||
|
||||
The changelog and bogons downloads do not follow a custom mirror:
|
||||
`opnsense-update -X` reads core's `OPNsense.conf.sample`, which names the
|
||||
mirror without a port. On such a gateway the GUI changelog does not load
|
||||
and the bogons list keeps the version it has. Serving the proxy on 443
|
||||
inside the LAN avoids both.
|
||||
|
||||
**5. Drop the vendor's MonoGateway repository** and move `mono-gateway` to
|
||||
the OPNsense repository (`opnsense-update -P` of a major upgrade only
|
||||
upgrades that one):
|
||||
|
||||
```sh
|
||||
rm -f /usr/local/etc/pkg/repos/MonoGateway.conf
|
||||
pkg info -e mono-gateway && pkg annotate -qyM mono-gateway repository OPNsense
|
||||
```
|
||||
|
||||
**6. Reload and check.** `opnsense-update -M` must name the new mirror, and
|
||||
`pkg update -f` must accept the catalogue ("804 packages processed"; it
|
||||
fails on a key that is not trusted):
|
||||
|
||||
```sh
|
||||
configctl firmware reload
|
||||
opnsense-update -M
|
||||
grep -H url: /usr/local/etc/pkg/repos/OPNsense*.conf
|
||||
pkg update -f
|
||||
```
|
||||
|
||||
To undo before step 7: `cp -p $B/* /usr/local/etc/pkg/repos/`, remove the
|
||||
fingerprint file (and the custom mirror, in System > Configuration >
|
||||
History), `configctl firmware reload`. After step 7: `bectl activate
|
||||
pre-gwmirror` and reboot.
|
||||
|
||||
**7. Update** in System > Firmware > Updates: Check for updates, then
|
||||
update. This installs our core `26.1.11_2`, which trusts only our key and
|
||||
names only our mirror, the packages, base and kernel, then reboots.
|
||||
|
||||
**8. Reinstall everything once**, so no vendor-built binary remains, then
|
||||
reboot:
|
||||
|
||||
```sh
|
||||
sh
|
||||
opnsense-update -pf
|
||||
opnsense-update -bkf
|
||||
reboot
|
||||
```
|
||||
|
||||
**9. Check:**
|
||||
- `opnsense-version` shows the release, `uname -v` our src fork's commit and
|
||||
`MONO-GATEWAY`;
|
||||
- `kldstat` lists cdx, fci and the other board modules (`ina2xx` is built
|
||||
into the kernel: `kldstat -v | grep ina`), and mwifiex and dpaa_wifi when
|
||||
the Wi-Fi card is fitted;
|
||||
- System > Firmware > Status > Audit > Health is clean.
|
||||
|
||||
## Major upgrade (26.1 to 26.7)
|
||||
|
||||
|
|
@ -506,9 +548,16 @@ version it has. Serving Traefik on 443 inside the LAN avoids both.
|
|||
then verify and publish.
|
||||
6. **Back up:** full eMMC backup from Recovery Linux, or at least a
|
||||
configuration backup, with the 26.1 image at hand.
|
||||
7. **Offer the upgrade:** `sh migrate-device.sh enable-upgrade 26.7.x` on the
|
||||
gateway. Core only offers the upgrade once `packages-26.7.x` is on the
|
||||
mirror (checked in core 26.1.11's check.sh).
|
||||
7. **Offer the upgrade** on the gateway. Core only offers it once
|
||||
`packages-26.7.x` is on the mirror (checked in core 26.1.11's check.sh);
|
||||
`opnsense-update -SRp` prints its size once it is:
|
||||
|
||||
```sh
|
||||
sh
|
||||
sed -i '' '/^UPGRADE_RELEASE=/d' /usr/local/etc/opnsense-update.conf
|
||||
echo 'UPGRADE_RELEASE="26.7.x"' >> /usr/local/etc/opnsense-update.conf
|
||||
opnsense-update -SRp
|
||||
```
|
||||
8. **Upgrade in the GUI.** It reboots three times: kernel, then base, then
|
||||
packages.
|
||||
- Until the packages stage, the 26.1 board modules don't load under the
|
||||
|
|
@ -558,7 +607,7 @@ reflash from Recovery Linux with the signed image from `/releases/` (README.md,
|
|||
|
||||
```sh
|
||||
python3 -m unittest discover -s mirror/tests # gwmirror stage/verify/publish, incl. HTTPS
|
||||
python3 -m unittest discover -s release/tests # migrate-device.sh, 20-kernel-update, fetch-distfile.sh
|
||||
python3 -m unittest discover -s release/tests # build.sh, 20-kernel-update, fetch-distfile.sh
|
||||
release/vm.sh ssh 14.3 'cd /usr/deps && python3 -m unittest discover -s release/tests'
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
export PRODUCT_KERNEL=GATEWAY
|
||||
export PRODUCT_TARGET=arm64
|
||||
export PRODUCT_ARCH=aarch64
|
||||
export PRODUCT_WANTS_CROSS="aarch64-binutils qemu-user-static"
|
||||
export PRODUCT_COMSPEED=115200
|
||||
export HOSTNAME=mono-gateway
|
||||
export ARM_FAT_SIZE="80m -b 32m"
|
||||
|
|
|
|||
|
|
@ -84,18 +84,11 @@ zpool set bootfs=${ZPOOL}/ROOT/default ${ZPOOL}
|
|||
# ---------------------------------------------------------------
|
||||
setup_base ${STAGEDIR}
|
||||
setup_kernel ${STAGEDIR}
|
||||
setup_xtools ${STAGEDIR}
|
||||
setup_packages ${STAGEDIR}
|
||||
setup_extras ${STAGEDIR} ${SELF}
|
||||
setup_entropy ${STAGEDIR}
|
||||
setup_xbase ${STAGEDIR}
|
||||
|
||||
# setup_xtools copies the host's qemu emulator to /usr/local/bin but
|
||||
# setup_xbase only removes it from /usr/bin: drop the amd64 binary here.
|
||||
# (release/build.sh also moves the xtools set aside before building the
|
||||
# image so no other amd64 toolchain files are overlaid onto the image.)
|
||||
rm -f ${STAGEDIR}/usr/local/bin/qemu-*-static
|
||||
|
||||
# ZFS fstab: only the FAT boot partition
|
||||
cat > ${STAGEDIR}/etc/fstab << EOF
|
||||
# Device Mountpoint FStype Options Dump Pass#
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# build.sh: build and sign a complete OPNsense release for the Mono Gateway.
|
||||
# Runs as root on the FreeBSD build host: the amd64 VM of release/vm.sh (cross
|
||||
# build) or a native aarch64 machine. This repository must be at /usr/deps.
|
||||
# Runs as root on the FreeBSD aarch64 build host: the emulated arm64 VM of
|
||||
# release/vm.sh, or a real aarch64 machine. This repository must be at /usr/deps.
|
||||
#
|
||||
# build.sh setup install the host packages the build needs
|
||||
# build.sh build SERIES VERSION check out every repository at VERSION and build
|
||||
# base, kernel, xtools, ports, plugins, core and the
|
||||
# base, kernel, ports, plugins, core and the
|
||||
# mono-gateway package; nothing is signed yet
|
||||
# build.sh pilot SERIES VERSION PORT...
|
||||
# base, kernel and xtools, then the distfiles and
|
||||
# packages of only the given ports (e.g.
|
||||
# security/suricata, databases/py-duckdb@py313), timed
|
||||
# build.sh finish SERIES VERSION KEYDIR
|
||||
# sign every set with KEYDIR/repo.{key,pub} (must be
|
||||
# the key trusted in keys/fingerprints), build and
|
||||
|
|
@ -58,7 +54,7 @@ step()
|
|||
|
||||
usage()
|
||||
{
|
||||
sed -n '3,24p' "${0}" >&2
|
||||
sed -n '3,19p' "${0}" >&2
|
||||
DIED=yes
|
||||
exit 2
|
||||
}
|
||||
|
|
@ -386,10 +382,8 @@ setup()
|
|||
printf 'FreeBSD: { url: "pkg+https://pkg.FreeBSD.org/${ABI}/release_%s" }\n' "${2}" \
|
||||
> /usr/local/etc/pkg/repos/FreeBSD.conf
|
||||
env ASSUME_ALWAYS_YES=yes pkg bootstrap -f
|
||||
[ "$(uname -p)" = aarch64 ] || die "the build host must be aarch64 (release/vm.sh)"
|
||||
pkg install -y git python3 rsync
|
||||
if [ "$(uname -p)" != aarch64 ]; then
|
||||
pkg install -y qemu-user-static aarch64-binutils
|
||||
fi
|
||||
_pool=$(zpool list -Ho name | head -1)
|
||||
zfs set compression=zstd "${_pool}"
|
||||
zpool set autotrim=on "${_pool}"
|
||||
|
|
@ -438,9 +432,9 @@ build()
|
|||
fi
|
||||
checkout_all
|
||||
host_pkg
|
||||
step "base kernel xtools"
|
||||
step "base kernel"
|
||||
# shellcheck disable=SC2086
|
||||
${TOOLS} ${UNSIGNED} base kernel xtools
|
||||
${TOOLS} ${UNSIGNED} base kernel
|
||||
sysroot_base
|
||||
step "mono-gateway kernel modules (early check against the new kernel)"
|
||||
make -C "${DEPS}" -j"$(sysctl -n hw.ncpu)" modules OPS_SETTINGS="${SERIES}"
|
||||
|
|
@ -456,36 +450,6 @@ build()
|
|||
ls -l "${SETS}"
|
||||
}
|
||||
|
||||
pilot()
|
||||
{
|
||||
args "$@"
|
||||
shift 2
|
||||
[ $# -ge 1 ] || usage
|
||||
for _port in "$@"; do
|
||||
echo "${_port}" | grep -Eqx '[a-z0-9_-]+/[A-Za-z0-9_.+-]+(@[A-Za-z0-9_]+)?' || die "bad port '${_port}'"
|
||||
done
|
||||
checkout_all
|
||||
host_pkg
|
||||
_t0=$(date +%s)
|
||||
# shellcheck disable=SC2086
|
||||
${TOOLS} ${UNSIGNED} base kernel xtools
|
||||
step "base kernel xtools took $((($(date +%s) - _t0) / 60)) minutes"
|
||||
step "distfiles of ports-mgmt/pkg"
|
||||
repair_distfiles ports-mgmt/pkg
|
||||
# PORTSLIST limits the build to one port (and its dependencies); naming
|
||||
# the port in the target makes tools run the step again for each one
|
||||
for _port in "$@"; do
|
||||
_t0=$(date +%s)
|
||||
ports_run "ports-${_port}" PORTSLIST="${_port}" PORTSENV="DEPEND=no"
|
||||
step "${_port} (with its dependencies) took $((($(date +%s) - _t0) / 60)) minutes"
|
||||
done
|
||||
# the partial packages set is marked "ports done" and would make the real
|
||||
# build skip its ports; base, kernel and xtools are kept for it
|
||||
# shellcheck disable=SC2086
|
||||
${TOOLS} clean-packages
|
||||
step "pilot done; packages set removed, base/kernel/xtools sets kept"
|
||||
}
|
||||
|
||||
# scan_image IMAGE: no amd64 (or other non-aarch64) ELF file may end up in the image
|
||||
# (firmware blobs aside). The image's pool is imported read-only without mounting
|
||||
# anything, and each dataset is mounted read-only by itself: mounting them all at
|
||||
|
|
@ -571,18 +535,11 @@ finish()
|
|||
${TOOLS} ${SIGNED} sign-base,kernel,packages,aux
|
||||
|
||||
step "building the eMMC image"
|
||||
mkdir -p "${SETS}/.xtools-aside"
|
||||
mv "${SETS}"/xtools-* "${SETS}/.xtools-aside/" 2>/dev/null || true
|
||||
cp "${DEPS}/mk-image.sh" /usr/tools/build/arm.sh
|
||||
cp "${DEPS}/tools/mkgpt.py" /usr/tools/build/mkgpt.py
|
||||
rm -f "${IMAGES}"/OPNsense-*-"${DEVICE}".img*
|
||||
# shellcheck disable=SC2086
|
||||
if ! ${TOOLS} ${SIGNED} arm-5G; then
|
||||
mv "${SETS}"/.xtools-aside/* "${SETS}/" 2>/dev/null || true
|
||||
die "image build failed"
|
||||
fi
|
||||
mv "${SETS}"/.xtools-aside/* "${SETS}/" 2>/dev/null || true
|
||||
rmdir "${SETS}/.xtools-aside"
|
||||
${TOOLS} ${SIGNED} arm-5G || die "image build failed"
|
||||
git -C /usr/tools checkout -q -- build/arm.sh
|
||||
rm -f /usr/tools/build/mkgpt.py
|
||||
|
||||
|
|
@ -602,7 +559,6 @@ shift
|
|||
case "${CMD}" in
|
||||
setup) [ $# -eq 0 ] || usage; setup ;;
|
||||
build) [ $# -eq 2 ] || usage; build "$@" ;;
|
||||
pilot) pilot "$@" ;;
|
||||
finish) [ $# -eq 3 ] || usage; finish "$@" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -1,213 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# migrate-device.sh: point a Mono Gateway at the opnsense.karsttech.com mirror.
|
||||
# Runs on the firewall as root; copy it over together with the fingerprint:
|
||||
#
|
||||
# scp release/migrate-device.sh keys/fingerprints/trusted/opnsense.karsttech.com.20261117 root@fw:/root/
|
||||
# ssh root@fw sh /root/migrate-device.sh repoint --mirror https://opnsense.karsttech.com \
|
||||
# --fingerprint /root/opnsense.karsttech.com.20261117 --dry-run
|
||||
#
|
||||
# Commands:
|
||||
# repoint --mirror URL --fingerprint FILE [--dry-run]
|
||||
# Trust our signing key, rewrite the repository URLs (OPNsense.conf is
|
||||
# regenerated from the .sample files, which also drive the changelog
|
||||
# and bogons downloads), drop the vendor's MonoGateway repository and
|
||||
# move the mono-gateway package to the OPNsense repository. Afterwards
|
||||
# System > Firmware > Updates works against the new mirror; the first
|
||||
# update installs our core package, which makes all of this permanent.
|
||||
# enable-upgrade VERSION [--dry-run]
|
||||
# Offer the major upgrade to VERSION (e.g. 26.7.9) in the GUI. Core only
|
||||
# shows it once the mirror carries packages-VERSION, so this is safe early.
|
||||
#
|
||||
# Every file is backed up to /root/gwmirror-backup-<time>/ before it changes.
|
||||
# GW_ROOT prefixes all paths (tests only).
|
||||
#
|
||||
# Copyright 2026 Karst Tech
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
set -u
|
||||
|
||||
ROOT=${GW_ROOT:-}
|
||||
REPOS=${ROOT}/usr/local/etc/pkg/repos
|
||||
TRUSTED=${ROOT}/usr/local/etc/pkg/fingerprints/OPNsense/trusted
|
||||
UPDATE_CONF=${ROOT}/usr/local/etc/opnsense-update.conf
|
||||
BACKUP=${ROOT}/root/gwmirror-backup-$(date +%Y%m%d%H%M%S)
|
||||
DRY=0
|
||||
|
||||
die()
|
||||
{
|
||||
echo "migrate-device: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
say()
|
||||
{
|
||||
echo ">>> $*"
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
sed -n '3,25p' "${0}" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
# backup FILE: keep a copy (once per run) before FILE changes
|
||||
backup()
|
||||
{
|
||||
[ -e "${1}" ] || return 0
|
||||
_rel=${1#"${ROOT}"}
|
||||
[ -e "${BACKUP}${_rel}" ] && return 0
|
||||
mkdir -p "${BACKUP}$(dirname "${_rel}")" || die "cannot create ${BACKUP}"
|
||||
cp -p "${1}" "${BACKUP}${_rel}" || die "cannot back up ${1}"
|
||||
}
|
||||
|
||||
# write FILE: replace FILE with stdin, after a backup (dry-run: show a diff)
|
||||
write()
|
||||
{
|
||||
if [ ${DRY} = 1 ]; then
|
||||
_tmp=$(mktemp "${TMPDIR:-/tmp}/gwmirror.XXXXXX") || die "mktemp failed"
|
||||
else
|
||||
_tmp="${1}.gwmirror.$$"
|
||||
fi
|
||||
cat > "${_tmp}" || { rm -f "${_tmp}"; die "cannot write ${1}"; }
|
||||
if [ -f "${1}" ] && cmp -s "${_tmp}" "${1}"; then
|
||||
rm -f "${_tmp}"
|
||||
return 0
|
||||
fi
|
||||
if [ ${DRY} = 1 ]; then
|
||||
say "would change ${1#"${ROOT}"}:"
|
||||
diff -u "${1}" "${_tmp}" 2>/dev/null | sed -n '3,$p'
|
||||
rm -f "${_tmp}"
|
||||
return 0
|
||||
fi
|
||||
backup "${1}"
|
||||
chmod 644 "${_tmp}" && mv "${_tmp}" "${1}" || { rm -f "${_tmp}"; die "cannot replace ${1}"; }
|
||||
say "changed ${1#"${ROOT}"}"
|
||||
}
|
||||
|
||||
run()
|
||||
{
|
||||
if [ ${DRY} = 1 ]; then
|
||||
say "would run: $*"
|
||||
return 0
|
||||
fi
|
||||
say "running: $*"
|
||||
"$@"
|
||||
}
|
||||
|
||||
valid_url()
|
||||
{
|
||||
echo "${1}" | grep -Eqx 'https://[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)+'
|
||||
}
|
||||
|
||||
valid_fingerprint()
|
||||
{
|
||||
[ -f "${1}" ] && [ "$(wc -l < "${1}" | tr -d ' ')" -le 3 ] &&
|
||||
grep -Eqx 'function: "sha256"' "${1}" &&
|
||||
grep -Eqx 'fingerprint: "[0-9a-f]{64}"' "${1}" &&
|
||||
[ "$(grep -cv -E '^(function: "sha256"|fingerprint: "[0-9a-f]{64}")?$' "${1}")" = 0 ]
|
||||
}
|
||||
|
||||
repoint()
|
||||
{
|
||||
MIRROR=
|
||||
FPFILE=
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--mirror) [ $# -ge 2 ] || usage; MIRROR=${2}; shift 2 ;;
|
||||
--fingerprint) [ $# -ge 2 ] || usage; FPFILE=${2}; shift 2 ;;
|
||||
--dry-run) DRY=1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
[ -n "${MIRROR}" ] && [ -n "${FPFILE}" ] || usage
|
||||
valid_url "${MIRROR}" || die "mirror must be https://<host>, got '${MIRROR}'"
|
||||
valid_fingerprint "${FPFILE}" || die "${FPFILE} is not a sha256 fingerprint file"
|
||||
FPNAME=$(basename "${FPFILE}")
|
||||
echo "${FPNAME}" | grep -Eqx '[A-Za-z0-9][A-Za-z0-9._-]*' || die "bad fingerprint file name '${FPNAME}'"
|
||||
|
||||
ABI=$(opnsense-verify -a 2>/dev/null) || die "opnsense-verify -a failed"
|
||||
SERIES=$(opnsense-version -a 2>/dev/null) || die "opnsense-version -a failed"
|
||||
echo "${ABI}" | grep -Eqx 'FreeBSD:[0-9]+:[a-z0-9]+' || die "unexpected ABI '${ABI}'"
|
||||
echo "${SERIES}" | grep -Eqx '[0-9]{2}\.[0-9]' || die "unexpected series '${SERIES}'"
|
||||
|
||||
GUI_MIRROR=$(pluginctl -g system.firmware.mirror 2>/dev/null)
|
||||
if [ -n "${GUI_MIRROR}" ] && [ "${GUI_MIRROR}" != "${MIRROR}" ]; then
|
||||
die "System > Firmware > Settings has mirror '${GUI_MIRROR}'; set it to (default) and rerun"
|
||||
fi
|
||||
|
||||
say "checking ${MIRROR} from this firewall"
|
||||
fetch -qo /dev/null "${MIRROR}/healthz" ||
|
||||
die "cannot reach ${MIRROR}/healthz (DNS override to the proxy's LAN address needed?)"
|
||||
fetch -qo /dev/null "${MIRROR}/${ABI}/${SERIES}/latest/meta.conf" ||
|
||||
die "${MIRROR} has no ${ABI}/${SERIES} repository yet"
|
||||
|
||||
if [ ${DRY} = 0 ] && command -v bectl > /dev/null 2>&1; then
|
||||
bectl create "pre-gwmirror-$(date +%Y%m%d%H%M%S)" &&
|
||||
say "created boot environment pre-gwmirror-*" ||
|
||||
say "WARNING: could not create a boot environment"
|
||||
fi
|
||||
|
||||
[ -d "${TRUSTED}" ] || die "no ${TRUSTED}"
|
||||
write "${TRUSTED}/${FPNAME}" < "${FPFILE}"
|
||||
|
||||
for conf in OPNsense.conf.sample OPNsense-aux.conf.sample OPNsense.conf OPNsense-aux.conf; do
|
||||
f=${REPOS}/${conf}
|
||||
[ -f "${f}" ] || continue
|
||||
grep -q 'url:.*/${ABI}/' "${f}" || die "${f} has no url with a literal \${ABI}"
|
||||
sed 's|^\([[:space:]]*url:[[:space:]]*"\)[^"]*\(/${ABI}/\)|\1'"${MIRROR}"'\2|' "${f}" | write "${f}"
|
||||
done
|
||||
|
||||
if [ -f "${REPOS}/MonoGateway.conf" ]; then
|
||||
if [ ${DRY} = 1 ]; then
|
||||
say "would remove ${REPOS#"${ROOT}"}/MonoGateway.conf"
|
||||
else
|
||||
backup "${REPOS}/MonoGateway.conf"
|
||||
rm -f "${REPOS}/MonoGateway.conf" && say "removed MonoGateway.conf"
|
||||
fi
|
||||
fi
|
||||
|
||||
if pkg info -e mono-gateway 2>/dev/null; then
|
||||
run pkg annotate -qyM mono-gateway repository OPNsense
|
||||
fi
|
||||
|
||||
run configctl firmware reload
|
||||
if [ ${DRY} = 0 ]; then
|
||||
say "mirror is now: $(opnsense-update -M)"
|
||||
run pkg update -f || die "pkg update failed; backups are in ${BACKUP}"
|
||||
say "done; backups in ${BACKUP}. Next: System > Firmware > Updates > Check for updates"
|
||||
fi
|
||||
}
|
||||
|
||||
enable_upgrade()
|
||||
{
|
||||
VERSION=
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--dry-run) DRY=1; shift ;;
|
||||
-*) usage ;;
|
||||
*) [ -z "${VERSION}" ] || usage; VERSION=${1}; shift ;;
|
||||
esac
|
||||
done
|
||||
[ -n "${VERSION}" ] || usage
|
||||
echo "${VERSION}" | grep -Eqx '[0-9]{2}\.[0-9]+(\.[0-9]+)?' || die "bad version '${VERSION}'"
|
||||
[ -f "${UPDATE_CONF}" ] || die "no ${UPDATE_CONF}"
|
||||
{ grep -v '^UPGRADE_RELEASE=' "${UPDATE_CONF}"; echo "UPGRADE_RELEASE=\"${VERSION}\""; } | write "${UPDATE_CONF}"
|
||||
if [ ${DRY} = 0 ]; then
|
||||
SIZE=$(opnsense-update -SRp 2>/dev/null)
|
||||
if [ -n "${SIZE}" ]; then
|
||||
say "mirror offers packages-${VERSION} (${SIZE}); check for updates in the GUI"
|
||||
else
|
||||
say "WARNING: mirror does not offer packages-${VERSION} yet; the GUI shows the upgrade once it does"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
[ $# -ge 1 ] || usage
|
||||
CMD=${1}
|
||||
shift
|
||||
case "${CMD}" in
|
||||
repoint) repoint "$@" ;;
|
||||
enable-upgrade) enable_upgrade "$@" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
|
@ -4,55 +4,23 @@
|
|||
|
||||
Run: python3 -m unittest discover -s release/tests
|
||||
|
||||
The scripts are run for real against a fixture root (GW_ROOT) with fake
|
||||
OPNsense commands first in PATH, so the same tests run on Linux and on the
|
||||
FreeBSD build VM. The fixtures mirror what a vendor 26.1.9 box carries.
|
||||
The scripts are run for real, against a fixture root (GW_ROOT) where they
|
||||
take one, with fake commands first in PATH, so the same tests run on Linux
|
||||
and on the FreeBSD build VM.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
REPO = os.path.dirname(os.path.dirname(HERE))
|
||||
MIGRATE = os.path.join(REPO, "release", "migrate-device.sh")
|
||||
KERNEL_HOOK = os.path.join(REPO, "rc.d", "20-kernel-update")
|
||||
FETCH_REPAIR = os.path.join(REPO, "release", "fetch-distfile.sh")
|
||||
MIRROR = "https://opnsense.karsttech.com"
|
||||
FP_NAME = "opnsense.karsttech.com.20261117"
|
||||
|
||||
VENDOR_CONF = """OPNsense: {
|
||||
fingerprints: "/usr/local/etc/pkg/fingerprints/OPNsense",
|
||||
url: "https://opnsense.mono.si/${ABI}/26.1/latest",
|
||||
signature_type: "fingerprints",
|
||||
priority: 11,
|
||||
enabled: yes
|
||||
}
|
||||
"""
|
||||
VENDOR_AUX = VENDOR_CONF.replace("OPNsense: {", "OPNsense-aux: {").replace("/latest", "/aux").replace("yes", "no")
|
||||
VENDOR_MONO = """MonoGateway: {
|
||||
fingerprints: "/usr/local/etc/pkg/fingerprints/OPNsense",
|
||||
url: "https://opnsense.mono.si/${ABI}/26.1/mono",
|
||||
signature_type: "fingerprints",
|
||||
priority: 11,
|
||||
enabled: yes
|
||||
}
|
||||
"""
|
||||
|
||||
# Fake commands: each logs its argv to $FAKE_LOG and answers like OPNsense.
|
||||
# Fake commands: each logs its argv to $FAKE_LOG; tests add their own.
|
||||
FAKES = {
|
||||
"opnsense-verify": 'echo "${FAKE_ABI:-FreeBSD:14:aarch64}"',
|
||||
"opnsense-version": 'echo "${FAKE_SERIES:-26.1}"',
|
||||
"pluginctl": 'echo "${FAKE_GUI_MIRROR:-}"',
|
||||
"fetch": 'for a; do last=$a; done; case "$last" in *"${FAKE_FETCH_FAIL:-@none@}"*) exit 1;; esac',
|
||||
"bectl": "exit 0",
|
||||
"configctl": "echo OK",
|
||||
"pkg": 'case "$1 $2" in "info -e") [ -n "${FAKE_HAS_MONO:-}" ];; "update -f") exit ${FAKE_PKG_UPDATE_RC:-0};; esac',
|
||||
"opnsense-update": 'case "$1" in -M) echo "$FAKE_MIRROR_URL";; -SRp) echo "${FAKE_SRP:-}";; esac',
|
||||
"logger": "exit 0",
|
||||
"df": 'echo "Filesystem 1024-blocks Used Avail Capacity Mounted"; echo "fake 81920 0 ${FAKE_FREE_KB:-80000} 0% /"',
|
||||
}
|
||||
|
|
@ -85,13 +53,9 @@ class Fixture:
|
|||
os.chmod(p, mode)
|
||||
return p
|
||||
|
||||
def read(self, rel):
|
||||
with open(self.path(rel)) as f:
|
||||
return f.read()
|
||||
|
||||
def run(self, script, *args, **env):
|
||||
e = {"PATH": f"{self.bin}:/usr/bin:/bin", "GW_ROOT": self.root, "FAKE_LOG": self.log,
|
||||
"TMPDIR": self.tmp, "FAKE_MIRROR_URL": f"{MIRROR}/FreeBSD:14:aarch64/26.1"}
|
||||
"TMPDIR": self.tmp}
|
||||
e.update(env)
|
||||
return subprocess.run(["sh", script, *args], env=e, capture_output=True, text=True)
|
||||
|
||||
|
|
@ -101,196 +65,6 @@ class Fixture:
|
|||
with open(self.log) as f:
|
||||
return f.read().splitlines()
|
||||
|
||||
def snapshot(self):
|
||||
"""Every file under root with its content hash (to prove nothing changed)."""
|
||||
out = {}
|
||||
for d, _, files in os.walk(self.root):
|
||||
for n in files:
|
||||
p = os.path.join(d, n)
|
||||
with open(p, "rb") as f:
|
||||
out[os.path.relpath(p, self.root)] = hashlib.sha256(f.read()).hexdigest()
|
||||
return out
|
||||
|
||||
|
||||
class MigrateTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp(prefix="gw-migrate-")
|
||||
self.addCleanup(shutil.rmtree, self.tmp)
|
||||
self.fx = Fixture(self.tmp)
|
||||
repos = "/usr/local/etc/pkg/repos/"
|
||||
for name, body in (("OPNsense.conf.sample", VENDOR_CONF), ("OPNsense.conf", VENDOR_CONF),
|
||||
("OPNsense-aux.conf.sample", VENDOR_AUX), ("MonoGateway.conf", VENDOR_MONO),
|
||||
("MonoGateway.conf.sample", VENDOR_MONO),
|
||||
("FreeBSD.conf.sample", "FreeBSD: { enabled: no }\n")):
|
||||
self.fx.write(repos + name, body)
|
||||
self.fx.write("/usr/local/etc/pkg/fingerprints/OPNsense/trusted/opnsense.mono.si.20260305",
|
||||
'function: "sha256"\nfingerprint: "' + "e" * 64 + '"\n')
|
||||
self.fx.write("/usr/local/etc/opnsense-update.conf", "# configuration for opnsense-update(8), do not edit\n")
|
||||
os.makedirs(self.fx.path("/root"))
|
||||
self.fp = os.path.join(self.tmp, FP_NAME)
|
||||
with open(self.fp, "w") as f:
|
||||
f.write('function: "sha256"\nfingerprint: "' + "5f" * 32 + '"\n')
|
||||
|
||||
def repoint(self, *extra, **env):
|
||||
return self.fx.run(MIGRATE, "repoint", "--mirror", MIRROR, "--fingerprint", self.fp, *extra, **env)
|
||||
|
||||
def test_repoint(self):
|
||||
r = self.repoint(FAKE_HAS_MONO="1")
|
||||
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
||||
for conf in ("OPNsense.conf.sample", "OPNsense.conf", "OPNsense-aux.conf.sample"):
|
||||
text = self.fx.read(f"/usr/local/etc/pkg/repos/{conf}")
|
||||
self.assertIn(f'url: "{MIRROR}/${{ABI}}/26.1/', text, conf)
|
||||
self.assertNotIn("mono.si", text)
|
||||
self.assertEqual(self.fx.read("/usr/local/etc/pkg/repos/FreeBSD.conf.sample"), "FreeBSD: { enabled: no }\n")
|
||||
self.assertFalse(os.path.exists(self.fx.path("/usr/local/etc/pkg/repos/MonoGateway.conf")))
|
||||
with open(self.fp) as f:
|
||||
self.assertEqual(self.fx.read(f"/usr/local/etc/pkg/fingerprints/OPNsense/trusted/{FP_NAME}"), f.read())
|
||||
calls = self.fx.calls()
|
||||
self.assertIn(f"fetch -qo /dev/null {MIRROR}/healthz", calls)
|
||||
self.assertIn(f"fetch -qo /dev/null {MIRROR}/FreeBSD:14:aarch64/26.1/latest/meta.conf", calls)
|
||||
self.assertIn("pkg annotate -qyM mono-gateway repository OPNsense", calls)
|
||||
self.assertIn("configctl firmware reload", calls)
|
||||
self.assertIn("pkg update -f", calls)
|
||||
self.assertTrue(any(c.startswith("bectl create pre-gwmirror-") for c in calls))
|
||||
# backups of everything that changed or was removed
|
||||
backups = [d for d in os.listdir(self.fx.path("/root")) if d.startswith("gwmirror-backup-")]
|
||||
self.assertEqual(len(backups), 1)
|
||||
b = os.path.join(self.fx.path("/root"), backups[0], "usr/local/etc/pkg/repos")
|
||||
self.assertEqual(sorted(os.listdir(b)), ["MonoGateway.conf", "OPNsense-aux.conf.sample",
|
||||
"OPNsense.conf", "OPNsense.conf.sample"])
|
||||
with open(os.path.join(b, "OPNsense.conf.sample")) as f:
|
||||
self.assertEqual(f.read(), VENDOR_CONF)
|
||||
leftovers = [n for d, _, fs in os.walk(self.fx.root) for n in fs if ".gwmirror." in n]
|
||||
self.assertEqual(leftovers, [])
|
||||
|
||||
def test_idempotent(self):
|
||||
self.assertEqual(self.repoint().returncode, 0)
|
||||
before = self.fx.snapshot()
|
||||
r = self.repoint()
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
after = {k: v for k, v in self.fx.snapshot().items() if "gwmirror-backup-" not in k}
|
||||
self.assertEqual(after, {k: v for k, v in before.items() if "gwmirror-backup-" not in k})
|
||||
self.assertNotIn("changed", r.stdout)
|
||||
|
||||
def test_dry_run_touches_nothing(self):
|
||||
before = self.fx.snapshot()
|
||||
r = self.repoint("--dry-run", FAKE_HAS_MONO="1")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.fx.snapshot(), before)
|
||||
self.assertIn("would change /usr/local/etc/pkg/repos/OPNsense.conf.sample", r.stdout)
|
||||
self.assertIn("would remove /usr/local/etc/pkg/repos/MonoGateway.conf", r.stdout)
|
||||
self.assertIn("would run: pkg annotate", r.stdout)
|
||||
calls = self.fx.calls()
|
||||
for mutating in ("pkg annotate", "configctl", "pkg update", "bectl"):
|
||||
self.assertFalse(any(c.startswith(mutating) for c in calls), mutating)
|
||||
self.assertEqual([n for n in os.listdir(self.tmp) if n.startswith("gwmirror.")], [])
|
||||
|
||||
def test_rejects_bad_mirror(self):
|
||||
for bad in ("http://opnsense.karsttech.com", "https://opnsense.karsttech.com/", "https://x.com/path",
|
||||
"https://a|b.com", "https://evil.com\"; rm -rf /", "https://-a.com", "https://localhost",
|
||||
"https://opnsense.karsttech.com&x", "https://a..b"):
|
||||
with self.subTest(bad):
|
||||
r = self.fx.run(MIGRATE, "repoint", "--mirror", bad, "--fingerprint", self.fp)
|
||||
self.assertEqual(r.returncode, 1, r.stdout)
|
||||
self.assertIn("mirror must be", r.stderr)
|
||||
self.assertEqual(self.fx.calls(), [])
|
||||
|
||||
def test_rejects_bad_fingerprint(self):
|
||||
bad = {"short": 'function: "sha256"\nfingerprint: "abc"\n',
|
||||
"md5": 'function: "md5"\nfingerprint: "' + "a" * 64 + '"\n',
|
||||
"extra": 'function: "sha256"\nfingerprint: "' + "a" * 64 + '"\nurl: "evil"\n',
|
||||
"upper": 'function: "sha256"\nfingerprint: "' + "A" * 64 + '"\n',
|
||||
"empty": ""}
|
||||
for label, body in bad.items():
|
||||
with self.subTest(label):
|
||||
path = os.path.join(self.tmp, f"fp-{label}")
|
||||
with open(path, "w") as f:
|
||||
f.write(body)
|
||||
r = self.fx.run(MIGRATE, "repoint", "--mirror", MIRROR, "--fingerprint", path)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("not a sha256 fingerprint file", r.stderr)
|
||||
r = self.fx.run(MIGRATE, "repoint", "--mirror", MIRROR, "--fingerprint", os.path.join(self.tmp, "none"))
|
||||
self.assertEqual(r.returncode, 1)
|
||||
|
||||
def test_rejects_bad_fingerprint_name(self):
|
||||
path = os.path.join(self.tmp, "-rf")
|
||||
shutil.copyfile(self.fp, path)
|
||||
r = self.fx.run(MIGRATE, "repoint", "--mirror", MIRROR, "--fingerprint", path)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("bad fingerprint file name", r.stderr)
|
||||
|
||||
def test_unreachable_mirror_changes_nothing(self):
|
||||
before = self.fx.snapshot()
|
||||
r = self.repoint(FAKE_FETCH_FAIL="healthz")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("cannot reach", r.stderr)
|
||||
self.assertEqual(self.fx.snapshot(), before)
|
||||
|
||||
def test_series_missing_on_mirror(self):
|
||||
r = self.repoint(FAKE_FETCH_FAIL="meta.conf")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("has no FreeBSD:14:aarch64/26.1 repository", r.stderr)
|
||||
|
||||
def test_gui_mirror_pinned(self):
|
||||
before = self.fx.snapshot()
|
||||
r = self.repoint(FAKE_GUI_MIRROR="https://opnsense.mono.si")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("set it to (default)", r.stderr)
|
||||
self.assertEqual(self.fx.snapshot(), before)
|
||||
self.assertEqual(self.repoint(FAKE_GUI_MIRROR=MIRROR).returncode, 0)
|
||||
|
||||
def test_unexpected_abi_output(self):
|
||||
r = self.repoint(FAKE_ABI="FreeBSD:14:aarch64; rm -rf /")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("unexpected ABI", r.stderr)
|
||||
|
||||
def test_conf_without_abi_placeholder(self):
|
||||
self.fx.write("/usr/local/etc/pkg/repos/OPNsense.conf.sample",
|
||||
VENDOR_CONF.replace("${ABI}", "FreeBSD:14:aarch64"))
|
||||
r = self.repoint()
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("literal ${ABI}", r.stderr)
|
||||
|
||||
def test_pkg_update_failure_reported(self):
|
||||
r = self.repoint(FAKE_PKG_UPDATE_RC="70")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("pkg update failed", r.stderr)
|
||||
|
||||
def test_without_mono_gateway(self):
|
||||
r = self.repoint()
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertFalse(any(c.startswith("pkg annotate") for c in self.fx.calls()))
|
||||
|
||||
def test_usage_errors(self):
|
||||
for args in ((), ("bogus",), ("repoint",), ("repoint", "--mirror"), ("repoint", "--mirror", MIRROR),
|
||||
("repoint", "--mirror", MIRROR, "--fingerprint", self.fp, "--what"),
|
||||
("enable-upgrade",), ("enable-upgrade", "26.7.9", "26.7.8")):
|
||||
with self.subTest(args):
|
||||
self.assertEqual(self.fx.run(MIGRATE, *args).returncode, 2)
|
||||
|
||||
def test_enable_upgrade(self):
|
||||
r = self.fx.run(MIGRATE, "enable-upgrade", "26.7.9", FAKE_SRP="1.1GiB")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.fx.read("/usr/local/etc/opnsense-update.conf"),
|
||||
'# configuration for opnsense-update(8), do not edit\nUPGRADE_RELEASE="26.7.9"\n')
|
||||
self.assertIn("mirror offers packages-26.7.9", r.stdout)
|
||||
r = self.fx.run(MIGRATE, "enable-upgrade", "26.7.10")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.fx.read("/usr/local/etc/opnsense-update.conf").count("UPGRADE_RELEASE"), 1)
|
||||
self.assertIn("does not offer packages-26.7.10 yet", r.stdout)
|
||||
|
||||
def test_enable_upgrade_dry_run_and_validation(self):
|
||||
before = self.fx.snapshot()
|
||||
r = self.fx.run(MIGRATE, "enable-upgrade", "26.7.9", "--dry-run")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("would change", r.stdout)
|
||||
self.assertEqual(self.fx.snapshot(), before)
|
||||
for bad in ("26.7.9\"; reboot", "26", "x26.7", "26.7.9 ", "$(id)"):
|
||||
with self.subTest(bad):
|
||||
r = self.fx.run(MIGRATE, "enable-upgrade", bad)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("bad version", r.stderr)
|
||||
|
||||
|
||||
class KernelHookTest(unittest.TestCase):
|
||||
OLD, NEW, OLD_DTB, NEW_DTB = b"old-kernel" * 100, b"new-kernel" * 120, b"old-dtb", b"new-dtb"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue