First support PL2303-HXD GPIO 2 & 3
[pub/pl2303-ft232-gpio.git] / extra / serverctl
1 #!/bin/sh
2 #Usage: serverctl action [servername] [minicom args]
3
4
5 DEVDIR=/sys/bus/usb/devices/
6 DELAY=2500
7 list_servers() {
8 ls $DEVDIR | while read line; do
9 if [ "`ls ${DEVDIR}/${line}/|grep tty|wc -l`" != "0" ]; then
10 tty="`ls ${DEVDIR}/${line}/|grep tty`"
11 base="`echo $line|cut -f1 -d:`"
12 m="`cat ${DEVDIR}/${base}/manufacturer`"
13 p="`cat ${DEVDIR}/${base}/product`"
14 s="`cat ${DEVDIR}/${base}/serial`"
15 echo "$line;$base;$tty;$m;$p;$s"
16 fi
17 done
18 }
19
20 action=$1
21 node=$2
22
23 check_node() {
24 if [ "`list_servers|grep $node|wc -l`" -eq "0" ]; then
25 echo "No such node: $node"
26 exit 1
27 fi
28 }
29
30 case $action in
31 "list")
32 list_servers|while read line; do
33 echo $line|awk -F";" '{print "/dev/"$3": "$4" "$5" "$6 }'
34 done
35 ;;
36 "reboot")
37 check_node
38 cp2103gpio --serial=$node --gpio=3 --out=0 --sleep $DELAY --out=1
39 ;;
40 "off")
41 check_node
42 cp2103gpio --serial=$node --gpio=3 --out=0
43 ;;
44 "on")
45 check_node
46 cp2103gpio --serial=$node --gpio=3 --out=0
47 ;;
48 "term")
49 check_node
50 shift
51 shift
52 miniargs=$*
53 [ -z "$*" ] && miniargs="-b 115200"
54 tty=/dev/`list_servers|grep $node|cut -d";" -f3`
55 minicom -o -D $tty $miniargs
56 ;;
57 *)
58 echo "Server control utility"
59 echo "Usage: $0 action node"
60 echo "Valid actions are: "
61 echo " list"
62 echo " reboot"
63 echo " on"
64 echo " off"
65 echo " term"
66 ;;
67 esac