Check if Busybox supports oflag (#1692) (#1694)

* Check if Busybox supports oflag

It seems that Busybox' dd shipped with OS release 5 and earlier does not
support oflag. Check if the flag is supported before making use of it.

* Exit if a command in the update scripts returns an error

This makes sure that the update isn't marked as successful in case there
is an error in the update script.
This commit is contained in:
Stefan Agner 2021-12-27 14:58:19 +01:00
parent 372d604f7c
commit 93b4997989
No known key found for this signature in database
GPG Key ID: AE01353D1E44747D

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -o errexit
## ##
# Hooks # Hooks
@ -65,12 +67,17 @@ if [ "${RAUC_SLOT_CLASS}" = "spl" ]; then
DEVICE_ROOT="/dev/$(lsblk -no pkname "${DEVICE_CHILD}")" DEVICE_ROOT="/dev/$(lsblk -no pkname "${DEVICE_CHILD}")"
PART_TABLE="$(sfdisk -lqJ "${DEVICE_ROOT}")" PART_TABLE="$(sfdisk -lqJ "${DEVICE_ROOT}")"
PART_LABEL="$(echo "${PART_TABLE}" | jq -r '.partitiontable.label')" PART_LABEL="$(echo "${PART_TABLE}" | jq -r '.partitiontable.label')"
FLAGS=""
if dd oflag=direct if=/dev/null 2> /dev/null; then
FLAGS="oflag=direct"
fi
if [ "${PART_LABEL}" = "gpt" ]; then if [ "${PART_LABEL}" = "gpt" ]; then
dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc oflag=direct bs=512 seek=2 skip=2 dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc ${FLAGS} bs=512 seek=2 skip=2
else else
dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc oflag=direct bs=1 count=440 dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc ${FLAGS} bs=1 count=440
dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc oflag=direct bs=512 seek=1 skip=1 dd if="${RAUC_IMAGE_NAME}" of="${DEVICE_ROOT}" conv=notrunc ${FLAGS} bs=512 seek=1 skip=1
fi fi
# Flash to eMMC boot partition if necessary # Flash to eMMC boot partition if necessary