Commit | Line | Data |
---|---|---|
b3999d7b DO |
1 | #!/bin/sh |
2 | ||
3 | [ $# = 3 ] || exit 1 | |
4 | ||
5 | ENDPOINT=$1 | |
6 | COMMAND=$2 | |
7 | WORKFILE=$3 | |
8 | ||
9 | prepare_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` | |
31 | [ "$username" != "-" ] && echo $username > "$SESSION" | |
32 | # access password | |
33 | access_password=`echo $line | cut -s -d' ' -f6` | |
34 | [ "$access_password" != "-" ] && echo "$access_password" >> "$SESSION" | |
35 | printf "super\n" >> "$SESSION" | |
36 | enable_password=`echo $line | cut -s -d' ' -f7` | |
37 | [ "$enable_password" != "-" ] && echo $enable_password >> "$SESSION" | |
38 | break | |
39 | fi | |
40 | done < "$MYDIR/switch.secrets.php" | |
41 | [ "$found" = "yes" ] && return | |
42 | exit 3 | |
43 | } | |
44 | ||
a97fb347 DO |
45 | MYNAME=`basename $0` |
46 | SESSION=`mktemp /tmp/$MYNAME.XXXX` | |
b3999d7b DO |
47 | [ -f "$SESSION" ] || exit 5 |
48 | prepare_connect_commands $ENDPOINT | |
49 | case $COMMAND in | |
50 | retrieve) | |
51 | printf 'display current-configuration\n' >> "$SESSION" | |
52 | outfile="$WORKFILE" | |
53 | ;; | |
54 | deploy) | |
55 | cat "$WORKFILE" >> "$SESSION" | |
c150f1db | 56 | outfile=/dev/null |
b3999d7b DO |
57 | ;; |
58 | *) | |
59 | outfile=/dev/null | |
60 | esac | |
61 | printf 'quit\n' >> "$SESSION" | |
a97fb347 | 62 | nc $ENDPOINT 23 < "$SESSION" > "$outfile" |
b3999d7b DO |
63 | rm -f "$SESSION" |
64 | exit 0 |