add support for wndr3700 style power switch
authorIan Kelling <iank@fsf.org>
Mon, 6 May 2019 00:42:28 +0000 (20:42 -0400)
committerIan Kelling <iank@fsf.org>
Mon, 6 May 2019 00:42:28 +0000 (20:42 -0400)
README
libremanage

diff --git a/README b/README
index 5a866d974d2394fb2d616b381489061974945bcb..0bdf655a4d71f7831700a0a39591cbbbdc56d43d 100644 (file)
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ GNUtoo has been working on a similar setup. see
 https://wiki.parabola.nu/Standalone_BMC. fsf sysadmins, see rt 1346340
 for further development ideas.
 
- Ian Kelling also has a package for openwrt, not yet published.  Ask him
+Ian Kelling also has a package for librecmc, not yet published.  Ask him
 if you are interested.
 
 
index bbc3ff235c1c7a668d8fc7e551d5431022b87d69..3bb2c629302bc3efc554727929d0193ebd06b110 100755 (executable)
@@ -33,7 +33,7 @@ setting up a new device.
 
 
 
-Advanced Usage: libremanage poweroff|poweron|reboot HOSTNAME|CHANNEL [BOARD_ID]
+Advanced Usage: libremanage [--switch] poweroff|poweron|reboot HOSTNAME|CHANNEL [BOARD_ID]
 
 Note, the relay's channels default state when plugged in are off.
 
@@ -44,10 +44,20 @@ cephserver3_channel=1
 cephserver3_board_id=HURTM
 cephserver2_channel=2
 cephserver2_board_id=HURTM
+
+librecmc1_type=switch
+cephserver2_type=button # default
+
 # end of config
 
 
-libremanage reboot cephserver3
+Example use:
+
+$ libremanage reboot cephserver3
+
+--switch means means that the relay controls on an on/off switch (with
+default on), instead of a pc power button, which is the default. This
+corresponds to the config option HOST_type=switch.
 
 BOARD_ID is not needed if only 1 relay device is connected, or if it is
 defined in the config. To understand CHANNEL and BOARD_ID, run
@@ -79,6 +89,11 @@ if (( $# < 2 )); then
   usage
 fi
 
+switch=false
+if [[ $1 == --switch ]]; then
+  switch=true
+fi
+
 read action chan board_id  <<<"$@"
 
 if [[ -e /etc/libremanage.conf ]]; then
@@ -137,23 +152,37 @@ trap '' HUP INT QUIT TERM
 echo "$0: doing $action. shell commands will be printed to the terminal."
 case $action in
   poweroff)
-    v hidusb-relay-cmd $board_id_arg on $chan
-    v sleep 6
-    v hidusb-relay-cmd $board_id_arg off $chan
+    if $switch; then
+      v hidusb-relay-cmd $board_id_arg off $chan
+    else
+      v hidusb-relay-cmd $board_id_arg on $chan
+      v sleep 6
+      v hidusb-relay-cmd $board_id_arg off $chan
+    fi
     ;;
   poweron)
-    v hidusb-relay-cmd $board_id_arg on $chan
-    v sleep 1
-    v hidusb-relay-cmd $board_id_arg off $chan
+    if $switch; then
+      v hidusb-relay-cmd $board_id_arg on $chan
+    else
+      v hidusb-relay-cmd $board_id_arg on $chan
+      v sleep 1
+      v hidusb-relay-cmd $board_id_arg off $chan
+    fi
     ;;
   reboot)
-    v hidusb-relay-cmd $board_id_arg on $chan
-    v sleep 6
-    v hidusb-relay-cmd $board_id_arg off $chan
-    v sleep 1
-    v hidusb-relay-cmd $board_id_arg on $chan
-    v sleep 1
-    v hidusb-relay-cmd $board_id_arg off $chan
+    if $switch; then
+      v hidusb-relay-cmd $board_id_arg off $chan
+      v sleep 4
+      v hidusb-relay-cmd $board_id_arg on $chan
+    else
+      v hidusb-relay-cmd $board_id_arg on $chan
+      v sleep 6
+      v hidusb-relay-cmd $board_id_arg off $chan
+      v sleep 1
+      v hidusb-relay-cmd $board_id_arg on $chan
+      v sleep 1
+      v hidusb-relay-cmd $board_id_arg off $chan
+    fi
     ;;
   *)
     echo "error: action arg not supported" >&2