-
Notifications
You must be signed in to change notification settings - Fork 1
/
frequest
executable file
·127 lines (104 loc) · 2.42 KB
/
frequest
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
#!/bin/bash
#
# frequest v1.03
# (c) 2012-2017 by Markus Reschke
# Create or update a request file for a FTS system
#
# Supported outbound format (binkley style):
# - out/NNNNnnnn.req
# - out.ZZZ/NNNNnnnn.req
# - out/NNNNnnnn.pnt/0000PPPP.req
# - out.ZZZ/NNNNnnnn.pnt/0000PPPP.req
#
# 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: frequest files from 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 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 REQ file path
if [ "$POINT" == "" ] || [ "$POINT" == "0" ]; then
# node
REQ_FILE=`printf "%04x%04x.req" $NET $NODE`
REQ_DIR="$OUTBOUND"
else
# point
REQ_FILE=`printf "0000%04x.req" $POINT`
REQ_DIR="$OUTBOUND"/`printf "%04x%04x.pnt" $NET $NODE`
fi
REQ_FILEPATH="$REQ_DIR"/"$REQ_FILE"
# create zone based outbound if required
if [ ! -d "$OUTBOUND" ]; then
mkdir "$OUTBOUND"
fi
# create REQ path if required
if [ ! -d "$REQ_DIR" ]; then
mkdir "$REQ_DIR"
fi
# tell user
if [ -r "$REQ_FILEPATH" ]; then
echo "Adding files for $ADDRESS:"
else
echo "Creating new request file for $ADDRESS:"
fi
# add files to request file
shift
while [ "$1" ]
do
echo "$1" >> "$REQ_FILEPATH"
echo "- $1"
shift
done
# trigger call
CONTROL=`printf "%04x%04x.ilo" $NET $NODE`
# create control file if there is none yet
if [ ! -f "$REQ_DIR/$CONTROL" ]; then
echo "" > "$REQ_DIR/$CONTROL"
fi
# successful end
STAT=0