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 committed by GitHub
parent 580e541f77
commit 55c9b54b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
fi fi