aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh164
1 files changed, 69 insertions, 95 deletions
diff --git a/build.sh b/build.sh
index bb9d770..07f9811 100755
--- a/build.sh
+++ b/build.sh
@@ -103,11 +103,6 @@ run_stage(){
if [ ! -f SKIP ]; then
load_qimage
fi
- else
- # make sure we are not umounting during export-image stage
- if [ "${USE_QCOW2}" = "0" ] && [ "${NO_PRERUN_QCOW2}" = "0" ]; then
- unmount "${WORK_DIR}/${STAGE}"
- fi
fi
if [ ! -f SKIP_IMAGES ]; then
@@ -135,11 +130,6 @@ run_stage(){
if [ "${USE_QCOW2}" = "1" ]; then
unload_qimage
- else
- # make sure we are not umounting during export-image stage
- if [ "${USE_QCOW2}" = "0" ] && [ "${NO_PRERUN_QCOW2}" = "0" ]; then
- unmount "${WORK_DIR}/${STAGE}"
- fi
fi
PREV_STAGE="${STAGE}"
@@ -252,17 +242,11 @@ source "${SCRIPT_DIR}/common"
# shellcheck source=scripts/dependencies_check
source "${SCRIPT_DIR}/dependencies_check"
-export NO_PRERUN_QCOW2="${NO_PRERUN_QCOW2:-1}"
-export USE_QCOW2="${USE_QCOW2:-1}"
+# merely a local flag for `run_stage` for EXPORT_DIRS (images) only
+export USE_QCOW2=1
+
export BASE_QCOW2_SIZE=${BASE_QCOW2_SIZE:-16G}
source "${SCRIPT_DIR}/qcow2_handling"
-if [ "${USE_QCOW2}" = "1" ]; then
- NO_PRERUN_QCOW2=1
-else
- NO_PRERUN_QCOW2=0
-fi
-
-export NO_PRERUN_QCOW2="${NO_PRERUN_QCOW2:-1}"
dependencies_check "${BASE_DIR}/depends"
@@ -303,85 +287,77 @@ for EXPORT_DIR in ${EXPORT_DIRS}; do
# shellcheck source=/dev/null
source "${EXPORT_DIR}/EXPORT_IMAGE"
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
- if [ "${USE_QCOW2}" = "1" ]; then
- USE_QCOW2=0
- EXPORT_NAME="${IMG_FILENAME}${IMG_SUFFIX}"
- echo "------------------------------------------------------------------------"
- echo "Running export stage for ${EXPORT_NAME}"
- rm -f "${WORK_DIR}/export-image/${EXPORT_NAME}.img" || true
- rm -f "${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2" || true
- rm -f "${WORK_DIR}/${EXPORT_NAME}.img" || true
- rm -f "${WORK_DIR}/${EXPORT_NAME}.qcow2" || true
- EXPORT_STAGE=$(basename "${EXPORT_DIR}")
- for s in $STAGE_LIST; do
- TMP_LIST=${TMP_LIST:+$TMP_LIST }$(basename "${s}")
- done
- FIRST_STAGE=${TMP_LIST%% *}
- FIRST_IMAGE="image-${FIRST_STAGE}.qcow2"
-
- pushd "${WORK_DIR}" > /dev/null
- echo "Creating new base "${EXPORT_NAME}.qcow2" from ${FIRST_IMAGE}"
- cp "./${FIRST_IMAGE}" "${EXPORT_NAME}.qcow2"
-
- ARR=($TMP_LIST)
- # rebase stage images to new export base
- for CURR_STAGE in "${ARR[@]}"; do
- if [ "${CURR_STAGE}" = "${FIRST_STAGE}" ]; then
- PREV_IMG="${EXPORT_NAME}"
- continue
- fi
- echo "Rebasing image-${CURR_STAGE}.qcow2 onto ${PREV_IMG}.qcow2"
- qemu-img rebase -f qcow2 -u -b ${PREV_IMG}.qcow2 image-${CURR_STAGE}.qcow2
- if [ "${CURR_STAGE}" = "${EXPORT_STAGE}" ]; then
- break
- fi
- PREV_IMG="image-${CURR_STAGE}"
- done
+ USE_QCOW2=0
+ EXPORT_NAME="${IMG_FILENAME}${IMG_SUFFIX}"
+ echo "------------------------------------------------------------------------"
+ echo "Running export stage for ${EXPORT_NAME}"
+ rm -f "${WORK_DIR}/export-image/${EXPORT_NAME}.img" || true
+ rm -f "${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2" || true
+ rm -f "${WORK_DIR}/${EXPORT_NAME}.img" || true
+ rm -f "${WORK_DIR}/${EXPORT_NAME}.qcow2" || true
+ EXPORT_STAGE=$(basename "${EXPORT_DIR}")
+ for s in $STAGE_LIST; do
+ TMP_LIST=${TMP_LIST:+$TMP_LIST }$(basename "${s}")
+ done
+ FIRST_STAGE=${TMP_LIST%% *}
+ FIRST_IMAGE="image-${FIRST_STAGE}.qcow2"
+
+ pushd "${WORK_DIR}" > /dev/null
+ echo "Creating new base "${EXPORT_NAME}.qcow2" from ${FIRST_IMAGE}"
+ cp "./${FIRST_IMAGE}" "${EXPORT_NAME}.qcow2"
+
+ ARR=($TMP_LIST)
+ # rebase stage images to new export base
+ for CURR_STAGE in "${ARR[@]}"; do
+ if [ "${CURR_STAGE}" = "${FIRST_STAGE}" ]; then
+ PREV_IMG="${EXPORT_NAME}"
+ continue
+ fi
+ echo "Rebasing image-${CURR_STAGE}.qcow2 onto ${PREV_IMG}.qcow2"
+ qemu-img rebase -f qcow2 -u -b ${PREV_IMG}.qcow2 image-${CURR_STAGE}.qcow2
+ if [ "${CURR_STAGE}" = "${EXPORT_STAGE}" ]; then
+ break
+ fi
+ PREV_IMG="image-${CURR_STAGE}"
+ done
+
+ # commit current export stage into base export image
+ echo "Committing image-${EXPORT_STAGE}.qcow2 to ${EXPORT_NAME}.qcow2"
+ qemu-img commit -f qcow2 -p -b "${EXPORT_NAME}.qcow2" image-${EXPORT_STAGE}.qcow2
+
+ # rebase stage images back to original first stage for easy re-run
+ for CURR_STAGE in "${ARR[@]}"; do
+ if [ "${CURR_STAGE}" = "${FIRST_STAGE}" ]; then
+ PREV_IMG="image-${CURR_STAGE}"
+ continue
+ fi
+ echo "Rebasing back image-${CURR_STAGE}.qcow2 onto ${PREV_IMG}.qcow2"
+ qemu-img rebase -f qcow2 -u -b ${PREV_IMG}.qcow2 image-${CURR_STAGE}.qcow2
+ if [ "${CURR_STAGE}" = "${EXPORT_STAGE}" ]; then
+ break
+ fi
+ PREV_IMG="image-${CURR_STAGE}"
+ done
+ popd > /dev/null
+
+ mkdir -p "${WORK_DIR}/export-image/rootfs"
+ mv "${WORK_DIR}/${EXPORT_NAME}.qcow2" "${WORK_DIR}/export-image/"
+ echo "Mounting image ${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2 to rootfs ${WORK_DIR}/export-image/rootfs"
+ mount_qimage "${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2" "${WORK_DIR}/export-image/rootfs"
+
+ CLEAN=0
+ run_stage
+ CLEAN=1
+ USE_QCOW2=1
- # commit current export stage into base export image
- echo "Committing image-${EXPORT_STAGE}.qcow2 to ${EXPORT_NAME}.qcow2"
- qemu-img commit -f qcow2 -p -b "${EXPORT_NAME}.qcow2" image-${EXPORT_STAGE}.qcow2
-
- # rebase stage images back to original first stage for easy re-run
- for CURR_STAGE in "${ARR[@]}"; do
- if [ "${CURR_STAGE}" = "${FIRST_STAGE}" ]; then
- PREV_IMG="image-${CURR_STAGE}"
- continue
- fi
- echo "Rebasing back image-${CURR_STAGE}.qcow2 onto ${PREV_IMG}.qcow2"
- qemu-img rebase -f qcow2 -u -b ${PREV_IMG}.qcow2 image-${CURR_STAGE}.qcow2
- if [ "${CURR_STAGE}" = "${EXPORT_STAGE}" ]; then
- break
- fi
- PREV_IMG="image-${CURR_STAGE}"
- done
- popd > /dev/null
-
- mkdir -p "${WORK_DIR}/export-image/rootfs"
- mv "${WORK_DIR}/${EXPORT_NAME}.qcow2" "${WORK_DIR}/export-image/"
- echo "Mounting image ${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2 to rootfs ${WORK_DIR}/export-image/rootfs"
- mount_qimage "${WORK_DIR}/export-image/${EXPORT_NAME}.qcow2" "${WORK_DIR}/export-image/rootfs"
-
- CLEAN=0
- run_stage
- CLEAN=1
- USE_QCOW2=1
-
- else
- run_stage
- fi
if [ "${USE_QEMU}" != "1" ]; then
if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
# shellcheck source=/dev/null
source "${EXPORT_DIR}/EXPORT_NOOBS"
STAGE_DIR="${BASE_DIR}/export-noobs"
- if [ "${USE_QCOW2}" = "1" ]; then
- USE_QCOW2=0
- run_stage
- USE_QCOW2=1
- else
- run_stage
- fi
+ USE_QCOW2=0
+ run_stage
+ USE_QCOW2=1
fi
fi
done
@@ -393,8 +369,6 @@ if [ -x postrun.sh ]; then
log "End postrun.sh"
fi
-if [ "${USE_QCOW2}" = "1" ]; then
- unload_qimage
-fi
+unload_qimage
log "End ${BASE_DIR}"