From 4c80999e6de1da3c5e535ef1126aa41a6f5d303a Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Sun, 9 Feb 2014 00:31:13 +0100 Subject: [PATCH] started a function library for bash --- bashlib/bashlib.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 bashlib/bashlib.sh diff --git a/bashlib/bashlib.sh b/bashlib/bashlib.sh new file mode 100755 index 0000000..cc815b5 --- /dev/null +++ b/bashlib/bashlib.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +function onOSX () { + return [[ $(uname) == "Darwin" ]] +} + +function findLocalService () { + + local SVC="$1" + + if onOSX; then + local OUT="$( + echo -e "spawn -noecho dns-sd -Z $SVC\nexpect -timeout 1 eof {}" | + expect -f - | + grep SRV | egrep -v '^\s*;' + )" + local PORT="$(echo $OUT | awk '{print $5}')" + local HOST="$(echo $OUT | awk '{print $6}')" + else + # linux only for now + local OUT="$(avahi-browse -p -t -r $SVC | grep '^=' | head -1)" + local NAME="$(echo \"$AL\" | cut -d';' -f 8)" + local PORT="$(echo \"$AL\" | cut -d';' -f 9)" + fi + + echo $HOST:$PORT +}