From: Andrew 'Necromant' Andrianov Date: Fri, 13 Feb 2015 22:08:39 +0000 (+0300) Subject: extra: add serverctl script X-Git-Tag: v0.1~18 X-Git-Url: http://git.linex4red.de/pub/pl2303-ft232-gpio.git/commitdiff_plain/463794aed37e9719bb3d3d8304e6deb354cc68ff extra: add serverctl script Signed-off-by: Andrew 'Necromant' Andrianov --- diff --git a/extra/serverctl b/extra/serverctl new file mode 100755 index 0000000..cb6dd9f --- /dev/null +++ b/extra/serverctl @@ -0,0 +1,67 @@ +#!/bin/bash +#Usage: serverctl action [servername] [minicom args] + + +DEVDIR=/sys/bus/usb/devices/ +DELAY=2500 +list_servers() { + ls $DEVDIR | while read line; do + if [ "`ls ${DEVDIR}/${line}/|grep tty|wc -l`" != "0" ]; then + tty="`ls ${DEVDIR}/${line}/|grep tty`" + base="`echo $line|cut -f1 -d:`" + m="`cat ${DEVDIR}/${base}/manufacturer`" + p="`cat ${DEVDIR}/${base}/product`" + s="`cat ${DEVDIR}/${base}/serial`" + echo "$line;$base;$tty;$m;$p;$s" + fi + done +} + +action=$1 +node=$2 + +check_node() { + if [ "`list_servers|grep $node|wc -l`" -eq "0" ]; then + echo "No such node: $node" + exit 1 + fi +} + +case $action in + "list") + list_servers|while read line; do + echo $line|awk -F";" '{print "/dev/"$3": "$4" "$5" "$6 }' + done + ;; + "reboot") + check_node + cp2103gpio --serial=$node --gpio=3 --out=0 --sleep $DELAY --out=1 + ;; + "off") + check_node + cp2103gpio --serial=$node --gpio=3 --out=0 + ;; + "on") + check_node + cp2103gpio --serial=$node --gpio=3 --out=0 + ;; + "term") + check_node + shift + shift + miniargs=$* + [ -z "$*" ] && miniargs="-b 115200" + tty=/dev/`list_servers|cut -d";" -f3` + minicom -o -D $tty $miniargs + ;; + *) + echo "Server control utility" + echo "Usage: $0 action node" + echo "Valid actions are: " + echo " list" + echo " reboot" + echo " shutdown" + echo " poweron" + echo " term" + ;; +esac