-
Notifications
You must be signed in to change notification settings - Fork 97
/
install.sh
executable file
·199 lines (155 loc) · 4.48 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
#!/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
_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
FIRMWARE_CONFIG=/boot/firmware/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() {
# Check if the file /boot/firmware/config.txt exists
config_file=$FIRMWARE_CONFIG
if [ ! -f $config_file ]; then
config_file=$CONFIG
fi
egrep -q "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" $config_file
echo $?
}
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)
do_uninstall=false
if [ "$1" == "uninstall" ]; then
do_uninstall=true
fi
### Uninstall this package ###
if [ "$do_uninstall" == "true" ]; then
# To remove all users installaon
pip3 uninstall -y $_package_name
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
command -v python3 >/dev/null 2>&1 || { echo "Executable \"python3\" couldn't be found. Error occurred with RFR_Tools installation." >&2; exit 4; }
command -v pip3 >/dev/null 2>&1 || { echo "Executable \"pip3\" couldn't be found. Error occurred with RFR_Tools installation." >&2; exit 5; }
### Check i2c
if [ $(get_i2c) -ne 0 ]; then
echo I2C is not enabled.
echo "Please enable I2C by running raspi-config and selecting Interfacing Options -> I2C"
exit 1
fi
## install library rpi.gpio
if [ "X$platform" == "Xrpi" ]; then
(( r == 0 )) && { pip_install RPi.GPIO 'pip3 install RPi.GPIO'; r=$?; }
fi
## install library rpi-ws281x
if [ "X$platform" == "Xrpi" ]; then
(( r == 0 )) && { pip_install rpi-ws281x 'pip3 install rpi-ws281x'; r=$?; }
fi
## install library smbus
(( r == 0 )) && { pip_install smbus 'pip3 install smbus'; r=$?; }
## install library smbus2
(( r == 0 )) && { pip_install smbus2 'pip3 install smbus2'; r=$?; }
## install library bme680
(( r == 0 )) && { pip_install bme680 'pip3 install bme680'; r=$?; }
## install library bmm150
(( r == 0 )) && { pip_install bmm150 'pip3 install bmm150'; r=$?; }
## install library sgp30
(( r == 0 )) && { pip_install sgp30 'pip3 install sgp30'; r=$?; }
# install this python repository
(( r == 0 )) && { pip_install Seeed-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