-
Notifications
You must be signed in to change notification settings - Fork 0
/
micropython-install.sh
executable file
·184 lines (134 loc) · 8.28 KB
/
micropython-install.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
#!/bin/bash
# Sep 28, 2021, 03:28:22
# ------------------------------SPIN CODE-----------------------------------#
function _spinner() {
# $1 start/stop
#
# on start: $2 display message
# on stop : $2 process exit status
# $3 spinner function pid (supplied from stop_spinner)
local on_success="DONE"
local on_fail="FAIL"
local white="\e[1;37m"
local green="\e[1;32m"
local red="\e[1;31m"
local nc="\e[0m"
case $1 in
start)
# calculate the column where spinner and status msg will be displayed
let column=$(tput cols)-${#2}-8
# display message and position the cursor in $column column
echo -ne ${2}
printf "%${column}s"
# start spinner
i=1
sp='\|/-'
delay=${SPINNER_DELAY:-0.15}
while :
do
printf "\b${sp:i++%${#sp}:1}"
sleep $delay
done
;;
stop)
if [[ -z ${3} ]]; then
echo "spinner is not running.."
exit 1
fi
kill $3 > /dev/null 2>&1
# inform the user uppon success or failure
echo -en "\b["
if [[ $2 -eq 0 ]]; then
echo -en "${green}${on_success}${nc}"
else
echo -en "${red}${on_fail}${nc}"
fi
echo -e "]"
;;
*)
echo "invalid argument, try {start/stop}"
exit 1
;;
esac
}
function start_spinner {
# $1 : msg to display
_spinner "start" "${1}" &
# set global spinner pid
_sp_pid=$!
disown
}
function stop_spinner {
# $1 : command exit status
_spinner "stop" $1 $_sp_pid
unset _sp_pid
}
# --------------------------------------------------------------------------#
title="Micropython Build Kit"
blue="\e[1;34m"
white="\e[1;37m"
green="\e[1;32m"
red="\e[1;31m"
blue="\e[1;34m"
nc="\e[0m"
echo -en " ${blue}${title}${nc}" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr -d '\n' | head -c $(tput cols)
echo -e "\n \n \n"
read -p "Press [Enter] to start the installation"
clear
echo ""
echo -en " ${blue}${title}${nc}" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr -d '\n' | head -c $(tput cols)
echo -e "\n \n \n"
echo -en "${red}Install requires root privlages${nc}\n \n"
sudo echo""
clear
echo ""
echo -en " ${blue}${title}${nc}" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr -d '\n' | head -c $(tput cols)
echo -e "\n \n \n"
if [ -d "esp" ]
then
echo -en "${red}"" WARNING: ""${white}""esp directory already exists?""${nc}" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr -d '\n' | head -c $(tput cols)
echo -e "\n \n \n \n \n \n \n \n"
read -p ""
else
#start_spinner "ㅤGetting esp-idf export..."
#command /dev/null 2>&1
#stop_spinner $?
start_spinner "ㅤInstalling Required Libraries..."
sudo apt-get -y install build-essential libffi-dev git pkg-config cmake virtualenv python3-pip python3-virtualenv > /dev/null 2>&1
pip3 install esptool > /dev/null 2>&1
stop_spinner $?
start_spinner "ㅤSymlink python3 to python..."
sudo ln -s /usr/bin/python3 /usr/bin/python > /dev/null 2>&1
stop_spinner $?
mkdir esp
cd esp
start_spinner "ㅤDownloading MicroPython..."
git clone --depth 2 https://github.com/micropython/micropython.git > /dev/null 2>&1
stop_spinner $?
start_spinner "ㅤDownloading Esp-idf..."
git clone -b v4.3-dev --recursive --depth 2 https://github.com/espressif/esp-idf.git > /dev/null 2>&1
stop_spinner $?
start_spinner "ㅤInstall idf modules (slow!)..."
cd esp-idf/
./install.sh > /dev/null 2>&1
source export.sh > /dev/null 2>&1
stop_spinner $?
cd ..
cd micropython/
start_spinner "ㅤInstall MicroPython submodules (slow!)..."
git submodule update --init > /dev/null 2>&1
stop_spinner $?
start_spinner "ㅤMPY cross compile setup"
cd mpy-cross/
make > /dev/null 2>&1
stop_spinner $?
cd ../..
start_spinner "ㅤExport auto-build firmware script..."
echo IyEvYmluL2Jhc2gKIyBTZXAgMjgsIDIwMjEsIDAwOjE0OjUxJwoKCiMgLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tU1BJTiBDT0RFLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0jCgpmdW5jdGlvbiBfc3Bpbm5lcigpIHsKICAgICMgJDEgc3RhcnQvc3RvcAogICAgIwogICAgIyBvbiBzdGFydDogJDIgZGlzcGxheSBtZXNzYWdlCiAgICAjIG9uIHN0b3AgOiAkMiBwcm9jZXNzIGV4aXQgc3RhdHVzCiAgICAjICAgICAgICAgICAkMyBzcGlubmVyIGZ1bmN0aW9uIHBpZCAoc3VwcGxpZWQgZnJvbSBzdG9wX3NwaW5uZXIpCgogICAgbG9jYWwgb25fc3VjY2Vzcz0iRE9ORSIKICAgIGxvY2FsIG9uX2ZhaWw9IkZBSUwiCiAgICBsb2NhbCB3aGl0ZT0iXGVbMTszN20iCiAgICBsb2NhbCBncmVlbj0iXGVbMTszMm0iCiAgICBsb2NhbCByZWQ9IlxlWzE7MzFtIgogICAgbG9jYWwgbmM9IlxlWzBtIgoKICAgIGNhc2UgJDEgaW4KICAgICAgICBzdGFydCkKICAgICAgICAgICAgIyBjYWxjdWxhdGUgdGhlIGNvbHVtbiB3aGVyZSBzcGlubmVyIGFuZCBzdGF0dXMgbXNnIHdpbGwgYmUgZGlzcGxheWVkCiAgICAgICAgICAgIGxldCBjb2x1bW49JCh0cHV0IGNvbHMpLSR7IzJ9LTgKICAgICAgICAgICAgIyBkaXNwbGF5IG1lc3NhZ2UgYW5kIHBvc2l0aW9uIHRoZSBjdXJzb3IgaW4gJGNvbHVtbiBjb2x1bW4KICAgICAgICAgICAgZWNobyAtbmUgJHsyfQogICAgICAgICAgICBwcmludGYgIiUke2NvbHVtbn1zIgoKICAgICAgICAgICAgIyBzdGFydCBzcGlubmVyCiAgICAgICAgICAgIGk9MQogICAgICAgICAgICBzcD0nXHwvLScKICAgICAgICAgICAgZGVsYXk9JHtTUElOTkVSX0RFTEFZOi0wLjE1fQoKICAgICAgICAgICAgd2hpbGUgOgogICAgICAgICAgICBkbwogICAgICAgICAgICAgICAgcHJpbnRmICJcYiR7c3A6aSsrJSR7I3NwfToxfSIKICAgICAgICAgICAgICAgIHNsZWVwICRkZWxheQogICAgICAgICAgICBkb25lCiAgICAgICAgICAgIDs7CiAgICAgICAgc3RvcCkKICAgICAgICAgICAgaWYgW1sgLXogJHszfSBdXTsgdGhlbgogICAgICAgICAgICAgICAgZWNobyAic3Bpbm5lciBpcyBub3QgcnVubmluZy4uIgogICAgICAgICAgICAgICAgZXhpdCAxCiAgICAgICAgICAgIGZpCgogICAgICAgICAgICBraWxsICQzID4gL2Rldi9udWxsIDI+JjEKCiAgICAgICAgICAgICMgaW5mb3JtIHRoZSB1c2VyIHVwcG9uIHN1Y2Nlc3Mgb3IgZmFpbHVyZQogICAgICAgICAgICBlY2hvIC1lbiAiXGJbIgogICAgICAgICAgICBpZiBbWyAkMiAtZXEgMCBdXTsgdGhlbgogICAgICAgICAgICAgICAgZWNobyAtZW4gIiR7Z3JlZW59JHtvbl9zdWNjZXNzfSR7bmN9IgogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBlY2hvIC1lbiAiJHtyZWR9JHtvbl9mYWlsfSR7bmN9IgogICAgICAgICAgICBmaQogICAgICAgICAgICBlY2hvIC1lICJdIgogICAgICAgICAgICA7OwogICAgICAgICopCiAgICAgICAgICAgIGVjaG8gImludmFsaWQgYXJndW1lbnQsIHRyeSB7c3RhcnQvc3Rvc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