Commit | Line | Data |
---|---|---|
e77d763c DO |
1 | #!/bin/sh |
2 | ||
3 | # This is a RackTables gateway for arbitrary file export. File contents doesn't | |
4 | # matter here and will only be somehow sent to the remote host for further | |
5 | # processing. | |
6 | # | |
7 | # The only supported command is: | |
8 | # | |
1ee5488d | 9 | # * submit <username> <endpoint> <handler name> [filename1] [filename2] [...] |
e77d763c DO |
10 | # |
11 | # Handler name can be any string used to distinguish different file processors. | |
12 | # The temporary file will be passed to a script in current directory, if it exists. | |
13 | # Script name is "<handlername>.install" | |
14 | ||
15 | user= | |
16 | endpoint= | |
17 | cfgfile= | |
18 | MYDIR=`dirname $0` | |
19 | ||
20 | do_submit() | |
21 | { | |
f3d274bf DO |
22 | user=$1 |
23 | endpoint=$2 | |
24 | handler=$3 | |
1ee5488d DO |
25 | # 0 or more files |
26 | files=$4 | |
e77d763c | 27 | # sanity checks |
1ee5488d | 28 | if [ -z "$user" -o -z "$endpoint" -o -z "$handler" ]; then |
e77d763c DO |
29 | echo 'ERR!invalid arguments' |
30 | return | |
31 | fi | |
1ee5488d DO |
32 | for cfgfile in $files; do |
33 | if [ ! -f "$cfgfile" ]; then | |
34 | echo "ERR!File $cfgfile is missing." | |
35 | return | |
36 | fi | |
37 | done | |
e77d763c DO |
38 | if [ ! -x "$MYDIR/$handler.install" ]; then |
39 | echo "ERR!Cannot execute $MYDIR/$handler.install" | |
40 | return | |
41 | fi | |
1ee5488d | 42 | "$MYDIR/$handler.install" "$user" "$endpoint" $files |
e77d763c DO |
43 | ret=$? |
44 | if [ $ret = 0 ]; then | |
03e6ef01 | 45 | echo "OK!" |
e77d763c | 46 | else |
9bc28e53 | 47 | echo "ERR!Main dispatcher: handler '$handler' returned code $ret" |
e77d763c DO |
48 | fi |
49 | } | |
50 | ||
51 | # main loop | |
f3d274bf | 52 | while read cmd arg1 arg2 arg3 arg4; do |
e77d763c DO |
53 | case $cmd in |
54 | submit) | |
f3d274bf | 55 | do_submit "$arg1" "$arg2" "$arg3" "$arg4" |
e77d763c DO |
56 | ;; |
57 | *) | |
58 | echo "ERR!unknown command $cmd" | |
59 | esac | |
60 | done | |
61 | ||
62 | exit 0 |