-
Notifications
You must be signed in to change notification settings - Fork 1
/
notice.sh
executable file
·219 lines (188 loc) · 4.45 KB
/
notice.sh
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# vim: ts=2 sw=2
set -e
shopt -s lastpipe
TMP_FILE="/tmp/db-query-notice.txt"
# This script is desinged to send a notice to a trustee based on the record ID.
#default for NODUPDATE
NOUPDATE='0'
function Query_DB {
#Function to query the DB
Query="SELECT Latitude, Longitude, antenna_Height_Meters , ERP, Output_frequency,
REPLACE(Repeater_city, ' ','-') AS City, Repeater_callsign, emission_1, emission_2,
COORDINATED, chan_Size_kHz, record_ID, Service_Ring_km, Interference_Ring_km, adj1_ring_km, adj2_ring_km, modeled, model_Required, model_Name,
CTCSS_IN, CTCSS_OUT, DCS_CODE, Holder_name, Trustee_name, Trustee_email_adddress, County, Repeater_city
FROM filemaker WHERE record_ID = '${RECORD_ID}';"
# echo "$Query"
mysql import -e "$Query" -NB | tr '\t' '|' >"$TMP_FILE"
#cat $TMP_FILE
}
function READ_FILE {
while IFS='|' read -a array
do
#0 Lat | 1 Long | 2 AGL | 3 ERP | 4 Freq | 5 City | 6 call | 7 em1 | 8 em2 | 9 COORDINATED | 10 chan_Size | 11 record_ID
#12 Service_Ring_km | 13 Interference_Ring_km | 14 adj1_ring_km | 15 adj2_ring_km | 16 modeled | 17 model_Required | 18 model_Name
#19 CTCSS_IN | 20 CTCSS_OUT | 21 DCS_CODE | 22 Holder | 23 Trustee | 24 Trustee Email | 25 County | 26 City
LAT="${array[0]}"
LON="${array[1]}"
AGL="${array[2]}"
ERP="${array[3]}"
FREQ="${array[4]}"
CITY="${array[5]}"
CALL="${array[6]}"
EM1="${array[7]}"
EM2="${array[8]}"
if [[ ${array[9]} = 1 ]]
then
COORD="COORDINATED"
else
COORD="UNCOORDINATED"
fi
CHAN_SIZE="${array[10]}"
ID="${array[11]}"
SVC_RING="${array[12]}"
INT_RING="${array[13]}"
ADJ1_RING="${array[14]}"
ADJ2_RING="${array[15]}"
MODELED="${array[16]}"
MOD_REQ="${array[17]}"
MODEL_URL="${array[18]}"
CTCSS_IN="${array[19]}"
CTCSS_OUT="${array[20]}"
DCS_CODE="${array[21]}"
HOLDER="${array[22]}"
TRUSTEE="${array[23]}"
TRUSTEE_EMAIL="${array[24]}"
REPEATER_COUNTY="${array[25]}"
REPEATER_CITY="${array[26]}"
done < "$TMP_FILE"
# rm "$TMP_FILE"
}
function COMPOSE_EMAIL {
if [ -z ${TRUSTEE_EMAIL} ] || [ ${TRUSTEE_EMAIL} = NULL ]
then
echo "ERROR: Record: ${ID} TRUSTEE_EMAIL is NULL or Empty"
exit 255
fi
while IFS= read -r line
do
while [[ "$line" =~ (\$\{[a-zA-Z_][a-zA-Z_0-9]*\}) ]] ; do
LHS=${BASH_REMATCH[1]}
RHS="$(eval echo "\"$LHS\"")"
line=${line//$LHS/$RHS}
done
TICKET="${TICKET}""${line}"$'\n'
done < "$TEXT_FILE"
}
function SUBMIT_TICKET {
echo "Submitting Ticket to FASMA"
echo "$TICKET" | curl --data-urlencode content@- "https://rt.fasma.org/REST/1.0/ticket/new?user=${USER}&pass=${PASS}"
}
# Options
# -id database ID
# -model even if modeled flag is set in db
# -noupdate don't update db
# frequency range -flow 144.0000 -fhigh 146.0000
# -scandb scan the db for models needing to be built and process them
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-id) #db ID to model
RECORD_ID="$2"
shift # past argument=value
shift
;;
-input) #input file name
TEXT_FILE="$2"
shift
shift
;;
-noupdate)
NOUPDATE='1'
shift # past argument=value
;;
-scandb)
SCANDB='1'
shift # past argument=value
;;
-send)
SEND='1'
shift # past argument=value
;;
-show)
SHOW='1'
shift # past argument=value
;;
-i)
INTERACTIVE='1'
shift
;;
*)
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
#Below is run to match the DB
if [[ ! -z ${RECORD_ID} ]]
then
Query_DB
else
echo "ERROR: -id is missing record ID"
exit 255
fi
if [[ -z ${TEXT_FILE} ]]
then
echo "ERROR: -input missing template file name"
exit 255
fi
#check for RTUSER and RTPASS set
if [[ -z "${RTUSER}" ]]; then
echo "ERROR: RTUSER is not set"
exit 255
else
USER="${RTUSER}"
fi
if [[ -z "${RTPASSWD}" ]]; then
echo "ERROR: RTPASSWD is not set"
exit 255
else
PASS="${RTPASSWD}"
fi
#below calls the functions
READ_FILE
COMPOSE_EMAIL
if [[ ${INTERACTIVE} = '1' ]];
then
while true; do
read -p "Do you wish to view the ticket?" yn
case $yn in
[Yy]* ) echo "${TICKET}" ; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Do you wish to SUBMIT the Ticket?" yn
case $yn in
[Yy]* ) SUBMIT_TICKET; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
exit
fi
# IF Show is set
if [[ ${SHOW} = '1' ]]
then
echo "${TICKET}"
fi
# If Submit is set
if [[ ${SEND} = '1' ]]
then
SUBMIT_TICKET
fi
exit