-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup-base-images.sh
executable file
·55 lines (47 loc) · 1.46 KB
/
setup-base-images.sh
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
#!/bin/bash
set -o xtrace
set -o errexit
set -o pipefail
set -o nounset
dataset=${FALCON_DATASET:-rpool/falcon}
echo "dataset is: $dataset"
# Images follow the naming scheme
# <name>-<os_version>-<image_version>
#
# Old method of pulling statically defined images
# TODO create new build pipelines for the following images
images="debian-11.0_0 helios-2.5_0"
mkdir -p .img
pushd .img
for img in $images; do
name=${img%_*}
file=$img.raw.xz
if [[ -n "${FORCE+x}" ]]; then
rm -f $file
rm -rf $img.raw
echo "Deleting $name image"
pfexec zfs destroy -r $dataset/img/$name || true
fi
if [[ -b /dev/zvol/dsk/$dataset/img/$name ]]; then
continue
fi
if [[ ! -f $file ]]; then
echo "Pulling $file"
echo "https://oxide-falcon-assets.s3.us-west-2.amazonaws.com/$file"
curl -OL https://oxide-falcon-assets.s3.us-west-2.amazonaws.com/$file
fi
if [[ ! -f $img.raw ]]; then
echo "Extracting $file"
unxz --keep -T 0 $file
fi
file=$img.raw
echo "Creating ZFS volume $name"
fsize=`stat --format "%s" $img.raw`
(( vsize = fsize + 4096 - ( fsize % 4096 ) ))
pfexec zfs create -p -V $vsize -o volblocksize=4k "$dataset/img/$name"
echo "Copying contents of image into volume"
pfexec dd if=$img.raw of="/dev/zvol/rdsk/$dataset/img/$name" bs=1024k status=progress
echo "Creating base image snapshot"
pfexec zfs snapshot "$dataset/img/$name@base"
done
popd