-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinstall.sh
executable file
·201 lines (184 loc) · 5.24 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
#!/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
#Set pip install configuration to no-cache-dir
pip3 config set install.no-cache-dir on
#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 ./home-assistant-on-openwrt/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 ./home-assistant-on-openwrt/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 ./home-assistant-on-openwrt/sodium.h /usr/include/python3.6/ && \
cp -r ./home-assistant-on-openwrt/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==1.3.0
if [ $? -ne 0 ]; then
continue
else
break
fi
else
echo -e "\033[31m ERROR! Install PyNacl failed, exit. \033[0m"
exit 0
fi
done
#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
continue
else
break
fi
else
echo -e "\033[33m Install HomeAssistant failed, exit. \033[0m"
exit 0
fi
done
#Config the homeassistant
mkdir -p /data/.homeassistant
cp ./home-assistant-on-openwrt/configuration/* /data/.homeassistant/
#Install finished
echo -e "\033[32m HomeAssistant installation finished. Use command \"hass -c /data/.homeassistant\" to start it. \033[0m"
echo -e "\033[32m Note that the firstly start will take 20~30 minutes. If failed, retry it. \033[0m"