r2098 + initial router management prototype
[racktables] / gateways / rtrconfig / main
1 #!/bin/sh
2
3 # This is a RackTables gateway for router configuration export. The configuration
4 # is fed in arbitrary format and should only be somehow sent to the remote host
5 # for further processing. This is a quick hack and should be replaced with a
6 # generic file sender gateway in future.
7 #
8 # The only supported command is:
9 #
10 # * submit <username> <endpoint> <filename>: send the file
11 #
12
13 user=
14 endpoint=
15 cfgfile=
16 MYDIR=`dirname $0`
17
18 do_submit()
19 {
20 user=`echo $args | cut -s -d' ' -f1`
21 endpoint=`echo $args | cut -s -d' ' -f2`
22 cfgfile=`echo $args | cut -s -d' ' -f3`
23 # sanity checks
24 if [ -z "$user" -o -z "$endpoint" -o -z "$cfgfile" ]; then
25 echo 'ERR!invalid arguments'
26 return
27 fi
28 if [ ! -s "$cfgfile" ]; then
29 echo "ERR!File $cfgfile is either missing or empty."
30 return
31 fi
32 if [ ! -x "$MYDIR/install" ]; then
33 echo "ERR!Cannot execute $MYDIR/install"
34 return
35 fi
36 "$MYDIR/install" $user $endpoint $cfgfile
37 ret=$?
38 if [ $ret = 0 ]; then
39 echo "OK!File sent successfully"
40 else
41 echo "ERR!File installer returned code $ret"
42 fi
43 }
44
45 # main loop
46 while read cmd args; do
47 case $cmd in
48 submit)
49 do_submit $args
50 ;;
51 *)
52 echo "ERR!unknown command $cmd"
53 esac
54 done
55
56 exit 0