r3755 setDevice8021QConfig(): move push translators map to top level
[racktables] / gateways / deviceconfig / fdry5.connector
CommitLineData
737e04fc
DO
1#!/bin/sh
2
a1be4d75 3[ $# = 3 ] || exit 1
737e04fc
DO
4
5ENDPOINT=$1
a1be4d75
DO
6COMMAND=$2
7WORKFILE=$3
737e04fc
DO
8
9prepare_connect_commands()
10{
11 [ $# = 1 ] || exit 2
12 local skip=yes cval found=no MYDIR=`dirname $0`
13 while read line; do
14 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
15 skip=no
16 continue
17 fi
18 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
19 skip=yes
20 continue
21 fi
22 [ "$skip" = "yes" ] && continue
23 # ignore comments
24 [ -z "${line###*}" ] && continue
25
26 # First endpoint string/regexp match is sufficient for us.
27 cval=`echo $line | cut -s -d' ' -f1`
28 if [ -z "${1##$cval}" ]; then
29 found=yes
30 username=`echo $line | cut -s -d' ' -f5`
a1be4d75 31 [ "$username" != "-" ] && echo $username > "$SESSION"
737e04fc
DO
32 # access password
33 access_password=`echo $line | cut -s -d' ' -f6`
a1be4d75
DO
34 [ "$access_password" != "-" ] && echo "$access_password" >> "$SESSION"
35 printf "en\r\n" >> "$SESSION"
737e04fc 36 enable_password=`echo $line | cut -s -d' ' -f7`
a1be4d75 37 [ "$enable_password" != "-" ] && echo $enable_password >> "$SESSION"
737e04fc
DO
38 break
39 fi
0f86f02c 40 done < "$MYDIR/switch.secrets.php"
737e04fc
DO
41 [ "$found" = "yes" ] && return
42 exit 3
43}
44
a1be4d75
DO
45SESSION=`mktemp /tmp/fdry5.connector.XXXX`
46[ -f "$SESSION" ] || exit 5
737e04fc 47prepare_connect_commands $ENDPOINT
a1be4d75 48case $COMMAND in
db64180c 49get8021q)
a1be4d75
DO
50 printf 'skip-page-display\r\nshow running-config\r\n' >> "$SESSION"
51 outfile="$WORKFILE"
52 ;;
53deploy)
54 cat "$WORKFILE" >> "$SESSION"
55 outfile=/dev/null
56 ;;
57*)
58 outfile=/dev/null
59esac
60printf 'exit\r\nexit\r\n' >> "$SESSION"
28051ccc 61nc -w 30 -i 1 $ENDPOINT 23 < "$SESSION" > "$outfile"
a1be4d75 62rm -f "$SESSION"
737e04fc 63exit 0