aboutsummaryrefslogtreecommitdiffstats
path: root/radio.sh
blob: d475ce4690bfd89644795ee44bf61df8725f9fb2 (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
48
49
50
51
52
#!/bin/bash
#
# Start the encoder for the radio

# Declare radios to be an associative array
declare -A radios

source site/configuration.sh

printerr() {
    echo -e "\033[01;31m$1\033[0m"
}

printmsg() {
    echo -e "\033[01;32m$1\033[0m"
}

script_pid=0
sigint_trap() {
    printerr "Got Ctrl-C, killing radio encoder script"
    if [[ "$script_pid" != "0" ]] ; then
        kill $script_pid
        script_pid=0
        wait
    fi
}

set -e

# check number of arguments
if [[ "$#" < 1 ]] ; then
    echo "Usage $0 radio-id"
    echo "You must specify which radio to start"
    exit 1
fi

RADIO=$1

if [ ${radios[$RADIO]+_} ] ; then
    COMMAND=${radios[$RADIO]}

    trap sigint_trap SIGINT

    # execute script
    $COMMAND &
    script_pid=$!
    wait
else
    echo "Radio $RADIO not defined in configuration"
    exit 1
fi