From: Ian Kelling Date: Mon, 6 May 2019 16:49:32 +0000 (-0400) Subject: fixes for switch type X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ef3ced5365c37d338879bc6cfd3db326aa707bd0;p=libremanage.git fixes for switch type --- diff --git a/libremanage b/libremanage index e34fc97..5994e16 100755 --- a/libremanage +++ b/libremanage @@ -85,9 +85,6 @@ EOF } -if (( $# < 2 )); then - usage -fi switch=false if [[ $1 == --switch ]]; then @@ -95,7 +92,11 @@ if [[ $1 == --switch ]]; then shift fi -read action chan board_id <<<"$@" +if (( $# < 2 )); then + usage +fi + +read action hostchan board_id <<<"$@" if [[ -e /etc/libremanage.conf ]]; then source /etc/libremanage.conf @@ -103,24 +104,46 @@ fi # Use config vars when appropriate. We know the arg is a HOSTNAME if it # doesn't start with a number. -if [[ $chan != [0-9]* ]]; then - if [[ ! $board_id ]]; then - board_id_var=${chan}_board_id - board_id=${!board_id_var} - fi - chan_var=${chan}_channel - chan=${!chan_var} +case $hostchan in + [0-9]*) + chan=$hostchan + ;; + *) - if [[ ! $chan ]]; then - echo "error: channel not found in /etc/libremanage.conf" >&2 - exit 1 - fi -fi + # allow board_id to be empty if its unset + if [[ ! $board_id ]]; then + board_id_var=${hostchan}_board_id + board_id=${!board_id_var} + fi + + chan_var=${hostchan}_channel + chan=${!chan_var} + if [[ ! $chan ]]; then + echo "error: channel not set on cli and not found in /etc/libremanage.conf" >&2 + exit 1 + fi + + type_var=${hostchan}_type + type=${!type_var} + if [[ $type == switch ]]; then + switch=true + fi + ;; +esac -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 - # TODO: exit in this case and print out the command to turn it off. +if ! $switch && hidusb-relay-cmd state | grep -F R$CHAN=ON; then + cat >&2 <