Show each device checked during Ollama scan; prompt user if not found
This commit is contained in:
parent
61a054f376
commit
9fa3efacf6
1 changed files with 43 additions and 35 deletions
|
|
@ -78,19 +78,23 @@ detect_ollama_host() {
|
||||||
local ARP_IPS
|
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 '()')
|
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
|
if [ -z "$ARP_IPS" ]; then
|
||||||
echo ""
|
echo "" >&2
|
||||||
return
|
print_warning "No devices found in ARP table." >&2
|
||||||
fi
|
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
|
local TMPFILE
|
||||||
TMPFILE=$(mktemp)
|
TMPFILE=$(mktemp)
|
||||||
|
|
||||||
while IFS= read -r ip; do
|
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" ) &
|
( nc -z -w 1 "$ip" 11434 2>/dev/null && echo "$ip" >> "$TMPFILE" ) &
|
||||||
done <<< "$ARP_IPS"
|
done <<< "$ARP_IPS"
|
||||||
wait
|
wait
|
||||||
|
|
||||||
local FOUND=()
|
local FOUND=()
|
||||||
while IFS= read -r ip; do
|
while IFS= read -r ip; do
|
||||||
FOUND+=("$ip")
|
FOUND+=("$ip")
|
||||||
|
|
@ -99,6 +103,7 @@ detect_ollama_host() {
|
||||||
|
|
||||||
if [ ${#FOUND[@]} -eq 1 ]; then
|
if [ ${#FOUND[@]} -eq 1 ]; then
|
||||||
echo "${FOUND[0]}"
|
echo "${FOUND[0]}"
|
||||||
|
return
|
||||||
elif [ ${#FOUND[@]} -gt 1 ]; then
|
elif [ ${#FOUND[@]} -gt 1 ]; then
|
||||||
echo "" >&2
|
echo "" >&2
|
||||||
print_warning "Multiple hosts with Ollama found:" >&2
|
print_warning "Multiple hosts with Ollama found:" >&2
|
||||||
|
|
@ -106,11 +111,19 @@ detect_ollama_host() {
|
||||||
echo " $((i+1))) ${FOUND[$i]}" >&2
|
echo " $((i+1))) ${FOUND[$i]}" >&2
|
||||||
done
|
done
|
||||||
echo "" >&2
|
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))]}"
|
echo "${FOUND[$((pick-1))]}"
|
||||||
else
|
return
|
||||||
echo ""
|
|
||||||
fi
|
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..."
|
print_warning "Detecting Ollama host..."
|
||||||
OLLAMA_HOST=$(detect_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
|
if [ "$OLLAMA_HOST" = "host.docker.internal" ]; then
|
||||||
print_success "Ollama detected on this machine (single-device mode)"
|
print_success "Ollama detected on this machine (single-device mode)"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue