scripts: mkbootimg_rpi4.sh: Stop build on any kind of errors
[platform/kernel/linux-rpi.git] / 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