forked from n7tae/mrefd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrconfig
executable file
·199 lines (188 loc) · 4.89 KB
/
rconfig
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
#!/bin/bash
#
# Copyright (c) 2020 by Thomas A. Early N7TAE
#
# 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/>.
SetBooleanValue ()
{
local dvname
local cv
if [ -z $2 ]; then
if [ -z ${!1+x} ]; then
if [[ "$1" == module_[abc]_* ]]; then
echo matches
dvname=${1//_[abc]_/_x_}
else
echo does not match
dvname=${1}_d
fi
cv=${!dvname}
else
cv=${!1}
fi
if [[ $cv == [tT]* ]]; then
eval ${1}=false
else
eval ${1}=true
fi
elif [[ "$2" == [tT]* ]]; then
eval ${1}=true
else
eval ${1}=false
fi
}
EvaluateVar ()
{
if [ -z ${!1+x} ]; then
if [ -z "${!2}" ]; then
echo "'' <DEFAULT>"
else
echo "${!2} <DEFAULT>"
fi
else
if [ -z "${!1}" ]; then
echo "''"
else
echo "${!1}"
fi
fi
}
WriteMemFile ()
{
local file
file="$rcfg"
echo "# created on `date`" > $file
[ -z ${callsign+x} ] || echo "callsign='$callsign'" >> $file
[ -z ${nummod+x} ] || echo "nummod=$nummod" >> $file
[ -z ${ip4addr+x} ] || echo "ip4addr='$ip4addr'" >> $file
[ -z ${ip6addr+x} ] || echo "ip6addr='$ip6addr'" >> $file
[ -z ${dbsupport+x} ] || echo "dbsupport=$dbsupport" >> $file
}
WriteSRCHFile ()
{
local file m
file="$srch"
echo "// Created on `date`" > $file
echo "#define CALLSIGN \"${callsign}\"" >> $file
if [ -z ${nummod+x} ]; then
echo "#define NB_OF_MODULES ${nummod_d}" >> $file
else
echo "#define NB_OF_MODULES ${nummod}" >> $file
fi
if [ ! -z ${ip4addr+x} ]; then
echo "#define LISTEN_IPV4 \"${ip4addr}\"" >> $file
fi
if [ ! -z ${ip6addr+x} ]; then
echo "#define LISTEN_IPV6 \"${ip6addr}\"" >> $file
fi
}
WriteSRCMKFile ()
{
local file
file="$srcm"
echo "# Created on `date`" > $file
if [ -z ${dbsupport+x} ]; then
echo "debug = $dbsupport_d" >> $file
else
echo "debug = $dbsupport" >> $file
fi
}
WriteCFGFiles ()
{
WriteMemFile
WriteSRCHFile
WriteSRCMKFile
}
ListCFGFiles ()
{
echo "===========${rcfg}============="
cat $rcfg
echo "===========${srch}============="
cat $srch
echo "===========${srcm}============="
cat $srcm
}
# Execution starts here!
# file locations
rcfg='reflector.cfg'
srch='configure.h'
srcm='configure.mk'
mrefserv='/etc/systemd/system/mrefd.service'
# default values
callsign_d='CHNGME'
nummod_d=26
ip4addr_d='none'
ip6addr_d='none'
dbsupport_d=false
if [ -e reflector.cfg ]; then
source reflector.cfg
else
echo 'No configuration file found...'
sleep 1
fi
if [ -z ${expertmode+x} ]; then
if [ -e $mrefserv ]; then
echo -n "You cannot change the configuration right now beacuse there is an m17 server running."
echo "===========${rcfg}============="
cat $rcfg
echo
echo "Please uninstall the running server before attempting to modify the configuration."
exit 1
fi
fi
key='x'
# main loop
while [[ "$key" != q* ]]
do
clear
echo
echo " Reflector Configuration, Version #200821"
echo
echo " ******* REFLECTOR ********"
echo -n "cs : Reflector Callsign = "; EvaluateVar callsign{,_d}
echo -n "nm : Number of Modules = "; EvaluateVar nummod{,_d}
echo " ******* ADDRESSES ********"
echo -n "i4 : IPv4 Listen Address = "; EvaluateVar ip4addr{,_d}
echo -n "i6 : IPv6 Listen Address = "; EvaluateVar ip6addr{,_d}
echo " ******* DEBUGGING ********"
echo -n "db : Debugging Support = "; EvaluateVar dbsupport{,_d}
echo
if [[ "$callsign" == M17-* ]]; then
echo "w : Write configuration files (overwrites any existing files) and quit"
fi
echo "q : Quit without saving"
echo "u : Unset the value of <key> (revert to the default value)."
echo
read -p "Please input <key> <value> - omit value to toggle a true/false : " key value garbage
if [[ "$key" == cs* && ${value^^} == M17-* ]]; then
callsign="${value^^}"
callsign="${callsign:0:7}"
elif [[ "$key" == nm* ]]; then nummod="$value"
elif [[ "$key" == i4* ]]; then ip4addr="$value"
elif [[ "$key" == i6* ]]; then ip6addr="$value"
elif [[ "$key" == db* ]]; then SetBooleanValue dbsupport "$value"
elif [[ "$key" == w* ]]; then
WriteCFGFiles
ListCFGFiles
exit 0
elif [[ "$key" == u* ]]; then
if [[ "$value" == cs* ]]; then unset callsign
elif [[ "$value" == nm* ]]; then unset nummod
elif [[ "$value" == i4* ]]; then unset ip4addr
elif [[ "$value" == i6* ]]; then unset ip6addr
elif [[ "$value" == db* ]]; then unset dbsupport
fi
fi
done
exit 0