Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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=$?
Expand All @@ -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
# =============================================================================
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions tests/test_helper/mocks/unzip
Original file line number Diff line number Diff line change
@@ -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 <dest> 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)
Expand Down
Loading