-Move libremanage to your path and add a configuration. See the USAGE which will
-pop up if you make a mistake!
+Run hidusb-relay-cmd-setup.
+
+relay-cmd is a very simple command to use the relay.
+
+libremanage is an overly complicated command. It requires a
+configuration. See the USAGE which will pop up if you make a mistake!
TODO
* IMPORTANT: libremanage right now does ssh relay command 1; sleep; ssh
--- /dev/null
+#!/bin/bash
+
+# usage: relay-cmd poweroff|poweron|reboot chan [relay_id]
+# relay_id not required if there is only one relay.
+
+if hidusb-relay-cmd state | grep ON; then
+ 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
+fi
+
+read action chan relay_id <<<"$@"
+
+case $(hidusb-relay-cmd state|wc -l) in
+ 0)
+ echo "error: got 0 lines from running hidusb-relay-cmd state" >&2
+ exit 1
+ ;;
+ 1) : ;;
+ *) if [[ ! $relay_id ]]; then
+ echo "error: more than 1 relay device, so passing its id is required" >&2
+ exit 1
+ fi
+ ;;
+esac
+
+if [[ $relay_id ]]; then
+ # leave this as an empty var if its not passed
+ relay_id_arg="id=$relay_id"
+fi
+
+# ignore hup so we complete
+trap '' HUP
+case $action in
+ poweroff)
+ hidusb-relay-cmd $relay_id_arg on $chan
+ sleep 6
+ hidusb-relay-cmd $relay_id_arg off $chan
+ ;;
+ poweron)
+ hidusb-relay-cmd $relay_id_arg on $chan
+ sleep 1
+ hidusb-relay-cmd $relay_id_arg off $chan
+ ;;
+ reboot)
+ hidusb-relay-cmd $relay_id_arg on $chan
+ sleep 6
+ hidusb-relay-cmd $relay_id_arg off $chan
+ sleep 1
+ hidusb-relay-cmd $relay_id_arg on $chan
+ sleep 1
+ hidusb-relay-cmd $relay_id_arg off $chan
+ ;;
+ *)
+ echo "error: action arg not supported" >&2
+ exit 1
+esac