-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathfreebsd_setup_base.sh
More file actions
executable file
·71 lines (55 loc) · 2.5 KB
/
freebsd_setup_base.sh
File metadata and controls
executable file
·71 lines (55 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
# SPDX-FileCopyrightText: Copyright (c) Marcus Holland-Moritz
# SPDX-License-Identifier: MIT
set -euo pipefail
# ===== Config =====
FREEBSD_REL="${FREEBSD_REL:-14.3-RELEASE}"
FREEBSD_VER_TAG="${FREEBSD_VER_TAG:-14_3}"
SNAP_LABEL="${SNAP_LABEL:-base-$(date +%Y%m%d)}"
ZPOOL="${ZPOOL:-zroot}"
JAILS_DS="${JAILS_DS:-${ZPOOL}/z/jails}"
JAILS_MP="${JAILS_MP:-/z/jails}"
PKG_REPO_URL='pkg+http://pkg.FreeBSD.org/${ABI}/latest'
PKGS="boost-all brotli ccache cmake date double-conversion flac fuse fusefs-libs fusefs-libs3 glog gnulibiberty libarchive liblz4 mold ninja nlohmann-json openssl parallel-hashmap pkgconf range-v3 utf8cpp xxhash zstd ca_root_nss git"
# ===== Layout =====
sudo zfs list -H "${ZPOOL}" >/dev/null 2>&1 || { echo "No pool ${ZPOOL}"; exit 1; }
sudo zfs create -o mountpoint=/z "${ZPOOL}/z" >/dev/null 2>&1 || true
sudo zfs create -o mountpoint=/z/jails "${JAILS_DS}" >/dev/null 2>&1 || true
BASE_DS="${JAILS_DS}/${FREEBSD_VER_TAG}"
BASE_MP="${JAILS_MP}/${FREEBSD_VER_TAG}"
if ! sudo zfs list -H "${BASE_DS}" >/dev/null 2>&1; then
sudo zfs create -o mountpoint="${BASE_MP}" "${BASE_DS}"
fi
# ===== Fetch & extract base.txz =====
if [ ! -f "${BASE_MP}/.seeded" ]; then
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
fetch -o "${TMPDIR}/base.txz" "https://download.freebsd.org/releases/amd64/${FREEBSD_REL}/base.txz"
sudo tar -xpf "${TMPDIR}/base.txz" -C "${BASE_MP}"
sudo touch "${BASE_MP}/.seeded"
fi
# ===== Provide networking config to the chroot =====
sudo mkdir -p "${BASE_MP}/etc"
# copy DNS + name service config from host so pkg can resolve names
sudo cp /etc/resolv.conf "${BASE_MP}/etc/resolv.conf"
[ -f /etc/hosts ] && sudo cp /etc/hosts "${BASE_MP}/etc/hosts"
[ -f /etc/nsswitch.conf ] && sudo cp /etc/nsswitch.conf "${BASE_MP}/etc/nsswitch.conf"
# ===== Preinstall deps inside the tree =====
sudo mount -t devfs devfs "${BASE_MP}/dev"
sudo mount -t fdescfs fdesc "${BASE_MP}/dev/fd"
sudo mount -t procfs proc "${BASE_MP}/proc"
sudo chroot "${BASE_MP}" /bin/sh -lc "
set -e
env ASSUME_ALWAYS_YES=yes pkg bootstrap -f
mkdir -p /usr/local/etc/pkg/repos
echo 'FreeBSD: { url: \"${PKG_REPO_URL}\" }' > /usr/local/etc/pkg/repos/FreeBSD.conf
pkg update
pkg install -y ${PKGS}
mkdir -p /root/.ccache
"
sudo umount -f "${BASE_MP}/proc" || true
sudo umount -f "${BASE_MP}/dev/fd" || true
sudo umount -f "${BASE_MP}/dev" || true
# ===== Snapshot =====
sudo zfs snapshot "${BASE_DS}@${SNAP_LABEL}"
echo "Snapshot created: ${BASE_DS}@${SNAP_LABEL}"