summaryrefslogtreecommitdiffstats
path: root/generate-ubi
diff options
context:
space:
mode:
authorGunnar Mills <gmills@us.ibm.com>2017-10-25 11:35:18 -0500
committerGunnar Mills <gmills@us.ibm.com>2017-11-06 18:20:43 +0000
commit0e30f86cb44f3ab0aa4080faf32eb4bf2a9b12b2 (patch)
treedd202e76112accef997186c27c5aad52cc9de654 /generate-ubi
parent8f618671364e4dc88c58446b4dd96ec06dbd8e2f (diff)
downloadopenpower-pnor-code-mgmt-0e30f86cb44f3ab0aa4080faf32eb4bf2a9b12b2.tar.gz
openpower-pnor-code-mgmt-0e30f86cb44f3ab0aa4080faf32eb4bf2a9b12b2.zip
Always clean up the scratch dir
The scratch directory, holding the extracted squashfs image and the temporary UBI image, can be quite large, >40MB. Use trap to make sure it always gets cleaned up. Signed-off-by: Gunnar Mills <gmills@us.ibm.com> Change-Id: I0289036dcf2bbf40fc76cf5ebf9dde1d47379435
Diffstat (limited to 'generate-ubi')
-rwxr-xr-xgenerate-ubi8
1 files changed, 4 insertions, 4 deletions
diff --git a/generate-ubi b/generate-ubi
index 511edcb7b..5c2b1b832 100755
--- a/generate-ubi
+++ b/generate-ubi
@@ -66,6 +66,9 @@ manifest_file_name="MANIFEST"
# Scratch directory for untarring and config file
scratch_dir=`mktemp -d`
+# Make sure scratch directory always gets cleaned up
+trap "{ rm -r ${scratch_dir}; }" EXIT
+
squashfs_file=${scratch_dir}/${squashfs_file_name}
manifest_file=${scratch_dir}/${manifest_file_name}
# Untar tarball
@@ -74,14 +77,12 @@ tar -xvf ${tarball} -C ${scratch_dir} ${squashfs_file_name} ${manifest_file_name
# All valid PNOR SquashFS Tarballs have a file named "pnor.xz.squashfs"
if [ ! -f "${squashfs_file}" ]; then
echo "No \"${squashfs_file_name}\" file in the tarball!"
- rm -r "${scratch_dir}"
exit 1
fi
# Need the manifest file for calculating the version id
if [ ! -f "${manifest_file}" ]; then
echo "No \"${manifest_file_name}\" file in the tarball!"
- rm -r "${scratch_dir}"
exit 1
fi
@@ -124,7 +125,7 @@ mk_nor_image()
dd if=/dev/zero bs=1k count=$image_size_kb | tr '\000' '\377' > $image_dst
}
-# Used to temporary hold the UBI volume
+# Used to temporary hold the UBI image
tmpfile=$(mktemp ${scratch_dir}/ubinized.XXXXXX)
# Configuration file used to create UBI image
@@ -145,4 +146,3 @@ mk_nor_image ${outfile} ${image_size}
dd bs=1k conv=notrunc seek=0 if=${tmpfile} of=${outfile}
echo "PNOR UBI image at ${outfile}"
-rm -r "${scratch_dir}"
OpenPOWER on IntegriCloud