From 977b2371952187699e2050ad5fb0cfaf93c84240 Mon Sep 17 00:00:00 2001 From: bain Date: Sat, 31 Dec 2022 14:30:06 +0100 Subject: [PATCH] better temp dir handling --- run.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/run.sh b/run.sh index f9ece05..4007853 100755 --- a/run.sh +++ b/run.sh @@ -7,13 +7,14 @@ export HL_ROOT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null & export HL_AGE_IDENTITY="${HL_AGE_IDENTITY:-$HL_ROOT_DIR/ident}"; export HL_LIB="$HL_ROOT_DIR/_lib.sh"; -# create private temp dir -export HL_TMP_DIR="$(mktemp -d)"; -chmod a-rwx,u+rwx "$HL_TMP_DIR"; - pushd "$HL_ROOT_DIR" > /dev/null; for var in "$@"; do sudo whoami > /dev/null # pre-authorize sudo + + # create private temp dir + export HL_TMP_DIR="$(mktemp -d)"; + chmod a-rwx,u+rwx "$HL_TMP_DIR"; + pushd scripts/$var > /dev/null; if [ "${DONT_HIDE:-0}" -eq "1" ]; then echo "" | bash script.sh; @@ -21,10 +22,13 @@ for var in "$@"; do TEMP_OUT=$(mktemp); chmod a-rwx,u+rw "$TEMP_OUT"; echo -n "scripts/base... "; + OK=0 echo "" | bash script.sh > "$TEMP_OUT" 2>&1 || OK=1; + if [ $OK -eq 0 ]; then echo -e "\033[32mOK\033[0m"; + rm -r "$HL_TMP_DIR" else echo -e "\033[1;31mFAILED\033[0m"; tail -n 10 "$TEMP_OUT" | sed 's/^/ /'; @@ -35,6 +39,3 @@ for var in "$@"; do popd > /dev/null; done popd > /dev/null - -# remove temp dir -rm -r "$HL_TMP_DIR"