fix cleanup func

This commit is contained in:
Trevor Batley 2023-09-28 21:17:09 +10:00
parent 338c05bb56
commit 5cce0eeb5e

View File

@ -38,6 +38,7 @@ KOJI_HUB_FQDN="$(hostname -f)"
if [ ! -d $SCRIPT_DIR ] ; then mkdir -p $SCRIPT_DIR ; fi
if [ ! -f $SCRIPT_DIR/koji-gencert.sh ] ; then
curl $SILENT $SCRIPT_GIT/koji-gencert.sh > $SCRIPT_DIR/koji-gencert.sh
chmod o+x $SCRIPT_DIR/koji-gencert.sh
fi
# Add the new user into the database
@ -55,12 +56,18 @@ if [[ ! -d $KOJI_PKI_DIR/bundle ]] ; then
mkdir -p $KOJI_PKI_DIR/bundle
fi
WORK_DIR=`mktemp -d $NEW_USER-XXXXXXXX`
WORK_DIR=`mktemp -p /tmp -d $NEW_USER-XXXXXXXX`
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
# function to delete the temp directory
function cleanup {
rm -rf "$WORK_DIR"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
@ -85,8 +92,3 @@ cp koji-"$NEW_USER"-bundle.tgz $KOJI_PKI_DIR/bundle/.
popd
echo "The Koji CLI and Web key bundle for $NEW_USER is $KOJI_PKI_DIR/bundle/koij-$NEW_USER-bundle.tgz"
# function to delete the temp directory
function cleanup {
rm -rf "$WORK_DIR"
}