forked from on7lds/NextionDriverInstaller
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NextionDriver_ConvertConfig
executable file
·227 lines (198 loc) · 7.8 KB
/
NextionDriver_ConvertConfig
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
#!/bin/bash
# Copyright (C) by Lieven De Samblanx ON7LDS
#
# 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#########################################################
# #
# MMDVMHost configuration patcher #
# #
# (c)2018 by ON7LDS #
# #
# V1.04 #
# #
# This program changes the MMDVMHost configuration #
# file to suit the needs of NextionDriver #
# #
#########################################################
#Where do we find the data files (groups and DMR is's)
#for Pi-Star : /usr/local/etc/
DATAFILES="/usr/local/etc/"
#########################################################
if [ "$1" == "" ]; then
echo "You have to specify the config file !"
exit 1
fi
MMDVMConfig=$1
VERSION="1.04"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" #"
echo ""
echo "-----------------------------------------------------------"
echo "NOTE: I tried to make this script as foolproof as possible."
echo " There might still be situations where it does not work"
echo " as expected."
echo " If you should discover any bugs, please let me know."
echo "-----------------------------------------------------------"
echo ""
echo "Starting NextionDriver_ConvertConfig $VERSION"
echo ""
if [[ -f "$MMDVMConfig" && -w "$MMDVMConfig" ]]; then
echo "Processing ..."
else
echo "The file is not a regular file or writable !"
exit 2
fi
if [[ -f "$MMDVMConfig.old" ]]; then
echo "There already is a backup file $MMDVMConfig.old"
echo "This could be because NextionDriver already was installed earlier."
echo "If this is the case, there probably is no need to run this convertor."
echo "If, however, you are sure to run this convertor again,"
echo " then please rename or remove $MMDVMConfig.old."
echo ""
echo "Mind you, running the convertor twice might result in a"
echo " broken configuration"
exit 3
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ "$line" == "[NextionDriver]" ]; then
echo "There already is a [NextionDriver] section."
echo " I'm going to leave the file as is."
echo " You'll have to change it by hand if necessary."
exit 4
fi
done < "$MMDVMConfig"
# Ok, alles lijkt goed.
mv "$MMDVMConfig" "$MMDVMConfig.old"
NEXTIONPORT_IS_MODEM=""
NEXTIONPORT_IS_DRIVER=""
TRANSPARENT=""
while IFS='' read -r line || [[ -n "$line" ]]; do
#sectie bepalen
if [[ "${line:0:1}" == "[" ]]; then
SECTION=${line:1:-1}
fi
#Port van Nextion zoeken,
#we moeten weten of het modem is of niet
if [[ "$SECTION" == "Nextion" && "$line" == "Port=modem" ]]; then
NEXTIONPORT_IS_MODEM="1"
echo "Info: Serial port for Nextion is modem."
echo " We will have to enable Transparent Data!"
fi
if [[ "$SECTION" == "Nextion" && "$line" == "Port="*"ttyNextionDriver" ]]; then
NEXTIONPORT_IS_DRIVER="1"
echo "ERROR: The driver already seems to be installed,"
echo " so I will not change the configuration."
echo " If something is wrong, please correct it by hand."
mv "$MMDVMConfig.old" "$MMDVMConfig"
exit 1
fi
if [[ "$SECTION" == "Transparent Data" && "$TRANSPARENT" == "" ]]; then
TRANSPARENT="1"
echo "Info: Transparent Data section found."
fi
if [[ "$SECTION" == "Transparent Data" && "$TRANSPARENT" == "1" && "$line" == "SendFrameType="* ]]; then
TRANSPARENT="2"
echo "Info: SendFrameType option found."
fi
done < "$MMDVMConfig.old"
if [[ "$NEXTIONPORT_IS_MODEM" == "1" && "$TRANSPARENT" == "" ]]; then
echo "Info: No Transparent Data section."
echo " Will be inserted !"
TRANSPARENT="3"
fi
echo "---> Creating new ini file..."
SECTION=""
SERIALPORT=""
FOUND_NEXTION=""
FOUND_MODEM=""
while IFS='' read -r line || [[ -n "$line" ]]; do
#sectie bepalen
if [[ "${line:0:1}" == "[" ]]; then
SECTION=${line:1:-1}
fi
#[Modem]
if [[ "$SECTION" == "Modem" ]]; then
FOUND_MODEM="1"
fi
#[Transparent data]
if [[ "$NEXTIONPORT_IS_MODEM" == "1" && "$SECTION" == "Transparent Data" ]]; then
if [[ "${line:0:7}" == "Enable=" ]]; then
TRANSPARENT_ENABLE=${line:7:1}
echo "Info: Transparent data enable: $TRANSPARENT_ENABLE"
if [[ "$TRANSPARENT_ENABLE" != "1" ]]; then
echo " changing to 1"
line="Enable=1"
else
echo " OK !"
fi
if [[ "$TRANSPARENT" == "1" ]]; then
TRANSPARENT="x"
echo "Info: Inserting SendFrameType=1"
echo "$line" >> "$MMDVMConfig"
line="SendFrameType=1"
fi
fi
if [[ "$TRANSPARENT" == "2" && "${line:0:14}" == "SendFrameType=" ]]; then
SENDFRAMETYPE=${line:14:1}
echo "Info: SendFrameType: $SENDFRAMETYPE"
if [[ "$SENDFRAMETYPE" != "1" ]]; then
echo " changing to 1"
line="SendFrameType=1"
else
echo " OK !"
fi
fi
fi
#[Nextion]
if [[ "$SECTION" == "Nextion" ]]; then
FOUND_NEXTION="1"
#Port van Nextion gevonden ?
# bewaren welke dat is !
if [[ "${line:0:5}" == "Port=" ]]; then
SERIALPORT="${line:5}"
echo "Info: Serial port for Nextion was $SERIALPORT"
echo " changing to /dev/ttyNextionDriver"
line="Port=/dev/ttyNextionDriver"
fi
fi
#eerste sectie na [Nextion] gevonden ?
# hier zetten we onze gegevens tussen
if [[ "$SECTION" != "Nextion" && "$FOUND_NEXTION" == "1" && "${line:0:1}" == "[" ]]; then
echo "Info: Inserting [NextionDriver] section"
SECTION="[NextionDriver]\nPort=$SERIALPORT\nDataFilesPath=$DATAFILES\n"$(cat $DIR/NextionDriver.cfg)"\n"
echo -e "$SECTION" >> "$MMDVMConfig"
echo -e "\n\nInserted section :"
echo "------------------------------"
echo -e "$SECTION"
echo "------------------------------"
echo ""
FOUND_NEXTION=""
if [ "$SERIALPORT" == "" ]; then
echo -e "WARNING : no serial port for Nextion found. Check your $MMDVMConfig\n"
fi
fi
if [[ "$SECTION" != "Modem" && "$FOUND_MODEM" == "1" && "${line:0:1}" == "[" && "$TRANSPARENT" == "3" ]]; then
echo "Info: Inserting [Transparent Data] section"
SECTION="[Transparent Data]\nEnable=1\nRemoteAddress=127.0.0.1\nRemotePort=40094\nLocalPort=40095\nSendFrameType=1\n\n"
echo -e "$SECTION" >> "$MMDVMConfig"
echo -e "\n\nInserted section :"
echo "------------------------------"
echo -e "$SECTION"
echo "------------------------------"
echo ""
FOUND_MODEM=""
fi
echo "$line" >> "$MMDVMConfig"
done < "$MMDVMConfig.old"