cleanup with a trap

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2021-03-06 11:29:30 +03:00
parent 0181a1099f
commit 8adeef05bc

View File

@ -1,19 +1,23 @@
#!/usr/bin/env bash #!/usr/bin/env bash
shopt -s nullglob shopt -s nullglob
cleanup() { rm -rf "$tmpdir"; }
trap 'cleanup' EXIT
did="pkg-build-$$.$SRANDOM" did="pkg-build-$$.$SRANDOM"
mkdir "/tmp/$did" tmpdir="/tmp/$did"
mkdir "$tmpdir"
pkg_dest=$1 pkg_dest=$1
pkg_url=$2 pkg_url=$2
mkdir -p "$pkg_dest" || exit 1 mkdir -p "$pkg_dest" || exit 1
git clone "$pkg_url" "/tmp/$did" git clone "$pkg_url" "$tmpdir"
cd "/tmp/$did" cd "$tmpdir"
makepkg-podman --noconfirm -sL makepkg-podman --noconfirm -sL
artifacts=( "/tmp/$did/"*.pkg.* ) artifacts=( "$tmpdir/"*.pkg.* )
for i in "${artifacts[@]}"; do for i in "${artifacts[@]}"; do
i_name="${i##*/}" i_name="${i##*/}"
@ -26,6 +30,3 @@ for i in "${artifacts[@]}"; do
cp -vn "$i" "$pkg_dest" cp -vn "$i" "$pkg_dest"
fi fi
done done
# cleanup
rm -rf "/tmp/$did"