-
Notifications
You must be signed in to change notification settings - Fork 6
/
lemedia-update
executable file
·282 lines (238 loc) · 10.4 KB
/
lemedia-update
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
#!/bin/bash
#
# Copyright (C) 2014 LeMaker Community <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#--------------------------------------------------------------------------------------------------
TEMP_LEMEDIA_DIR=/tmp/lemedia.tmp
LATEST_LEMEDIA_VERSION=1.1 #initial value
CURRENT_LEMEDIA_VERSION=1.0 #initial value
#--------------------------------------------------------------------------------------------------
Get_LeMedia_Version()
{
if [ -d /allwinner/bpi-settings/version/ ];then
if [ "`ls -A /allwinner/bpi-settings/version/`" = "" ];then
CURRENT_LEMEDIA_VERSION=1.0
else
CURRENT_LEMEDIA_VERSION=`ls /allwinner/bpi-settings/version/ | sed 's/+//g'`
fi
else
CURRENT_LEMEDIA_VERSION=1.0
fi
LATEST_LEMEDIA_VERSION=`ls $TEMP_LEMEDIA_DIR/allwinner/bpi-settings/version/ | sed 's/+//g'`
echo -e "CURRENT_LEMEDIA_VERSION= $CURRENT_LEMEDIA_VERSION"
echo -e "LATEST_LEMEDIA_VERSION= $LATEST_LEMEDIA_VERSION"
}
LeVerCompare()
{
CURRENT_VERSION=`echo $1 | cut -d. -f1`
UPGRADE_VERSION=`echo $2 | cut -d. -f1`
CURRENT_PATCHLEVEL=`echo $1 | cut -d. -f2`
UPGRADE_PATCHLEVEL=`echo $2 | cut -d. -f2`
if [ "$UPGRADE_VERSION" -gt "$CURRENT_VERSION" ];then
return 0
elif [ "$UPGRADE_VERSION" -eq "$CURRENT_VERSION" ];then
if [ "$UPGRADE_PATCHLEVEL" -gt "$CURRENT_PATCHLEVEL" ];then
return 0
elif [ "$UPGRADE_PATCHLEVEL" -eq "$CURRENT_PATCHLEVEL" ];then
return 1
else
return -1
fi
else
return -1
fi
}
action()
{
echo -e $1 && $1
if [ $? -ne 0 ];then
echo -e $2
exit -1
fi
}
#Return value 0:upgrade success 1: don't upgrade -1:upgrade failure
upgradeLeMedia()
{
if [ -d $TEMP_LEMEDIA_DIR ];then
rm -rf $TEMP_LEMEDIA_DIR
fi
echo -e "\033[32mCreate dirctory $TEMP_LEMEDIA_DIR ...\033[0m"
mkdir -p $TEMP_LEMEDIA_DIR
type wget > /dev/null 2>&1
if [ 0 -ne $? ];then
echo -e "\033[31mwget command not found, will install the wget package now...\033[0m"
#exit -1
apt-get install wget
sleep 1
fi
echo -e "\033[32mDownload the LeMedia upgarde packet, Please wait ...\033[0m"
echo -e "-----------------------------------------------------------"
wget -c --no-check-certificate -t 3 https://raw.githubusercontent.com/LeMaker/firmware/master/lemedia-latest.tgz -O $TEMP_LEMEDIA_DIR/lemedia-latest.tgz
wget -c --no-check-certificate -t 3 https://raw.githubusercontent.com/LeMaker/firmware/master/lemedia-latest.tgz.asc -O $TEMP_LEMEDIA_DIR/lemedia-latest.tgz.asc
echo -e "-----------------------------------------------------------"
echo -e "\033[32mVerifying signature... \033[0m\n"
echo -e "-----------------------------------------------------------"
gpg --verify $TEMP_LEMEDIA_DIR/lemedia-latest.tgz.asc
if [ $? -ne 0 ]; then
echo -e "\n\033[31minvalid signature. exiting!\033[0m"
rm -rf $TEMP_LEMEDIA_DIR
exit -1
else
echo -e "\n\033[32msignature okay.\033[0m\n"
fi
echo -e "-----------------------------------------------------------"
tar xvzf $TEMP_LEMEDIA_DIR/lemedia-latest.tgz -C $TEMP_LEMEDIA_DIR #Decompressing file
if [ $? -ne 0 ];then
echo -e "\033[31Failed to decompress $$TEMP_LEMEDIA_DIR/lemedia-latest.tgz\033[0m"
exit -1
fi
#--------------------------------------------------------------
Get_LeMedia_Version
LeVerCompare $CURRENT_LEMEDIA_VERSION $LATEST_LEMEDIA_VERSION
case $? in
'0')
clear
echo -e "\033[32mUpdate the LeMedia ...\033[0m"
#---------------------------------------------------------------------------------------------
cd ~
umount /mnt
sleep 1
action "mount /dev/mmcblk0p1 /mnt" "\033[31mFailed to mount the /dev/mmcblk0p1\033[0m"
echo -e "\033[32m 1.Update the file uEnv.txt and script.bin ...\033[0m"
action "rm -rf /mnt/uEnv.txt script.bin" "\033[31mFailed to remove the file uEnv.txt and script.bin\033[0m"
action "cp -f $TEMP_LEMEDIA_DIR/uEnv.txt /mnt/uEnv.txt" "\033[31mFailed to copy the uEnv.txt\033[0m"
action "cp -f $TEMP_LEMEDIA_DIR/script.bin /mnt/script.bin" "\033[31mFailed to copy the script.bin\033[0m"
action "sync" "\033[31mFailed to sync\033[0m"
action "umount /mnt" "\033[31mFailed to umount /mnt\033[0m"
sleep 1
#---------------------------------------------------------------------------------------------
echo -e "\033[32m 2.Update the /root/.profile ...\033[0m"
action "cp -f $TEMP_LEMEDIA_DIR/root/profile /root/.profile" "\033[31mFailed to copy the .profile\033[0m"
#---------------------------------------------------------------------------------------------
echo -e "\033[32m 3.Update the /etc/modules ...\033[0m"
action "cp -rf $TEMP_LEMEDIA_DIR/etc/modules /etc/modules" "\033[31mFailed to copy the file modules\033[0m"
#---------------------------------------------------------------------------------------------
echo -e "\033[32m 4.Update the audio output device setting ...\033[0m"
action "cp -rf $TEMP_LEMEDIA_DIR/allwinner/bpi-settings /allwinner/" "\033[31mFailed to copy bpi-settings\033[0m"
action "cp -rf $TEMP_LEMEDIA_DIR/usr/bin/* /usr/bin/" "\033[31mFailed to copy bin files\033[0m"
chmod +x /usr/bin/xbmc-audio-hdmi
chmod +x /usr/bin/xbmc-audio-jack
apt-get install alsa alsa-base alsa-utils
#---------------------------------------------------------------------------------------------
echo -e "\033[32m 5.Update the wireless network ...\033[0m"
echo -e "-----------------------------------------------------------"
echo -e "\033[32m now,will install firmware-linux-free...\033[0m"
apt-get install firmware-linux-free
echo -e "-----------------------------------------------------------"
echo -e "\033[32m now,will install dhcpcd...\033[0m"
apt-get install dhcpcd
echo -e "\033[32m now,will install wireless-tools...\033[0m"
apt-get install wireless-tools
echo -e "\033[32m Decompressing the packages for installing wpa_supplicant...\033[0m"
tar xvzf $TEMP_LEMEDIA_DIR/wpa.tgz -C $TEMP_LEMEDIA_DIR #Decompressing file
if [ $? -ne 0 ];then
echo -e "\033[31Failed to decompress $$TEMP_LEMEDIA_DIR/wpa.tgz\033[0m"
exit -1
fi
echo -e "-----------------------------------------------------------"
echo -e "\033[32m Make and install libnl...\033[0m"
chmod +x $TEMP_LEMEDIA_DIR/wpa/libnl-1.1/configure
cd $TEMP_LEMEDIA_DIR/wpa/libnl-1.1/
./configure
cd ~
make -C $TEMP_LEMEDIA_DIR/wpa/libnl-1.1/
if [ 0 -ne $? ];then
echo -e "\033[31libnl make failed,please check the log...\033[0m"
exit -1
fi
make install -C $TEMP_LEMEDIA_DIR/wpa/libnl-1.1/
echo -e "-----------------------------------------------------------"
echo -e "\033[32m Make and install openssl...\033[0m"
make -C $TEMP_LEMEDIA_DIR/wpa/openssl-1.0.1c/
if [ 0 -ne $? ];then
echo -e "\033[31openssl make failed,please check the log...\033[0m"
exit -1
fi
make install -C $TEMP_LEMEDIA_DIR/wpa/openssl-1.0.1c/
echo -e "-----------------------------------------------------------"
echo -e "\033[32m Make and install wpa_supplicant...\033[0m"
make -C $TEMP_LEMEDIA_DIR/wpa/wpa_supplicant-2.3/wpa_supplicant/
if [ 0 -ne $? ];then
echo -e "\033[31wpa_supplicant make failed,please check the log...\033[0m"
exit -1
fi
make install -C $TEMP_LEMEDIA_DIR/wpa/wpa_supplicant-2.3/wpa_supplicant/
echo -e "Now, configure the wpa..."
action "cp -rf $TEMP_LEMEDIA_DIR/etc/wpa_supplicant/ /etc/" "\033[31mFailed to copy the file wpa_supplicant.conf\033[0m"
action "cp -f $TEMP_LEMEDIA_DIR/etc/network/interfaces /etc/network/" "\033[31mFailed to copy the file interfaces\033[0m"
action "rm -rf /etc/udev/rules.d/70-persistant-net.rules" "\033[31mFailed to remove the file 70-persistant-net.rules\033[0m"
echo -e "\033[31m----------------------------------------------------------->>>>>>\033[0m"
echo -e "\033[31m*******LeMedia is updated to version $LATEST_LEMEDIA_VERSION , Please check and enjoy it:):) ********\033[0m"
echo -e "\033[31m<<<<<<<-----------------------------------------------------------\033[0m"
rm -rf $TEMP_LEMEDIA_DIR
exit 0
;;
'1')
echo -e "\033[32mThe LeMedia is the latest, don't need to upgrade\033[0m"
rm -rf $TEMP_LEMEDIA_DIR
exit 1
;;
*)
echo -e "\033[31mThe LeMedia upgrade error and $LATEST_LEMEDIA_VERSION < $CURRENT_LEMEDIA_VERSION\033[0m"
rm -rf $TEMP_LEMEDIA_DIR
exit -1
esac
#;;
}
#----------------------------Start Run------------------------------
# Clear screen
clear
sleep 1
echo -e "\033[36mWelcome to upgrade the LeMedia for BananaPi/BananaPro ... \033[0m"
# Detect user
TEMP_USER=`whoami`
if ! [ "$TEMP_USER" = "root" ];then
echo -e "\033[31mPlease use the root account \033[0m"
exit -1
fi
# Make sure the BananaPi/Pro links to the network.
echo -e "\033[31mPlease make sure the BananaPi/Pro links to the network!!! \033[0m"
#update the system date
echo -e "-----------------------------------------------------------"
echo -e "\033[32m Update the system date ...\033[0m"
ntpdate ntp1.nl.net
if [ 0 -ne $? ];then
echo -e "\033[31 ntpdate failed ,there may be some issues due to the wrong time!!!!\033[0m"
sleep 2
fi
echo -e "-----------------------------------------------------------"
# Create a default GnuPG config
type gpg > /dev/null 2>&1
if [ 0 -ne $? ];then
echo -e "\033[31mgpg command not found, will install the gnupg package now...\033[0m"
#exit -1
apt-get install gnupg
sleep 3
fi
if ! [ -f /root/.gnupg/gpg.conf ];then
echo -e "\033[32mCreate a default GnuPG config...\033[0m"
gpg -k
fi
# Receiving/updating public key
echo -e "-----------------------------------------------------------"
echo -e "\033[32mReceiving/updating public key ...\033[0m"
gpg --recv-keys 077E8FE9
echo -e "-----------------------------------------------------------"
upgradeLeMedia
# The script end.