blob: 5983a11f9b2502b3bfb8f33dd22ac2411e59d73b [file] [log] [blame]
#!/bin/selfclean sh
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <remoteip | --use-storage-box> <isostream options...>" >&2
echo ' $ISOSTREAM_DISABLE_IF_PORT: if set, stops automatically if the' >&2
echo " given port is in use." >&2
exit 99
fi
xport_is_open() {
[ -n "$ISOSTREAM_DISABLE_IF_PORT" ] &&
[ "$ISOSTREAM_DISABLE_IF_PORT" != "0" ] &&
netstat -an | grep -q ":$ISOSTREAM_DISABLE_IF_PORT .*ESTABLISHED"
}
(
(
remote=$1
shift
if [ "$remote" = "--use-storage-box" ]; then
remote=
STORAGE_BOX_NAME=gfiberstorage.local
echo "$0: use-storage-box: trying to find server: $STORAGE_BOX_NAME" >&2
while [ -z "$remote" ]; do
out=$(avahi-resolve -6n "$STORAGE_BOX_NAME")
if [ "$?" -ne "0" ]; then
sleep 1
elif [ -z "$out" ]; then
sleep 1
else
remote=$(echo "$out" | head -n 1 | cut -f 2)
fi
done
echo "$0: use-storage-box: found a server: $remote" >&2
fi
pid=
while :; do
if xport_is_open; then
if [ -n "$pid" ]; then
echo "pausing test because port $ISOSTREAM_DISABLE_IF_PORT open" >&2
kill -15 "$pid"
pid=
fi
else
if [ -z "$pid" ]; then
echo "Starting: isostream $* '$remote'" >&2
isostream "$@" "$remote" &
pid=$!
fi
fi
sleep 1
done
) 2>&1 | tee /proc/self/fd/5 | logos isostream # Send output to isostream, and also fd #5 so it ends up back on stdout
) 5>&1 # make fd #5 a copy of the original stdout