From 8de1992e1a5b7c37a04b511d641aebe38858a338 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 5 May 2019 20:42:28 -0400 Subject: [PATCH] add support for wndr3700 style power switch --- README | 2 +- libremanage | 59 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/README b/README index 5a866d9..0bdf655 100644 --- 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. diff --git a/libremanage b/libremanage index bbc3ff2..3bb2c62 100755 --- a/libremanage +++ b/libremanage @@ -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 -- 2.25.1