@@ -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"
0 commit comments