forked from armbian/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.sh
325 lines (277 loc) · 12.6 KB
/
upgrade.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
#
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of tool chain https://github.com/igorpecovnik/lib
#
BOARD=""
RELEASE=$(lsb_release -cs)
if [[ "$RELEASE" == "sid" ]]; then RELEASE="jessie"; fi
if [[ "$RELEASE" == "testing" ]]; then RELEASE="jessie"; fi
backtitle="Armbian install script, http://www.armbian.com | Author: Igor Pecovnik"
title="Armbian universal installer 2015.11"
#-----------------------------------------------------------------------------------------------------------------------
# Show warning at start
#-----------------------------------------------------------------------------------------------------------------------
display_warning()
{
read -r -d '' MOJTEXT << EOM
1. Please do a backup even the script doesn't plan to ruin anything critical.
2. If you choose wrong board you might end up with not bootable system.
3. We are going to remove current kernel package together with headers, firmware and board definitions.
4. The script will also conduct apt-get upgrade so all packages will be upgraded.
5. Where possible you can upgrade/downgrade kernel from legacy to vanilla and vice versa.
6. The whole process takes at least 8 minutes on a fresh image to 30 minutes if you upgrade from other system.
7. You might need to power cycle the board.
EOM
dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Z0\n$MOJTEXT" 36 74
if [ $? -ne 0 ]; then exit 1; fi
}
#-----------------------------------------------------------------------------------------------------------------------
# Create boot scripts for Allwinner boards
#-----------------------------------------------------------------------------------------------------------------------
create_boot_script ()
{
[ -f "/boot/boot.cmd" ] && cp /boot/boot.cmd /boot/boot.cmd.backup
cat > /boot/boot.cmd <<EOT
setenv bootargs "console=tty1 root=$rootdevice rootwait rootfstype=ext4 sunxi_ve_mem_reserve=0 sunxi_g2d_mem_reserve=0 \
sunxi_no_mali_mem_reserve sunxi_fb_mem_reserve=16 hdmi.audio=EDID:0 disp.screen0_output_mode=1920x1080p60 panic=10 \
consoleblank=0 enforcing=0 loglevel=1"
#-----------------------------------------------------------------------------------------------------------------------
# Boot loader script to boot with different boot methods for old and new kernel
#-----------------------------------------------------------------------------------------------------------------------
if ext4load mmc 0 0x00000000 /boot/.next || fatload mmc 0 0x00000000 .next
then
# sunxi mainline kernel
#-----------------------------------------------------------------------------------------------------------------------
ext4load mmc 0 0x49000000 /boot/dtb/\${fdtfile} || fatload mmc 0 0x49000000 /dtb/\${fdtfile}
ext4load mmc 0 0x46000000 /boot/zImage || fatload mmc 0 0x46000000 zImage
env set fdt_high ffffffff
bootz 0x46000000 - 0x49000000
#-----------------------------------------------------------------------------------------------------------------------
else
# sunxi android kernel
#-----------------------------------------------------------------------------------------------------------------------
ext4load mmc 0 0x43000000 /boot/script.bin || fatload mmc 0 0x43000000 script.bin
ext4load mmc 0 0x48000000 /boot/zImage || fatload mmc 0 0x48000000 zImage
bootz 0x48000000
#-----------------------------------------------------------------------------------------------------------------------
fi
# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
EOT
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1
}
#-----------------------------------------------------------------------------------------------------------------------
# Install packeges and repository
#-----------------------------------------------------------------------------------------------------------------------
install_repo ()
{
dialog --title "$title" --backtitle "$backtitle" --infobox "\nAdding repository and running pkg list update." 5 50
# remove system hostapd
apt-get -f -qq install
apt-get clean
apt-get -y -qq remove hostapd
if [ $? -ne 0 ]; then
dialog --title "$title" --backtitle "$backtitle" --infobox "\nError in apt-get. Can not continue." 5 40
exit 1
fi
# move armbian to separate list and remove others
sed -i '/armbian/d' /etc/apt/sources.list
if [ -f "/etc/apt/sources.list.d/bananian.list" ]; then
rm -f /etc/apt/sources.list.d/bananian.list
rm -f /etc/kernel/postinst.d/bananian-kernel-postinst
chsh -s /bin/bash
echo "Armbian lite" > /etc/motd
echo "" >> /etc/motd
fi
if [ ! -f "/etc/apt/sources.list.d/armbian.list" ]; then
echo -e "[\e[0;32m o.k. \x1B[0m] Updating package list. Please wait"
echo "deb http://apt.armbian.com $RELEASE main" > /etc/apt/sources.list.d/armbian.list
apt-key adv --keyserver keys.gnupg.net --recv-keys 0x93D6889F9F0E78D5 >/dev/null 2>&1
apt-get update >/dev/null 2>&1
fi
}
get_hardware_info ()
#-----------------------------------------------------------------------------------------------------------------------
# determine root and boot partitions, arhitecture, cpu, ...
#-----------------------------------------------------------------------------------------------------------------------
{
# arhitecture
ARCH=$(lscpu | grep Architecture | awk '{print $2}')
if [[ "$ARCH" != arm* ]]; then
echo -e "[\e[0;31m error \x1B[0m] Architecture not supported"; exit;
fi
# CPU
HARDWARE=$(cat /proc/cpuinfo | grep Hardware | awk '{print $3}')
if [[ !( "$HARDWARE" == "sun7i" || "$HARDWARE" == "Allwinner" || "$HARDWARE" == "sun4i" ) ]]; then
echo -e "[\e[0;31m error \x1B[0m] Unsupported hw"; exit;
fi
# boot partition
bootdevice="/dev/mmcblk0p1";
# if mmc is not present than boot can only be nand1
if [[ "$(grep nand /proc/partitions)" != "" && "$(grep mmc /proc/partitions)" == "" ]]; then
bootdevice="/dev/nand1";
fi
# root partition
root_device=$(mountpoint -d /)
for file in /dev/* ; do
CURRENT_DEVICE=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file))
if [ $CURRENT_DEVICE = $root_device ]; then
rootdevice=$file
break;
fi
done
rootdevice="/dev/"$(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent)
}
mount_boot_device ()
#-----------------------------------------------------------------------------------------------------------------------
# mount boot device
#-----------------------------------------------------------------------------------------------------------------------
{
if [[ "$bootdevice" == "/dev/mmcblk0p1" && "$rootdevice" != "/dev/mmcblk0p1" ]]; then
umount /boot /media/mmc
mkdir -p /media/mmc/boot
mount /dev/mmcblk0p1 /media/mmc/
if [ -d "/media/mmc/boot/" ]; then
mount --bind /media/mmc/boot/ /boot/
else
mount --bind /media/mmc /boot/
fi
fi
if [[ "$bootdevice" == "/dev/nand1" ]]; then
umount /boot /mnt
mount /dev/nand1 /boot
fi
}
select_boards ()
#-----------------------------------------------------------------------------------------------------------------------
# This might be changed once with board detection which is already very accurate
#-----------------------------------------------------------------------------------------------------------------------
{
if [ -z "$BOARD" ]; then
IFS=" "
Options="Cubieboard A10 Cubieboard2 A20 Cubietruck A20 Lime-A10 A10 Lime \
A20 Lime2 A20 Micro A20 Bananapipro A20 Lamobo-R1 A20 Orangepi A20 Pcduino3nano A20"
BoardOptions=($Options);
BoardCmd=(dialog --title "Choose a board:" --backtitle "$backtitle" --menu "\n$infos" 20 60 26)
BoardChoices=$("${BoardCmd[@]}" "${BoardOptions[@]}" 2>&1 >/dev/tty)
BOARD=${BoardChoices,,}
fi
# exit the script on cancel
if [ "$BOARD" == "" ]; then echo "ERROR: You have to choose one board"; exit; fi
if [ -z "$BRANCH" ]; then
IFS="'"
declare -a Options=("legacy'3.4.x - 3.14.x most supported'vanilla'4.x Vanilla from www.kernel.org");
# Exceptions
if [[ $BOARD == "cubox-i" || $BOARD == "udoo-neo" || "$bootdevice" == "/dev/nand1" ]]; then
declare -a Options=("legacy'3.4.x - 3.14.x most supported");
fi
BoardOptions=($Options);
BoardCmd=(dialog --title "Choose a board:" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
BoardChoices=$("${BoardCmd[@]}" "${BoardOptions[@]}" 2>&1 >/dev/tty)
BRANCH=${BoardChoices,,}
fi
# exit the script on cancel
if [ "$BRANCH" == "" ]; then echo "ERROR: You have to choose one branch"; exit; fi
if [[ $BRANCH == "vanilla" ]] ; then
ROOT_BRACH="-next"
else
ROOT_BRACH=""
fi
case $BOARD in
bananapipro | lamobo-r1 | orangepi | orangepimini)
LINUXFAMILY="sun7i"
if [[ $BRANCH == "vanilla" ]] ; then LINUXFAMILY="sunxi"; fi
;;
cubox-i)
LINUXFAMILY="cubox"
;;
cubieboard | lime-a10)
LINUXFAMILY="sun4i"
if [[ $BRANCH == "vanilla" ]] ; then LINUXFAMILY="sunxi"; fi
;;
udoo | udoo-neo)
LINUXFAMILY="udoo"
;;
*)
LINUXFAMILY="sun7i"
if [[ $BRANCH == "vanilla" ]] ; then LINUXFAMILY="sunxi"; fi
;;
esac
if [[ $BOARD == "cubox-i" || $BOARD == udoo* || $BRANCH == "vanilla" ]];
then PACKETS="linux-dtb$ROOT_BRACH-$LINUXFAMILY";
fi
PACKETS="linux-image$ROOT_BRACH-$LINUXFAMILY linux-firmware-image$ROOT_BRACH-$LINUXFAMILY \
linux-u-boot-$BOARD$ROOT_BRACH linux-headers$ROOT_BRACH-$LINUXFAMILY linux-$RELEASE-root$ROOT_BRACH-$BOARD $PACKETS"
}
remove_old ()
#-----------------------------------------------------------------------------------------------------------------------
# Delete previous kernel
#-----------------------------------------------------------------------------------------------------------------------
{
clear
dialog --title "$title" --backtitle "$backtitle" --infobox "\nRemoving conflicting packages ..." 5 41
aptitude remove ~nlinux-dtb --quiet=100 >> upgrade.log
aptitude remove ~nlinux-u-boot --quiet=100 >> upgrade.log
aptitude remove ~nlinux-image --quiet=100 >> upgrade.log
aptitude remove ~nlinux-headers --quiet=100 >> upgrade.log
aptitude remove ~nlinux-firmware --quiet=100 >> upgrade.log
aptitude remove ~nlinux-$RELEASE-root --quiet=100 >> upgrade.log
}
install_new ()
#-----------------------------------------------------------------------------------------------------------------------
# install new one
#-----------------------------------------------------------------------------------------------------------------------
{
IFS=" "
apt-get $1 -y install $PACKETS 2>&1 | dialog --title "$title" --backtitle "$backtitle" --progressbox "$2" 20 80
if [ $? -ne 0 ]; then
dialog --title "$title" --backtitle "$backtitle" --infobox "\nError downloadiing." 5 41
exit 1;
fi
}
#-----------------------------------------------------------------------------------------------------------------------
#
# Program start
#
#-----------------------------------------------------------------------------------------------------------------------
# This tool must run under root
#-----------------------------------------------------------------------------------------------------------------------
if [[ ${EUID} -ne 0 ]]; then
echo "This tool must run as root. Exiting ..."
exit 1
fi
#-----------------------------------------------------------------------------------------------------------------------
# Downloading dependencies
#-----------------------------------------------------------------------------------------------------------------------
if [[ $(dpkg-query -W -f='${Status}' dialog 2>/dev/null | grep -c "ok installed") -eq 0 || \
$(dpkg-query -W -f='${Status}' u-boot-tools 2>/dev/null | grep -c "ok installed") -eq 0 || \
$(dpkg-query -W -f='${Status}' debconf-utils 2>/dev/null | grep -c "ok installed") -eq 0 || \
$(dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -c "ok installed") -eq 0 || \
$(dpkg-query -W -f='${Status}' aptitude 2>/dev/null | grep -c "ok installed") -eq 0 \
]]; then
echo "Downloading dependencies ... please wait"
apt-get install -qq -y dialog u-boot-tools debconf-utils lsb-release aptitude fake-hwclock >/dev/null 2>&1
fi
display_warning
install_repo
get_hardware_info
mount_boot_device
create_boot_script
select_boards
install_new "-d" "Downloading packages..."
remove_old
install_new "" "Installing packages..."
apt-get -y upgrade 2>&1 | dialog --title "$title" --backtitle "$backtitle" --progressbox "System upgrade" 20 80
[[ "$bootdevice" == "/dev/nand1" ]] && sed -e 's,script=.*,script=script.bin,g' -i /boot/uEnv.txt
ln -sf /boot/bin/$BOARD.bin /boot/script.bin || cp /boot/bin/$BOARD.bin /boot/script.bin
dialog --title "$title" --backtitle "$backtitle" --yes-label "Reboot" --no-label "Exit" \
--yesno "\nAll done." 7 60
if [ $? -eq 0 ]; then reboot; fi
echo "Visit: forum.armbian.com in case of troubles or just for fun ;)"
echo ""