This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodesetup.sh
executable file
·307 lines (279 loc) · 8.63 KB
/
nodesetup.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
# !/bin/bash
#
# nodesetup.sh
#
DRY_RUN=0
CONFIGS=/etc/asterisk
TMP=/tmp
SENABLE=1
function die {
echo "Fatal error: $1"
exit 255
}
function promptnum
{
ANSWER=""
while [ -z $ANSWER ] || [[ ! $ANSWER =~ [0-9]{3,}$ ]]
do
echo -n "$1: "
read ANSWER
done
}
function promptcall
{
ANSWER=""
while [ -z $ANSWER ] || [[ ! $ANSWER =~ [\/,0-9,a-z,A-Z]{3,}$ ]]
do
echo -n "$1: "
read ANSWER
done
}
function promptyn
{
echo -n "$1 [y/N]? "
read ANSWER
if [ ! -z $ANSWER ]
then
if [ $ANSWER = Y ] || [ $ANSWER = y ]
then
ANSWER=Y
else
ANSWER=N
fi
else
ANSWER=N
fi
}
function promptny
{
echo -n "$1 [Y/n]? "
read ANSWER
if [ ! -z $ANSWER ]
then
if [ $ANSWER = N ] || [ $ANSWER = n ]
then
ANSWER=N
else
ANSWER=Y
fi
else
ANSWER=Y
fi
}
echo "*************************************"
echo "* Simple Node Setup Script *"
echo "*************************************"
echo
promptny "Would you like your config files be provided by the Allstar Portal server"
if [ "$ANSWER" = "Y" ]
then
echo
echo "This requires you to have already applied for and received an approved"
echo "Allstar Link Portal user ID, set it up to be a system operator, created"
echo "an entry for, and properly configured information about this Server, and"
echo "requested, and received an approved Node entry for each of the Nodes on"
echo "this Server, and properly configured the inforation for each of the Nodes."
echo
promptyn "Have you estblished and entered the appropriate information on that server"
if [ "$ANSWER" = "Y" ]
then
if [ -x /usr/bin/curl ]
then
TMPF=/tmp/pcf.sh
/bin/rm $TMPF > /dev/null 2>&1
curl -L -s https://allstarlink.org/config/portalconfig.sh -o $TMPF
if [ $? -ne 0 ]
then
echo "curl was not able to download necessary script file, sorry."
exit 1
fi
sh $TMPF
if [ $? -ne 0 ]
then
rm $TMPF
echo "Allstar Link Portal Config Download Failed.. exiting"
exit 1
fi
rm $TMPF
echo
echo "Congradulations! From now on, you will be able to initiate an automatic"
echo "download of any Node or Server configuration changes from the Allstar"
echo "Portal (just from the Web, without even having to have any sort of terminal"
echo "session active to this system)."
echo
echo "You must now manually re-boot the system for these changes to take place."
echo
echo "Thank you for using the Allstar Link Network System!"
echo
exit 0
else
echo "curl and its associated cert file(s) can not be found, sorry!"
exit 1
fi
else
echo "Nothing changed!"
exit 0
fi
fi
echo
echo "Doing sanity checks on rpt.conf, extensions.conf, iax.conf, and savenode.conf..."
if [ -e $CONFIGS/extensions.conf ]
then
grep -q -s NODE= $CONFIGS/extensions.conf || die "extensions.conf missing NODE=xxxx"
NODE=$(grep NODE= /etc/asterisk/extensions.conf | gawk -F'=' '{print $2}')
else
die "$CONFIGS/extensions.conf not found"
fi
if [ -e $CONFIGS/rpt.conf ]
then
grep -q -s $NODE $CONFIGS/rpt.conf || die "Node numbers in rpt.conf and extensions.conf are different!"
else
die "$CONFIGS/rpt.conf not found"
fi
if [ -e $CONFIGS/iax.conf ]
then
grep -q -s register\.allstarlink\.org $CONFIGS/iax.conf || die "No allstar link register statement in iax.conf! (old file maybe?)"
REG1=$(grep register= $CONFIGS/iax.conf | gawk -F'=' '{print $2}')
REG=$(echo "$REG1" | gawk -F'@' '{print $1}')
REGNODE=$(echo "$REG" | gawk -F':' '{print $1}')
REGPSWD=$(echo "$REG" | gawk -F':' '{print $2}')
if [ $REGNODE != $NODE ]
then
die "Node numbers in rpt.conf and iax.conf are different!"
fi
else
die "$CONFIGS/iax.conf not found"
fi
if [ -e $CONFIGS/savenode.conf ]
then
grep -q -s NODE= $CONFIGS/savenode.conf || die "savenode.conf missing NODE=xxxx"
grep -q -s PASSWORD= $CONFIGS/savenode.conf || die "savenode.conf missing PASSWORD=xxxx"
grep -q -s ENABLE= $CONFIGS/savenode.conf || die "savenode.conf missing ENABLE=x"
SNODE=$(grep NODE= $CONFIGS/savenode.conf | gawk -F'=' '{print $2}')
SPASSWORD=$(grep PASSWORD= $CONFIGS/savenode.conf | gawk -F'=' '{print $2}')
SENABLE=$(grep ENABLE= $CONFIGS/savenode.conf | gawk -F'=' '{print $2}')
if [ $NODE != $SNODE ]
then
die "Node numbers in iax.conf and savenode.conf are different!"
fi
if [ $REGPSWD != $SPASSWORD ]
then
die "Passwords in iax.conf and savenode.conf are different!"
fi
if [ -z $SENABLE ]
then
die "Enable not fully specified in savenode.conf!"
fi
fi
echo "OK, the format of the files is understandable!"
echo
ANYNEW=0
NEWNODE=""
echo The system node number is: $NODE
promptyn "Would you like to change it?"
if [ "$ANSWER" = "Y" ]
then
promptnum "Enter the new node number"
NEWNODE=$ANSWER
ANYNEW=1
fi
NEWPSWD=""
echo The registration password is: $REGPSWD
promptyn "Would you like to change it?"
if [ "$ANSWER" = "Y" ]
then
promptnum "Enter the new registration password"
NEWPSWD=$ANSWER
ANYNEW=1
fi
ID=""
promptyn "Would you like to enter a callsign for the identifier"
if [ "$ANSWER" = "Y" ]
then
promptcall "Please enter your callsign"
ID=$ANSWER
ANYNEW=1
fi
SAVENODE_ENABLE=1
# if running Limey Linux, ask them
if [ -x /usr/local/sbin/svcfg ]
then
promptny "Would you like the system to save your configs offline"
if [ "$ANSWER" = "N" ]
then
SAVENODE_ENABLE=0
fi
fi
if [ $SAVENODE_ENABLE -ne $SENABLE ]
then
ANYNEW=1
fi
if [ $ANYNEW -gt 0 ]
then
echo "Copying original files to temporary work area..."
cp $CONFIGS/rpt.conf $TMP/rpt.conf.in || die "Could not copy $CONFIGS/rpt.conf"
cp $CONFIGS/extensions.conf $TMP/extensions.conf.in || die "Could not copy $CONFIGS/extensions.conf"
cp $CONFIGS/iax.conf $TMP/iax.conf.in || die "Could not copy $CONFIGS/iax.conf"
if [ -e $CONFIGS/savenode.conf ]
then
cp $CONFIGS/savenode.conf $TMP/savenode.in || die "Could not copy $CONFIGS/savenode.conf"
fi
else
echo "Nothing to do!"
exit 0
fi
if [ ! -z $ID ]
then
echo "Updating rpt.conf with new ID..."
sed "s~idrecording[ \t]*=[ \t]*|.*~idrecording = |i$ID\t\t\t; Main ID message~" <$TMP/rpt.conf.in >$TMP/rpt.conf.out
mv -f $TMP/rpt.conf.out $TMP/rpt.conf.in || die "mv 1 failed"
fi
if [ ! -z $NEWNODE ]
then
echo "Updating rpt.conf iax.conf, and extensions.conf with new node number..."
sed "s/$NODE/$NEWNODE/g" <$TMP/extensions.conf.in >$TMP/extensions.conf.out
mv -f $TMP/extensions.conf.out $TMP/extensions.conf.in || die "mv 2 failed"
sed "s/$NODE/$NEWNODE/g" <$TMP/rpt.conf.in >$TMP/rpt.conf.out
mv -f $TMP/rpt.conf.out $TMP/rpt.conf.in || die "mv 3 failed"
sed "s/$NODE/$NEWNODE/g" <$TMP/iax.conf.in >$TMP/iax.conf.out
mv -f $TMP/iax.conf.out $TMP/iax.conf.in || die "mv 4 failed"
if [ -e $CONFIGS/savenode.conf ]
then
sed "s/$NODE/$NEWNODE/g" <$TMP/savenode.in >$TMP/savenode.out
mv -f $TMP/savenode.out $TMP/savenode.in || die "mv 5 failed"
fi
fi
if [ ! -z $NEWPSWD ]
then
echo "Updating allstar link register statement in iax.conf with new password..."
sed "s/$REGPSWD/$NEWPSWD/g" <$TMP/iax.conf.in >$TMP/iax.conf.out
mv -f $TMP/iax.conf.out $TMP/iax.conf.in || die "mv 6 failed"
if [ -e $CONFIGS/savenode.conf ]
then
sed "s/$REGPSWD/$NEWPSWD/g" <$TMP/savenode.in >$TMP/savenode.out
mv -f $TMP/savenode.out $TMP/savenode.in || die "mv 7 failed"
fi
fi
if [ -e $CONFIGS/savenode.conf ]
then
sed "s/ENABLE=$SENABLE/ENABLE=$SAVENODE_ENABLE/g" <$TMP/savenode.in >$TMP/savenode.out
mv -f $TMP/savenode.out $TMP/savenode.in || die "mv 7 failed"
fi
if [ $DRY_RUN -eq 0 ]
then
echo "Updating original config files..."
mv -f $TMP/rpt.conf.in $CONFIGS/rpt.conf || die "mv 8 failed"
mv -f $TMP/extensions.conf.in $CONFIGS/extensions.conf || die "mv 9 failed"
mv -f $TMP/iax.conf.in $CONFIGS/iax.conf || die "mv 10 failed"
if [ -e $CONFIGS/savenode.conf ]
then
mv -f $TMP/savenode.in $CONFIGS/savenode.conf || die "mv 11 failed"
chmod +x $CONFIGS/savenode.conf || die "chmod failed!"
fi
echo "Config files updated. Done!!"
echo
else
echo "Dry run"
echo
fi
exit 0