From 9e8567a125612a2048b8f7e1e6c518c9fb0f0479 Mon Sep 17 00:00:00 2001 From: Alberto De Bortoli Date: Fri, 1 May 2026 08:53:49 +0100 Subject: [PATCH 1/2] Extract zip into temp dir to prevent leftover files on sudo cancel If the user cancelled the sudo password prompt during installation, the extracted binary was left behind in the current working directory. Using a temp directory (mktemp -d) with an EXIT trap ensures all intermediate files are cleaned up unconditionally regardless of how the script exits. --- install.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/install.sh b/install.sh index 5c3ced2..dd17cc1 100755 --- a/install.sh +++ b/install.sh @@ -27,6 +27,9 @@ POST_CHECKOUT_HOOK_URL="https://raw.githubusercontent.com/LucaTools/LucaScripts/ trap 'printf "\nโŒ Installation interrupted.\n"; exit 130' INT +TEMP_DIR=$(mktemp -d) +trap 'rm -rf "$TEMP_DIR"' EXIT + # Build curl options for GitHub API requests. # If GITHUB_TOKEN is set, include it as a Bearer token to avoid rate limiting # (5000 req/hr authenticated vs. 60 req/hr unauthenticated). @@ -173,7 +176,7 @@ fi echo "๐Ÿ“ฅ Downloading $TOOL_NAME ($REQUIRED_EXECUTABLE_VERSION)..." # Download the appropriate version for the detected OS -curl -LSsf --output "./$TEMP_EXECUTABLE_ZIP_FILENAME" \ +curl -LSsf --output "$TEMP_DIR/$TEMP_EXECUTABLE_ZIP_FILENAME" \ "$REPOSITORY_URL/releases/download/$REQUIRED_EXECUTABLE_VERSION/$TEMP_EXECUTABLE_ZIP_FILENAME" DOWNLOAD_SUCCESS=$? @@ -192,18 +195,13 @@ echo "โœ… Download completed successfully" echo "๐Ÿ“ฆ Extracting $TEMP_EXECUTABLE_ZIP_FILENAME..." # Extract the downloaded zip file quietly -if ! unzip -o -qq "./$TEMP_EXECUTABLE_ZIP_FILENAME" -d ./; then +if ! unzip -o -qq "$TEMP_DIR/$TEMP_EXECUTABLE_ZIP_FILENAME" -d "$TEMP_DIR"; then echo "โŒ ERROR: Failed to extract $TEMP_EXECUTABLE_ZIP_FILENAME" - rm -f "./$TEMP_EXECUTABLE_ZIP_FILENAME" exit 1 fi echo "โœ… Extraction completed" -# Clean up the downloaded zip file -rm "./$TEMP_EXECUTABLE_ZIP_FILENAME" -echo "๐Ÿงน Cleaned up temporary files" - # ============================================================================= # SYSTEM INSTALLATION WITH PRIVILEGE HANDLING # ============================================================================= @@ -237,10 +235,10 @@ fi # Move the executable to the install directory and make it executable # The zip may contain either 'Luca' (uppercase) or 'luca' (lowercase) depending on the release echo "๐Ÿš€ Installing $TOOL_NAME to $INSTALL_DIR..." -if [ -f "$TOOL_NAME" ]; then - EXTRACTED_BIN="$TOOL_NAME" -elif [ -f "$BIN_NAME" ]; then - EXTRACTED_BIN="$BIN_NAME" +if [ -f "$TEMP_DIR/$TOOL_NAME" ]; then + EXTRACTED_BIN="$TEMP_DIR/$TOOL_NAME" +elif [ -f "$TEMP_DIR/$BIN_NAME" ]; then + EXTRACTED_BIN="$TEMP_DIR/$BIN_NAME" else echo "โŒ ERROR: Could not find extracted binary (expected '$TOOL_NAME' or '$BIN_NAME')" exit 1 From 50fc3c2f289ec5cbc24c3909134e3e30ccf52966 Mon Sep 17 00:00:00 2001 From: Alberto De Bortoli Date: Fri, 1 May 2026 09:00:31 +0100 Subject: [PATCH 2/2] Fix mock unzip to write binary to the -d destination directory The mock was hardcoding ./Luca as the output path. Now it parses the -d argument so it correctly places the binary in the temp directory used by install.sh after the extraction refactor. --- tests/test_helper/mocks/unzip | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_helper/mocks/unzip b/tests/test_helper/mocks/unzip index b1f8746..deba6d1 100755 --- a/tests/test_helper/mocks/unzip +++ b/tests/test_helper/mocks/unzip @@ -1,13 +1,22 @@ #!/usr/bin/env bash -# Mock unzip - creates a fake Luca binary in the current directory +# Mock unzip - creates a fake Luca binary in the destination directory echo "unzip $*" >> "${MOCK_CALL_LOG:-/dev/null}" +# Parse the -d argument +DEST_DIR="." +while [[ $# -gt 0 ]]; do + case "$1" in + -d) DEST_DIR="$2"; shift 2 ;; + *) shift ;; + esac +done + case "${MOCK_UNZIP_BEHAVIOR:-success}" in success) - # Create a fake Luca executable (install.sh looks for ./Luca) - printf '#!/usr/bin/env bash\necho "%s"\n' "${MOCK_LUCA_VERSION:-v2.0.0}" > "./Luca" - chmod +x "./Luca" + # Create a fake Luca executable in the destination directory + printf '#!/usr/bin/env bash\necho "%s"\n' "${MOCK_LUCA_VERSION:-v2.0.0}" > "$DEST_DIR/Luca" + chmod +x "$DEST_DIR/Luca" exit 0 ;; fail)