aboutsummaryrefslogtreecommitdiffstats
path: root/teaqueue-client
blob: c52d01e301bf65f6eba985c0a422ee94ed2c2a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

set -eu

# default options
host="127.0.0.1"
port=1340
retry_timeout=10

usage()
{
    cat <<EOF
Usage: $0 [OPTIONS...] command [args...]

Connects to a teaqueue-server and call "command" with a line in stdin.

Options:
  -h, --help   show usage
  -H, --host   what teaqueue-server host (default: 127.0.0.1)
  -p, --port   what port to use (default: 1340)
EOF
}

# arg parsing
TEMP=$(getopt -o hH:p: --long help,host,port -n teaqueue-client -- "$@")
if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
eval set -- "$TEMP"
while true; do
    case "$1" in
        -h|--help) usage; exit 0;;
        -H|--host) host="$2"; shift 2;;
        -p|--port) port="$2"; shift 2;;
        --) shift; break;;
        *) echo "Arguments parsing error" >&2; exit 1;;
    esac
done

if test $# -lt 1; then
    echo "You must put a command to call" >&2; exit 1
fi

set +e

while true; do
    while ! nc -q0 "$host" "$port"; do sleep $retry_timeout; done | "$@"
    sleep 1
done