-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflash_your_device
executable file
·209 lines (188 loc) · 7.29 KB
/
flash_your_device
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
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
cleanup() {
rm -rf -- "${temp_directory}"
if [ "${machine}" == "Linux" ] &&
[ -n "${initial_tty_device_permissions:-}" ] &&
[ "$(stat -c '%a' "${tty_device}")" != "${initial_tty_device_permissions}" ]; then
sudo chmod "${initial_tty_device_permissions}" "${tty_device}"
fi
}
working_directory="${HOME}/Downloads/diy_jade"
temp_directory="${working_directory}/temp"
trap cleanup EXIT
jade_git_tag="1.0.26"
jade_save_directory="${working_directory}/jade"
jade_repo_url="https://github.com/blockstream/jade.git"
esp_idf_git_tag="v5.1.1"
esp_idf_temp_directory="${temp_directory}/esp-idf"
esp_idf_save_directory="${working_directory}/esp-idf"
esp_idf_repo_url="https://github.com/espressif/esp-idf.git"
device1="TTGO T-Display"
device2="M5Stack M5StickC PLUS"
device3="M5Stack Core Basic"
device4="M5Stack FIRE"
clear
echo "------------------------------------------------------------"
echo "------------------------------------------------------------"
echo "--- ---"
echo "--- Do-It-Yourself Jade Install Script ---"
echo "--- Written by Epic Curious ---"
echo "--- ---"
echo "------------------------------------------------------------"
echo "------------------------------------------------------------"
echo
if [ "$(whoami)" = "root" ]; then
echo -e "ALERT: You're running the script as root/superuser.\nYou may notice PIP 'sudo -H' warnings.\n"
fi
case "$(uname -s)" in
Linux*)
machine="Linux"
echo "Detected ${machine}."
echo -n "Checking for dependencies... "
while read -r dependency; do
if ! command -v "${dependency}" &> /dev/null; then
echo -en "\n\nERROR:\n${dependency} was not found on your system.\nPlease install ${dependency} by running:\n\n"
if [ "${dependency}" == "pip" ] || [ "${dependency}" == "virtualenv" ]; then
echo -en "sudo apt update && sudo apt install -y python3-${dependency}\n\n"
else
echo -en "sudo apt update && sudo apt install -y ${dependency}\n\n"
fi
exit 1
fi
done < <(curl -fsSL https://github.com/epiccurious/jade-diy/raw/master/depends.txt)
echo "ok."
;;
Darwin*)
machine="macOS"
echo "Detected ${machine}."
echo -n "Checking for cmake... "
if ! command -v cmake &> /dev/null; then
if [ ! -d /Applications/CMake.app ]; then
cmake_macos_url="https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-macos-universal.dmg"
cmake_macos_dmg="$(basename ${cmake_macos_url})"
if [ ! -f "${HOME}"/Downloads/"${cmake_macos_dmg}" ]; then
echo -ne "\n Downloading CMake... "
curl -sL "${cmake_macos_url}" --output "${HOME}"/Downloads/"${cmake_macos_dmg}"
echo "ok."
fi
echo -e "\n************************************************************"
echo "ERROR: Automatic installation of CMake is not supported yet."
echo "Please manually install ${cmake_macos_dmg}."
echo "Please open the file from your Downloads folder."
echo -e "************************************************************\n"
exit 1
fi
PATH="/Applications/CMake.app/Contents/bin${PATH:+:${PATH}}"
fi
echo "ok."
;;
MINGW*)
echo "Windows is not supported. Please run in WSL (Windows Subsystem for Linux)." && exit 0
;;
*) echo "Unsupported OS: $(uname -s)" && exit 0 ;;
esac
echo -n "Checking for the Espressif IoT Development Framework... "
if [ ! -f "${esp_idf_save_directory}"/export.sh ]; then
echo -ne "\n Downloading the framework... "
git -c advice.detachedHead=false clone --branch "${esp_idf_git_tag}" --single-branch --depth 1 --quiet "${esp_idf_repo_url}" "${esp_idf_temp_directory}"
cd "${esp_idf_temp_directory}"/
git submodule update --depth 1 --init --recursive --quiet &> /dev/null
mv "${esp_idf_temp_directory}" "${esp_idf_save_directory}"
echo "ok."
else
echo
fi
cd "${esp_idf_save_directory}"
echo -ne " Installing the framework... "
./install.sh esp32 1> /dev/null
echo -ne "ok.\n Exporting the framework... "
# shellcheck source=/dev/null
source ./export.sh 1> /dev/null
echo "ok."
echo -n "Checking for the Blockstream Jade repository... "
if [ ! -d "${jade_save_directory}" ]; then
echo -ne "\n Downloading Jade... "
git -c advice.detachedHead=false clone --branch "${jade_git_tag}" --single-branch --depth 1 --quiet "${jade_repo_url}" "${jade_save_directory}"
cd "${jade_save_directory}"
git submodule update --depth 1 --init --recursive --quiet &> /dev/null
fi
cd "${jade_save_directory}"
jade_version="$(git describe --tags)"
echo "ok."
if [ "${CI:-false}" = true ]; then
cp configs/sdkconfig_display_ttgo_tdisplay.defaults sdkconfig.defaults
else
echo -e "\nWhich device do you want to flash?"
PS3='Please enter the number for your device or QUIT: '
options=("${device1}" "${device2}" "${device3}" "${device4}" "QUIT")
select chosen_device in "${options[@]}"; do
case "${chosen_device}" in
"${device1}")
tty_device="/dev/ttyACM0"
flash_command="idf.py flash"
cp configs/sdkconfig_display_ttgo_tdisplay.defaults sdkconfig.defaults
break
;;
"${device2}")
tty_device="/dev/ttyUSB0"
flash_command="idf.py -b 115200 flash"
cp configs/sdkconfig_display_m5stickcplus.defaults sdkconfig.defaults
break
;;
"${device3}")
tty_device="/dev/ttyACM0"
flash_command="idf.py flash"
cp configs/sdkconfig_display_m5blackgray.defaults sdkconfig.defaults
break
;;
"${device4}")
tty_device="/dev/ttyACM0"
flash_command="idf.py flash"
cp configs/sdkconfig_display_m5fire.defaults sdkconfig.defaults
break
;;
"QUIT")
echo "You chose to quit."
exit 0
;;
*) echo "You entered ${REPLY}, which is invalid." ;;
esac
done
echo
fi
[ -f sdkconfig ] && rm sdkconfig
sed -i.bak '/CONFIG_DEBUG_MODE/d' ./sdkconfig.defaults
sed -i.bak '1s/^/CONFIG_LOG_DEFAULT_LEVEL_NONE=y\n/' sdkconfig.defaults
echo -n "Building the Jade firmware... "
idf.py build &> /dev/null
echo "ok."
[ "${CI:-false}" = true ] && echo "Exiting the script for CI runners." && exit 0
case "${machine}" in
Linux*)
while [ ! -c "${tty_device}" ]; do
read -srn1 -p "Connect your ${chosen_device} and PRESS ANY KEY to continue... " && echo
done
initial_tty_device_permissions="$(stat -c '%a' "${tty_device}")"
if [ "${initial_tty_device_permissions:2}" -lt 6 ]; then
echo -e "\nElevating write permissions for ${chosen_device}"
sudo chmod o+rw "${tty_device}"
echo
fi
;;
macOS*)
echo -e "Connect your ${chosen_device} with a USB-C cable,\n and click Allow if you see a security popup."
read -srn1 -p " PRESS ANY KEY to continue... " && echo && echo
;;
*) echo "Unsupported OS: $(uname -s)" && exit 0 ;;
esac
echo -e "Ready to install Jade ${jade_version} on your ${chosen_device}.\n (This process can take over 10 minutes.)"
read -srn1 -p " PRESS ANY KEY to continue... " && echo
final_confirmation_sleep_time="10"
echo -ne "\nContinuing Jade ${jade_version} installion in ${final_confirmation_sleep_time} seconds.\nPress Ctrl+C to abort ... "
sleep "${final_confirmation_sleep_time}"
echo
${flash_command}
echo -e "\nSUCCESS! Jade ${jade_version} is now installed on your ${chosen_device}.\nYou can close this window.\n"