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 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)