#!/bin/sh
#
# use avahi to find a _apt_proxy._tcp provider and return
# a http proxy string suitable for apt

SERVICE="_apt_proxy._tcp"

out=$(avahi-browse -kprt $SERVICE|grep '^=;.*;IPv4;.*'|head -n1)
PORT=$(echo "$out" | cut -d ';' -f9)
HOST=$(echo "$out" | cut -d ';' -f7)
IP=$(avahi-resolve -n4 "$HOST" | cut -f2)
echo "http://$IP:$PORT/"
