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