-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·230 lines (213 loc) · 6.08 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
#!/bin/sh
#Compare the first version and the second version. If the first lower than the second return 0 , or return 1
CompareVersion() {
fversion_1=`echo $1 | awk -F '.' '{print $1}'`
fversion_2=`echo $1 | awk -F '.' '{print $2}'`
fversion_3=`echo $1 | awk -F '.' '{print $3}'`
sversion_1=`echo $2 | awk -F '.' '{print $1}'`
sversion_2=`echo $2 | awk -F '.' '{print $2}'`
sversion_3=`echo $2 | awk -F '.' '{print $3}'`
if [ $fversion_1 -lt $sversion_1 ]; then
return 0
elif [ $fversion_1 -gt $sversion_1 ]; then
return 1
fi
if [ $fversion_2 -lt $sversion_2 ]; then
return 0
elif [ $fversion_2 -gt $sversion_2 ]; then
return 1
fi
if [ $fversion_3 -lt $sversion_3 ]; then
return 0
elif [ $fversion_3 -gt $sversion_3 ]; then
return 1
fi
return 0
}
#Get into the installation path /root/
cd /root/
currentpath=`pwd`
if [ "$currentpath" != "/root" ]; then
echo -e "\033[31m ERROR! Cannot get into installation path, exit. \033[0m"
exit 0
fi
#Update the opkg package info
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m opkg update...... try $try. \033[0m"
opkg update
if [ $? -ne 0 ]; then
continue
else
break
fi
else
echo -e "\033[31m ERROR! opkg update failed, check the network connection, exit. \033[0m"
exit 0
fi
done
#Install python3.6
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Installing python3.6...... try $try. \033[0m"
opkg install python3
if [ $? -ne 0 ]; then
continue
else
break
fi
else
echo -e "\033[31m ERROR! Install python3.6 failed, check the network connection, exit. \033[0m"
exit 0
fi
done
#Download and install latest pip for python3
pipreq=0
command -v pip > /dev/null 2>&1
if [ $? -eq 0 ]; then
CompareVersion 19.1.1 `pip --version | awk '{print $2}'`
if [ $? -eq 0 ]; then
pipreq=1
fi
fi
if [ $pipreq -ne 1 ]; then
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Download and install pip...... try $try. \033[0m"
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py && python3 get-pip.py
if [ $? -ne 0 ]; then
rm ./get-pip.py
continue
else
break
fi
else
echo -e "\033[31m ERROR! Install pip failed, exit. \033[0m"
exit 0
fi
done
rm ./get-pip.py
fi
#Install gcc
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Download and install gcc...... try $try. \033[0m"
opkg install gcc
if [ $? -ne 0 ]; then
continue
else
break
fi
else
echo -e "\033[31m ERROR! Install gcc failed, exit. \033[0m"
exit 0
fi
done
#Install dependent C library
opkg install python3-dev
if [ $? -ne 0 ]; then
echo -e "\033[31m ERROR! Install python-dev failed, exit. \033[0m"
exit 0
fi
echo -e "\033[32m Install C library......libffi \033[0m"
mkdir -p /usr/include/ffi && \
cp ./HomeAssistantOnOPENWRT/ffi* /usr/include/ffi && \
ln -s /usr/lib/libffi.so.6.0.1 /usr/lib/libffi.so
echo -e "\033[32m Install C library......libopenssl \033[0m"
cp -r ./HomeAssistantOnOPENWRT/openssl /usr/include/python3.6/ && \
ln -s /usr/lib/libcrypto.so.1.0.0 /usr/lib/libcrypto.so && \
ln -s /usr/lib/libssl.so.1.0.0 /usr/lib/libssl.so
echo -e "\033[32m Install C library......libsodium \033[0m"
opkg install libsodium
if [ $? -ne 0 ]; then
echo -e "\033[31m ERROR! Install libsodium failed, exit. \033[0m"
exit 0
fi
cp ./HomeAssistantOnOPENWRT/sodium.h /usr/include/python3.6/ && \
cp -r ./HomeAssistantOnOPENWRT/sodium /usr/include/python3.6/ && \
ln -s /usr/lib/libsodium.so.23.1.0 /usr/lib/libsodium.so
#Install dependent python module
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Install python module: PyNaCl...... try $try. \033[0m"
SODIUM_INSTALL=system pip3 install pynacl
if [ $? -ne 0 ]; then
rm -rf ./.cache/
continue
else
break
fi
else
echo -e "\033[31m ERROR! Install PyNacl failed, exit. \033[0m"
exit 0
fi
done
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Download python module: cryptography...... try $try. \033[0m"
curl https://files.pythonhosted.org/packages/07/ca/bc827c5e55918ad223d59d299fff92f3563476c3b00d0a9157d9c0217449/cryptography-2.6.1.tar.gz > cryptography-2.6.1.tar.gz
if [ $? -ne 0 ]; then
rm ./cryptography-2.6.1.tar.gz
rm -rf ./.cache/
continue
else
break
fi
else
echo -e "\033[31m ERROR! Download cryptography failed, exit. \033[0m"
exit 0
fi
done
echo -e "\033[32m Install python module: cryptography...... \033[0m"
tar -xzvf cryptography-2.6.1.tar.gz && \
cd ./cryptography-2.6.1 && \
LDFLAGS=-pthread python3 setup.py install && \
cd ../
if [ $? -ne 0 ]; then
echo -e "\033[31m ERROR! Install cryptography failed, exit. \033[0m"
exit 0
fi
rm -rf ./cryptography-2.6.1*
#Install Home Assistant
try=0
while true
do
try=$((try+1))
if [ $try -le 5 ]; then
echo -e "\033[33m Install HomeAssistant...... try $try. \033[0m"
python3 -m pip install homeassistant
if [ $? -ne 0 ]; then
rm -rf ./.cache/
continue
else
break
fi
else
echo -e "\033[33m Install HomeAssistant failed, exit. \033[0m"
exit 0
fi
done
#Config the homeassistant
mkdir -p ./.homeassistant
cp ./HomeAssistantOnOPENWRT/configuration/* ./.homeassistant/
#Install finished
echo -e "\033[32m HomeAssistant installation finished. Use command \"hass\" to start the HA. \033[0m"
echo -e "\033[32m Note that the firstly start will take 20~30 minutes. If failed, retry it. \033[0m"