-
Notifications
You must be signed in to change notification settings - Fork 2
/
ircddbconfig.sh
executable file
·328 lines (263 loc) · 6.96 KB
/
ircddbconfig.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/sh
#
#
# ircDDB auto config script
#
# Copyright (C) 2010 Michael Dirska, DL1BFF ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
comment_out() {
RETVAL=0
echo " looking for '$2' in file $1"
if grep -q "^[[:space:]]*$2" "$1"
then
echo " commenting out '$2'"
echo -e ",s/^[[:space:]]*\\($2\\)/# \\1\nwq" | ed -s "$1"
RETVAL=1
else
echo " '$2' not found in file $1"
fi
return $RETVAL
}
transfer_value() {
RETVAL=0
if [ $# != 4 ]
then
return $RETVAL
fi
echo " - $1($2) -> $3($4)"
if [ ! -f "$1" ]
then
echo " $1 does not exists"
return $RETVAL
fi
if [ ! -f "$3" ]
then
echo " $3 does not exists"
return $RETVAL
fi
if ! grep -q "^[[:space:]]*${2}[[:space:]]*=[[:space:]]*[[:graph:]][[:graph:]]*" "$1"
then
echo " $1 does not contain $2 property"
return $RETVAL
fi
VALUE=` gawk '
/^[[:space:]]*'"$2"'[[:space:]]*=[[:space:]]*[[:graph:]][[:graph:]]*/ {
match( $0, "^[[:space:]]*'"$2"'[[:space:]]*=[[:space:]]*([[:graph:]][[:graph:]]*)", a)
print a[1]
exit
} ' < "$1" `
if [ "x$VALUE" = "x" ]
then
echo " could not read property $2 from file $1"
return $RETVAL
fi
if grep -q "^[[:space:]]*${4}[[:space:]]*=[[:space:]]*[[:graph:]][[:graph:]]*" "$3"
then
if grep -q "^[[:space:]]*${4}[[:space:]]*=[[:space:]]*${VALUE}[[:space:]]*$" "$3"
then
echo " $3 already has ${4}=$VALUE"
else
echo " setting ${4}=$VALUE in file $3"
echo -e ",s/^[[:space:]]*${4}[[:space:]]*=[[:space:]]*[[:graph:]][[:graph:]]*/${4}=$VALUE/\nwq" | ed -s "$3"
RETVAL=1
fi
else
echo " adding ${4}=$VALUE to file $3"
echo "${4}=$VALUE" >> "$3"
fi
return $RETVAL
}
fix_dstar_gw_init_script() {
D="$1"
DBAK="$D".ircddb.bak
if cp "$D" "$DBAK"
then
sed '
/^start)$/ {
N
N
s/^\(start.\n start\n\)\( ;;\)$/\1 \/sbin\/service ircddbd start\n\2/
}
/^stop)$/ {
N
N
s/^\(stop.\n\)\( stop\n ;;\)$/\1 \/sbin\/service ircddbd stop\n\2/
}
/^restart)$/ {
N
N
N
s/^\(restart.\n\)\( stop\n start\n\)\( ;;\)$/\1 \/sbin\/service ircddbd stop\n\2 \/sbin\/service ircddbd start\n\3/
}
' < "$DBAK" > "$D"
fi
}
echo "*** ircDDB auto config script"
IRCDDB_CONFIG_CHANGED=0
echo ""
echo "* looking for ircDDB parameters that can be set automatically:"
transfer_value /etc/default/ircddbmhd MHEARD_UDP_PORT /etc/ircddbd/ircDDB.properties mheard_udp_port
if [ "$?" = 1 ]
then
IRCDDB_CONFIG_CHANGED=1
fi
transfer_value /opt/products/dstar/dstar_gw/dsipsvd/dsipsvd.conf ZR_CALLSIGN /etc/ircddbd/ircDDB.properties rptr_call
if [ "$?" = 1 ]
then
IRCDDB_CONFIG_CHANGED=1
fi
transfer_value /opt/ircDDB/ircDDB.properties irc_password /etc/ircddbd/ircDDB.properties irc_password
if [ "$?" = 1 ]
then
IRCDDB_CONFIG_CHANGED=1
fi
transfer_value /opt/products/dstar/dstar_gw/dsgwd/dsgwd.conf ZR_ADDR /etc/default/ircddbmhd ZR_ADDR
if [ "$?" = 1 ]
then
IRCDDB_CONFIG_CHANGED=1
fi
transfer_value /opt/products/dstar/dstar_gw/dsgwd/dsgwd.conf ZR_PORT /etc/default/ircddbmhd ZR_PORT
if [ "$?" = 1 ]
then
IRCDDB_CONFIG_CHANGED=1
fi
echo ""
echo "* DStarMonitor config cleanup"
if [ -d /opt/dstarmon ]
then
D=/opt/dstarmon/dstarmonitor.properties
if [ -f $D ]
then
config_changed=FALSE
PARAM_SUFFIX=` gawk '
/^[[:space:]]*LHURI[0-9]=jdbc:postgresql:.*ircddb/ { gsub("^[[:space:]]*", ""); print substr($0, 6, 1) } ' < $D `
if [ "x$PARAM_SUFFIX" != "x" ]
then
for i in $PARAM_SUFFIX
do
comment_out $D "LHURI${i}="
comment_out $D "LHDriver${i}="
comment_out $D "LHParameters${i}="
config_changed=TRUE
done
fi
if grep -q "^[[:space:]]*LHURI=jdbc:postgresql:.*ircddb" $D
then
comment_out $D "LHURI="
comment_out $D "LHDriver="
comment_out $D "LHParameters="
config_changed=TRUE
fi
if [ "$config_changed" = "TRUE" ]
then
echo " the configuration file $D was changed, restarting DStarMonitor"
if [ -x /etc/init.d/dsm ]
then
/etc/init.d/dsm restart
fi
else
echo " no old ircDDB config lines found"
fi
else
echo " file $D does not exist"
fi
else
echo " DStarMonitor not found"
fi
echo ""
echo "* dstar_gw startup script cleanup"
D=/etc/init.d/dstar_gw
if [ -f $D ]
then
config_changed=FALSE
if grep -q "^[[:space:]]*killall -q -u ircddb" $D
then
comment_out $D "killall -q -u ircddb"
config_changed=TRUE
fi
if grep -q "^[[:space:]]*[[:graph:]]*.start.sh 2>.1 > .dev.null" $D
then
comment_out $D "[[:graph:]]*.start.sh 2>.1 > .dev.null"
config_changed=TRUE
fi
if [ "$config_changed" = "FALSE" ]
then
echo " no old ircDDB config lines found"
fi
if grep -q "^ .sbin.service ircddbd start$" $D
then
echo " ircddbd start/stop commands already inserted"
else
echo " inserting ircddbd start/stop commands"
fix_dstar_gw_init_script $D
fi
else
echo " dstar_gw startup script could not be found"
fi
echo ""
echo "* ircDDB password"
D=/etc/ircddbd/ircDDB.properties
if [ -f $D ]
then
if grep -q "irc_password=IRCDDB_PASSWORD" $D
then
if [ $# != 1 ]
then
echo "#######################################"
echo "# please run this script again with #"
echo "# the ircDDB password as command line #"
echo "# argument: #"
echo "# /usr/sbin/ircddbconfig pAsSwOrD #"
echo "#######################################"
exit
else
TMP=` /bin/mktemp `
echo "irc_password=$1" > "$TMP"
transfer_value "$TMP" irc_password $D irc_password
/bin/rm -f "$TMP"
IRCDDB_CONFIG_CHANGED=1
fi
else
echo " a password is set in $D"
fi
else
echo " $D not found"
fi
echo ""
echo "* repeater callsign check"
if [ -f $D ]
then
if grep -q "rptr_call=CALLSIGN" $D
then
echo "#######################################"
echo "# The repeater callsign could not be #"
echo "# determined automatically. Please #"
echo "# edit /etc/ircddbd/ircDDB.properties #"
echo "#######################################"
else
echo " a repeater callsign is set in $D"
if [ "$IRCDDB_CONFIG_CHANGED" = 1 ]
then
echo " restarting ircDDB services"
service ircddbd stop
service ircddbmhd stop
service ircddbd start
service ircddbmhd start
fi
fi
else
echo " $D not found"
fi