Browse Source

started a function library for bash

pull/1/head
Jeffrey Paul 7 years ago
parent
commit
4c80999e6d
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      bashlib/bashlib.sh

+ 29
- 0
bashlib/bashlib.sh View File

@@ -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
}

Loading…
Cancel
Save