scripts: mkbootimg_rpi4.sh: Stop build on any kind of errors
authorDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 1 Dec 2021 05:28:26 +0000 (14:28 +0900)
committerHoegeun Kwon <hoegeun.kwon@samsung.com>
Thu, 3 Aug 2023 08:46:16 +0000 (17:46 +0900)
Currently, even if an error occurs during image creation, the script
does not abort, which may result in incorrect image creation. In order
to avoid confusion due to this, if any kind of error occurs during the
build process, the build will be stopped.

Change-Id: I8094f4b97128a8c754e5a9ff22f1b3395a3756b1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
scripts/mkbootimg_rpi4.sh

index babfd46..d49082c 100755 (executable)
@@ -1,9 +1,38 @@
 #!/bin/bash
 
+TMP_UBOOT_PATH=tmp_uboot
 BOOT_PATH="rpi4/boot"
 USER_ID=`id -u`
 GROUP_ID=`id -g`
 IS_64BIT=`cat .config | grep "CONFIG_64BIT=y"`
+BUILD_ROOT=$PWD
+
+cleanup() {
+       cd $BUILD_ROOT
+       if [ -e $TMP_UBOOT_PATH ]; then
+               rm -rf ${TMP_UBOOT_PATH}
+       fi
+
+       if [ -e tmp_modules ]; then
+               rm -rf tmp_modules
+       fi
+
+       if [ -e tmp/lib/modules ]; then
+               rm -rf tmp/lib/modules
+       fi
+
+       if [ -n "$(mount | grep ${BUILD_ROOT}/tmp)" ]; then
+               sudo umount tmp
+       fi
+
+       if [ -e tmp ]; then
+               rm -rf tmp
+       fi
+}
+
+trap cleanup EXIT
+
+set -e
 
 rm -f boot.img
 rm -rf tmp
@@ -32,7 +61,7 @@ else
 fi
 
 # install u-boot files extracted from u-boot-rpi4 rpm package in download.tizen.org.
-TMP_UBOOT_PATH=tmp_uboot
+
 mkdir -p ${TMP_UBOOT_PATH}
 pushd ${TMP_UBOOT_PATH}
 if [ -n "$IS_64BIT" ]; then
@@ -93,3 +122,5 @@ if [ "$?" != "0" ]; then
 fi
 
 echo ${BOOT_TARBALL}
+
+set +e