-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflash.sh
More file actions
executable file
·223 lines (189 loc) · 4.69 KB
/
flash.sh
File metadata and controls
executable file
·223 lines (189 loc) · 4.69 KB
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
#!/bin/bash
#################################################################
# This script will flash the TFT File into The Nextion Screen #
# Revised to use Python3 #
# VE3RD 2024/02/11 #
#################################################################
set -o errexit
set -o pipefail
ver="20201010"
#sudo apt-get install python serial
#sudo apt-get install -y python-serial
sudo apt update && sudo apt -y install python3-serial
export NCURSES_NO_UTF8_ACS=1
## Programmed Shutdown
function exitcode
{
clear
echo "Script Execution Failed "
echo "$scn"
echo "$errtext"
tput sgr0
exit
}
function killservices
{
echo "Stopping services - Reboot Required after This Script Finishes"
sudo systemctl stop pistar-watchdog > /dev/null
sudo systemctl stop mmdvmhost.timer > /dev/null
sudo systemctl stop mmdvmhost.service > /dev/null
sudo systemctl stop cron.service > /dev/null
sudo systemctl stop mmdvmhost.service > /dev/null
sudo systemctl stop mmdvmhost.timer > /dev/null
sudo systemctl stop nextiondriver.service > /dev/null
echo "Services Stopped"
}
function flashscreen
{
sudo python3 /usr/local/bin/Nextion/nextion.py "$pathstr" /dev/ttyUSB0
echo "Rebooting ......"
sudo reboot
}
sudo mount -o remount,rw /
# insure python3 seial module is loaded
errtxt="Nothing"
if [ -f ~/.dialog ]; then
j=1
else
dialog --create-rc ~/.dialogrc
fi
#use_colors = ON
#screen_color = (WHITE,BLUE,ON)
#title_color = (YELLOW,RED,ON)
sed -i '/use_colors = /c\use_colors = ON' ~/.dialogrc
sed -i '/screen_color = /c\screen_color = (WHITE,BLUE,ON)' ~/.dialogrc
sed -i '/title_color = /c\title_color = (YELLOW,RED,ON)' ~/.dialogrc
echo -e '\e[1;44m'
clear
homedir=/home/pi-star/
curdir=$(pwd)
clear
declare -i tst
tst=0
found1=$(sudo sh -c 'echo ls /usr/local/etc/NX*.tft' | cut -d' ' -f2)
found2=$(sudo sh -c 'echo ls /usr/local/etc/NX*.tft' | cut -d' ' -f3)
found3=$(sudo sh -c 'echo ls /usr/local/etc/NX*.tft' | cut -d' ' -f4)
if [ "$found3" ]; then
errtext="Too Many Screen files found in /ust/loca/etc/"
echo "Script Aborted"
exitcode
fi
if [ -z "$found1" ]; then
errtext=" Sorry! = Cannot find a Screen type in /usr/local/etc/"
echo " Script Aborted!"
exitcode
fi
if [ ! -f /usr/local/etc/NX*.tft ]; then
errtext="Screen File not found!"
exitcode
fi
HEIGHT=15
WIDTH=60
CHOICE_HEIGHT=5
BACKTITLE="Nextion Screen Flash Tool - VE3RD $ver"
TITLE="Flash Selected Screen Type"
MENU="Select your Screen Type from List Found"
if [ -z "$found2" ]; then
OPTIONS=(1 "Quit"
2 "$found1")
else
OPTIONS=(1 "Quit"
2 "$found1"
3 "$found2")
fi
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
echo -e '\e[1;44m'
if [ "$found2" ]; then
case $CHOICE in
1)
echo "You Chose to Quit"
echo "Script Aborted!"
tst=0
echo="You Selected Quit Option at Level 1"
sed -i '/use_colors = /c\use_colors = OFF' ~/.dialogrc
tput sgr0
clear
exit
;;
2)
scn="$found1"
tst=1
;;
3)
scn="$found2"
tst=2
;;
esac
else
case $CHOICE in
1)
errtext="You Chose to Quit"
echo "You Chose to Abort at Level2"
echo "Script Aborted!"
tst=0
sed -i '/use_colors = /c\use_colors = OFF' ~/.dialogrc
tput sgr0
clear
exit
;;
2)
scn="$found1"
tst=1
;;
esac
fi
#Setup the string for the screen name and location
pathstr="$scn"
if [ -f "$pathstr" ]; then
echo "File $pathstr Found - Proceeding to Flash"
tst=1
else
echo "File $pathstr NOT Found - Flash Aborted!"
tst=0
fi;
echo "Screen Type Entered to Flash = $pathstr"
if [ "$tst" > 0 ]; then
HEIGHT=15
WIDTH=60
CHOICE_HEIGHT=5
BACKTITLE="Nextion Screen Flash Tool - VE3RD $ver"
TITLE="You Have Chosen to Flash $scn"
MENU="Select Abort or Proceed"
OPTIONS=(1 "Abort"
2 "Proceed")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
echo -e '\e[1;44m'
case $CHOICE in
1)
errtext="You Chose to Abort"
echo "Script Aborted!"
tst=0
exitcode
;;
2)
echo "You Chose to Proceed and Flash the Screen"
tst=1
killservices
flashscreen
;;
esac
else
echo "Error Detected - No Action Taken - Script Aborted!"
sed -i '/use_colors = /c\use_colors = OFF' ~/.dialogrc
tput sgr0
clear
fi