Show each device checked during Ollama scan; prompt user if not found

This commit is contained in:
cediackermann 2026-04-24 11:16:21 +02:00
parent 61a054f376
commit 9fa3efacf6

View file

@ -78,19 +78,23 @@ detect_ollama_host() {
local ARP_IPS
ARP_IPS=$(arp -a 2>/dev/null | grep -v incomplete | grep -oE '\(([0-9]{1,3}\.){3}[0-9]{1,3}\)' | tr -d '()')
if [ -z "$ARP_IPS" ]; then
echo ""
return
fi
echo "" >&2
print_warning "No devices found in ARP table." >&2
else
local COUNT
COUNT=$(echo "$ARP_IPS" | wc -l | tr -d ' ')
echo "" >&2
print_warning "Scanning $COUNT network devices for Ollama (port 11434)..." >&2
print_warning "Ollama not found locally — checking $(echo "$ARP_IPS" | wc -l | tr -d ' ') network devices in parallel..."
# Check all ARP devices for port 11434 simultaneously
local TMPFILE
TMPFILE=$(mktemp)
while IFS= read -r ip; do
echo -e " ${BLUE}${NC} Checking $ip..." >&2
( nc -z -w 1 "$ip" 11434 2>/dev/null && echo "$ip" >> "$TMPFILE" ) &
done <<< "$ARP_IPS"
wait
local FOUND=()
while IFS= read -r ip; do
FOUND+=("$ip")
@ -99,6 +103,7 @@ detect_ollama_host() {
if [ ${#FOUND[@]} -eq 1 ]; then
echo "${FOUND[0]}"
return
elif [ ${#FOUND[@]} -gt 1 ]; then
echo "" >&2
print_warning "Multiple hosts with Ollama found:" >&2
@ -106,11 +111,19 @@ detect_ollama_host() {
echo " $((i+1))) ${FOUND[$i]}" >&2
done
echo "" >&2
read -p "Select the Ollama host (1-${#FOUND[@]}): " pick >&2
read -p "Select the Ollama host (1-${#FOUND[@]}): " pick <&2
echo "${FOUND[$((pick-1))]}"
else
echo ""
return
fi
echo "" >&2
print_warning "Ollama not found on any network device." >&2
fi
# Nothing found — ask the user directly
echo "" >&2
read -p "Enter the IP address of the Ollama device: " manual_ip <&2
echo "$manual_ip"
}
# ---------------------------------------------------------------------------
@ -141,11 +154,6 @@ else
print_warning "Detecting Ollama host..."
OLLAMA_HOST=$(detect_ollama_host)
if [ -z "$OLLAMA_HOST" ]; then
print_warning "Could not detect Ollama automatically."
read -p "Enter the IP address or hostname of the Ollama device: " OLLAMA_HOST
fi
if [ "$OLLAMA_HOST" = "host.docker.internal" ]; then
print_success "Ollama detected on this machine (single-device mode)"
else