-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendfile
executable file
·136 lines (104 loc) · 2.37 KB
/
sendfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# sendfile v1.03
# (c) 2012-2017 by Markus Reschke
# Create or update a FLO file for a FTS system.
#
# Supported outbound format (binkley style):
# - out/NNNNnnnn.flo
# - out.ZZZ/NNNNnnnn.flo
# - out/NNNNnnnn.pnt/0000PPPP.flo
# - out.ZZZ/NNNNnnnn.pnt/0000PPPP.flo
#
# Z = zone number in hex
# N = net number in hex
# n = node number in hex
# P = point number in hex
#
# script control
STAT=1
trap 'exit $STAT' 0 1 2 15
# global settings/variables
OUTBOUND="/var/spool/outbound"
MY_ZONE="2"
#
# main
#
# usage
case "$*" in
"") echo "Purpose: send files to a FTS system";
echo "Usage: `basename $0` <FTS address> <filename> [more filenames]";
exit;;
esac
# check if we got all required options
ADDRESS="$1"
FILENAME="$2"
if [ ! "$ADDRESS" ]; then
echo "Missing FTS address!"
exit
fi
if [ ! "$FILENAME" ]; then
echo "Missing filename!"
exit
fi
# check for absolute filepath
TEST1=`echo $FILENAME | grep '^/'`
if [ ! "$TEST1" ]; then
echo "Absolute filepath required!"
exit
fi
# check FTS address
TEST1=`echo "$ADDRESS" | grep '^[0-9][0-9]*:[0-9][0-9]*/[0-9][0-9]*\.[0-9][0-9]*$'`
TEST2=`echo "$ADDRESS" | grep '^[0-9][0-9]*:[0-9][0-9]*/[0-9][0-9]*$'`
if [ -z "$TEST1" ] && [ -z "$TEST2" ]; then
echo "Wrong FTS address format!"
exit
fi
# get elements of FTS address
FTS=`echo $ADDRESS | tr '.:/' ' '`
ZONE=`echo "$FTS" | awk '{print $1}'`
NET=`echo "$FTS" | awk '{print $2}'`
NODE=`echo "$FTS" | awk '{print $3}'`
POINT=`echo "$FTS" | awk '{print $4}'`
# zone based outbound
OUTBOUND="$OUTBOUND/out"
if [ "$ZONE" != "$MY_ZONE" ]; then
# add zone
TEMP1=`printf "%03x" $ZONE`
OUTBOUND="$OUTBOUND.$TEMP1"
fi
# create FLO file path
if [ "$POINT" == "" ] || [ "$POINT" == "0" ]; then
# node
FLO_FILE=`printf "%04x%04x.flo" $NET $NODE`
FLO_DIR="$OUTBOUND"
else
# point
FLO_FILE=`printf "0000%04x.flo" $POINT`
FLO_DIR="$OUTBOUND"/`printf "%04x%04x.pnt" $NET $NODE`
fi
FLO_FILEPATH="$FLO_DIR"/"$FLO_FILE"
# create zone based outbound if required
if [ ! -d "$OUTBOUND" ]; then
mkdir "$OUTBOUND"
fi
# create FLO path if required
if [ ! -d "$FLO_DIR" ]; then
mkdir "$FLO_DIR"
fi
# tell user
if [ -r "$FLO_FILEPATH" ]; then
echo "Adding files for $ADDRESS:"
else
echo "Creating new FLO file for $ADDRESS:"
fi
# add files to FLO file
shift
while [ "$1" ]
do
echo "$1" >> "$FLO_FILEPATH"
echo "- $1"
shift
done
# successful end
STAT=0