Add quotes around variables

This commit is contained in:
Jørn Åne de Jong 2022-05-25 12:09:19 +02:00 committed by Nico Schottelius
parent 02e273faf4
commit 39ff637064
1 changed files with 28 additions and 28 deletions

View File

@ -11,8 +11,8 @@ set -x
# XXX: Handle command-line arguments?
RELEASE=13.1-RELEASE
ARCH=amd64
IMAGE_PATH_ZFS=freebsd-zfs-$RELEASE-$(date -I).img.qcow2
IMAGE_PATH_UFS=freebsd-ufs-$RELEASE-$(date -I).img.qcow2
IMAGE_PATH_ZFS="freebsd-zfs-$RELEASE-$(date -I).img.qcow2"
IMAGE_PATH_UFS="freebsd-ufs-$RELEASE-$(date -I).img.qcow2"
IMAGE_SIZE=10G
DIST_BASE="https://download.freebsd.org/ftp/releases/$ARCH/$RELEASE"
@ -25,7 +25,7 @@ ZFSTARGET="$(mktemp -d /var/tmp/zfsbuild.XXXXX)"
UFSTARGET="$(mktemp -d /var/tmp/ufsbuild.XXXXX)"
CLOUDSETUP_WORK="$(mktemp -d /var/tmp/cloudsetup.XXXXX)"
if zpool list -Ho name $ZPOOL_TMP 2>/dev/null; then
if zpool list -Ho name "$ZPOOL_TMP" 2>/dev/null; then
echo "The pool $ZPOOL_TMP is already imported." >&2
exit 1
fi
@ -36,7 +36,7 @@ cleanup() {
umount "$UFSTARGET/tmp" ||:
umount "$UFSTARGET/var/tmp" ||:
umount "$UFSTARGET" ||:
zpool export $ZPOOL_TMP ||:
zpool export "$ZPOOL_TMP" ||:
mdconfig -du md0 ||:
mdconfig -du md1 ||:
rm -rf "$CLOUDSETUP_WORK" ||:
@ -61,9 +61,9 @@ fi
fetch -qo- "$CLOUDSETUP_URL" | tar -C "$CLOUDSETUP_WORK" --strip-components 1 -xzf-
ufsdisk=$(mktemp /var/tmp/ufsdisk.XXXXX)
truncate -s 6G $ufsdisk
mdconfig -a -t vnode -f $ufsdisk -u md1
ufsdisk="$(mktemp /var/tmp/ufsdisk.XXXXX)"
truncate -s 6G "$ufsdisk"
mdconfig -a -t vnode -f "$ufsdisk" -u md1
gpart create -s gpt /dev/md1
gpart add -t freebsd-boot -l bootfs -b 40 -s 512K md1
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 md1
@ -77,34 +77,34 @@ mount /dev/md1p2 "$UFSTARGET"
# We use "legacy boot", aka BIOS boot
# Preferably, we'd use EFI boot here, check the FreeBSD wiki link in the header
# to see how to make that change, but make the EFI partition larger
zfsdisk=$(mktemp /var/tmp/zfsdisk.XXXXX)
truncate -s 6G $zfsdisk
mdconfig -a -t vnode -f $zfsdisk -u md0
zfsdisk="$(mktemp /var/tmp/zfsdisk.XXXXX)"
truncate -s 6G "$zfsdisk"
mdconfig -a -t vnode -f "$zfsdisk" -u md0
gpart create -s gpt /dev/md0
gpart add -t freebsd-boot -l bootfs -b 40 -s 512K md0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 md0
gpart add -t freebsd-zfs -l zfs0 -b 1M -s 5G md0
zpool create -O compression=on -o ashift=12 -o altroot="$ZFSTARGET" -m none -t $ZPOOL_TMP $ZPOOL md0p2
zpool create -O compression=on -o ashift=12 -o "altroot=$ZFSTARGET" -m none -t "$ZPOOL_TMP" "$ZPOOL" md0p2
zfs create -o mountpoint=none $ZPOOL_TMP/ROOT
zfs create -o mountpoint=none "$ZPOOL_TMP/ROOT"
# We set zstd-19 so our image will become smaller, at the cost of a longer build time.
# At the end of the process, we disable zstd-19 again using zfs inherit compression,
# but all files already written will remain zstd-19 compressed
zfs create -o mountpoint=/ -o canmount=noauto $ZPOOL_TMP/ROOT/default
mount -t zfs $ZPOOL_TMP/ROOT/default "$ZFSTARGET"
zpool set bootfs=$ZPOOL_TMP/ROOT/default $ZPOOL_TMP
zfs create -o mountpoint=/ -o canmount=noauto "$ZPOOL_TMP/ROOT/default"
mount -t zfs "$ZPOOL_TMP/ROOT/default" "$ZFSTARGET"
zpool set "bootfs=$ZPOOL_TMP/ROOT/default" "$ZPOOL_TMP"
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off $ZPOOL_TMP/tmp
zfs create -o canmount=off -o mountpoint=/usr $ZPOOL_TMP/usr
zfs create $ZPOOL_TMP/usr/home
zfs create -o exec=off -o setuid=off $ZPOOL_TMP/usr/src
zfs create -o mountpoint=/usr/ports -o setuid=off $ZPOOL_TMP/usr/ports
zfs create -o canmount=off -o mountpoint=/var $ZPOOL_TMP/var
zfs create -o exec=off -o setuid=off $ZPOOL_TMP/var/audit
zfs create -o exec=off -o setuid=off $ZPOOL_TMP/var/crash
zfs create -o exec=off -o setuid=off $ZPOOL_TMP/var/log
zfs create -o atime=on -o exec=off -o setuid=off $ZPOOL_TMP/var/mail
zfs create -o exec=on -o setuid=off $ZPOOL_TMP/var/tmp
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off "$ZPOOL_TMP/tmp"
zfs create -o canmount=off -o mountpoint=/usr "$ZPOOL_TMP/usr"
zfs create "$ZPOOL_TMP/usr/home"
zfs create -o exec=off -o setuid=off "$ZPOOL_TMP/usr/src"
zfs create -o mountpoint=/usr/ports -o setuid=off "$ZPOOL_TMP/usr/ports"
zfs create -o canmount=off -o mountpoint=/var "$ZPOOL_TMP/var"
zfs create -o exec=off -o setuid=off "$ZPOOL_TMP/var/audit"
zfs create -o exec=off -o setuid=off "$ZPOOL_TMP/var/crash"
zfs create -o exec=off -o setuid=off "$ZPOOL_TMP/var/log"
zfs create -o atime=on -o exec=off -o setuid=off "$ZPOOL_TMP/var/mail"
zfs create -o exec=on -o setuid=off "$ZPOOL_TMP/var/tmp"
ln -s /usr/home "$ZFSTARGET/home"
chmod 1777 "$ZFSTARGET/var/tmp"
@ -172,13 +172,13 @@ rm -rf "$UFSTARGET/var/db/freebsd-update/"* ||:
# This will make the base image smaller, at the cost of taking longer to generate, as zstd-19 is slow to write
# Therefore, afterwards we restore compression to default, so written files stay zstd-19, which is fast to read,
# but files written by the user afterwards will be written with the default compression algorihtm.
zfs set compression=zstd-19 $ZPOOL_TMP/ROOT/default
zfs set compression=zstd-19 "$ZPOOL_TMP/ROOT/default"
umount "$UFSTARGET/dev" "$UFSTARGET/tmp" "$UFSTARGET/var/tmp"
rsync -aH --fileflags --inplace "$UFSTARGET/." "$ZFSTARGET"
sysrc -f "$UFSTARGET/boot/loader.conf" -x zfs_load
printf '%s\t%s\t\t%s\t%s\t%s\t%s\n' /dev/gpt/rootfs / ufs rw,noatime 1 1 >>"$UFSTARGET/etc/fstab"
sync ||:
zfs inherit compression $ZPOOL_TMP/ROOT/default
zfs inherit compression "$ZPOOL_TMP/ROOT/default"
trap : EXIT
cleanup