Verified Commit 8f896281 authored by Frederik Enste's avatar Frederik Enste
Browse files

added build script

parent ef3bb38e
#!/bin/bash
set -e
set -x
EXEC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_DIR=".build"
URL_SUM="https://cloud-images.ubuntu.com/focal/current/SHA256SUMS"
FILE_SUM="SHA256SUMS"
URL_IMG="https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
FILE_IMG="focal-server-cloudimg-amd64.img"
# cleanup old build dir
if [[ -d "${BUILD_DIR}" ]]; then
rm --recursive --force --verbose "${BUILD_DIR}"
fi
mkdir --parents --verbose "${BUILD_DIR}"
cd "${BUILD_DIR}"
# download checksums
curl --location --output "${FILE_SUM}" "${URL_SUM}"
# download cloud init image
curl --location --output "${FILE_IMG}" "${URL_IMG}"
sha256sum --ignore-missing --check SHA256SUMS
# convert image if necessary
if [[ "`qemu-img info focal-server-cloudimg-amd64.img | grep -c 'file format: qcow2'`" -eq "1" ]]; then
FILE_TEMP="`mktemp --dry-run`"
mv -v "${FILE_IMG}" "${FILE_TEMP}"
qemu-img convert -f qcow2 -O raw "${FILE_TEMP}" "${FILE_IMG}"
rm -v "${FILE_TEMP}"
fi
# mount image
MOUNT_ROOT="`mktemp --directory`"
SECTOR_SIZE="`sfdisk -d focal-server-cloudimg-amd64.img | grep -Eo 'sector-size: *[0-9]+' | grep -Eo '[0-9]+'`"
SECTOR_OFFSET="`sfdisk -d focal-server-cloudimg-amd64.img | grep -Eo '1 *: *start=[ 0-9]+,' | grep -Eo '= *[0-9]+' | grep -Eo '[0-9]+'`"
OFFSET="`expr ${SECTOR_SIZE} \* ${SECTOR_OFFSET}`"
sudo mount -o "loop,offset=${OFFSET}" "${FILE_IMG}" "${MOUNT_ROOT}"
# import custom pre configs and scripts
cd "${EXEC_DIR}/root"
sudo cp --recursive --verbose "." "${MOUNT_ROOT}/"
# unmount image
sudo umount "${MOUNT_ROOT}"
rmdir "${MOUNT_ROOT}"
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment