-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbp-update
executable file
·157 lines (137 loc) · 4.36 KB
/
bp-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
#!/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_KERNEL_DIR=/tmp/kernel.tmp
TEMP_ROOTFS_DIR=/tmp/rootfs.tmp
VERSION="v1.0.0"
uSage()
{
echo -e "bp-update: $VERSION"
echo -e "Usage:"
echo -e "\tbp-update [ pi|pro ] [ kernel|rootfs|all ]"
echo -e "\nReport bp-update bugs to http://bugs.lemaker.org/"
echo -e "For more information, Please visit the website at <https://github.com/LeMaker/scripts>"
exit -1
}
#Return value 0:upgrade success 1: don't upgrade -1:upgrade failure
upgradeKernel()
{
if [ -d $TEMP_KERNEL_DIR ];then
rm -rf $TEMP_KERNEL_DIR
fi
echo -e "\033[32mCreate dirctory $TEMP_KERNEL_DIR ...\033[0m"
mkdir $TEMP_KERNEL_DIR
type wget > /dev/null 2>&1
if [ 0 -ne $? ];then
echo -e "\033[31mwget command not found, please install the wget package ...\033[0m"
exit -1
fi
echo -e "\033[32mDownload the kernel upgarde packet, Please wait ...\033[0m"
echo -e "-----------------------------------------------------------"
wget -c --no-check-certificate -t 3 https://raw.githubusercontent.com/LeMaker/firmware/master/linux-latest.tar.bz2 -O $TEMP_KERNEL_DIR/linux-latest.tar.bz2
wget -c --no-check-certificate -t 3 https://raw.githubusercontent.com/LeMaker/firmware/master/linux-latest.tar.bz2.asc -O $TEMP_KERNEL_DIR/linux-latest.tar.bz2.asc
echo -e "-----------------------------------------------------------"
echo -e "\033[32mVerifying signature... \033[0m\n"
echo -e "-----------------------------------------------------------"
gpg --verify $TEMP_KERNEL_DIR/linux-latest.tar.bz2.asc
if [ $? -ne 0 ]; then
echo -e "\n\033[31minvalid signature. exiting!\033[0m"
rm -rf $TEMP_KERNEL_DIR
exit -1
else
echo -e "\n\033[32msignature okay.\033[0m\n"
fi
echo -e "-----------------------------------------------------------"
tar xf $TEMP_KERNEL_DIR/linux-latest.tar.bz2 -C $TEMP_KERNEL_DIR #Decompressing file
if [ $? -ne 0 ];then
echo -e "\033[31Failed to decompress $TEMP_KERNEL_DIR/linux-latest.tar.bz2\033[0m"
exit -1
fi
if ! [ -f $TEMP_KERNEL_DIR/bp-kernel-update ];then
echo -e "\033[31mUpgrade kernel error and TEMP_KERNEL_DIR/bp-kernel-update is not exist\033[0m"
exit -1
fi
if ! [ -x $TEMP_KERNEL_DIR/bp-kernel-update ];then
chmod +x $TEMP_KERNEL_DIR/bp-kernel-update
fi
$TEMP_KERNEL_DIR/bp-kernel-update $1 $TEMP_KERNEL_DIR && \
rm -rf $TEMP_KERNEL_DIR
}
upgradeRootfs()
{
return 0
}
#----------------------------Start Run------------------------------
if [ $# -lt 1 ] || [ "$1" != "pi" -a "$1" != "pro" ];then
uSage
fi
if [ "$2" = "all" ];then
OPTVAL=1
elif [ "$2" = "kernel" ];then
OPTVAL=2
elif [ "$2" = "rootfs" ];then
OPTVAL=3
else
uSage
fi
# Clear screen
clear
sleep 1
echo -e "\033[36mWelcome to upgrade the system 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
# Create a default GnuPG config
type gpg > /dev/null 2>&1
if [ 0 -ne $? ];then
echo -e "\033[31mgpg command not found, please install the gnupg package ...\033[0m"
exit -1
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 65524CFE
echo -e "-----------------------------------------------------------"
case $OPTVAL in
1)
upgradeKernel $1
if [ $? -ne 0 -a $? -ne 1 ];then
exit -1
fi
upgradeRootfs $1
if [ $? -eq 0 ];then
reboot
fi
;;
2)
upgradeKernel $1
if [ $? -eq 0 ];then
reboot
fi
;;
3)
upgradeRootfs $1
if [ $? -eq 0 ];then
reboot
fi
;;
esac