Skip to content

Commit 99022e5

Browse files
committed
refactor binary search logic in install script to improve accuracy; implement multiple strategies for locating binaries, including exact match, pattern match, and size-based fallback
1 parent 5589975 commit 99022e5

2 files changed

Lines changed: 87 additions & 17 deletions

File tree

handler/install.sh.qtpl

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,43 @@ function install {
154154
fail "unknown file type: $FTYPE"
155155
fi
156156
for PROG in "${PROG_LIST[@]}"; do
157-
BIN_PATH=$(find . -type f | grep -i "$PROG" | head -n 1)
158-
[[ -z "$BIN_PATH" ]] && fail "Binary $PROG not found"
157+
# Try to find binary intelligently:
158+
# 1. First try exact filename match (case-insensitive)
159+
# 2. Exclude common non-binary files
160+
# 3. Fall back to largest file if exact match fails
161+
BIN_PATH=""
162+
163+
# Strategy 1: Try exact name match, excluding non-binary extensions
164+
BIN_PATH=$(find . -type f -iname "$PROG" \
165+
! -iname "*.md" ! -iname "*.txt" ! -iname "*.sig" \
166+
! -iname "*.asc" ! -iname "LICENSE*" ! -iname "README*" \
167+
! -iname "CHANGELOG*" ! -iname "*.sha*" ! -iname "*.sum" \
168+
2>/dev/null | head -n 1)
169+
170+
# Strategy 2: If exact match failed, try pattern match excluding non-binaries
171+
if [[ -z "$BIN_PATH" ]]; then
172+
BIN_PATH=$(find . -type f \
173+
! -iname "*.md" ! -iname "*.txt" ! -iname "*.sig" \
174+
! -iname "*.asc" ! -iname "LICENSE*" ! -iname "README*" \
175+
! -iname "CHANGELOG*" ! -iname "*.sha*" ! -iname "*.sum" \
176+
2>/dev/null | grep -i "$PROG" | head -n 1)
177+
fi
178+
179+
# Strategy 3: If still not found, use largest file (likely the binary)
180+
if [[ -z "$BIN_PATH" ]]; then
181+
BIN_PATH=$(find . -type f \
182+
! -iname "*.md" ! -iname "*.txt" ! -iname "*.sig" \
183+
! -iname "*.asc" ! -iname "LICENSE*" ! -iname "README*" \
184+
! -iname "CHANGELOG*" ! -iname "*.sha*" ! -iname "*.sum" \
185+
2>/dev/null | xargs du 2>/dev/null | sort -n | tail -n 1 | cut -f 2)
186+
fi
187+
188+
[[ -z "$BIN_PATH" ]] && fail "Binary $PROG not found"
189+
190+
# Verify it's likely a binary (size check)
191+
if [[ $(du -k "$BIN_PATH" 2>/dev/null | cut -f1) -lt 10 ]]; then
192+
fail "Found file $BIN_PATH but it's too small (<10KB) to be a valid binary"
193+
fi
159194

160195
chmod +x "$BIN_PATH" || fail "chmod +x failed on $BIN_PATH"
161196
DEST="$OUT_DIR/$PROG"

handler/install.sh.qtpl.go

Lines changed: 50 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)