3 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
7 Usage: relay-cmd poweroff|poweron|reboot HOSTNAME|CHANNEL [RELAY_ID]
9 For CHANNEL and RELAY_ID, run hidusb-relay-cmd and hidusb-relay-cmd state.
10 I recommend writing a config to use HOSTNAME instead. Config is /etc/relay-cmd.conf
13 # This config is just bash that gets sourced.
14 # relay_id is not needed if only 1 relay is connected.
16 cephserver3_relay_id=HURTM
26 read action chan relay_id
<<<"$@"
28 if [[ -e /etc
/relay-cmd.conf
]]; then
29 source /etc
/relay-cmd.conf
32 if [[ $chan != [0-9]* ]]; then
33 chan_var
=${chan}_channel
35 if [[ ! $chan ]]; then
36 echo "error: channel not found in /etc/relay-cmd.conf" >&2
39 if [[ ! $relay_id ]]; then
40 relay_id_var
=${chan}_relay_id
41 relay
=${!relay_id_var}
46 if hidusb-relay-cmd state |
grep ON
; then
47 printf "%s\n" "WARNING: output from hidusb-relay-cmd state shows an ON relay. this could mean another command instance is running, or it got stuck on due to an uncompleted command." >&2
51 case $
(hidusb-relay-cmd state|
wc -l) in
53 echo "error: got 0 lines from running hidusb-relay-cmd state" >&2
58 if [[ ! $relay_id ]]; then
59 echo "error: more than 1 relay device, so passing its id is required" >&2
66 if [[ $relay_id ]]; then
67 # leave this as an empty var if its not passed
68 relay_id_arg
="id=$relay_id"
78 # ignore hup so we complete even if there is a connection problem.
80 echo "$0: doing $action. shell commands are printed to the terminal:"
83 v hidusb-relay-cmd
$relay_id_arg on
$chan
85 v hidusb-relay-cmd
$relay_id_arg off
$chan
88 v hidusb-relay-cmd
$relay_id_arg on
$chan
90 v hidusb-relay-cmd
$relay_id_arg off
$chan
93 v hidusb-relay-cmd
$relay_id_arg on
$chan
95 v hidusb-relay-cmd
$relay_id_arg off
$chan
97 v hidusb-relay-cmd
$relay_id_arg on
$chan
99 v hidusb-relay-cmd
$relay_id_arg off
$chan
102 echo "error: action arg not supported" >&2
105 echo "$0: script ended. exiting"