Skip to content

Commit

Permalink
bin/flatcar-install: use EXIT instead of RETURN traps
Browse files Browse the repository at this point in the history
Somehow, with the bash upgrade the trap RETURN signal is not handled
correctly (it's ignored).

We run now everything from a subshell and turn RETURN trap to an EXIT
trap.

Signed-off-by: Mathieu Tortuyaux <[email protected]>
  • Loading branch information
tormath1 committed Jun 26, 2023
1 parent 658eb0e commit 206f49a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/flatcar-install
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ function install_from_url() {
fi 3> >(write_to_disk)
}
function write_cloudinit() if [[ -n "${CLOUDINIT}${COPY_NET}" ]]; then
function write_cloudinit() {
if [[ -n "${CLOUDINIT}${COPY_NET}" ]]; then
(
# The ROOT partition should be #9 but make no assumptions here!
# Also don't mount by label directly in case other devices conflict.
local ROOT_DEV=$(blkid -t "LABEL=ROOT" -o device "${DEVICE}"*)
Expand All @@ -714,7 +716,7 @@ function write_cloudinit() if [[ -n "${CLOUDINIT}${COPY_NET}" ]]; then
"btrfs") mount -t btrfs -o subvol=root "${ROOT_DEV}" "${WORKDIR}/rootfs" ;;
*) mount "${ROOT_DEV}" "${WORKDIR}/rootfs" ;;
esac
trap 'umount "${WORKDIR}/rootfs"' RETURN
trap 'umount "${WORKDIR}/rootfs"' EXIT
if [[ -n "${CLOUDINIT}" ]]; then
echo "Installing cloud-config..."
Expand All @@ -727,20 +729,26 @@ function write_cloudinit() if [[ -n "${CLOUDINIT}${COPY_NET}" ]]; then
# Copy the entire directory, do not overwrite anything that might exist there, keep permissions, and copy the resolve.conf link as a file.
cp --recursive --no-clobber --preserve --dereference /run/systemd/network/* "${WORKDIR}/rootfs/etc/systemd/network"
fi
fi
)
fi
}
function write_ignition() if [[ -n "${IGNITION}" ]]; then
function write_ignition() {
if [[ -n "${IGNITION}" ]]; then
(
# The OEM partition should be #6 but make no assumptions here!
# Also don't mount by label directly in case other devices conflict.
local OEM_DEV=$(blkid -t "LABEL=OEM" -o device "${DEVICE}"*)
mkdir -p "${WORKDIR}/oemfs"
mount "${OEM_DEV}" "${WORKDIR}/oemfs" || { btrfstune -f -u "${OEM_DEV}" ; mount "${OEM_DEV}" "${WORKDIR}/oemfs" ; }
trap 'umount "${WORKDIR}/oemfs"' RETURN
trap 'umount "${WORKDIR}/oemfs"' EXIT
echo "Installing Ignition config ${IGNITION}..."
cp "${IGNITION}" "${WORKDIR}/oemfs/config.ign"
fi
)
fi
}
function create_uefi() {
ensure_tool "efibootmgr"
Expand Down

0 comments on commit 206f49a

Please sign in to comment.