From c3ddb7483d7a28d8e4ef42ab61ab6db239bc06bd Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:07:40 -0700 Subject: [PATCH] fix: only overwrite run.sh if successful response is received (#299) --- bitwarden.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bitwarden.sh b/bitwarden.sh index 6ef3bd1..3b52c27 100755 --- a/bitwarden.sh +++ b/bitwarden.sh @@ -93,16 +93,20 @@ function downloadRunFile() { then mkdir $SCRIPTS_DIR fi - run_file_status_code=$(curl -s -L -w "%{http_code}" -o $SCRIPTS_DIR/run.sh $RUN_SCRIPT_URL) + + local tmp_script=$(mktemp) + + run_file_status_code=$(curl -s -L -w "%{http_code}" -o $tmp_script $RUN_SCRIPT_URL) if echo "$run_file_status_code" | grep -q "^20[0-9]" then + mv $tmp_script $SCRIPTS_DIR/run.sh chmod u+x $SCRIPTS_DIR/run.sh rm -f $SCRIPTS_DIR/install.sh else echo "Unable to download run script from $RUN_SCRIPT_URL. Received status code: $run_file_status_code" echo "http response:" - cat $SCRIPTS_DIR/run.sh - rm -f $SCRIPTS_DIR/run.sh + cat $tmp_script + rm -f $tmp_script exit 1 fi }