forked from Seeed-Studio/grove.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·310 lines (254 loc) · 6.95 KB
/
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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/bin/bash
#
: <<'EOF'
The MIT License (MIT)
Seeed-Studio Raspberry Pi Hats.
Peter Yang, [email protected]
Copyright (C) 2018 Seeed Technology Co.,Ltd.
EOF
_DEBUG=0
_install_extra_library=true
_package_name=grove.py
_seeed_source_list=/etc/apt/sources.list.d/seeed.list
_seeed_apt_key="BB8F 40F3"
_repo_package_url=https://github.com/Seeed-Studio/$_package_name/archive/master.zip
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
CONFIG=/boot/config.txt
if [ $_DEBUG -ne 0 ]; then
BLACKLIST=./raspi-blacklist.conf
CONFIG=./config.txt
fi
set_config_var() {
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
if line:match("^#?%s*"..key.."=.*$") then
line=key.."="..value
made_change=true
end
print(line)
end
if not made_change then
print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}
get_i2c() {
egrep -q "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" $CONFIG
echo $?
}
do_i2c() {
DEFAULT=--defaultno
if [ $(get_i2c) -eq 0 ]; then
DEFAULT=
fi
RET=$1
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
return $RET
fi
set_config_var dtparam=i2c_arm $SETTING $CONFIG &&
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/"
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/"
if ! grep -q "^i2c[-_]dev" /etc/modules; then
printf "i2c-dev\n" >> /etc/modules
fi
dtparam i2c_arm=$SETTING
modprobe i2c-dev
}
function apt_install() {
pkg_name=$1
for ((i = 0; i < 3; i++)); {
apt-get install -y $pkg_name
pkg_status=$(dpkg -s $pkg_name | egrep "Status:.*" | awk '{ printf "%s", $2; }')
[ "$pkg_status" == "install" ] && return 0
}
return 1
}
alias pip=' pip --no-cache-dir'
alias pip3='pip3 --no-cache-dir'
function pip_install() {
local fields
pkg_name=$1
pip_cmd=${2}
fields=( $pip_cmd )
for ((i = 0; i < 3; i++)); {
$pip_cmd
pkg_status=$(${fields[0]} list --format=columns | egrep "$pkg_name " | awk '{ printf "%s", $1; }')
[ "$pkg_status" == "$pkg_name" ] && return 0
}
return 1
}
function platform_get() {
local dts_model platform
dts_model=$(strings /proc/device-tree/model)
case "$dts_model" in
TI\ AM335x*)
platform=bbb;;
Raspberry\ Pi*)
platform=rpi;;
Freescale\ i\.MX8MQ\ Phanbell)
platform=coral;;
NVIDIA\ Jetson\ Nano*)
platform=jetson_nano;;
*)
platform="unknown";;
esac
echo $platform
}
# Get platform type
platform=$(platform_get)
if [[ "$platform" == "jetson_nano" ]];then
_install_extra_library=false
fi
do_uninstall=false
if [ "$1" == "uninstall" ]; then
do_uninstall=true
fi
# Everything else needs to be run as root
if [ $(id -u) -ne 0 ]; then
printf "Script must be run as root. Try 'sudo $0'\n"
exit 1
fi
### Uninstall this package ###
if [ "$do_uninstall" == "true" ]; then
# To remove all users installaon
pip uninstall -y $_package_name
pip3 uninstall -y $_package_name
apt-get -y remove python-grove-py
apt-get -y remove python3-grove-py
exit 0
fi
# install dependencies
### add repository
if [ ! -f $_seeed_source_list ]; then
case "$platform" in
coral)
code_name="mendel-beaker";;
rpi)
code_name="stretch";;
jetson_nano)
code_name="bionic";;
*)
code_name="unknown";;
esac
echo "deb https://seeed-studio.github.io/pi_repo/ $code_name main" | tee $_seeed_source_list
fi
### add public GPG key
if ! apt-key list | egrep "$_seeed_apt_key" > /dev/null; then
curl https://seeed-studio.github.io/pi_repo/public.key | apt-key add -
fi
## Initial installation
r=0
## Update apt source
apt -y update
case "$platform" in
coral)
apt_install python-pip
apt_install python3-pip
apt_install python-setuptools
apt_install python3-setuptools
apt_install python-wheel
apt_install python3-wheel
## install library enum
;;
jetson_nano)
apt_install python-pip
apt_install python3-pip
apt_install python-setuptools
apt_install python3-setuptools
apt_install python-wheel
apt_install python3-wheel
pushd .
cd `dirname $0`
cp ./udev/jetson-nano/99-tegra-i2cset.rules /etc/udev/rules.d/
popd
;;
rpi)
apt_install python-pip
apt_install python3-pip
### install I2C ###
if [ $(get_i2c) -ne 0 ]; then
# enable i2c interface
echo Enable I2C interface ...
do_i2c 0
fi
echo I2C interface enabled...
## install library raspberry-gpio-python
(( r == 0 )) && { apt_install python-rpi.gpio; r=$?; }
(( r == 0 )) && { apt_install python3-rpi.gpio; r=$?; }
;;
*)
echo "unsupport platform $platform, abort ..."
exit 1
;;
esac
## install MRAA & UPM
### libmraa
(( r == 0 )) && { apt_install libmraa1; r=$?; }
### python2
(( r == 0 )) && { apt_install python-mraa; r=$?; }
(( r == 0 )) && { apt_install python-upm; r=$?; }
### python3
(( r == 0 )) && { apt_install python3-mraa;r=$?; }
(( r == 0 )) && { apt_install python3-upm; r=$?; }
## install library libbma456
if [[ "$_install_extra_library" == "true" ]];then
(( r == 0 )) && { apt_install libbma456; r=$?; }
fi
## install library libbmi088
if [[ "$_install_extra_library" == "true" ]];then
(( r == 0 )) && { apt_install libbmi088; r=$?; }
fi
## install library rpi-ws281x
if [ "X$platform" == "Xrpi" ]; then
(( r == 0 )) && { pip_install rpi-ws281x 'pip install rpi-ws281x'; r=$?; }
(( r == 0 )) && { pip_install rpi-ws281x 'pip3 install rpi-ws281x'; r=$?; }
fi
## install library smbus
(( r == 0 )) && { pip_install smbus 'pip install smbus'; r=$?; }
(( r == 0 )) && { pip_install smbus 'pip3 install smbus'; r=$?; }
## install library smbus2
(( r == 0 )) && { pip_install smbus2 'pip install smbus2'; r=$?; }
(( r == 0 )) && { pip_install smbus2 'pip3 install smbus2'; r=$?; }
## install library bme680
(( r == 0 )) && { pip_install bme680 'pip install bme680'; r=$?; }
(( r == 0 )) && { pip_install bme680 'pip3 install bme680'; r=$?; }
## install library rpi-vl53l0x
if [[ "$_install_extra_library" == "true" ]];then
(( r == 0 )) && { pip_install rpi-vl53l0x 'pip install rpi-vl53l0x'; r=$?; }
(( r == 0 )) && { pip_install rpi-vl53l0x 'pip3 install rpi-vl53l0x'; r=$?; }
fi
## install library sgp30
(( r == 0 )) && { pip_install sgp30 'pip install sgp30'; r=$?; }
(( r == 0 )) && { pip_install sgp30 'pip3 install sgp30'; r=$?; }
# install this python repository
(( r == 0 )) && { pip_install grove.py "pip install --upgrade $_repo_package_url"; r=$?; }
(( r == 0 )) && { pip_install grove.py "pip3 install --upgrade $_repo_package_url"; r=$?; }
(( r == 0 )) && { which grove_button > /dev/null; r=$?; }
(( r != 0 )) && {
echo "-------------------------------------------------------"
echo " Grove.py installation FAILED, FAILED, FAILED "
echo "-------------------------------------------------------"
exit 1
}
sync
sleep 1
sync
echo "#######################################################"
echo " Lastest Grove.py from github install complete !!!!!"
echo "#######################################################"
exit 0