Skip to content

Commit

Permalink
Use DVD image to bootstrap pkg
Browse files Browse the repository at this point in the history
Binary packages are not available anymore on some versions that are
not supported by upstream anymore.
  • Loading branch information
jacob-carlborg committed Feb 13, 2024
1 parent ef91fdc commit 0eb1698
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 16 deletions.
15 changes: 11 additions & 4 deletions freebsd.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ variable "qemu_architecture" {
description = "The name of the architecture in the QEMU binary"
}

variable "pkg_site_architecture" {
type = string
description = "The name of the architecture used by the pkg site: http://pkg.freebsd.org"
}

variable "machine_type" {
default = "pc"
type = string
Expand Down Expand Up @@ -103,7 +108,7 @@ variable "firmware" {

locals {
vm_name = "freebsd-${var.os_version}-${var.architecture}.qcow2"
iso_path = "ISO-IMAGES/${var.os_version}/FreeBSD-${var.os_version}-RELEASE-${var.image_architecture}-disc1.iso"
iso_path = "ISO-IMAGES/${var.os_version}/FreeBSD-${var.os_version}-RELEASE-${var.image_architecture}-dvd1.iso"
}

source "qemu" "qemu" {
Expand Down Expand Up @@ -149,6 +154,7 @@ source "qemu" "qemu" {
iso_checksum = var.checksum
iso_urls = [
"http://ftp.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
"http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/${local.iso_path}",
"http://ftp4.se.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
"http://ftp2.de.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
"http://ftp.lv.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
Expand All @@ -157,8 +163,7 @@ source "qemu" "qemu" {
"http://ftp6.tw.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
"http://ftp11.tw.freebsd.org/FreeBSD/releases/${local.iso_path}",
"http://ftp2.br.freebsd.org/FreeBSD/releases/${local.iso_path}",
"http://ftp.at.freebsd.org/pub/FreeBSD/releases/${local.iso_path}",
"http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/${local.iso_path}"
"http://ftp.at.freebsd.org/pub/FreeBSD/releases/${local.iso_path}"
]

http_directory = "."
Expand All @@ -175,7 +180,9 @@ build {
execute_command = "chmod +x {{ .Path }}; env {{ .Vars }} {{ .Path }}"
environment_vars = [
"SECONDARY_USER_USERNAME=${var.secondary_user_username}",
"SECONDARY_USER_PASSWORD=${var.secondary_user_password}"
"SECONDARY_USER_PASSWORD=${var.secondary_user_password}",
"OS_VERSION=${var.os_version}",
"PKG_SITE_ARCHITECTURE=${var.pkg_site_architecture}"
]
}

Expand Down
1 change: 1 addition & 0 deletions resources/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -exu

cleanup() {
pkg clean -a -y
sed -i '' 's/signature_type: "none"/signature_type: "fingerprints"/' /etc/pkg/FreeBSD.conf
}

minimize_disk() {
Expand Down
40 changes: 39 additions & 1 deletion resources/provision.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/sh

# Environment variables:
# OS_VERSION: the version of FreeBSD
# SECONDARY_USER_USERNAME: the username of the secondary user to create
# SECONDARY_USER_PASSWORD: the password of the secondary
# PKG_SITE_ARCHITECTURE: the name of the architecture used by the pkg site: http://pkg.freebsd.org

set -exu

ABI_VERSION="$(echo $OS_VERSION | cut -d . -f 1)"

configure_boot_flags() {
cat <<EOF >> /boot/loader.conf
autoboot_delay="-1"
Expand Down Expand Up @@ -72,8 +80,38 @@ EOF
chmod +x "$script"
}

upstream_pkg_site_available() {
local package_site="http://pkg.FreeBSD.org/FreeBSD:$ABI_VERSION:$PKG_SITE_ARCHITECTURE/quarterly/Latest"

fetch \
--one-file \
--print-size \
"$package_site/pkg.pkg" \
"$package_site/pkg.txz" \
2> /dev/null
}

bootstrap_pkg() {
sed -i '' 's/signature_type: "fingerprints"/signature_type: "none"/' /etc/pkg/FreeBSD.conf
mount -t cd9660 /dev/cd0 /mnt
export PACKAGESITE="file:///mnt/packages/FreeBSD:$ABI_VERSION:$PKG_SITE_ARCHITECTURE"
ASSUME_ALWAYS_YES=yes pkg bootstrap
}

install_local_package() {
ASSUME_ALWAYS_YES=yes pkg add "/mnt/packages/FreeBSD:12:amd64/All/$1"-[0123456789]*
}

install_extra_packages() {
ASSUME_ALWAYS_YES=yes pkg install sudo bash curl rsync
if upstream_pkg_site_available; then
ASSUME_ALWAYS_YES=yes pkg install sudo bash curl rsync
else
bootstrap_pkg
install_local_package sudo
install_local_package bash
install_local_package curl
install_local_package rsync
fi
}

configure_sudo() {
Expand Down
2 changes: 1 addition & 1 deletion var_files/12.2/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:289522e2f4e1260859505adab6d7b54ab83d19aeb147388ff7e28019984da5dc"
checksum = "sha256:bc997989eafb41fcabd6ed55e379134c7322425391d1cd0e5eff37759fc7f865"
2 changes: 1 addition & 1 deletion var_files/12.4/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:daa57f093f43804087b79f98aa7751c33b56c91c1f593041a015a59f4cbe3dbc"
checksum = "sha256:b20afd320d5a15394c376077a93f57b3433455d274047d90d7447b6f356789b1"
2 changes: 1 addition & 1 deletion var_files/12.4/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:606435637b76991f96df68f561badf03266f3d5452e9f72ed9b130d96b188800"
checksum = "sha256:f889113f4cb0dc50b443b3e5753861cfda1b6c08beb0c9bfc6b212572f19dc9f"
2 changes: 1 addition & 1 deletion var_files/13.0/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:a69840e22239a12138c0fda01f242bab201ed474414905554189ec87caf81ff0"
checksum = "sha256:870c5eadbc1a0055392142432b54779328097b8e286266ca9124705c5bfa329a"
2 changes: 1 addition & 1 deletion var_files/13.0/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:f78d4e5f53605592863852b39fa31a12f15893dc48cacecd875f2da72fa67ae5"
checksum = "sha256:d3df1818c0b90ae8d4c88c447dd158c3c3a3ddada4171ac7b0fe55baa040c821"
2 changes: 1 addition & 1 deletion var_files/13.1/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:ae8f9139153f31b193fff267f4935a64706c3dfc5015b4a2662c5663b77b4173"
checksum = "sha256:40c2c6ad0292f19553677de5afdf3570a2d2e9cbf51b075824cefbddd22787b6"
2 changes: 1 addition & 1 deletion var_files/13.1/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:697d81653fa246b921ddfcf1d15562c55249cc727b11fa3e47f470e2cf2b6a40"
checksum = "sha256:5b29c2cd5a604ad24810c994027ec13c9efc53778a307831f6181dfdaf02939f"
2 changes: 1 addition & 1 deletion var_files/13.2/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:edfaf27a4f33134691bdf782298a9dd11d173b7042363f1432f0f2e87807a648"
checksum = "sha256:a76faf6d534222455d82685f8d916fbdcde56f16030817c84e58b96e77a18253"
2 changes: 1 addition & 1 deletion var_files/13.2/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:b76ab084e339ee05f59be81354c8cb7dfadf9518e0548f88017d2759a910f17c"
checksum = "sha256:6b1159a204fd614410d32b15993416c745917e6de1781aa608e53d8c6b3d24a4"
2 changes: 1 addition & 1 deletion var_files/14.0/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:f16022a6567050e4831f15610a0981a998a57c6a5c7b69b012f43253ecf436ad"
checksum = "sha256:ab4c311aae56d5ec6edacd5a3951b6df1e9bfa94f964e1548c23ad058803c825"
2 changes: 1 addition & 1 deletion var_files/14.0/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
checksum = "sha256:7200214030125877561e70718781b435b703180c12575966ad1c7584a3e60dc6"
checksum = "sha256:de4fa9d7d199051860b80b84fbae51279a5ff5d92a2729a52bf0a3f79a5feb99"
1 change: 1 addition & 0 deletions var_files/arm64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
architecture = "arm64"
image_architecture = "arm64-aarch64"
qemu_architecture = "aarch64"
pkg_site_architecture = "aarch64"
machine_type = "virt"
cpu_type = "cortex-a57"
firmware = "edk2-aarch64-code.fd"
1 change: 1 addition & 0 deletions var_files/x86-64.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
architecture = "x86-64"
image_architecture = "amd64"
qemu_architecture = "x86_64"
pkg_site_architecture = "amd64"
firmware = "bios-256k.bin"

0 comments on commit 0eb1698

Please sign in to comment.