better temp dir handling

This commit is contained in:
bain 2022-12-31 14:30:06 +01:00
parent 5f455cd8d4
commit 977b237195

15
run.sh
View file

@ -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_AGE_IDENTITY="${HL_AGE_IDENTITY:-$HL_ROOT_DIR/ident}";
export HL_LIB="$HL_ROOT_DIR/_lib.sh"; 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; pushd "$HL_ROOT_DIR" > /dev/null;
for var in "$@"; do for var in "$@"; do
sudo whoami > /dev/null # pre-authorize sudo 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; pushd scripts/$var > /dev/null;
if [ "${DONT_HIDE:-0}" -eq "1" ]; then if [ "${DONT_HIDE:-0}" -eq "1" ]; then
echo "" | bash script.sh; echo "" | bash script.sh;
@ -21,10 +22,13 @@ for var in "$@"; do
TEMP_OUT=$(mktemp); TEMP_OUT=$(mktemp);
chmod a-rwx,u+rw "$TEMP_OUT"; chmod a-rwx,u+rw "$TEMP_OUT";
echo -n "scripts/base... "; echo -n "scripts/base... ";
OK=0 OK=0
echo "" | bash script.sh > "$TEMP_OUT" 2>&1 || OK=1; echo "" | bash script.sh > "$TEMP_OUT" 2>&1 || OK=1;
if [ $OK -eq 0 ]; then if [ $OK -eq 0 ]; then
echo -e "\033[32mOK\033[0m"; echo -e "\033[32mOK\033[0m";
rm -r "$HL_TMP_DIR"
else else
echo -e "\033[1;31mFAILED\033[0m"; echo -e "\033[1;31mFAILED\033[0m";
tail -n 10 "$TEMP_OUT" | sed 's/^/ /'; tail -n 10 "$TEMP_OUT" | sed 's/^/ /';
@ -35,6 +39,3 @@ for var in "$@"; do
popd > /dev/null; popd > /dev/null;
done done
popd > /dev/null popd > /dev/null
# remove temp dir
rm -r "$HL_TMP_DIR"