forked from longsleep/build-pine64-image
/
pine64_install_to_emmc.sh
executable file
·126 lines (105 loc) · 3.4 KB
/
pine64_install_to_emmc.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
#!/bin/bash
set -eo pipefail
if [[ "$(id -u)" -ne "0" ]]; then
echo "This script requires root."
exit 1
fi
echo "Pine A64/Pinebook release installer!"
echo "(C) 2017. Kamil Trzciński (https://ayufan.eu)."
echo ""
usage() {
echo "Usage:"
echo "$ $0 <system> [version]"
echo ""
echo "Systems:"
echo " - xenial|bionic-minimal (https://github.com/ayufan-pine64/linux-build/releases)"
echo " - xenial|bionic-mate (https://github.com/ayufan-pine64/linux-build/releases)"
echo " - xenial|bionic-lxde (https://github.com/ayufan-pine64/linux-build/releases)"
echo " - xenial|bionic-i3 (https://github.com/ayufan-pine64/linux-build/releases)"
echo " - android-7.0 (https://github.com/ayufan-pine64/android-7.0/releases)"
echo " - android-7.1 (https://github.com/ayufan-pine64/android-7.1/releases)"
echo ""
echo "Version:"
echo " - latest will be used if version is not defined"
exit 1
}
if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
usage
fi
if [[ ! -d /sys/devices/soc.0/1c10000.sdmmc/mmc_host/mmc1 ]]; then
echo "You should boot from SD card"
exit 1
fi
if [[ ! -e /dev/mmcblk1 ]]; then
echo "You should boot from SD card"
exit 1
fi
case "$1" in
xenial-*|bionic-*)
REPO="ayufan-pine64/linux-build"
PREFIX="$1-$(cat /etc/pine64_model)-bspkernel-"
SUFFIX="-[0-9]*.img.xz"
ARCHIVER="xz -d"
;;
android-7.0|android-7.1)
REPO="ayufan-pine64/$1"
if [[ "$(cat /etc/pine64_model)" == "pinebook" ]]; then
PREFIX="$1-pine-a64-pinebook-v"
elif [[ "$(cat /etc/pine64_model)" == "pinebook1080p" ]]; then
PREFIX="$1-pine-a64-pinebook1080p-v"
elif [[ "$(cat /etc/pine64_model)" == "sopine" ]]; then
PREFIX="$1-pine-a64-sopine-v"
else
PREFIX="$1-pine-a64-v"
fi
SUFFIX="-r[0-9]*.img.gz"
ARCHIVER="gzip -d"
;;
*)
echo "Unknown system: $1"
echo ""
usage
;;
esac
VERSION="$2"
if [[ -z "$VERSION" ]]; then
VERSION=$(curl -f -sS https://api.github.com/repos/$REPO/releases/latest | jq -r ".tag_name")
if [ -z "$VERSION" ]; then
echo "Latest release was not for $1."
echo "Please go to: https://github.com/$REPO/releases/latest"
exit 1
fi
echo "Using latest release: $VERSION from https://github.com/$REPO/releases."
fi
NAME="$PREFIX$VERSION$SUFFIX"
NAME_SAFE="${NAME//./\\.}"
VERSION_SAFE="${VERSION//./\\.}"
echo "Looking for download URL..."
DOWNLOAD_URL=$(curl -f -sS https://api.github.com/repos/$REPO/releases | \
jq -r ".[].assets | .[].browser_download_url" | \
( grep -o "https://github\.com/$REPO/releases/download/$VERSION_SAFE/$NAME_SAFE" || true))
if [[ -z "$DOWNLOAD_URL" ]]; then
echo "The download URL for $NAME not found".
echo "Look at https://github.com/$REPO/releases for correct versions."
exit 1
fi
echo "Doing this will overwrite all data stored on eMMC."
while true; do
echo "Type YES to continue or Ctrl-C to abort."
read CONFIRM
if [[ "$CONFIRM" == "YES" ]]; then
break
fi
done
echo ""
echo "Using $DOWNLOAD_URL..."
echo "Umounting..."
umount -f /dev/mmcblk1* || true
echo ""
echo "Downloading and writing to /dev/mmcblk1..."
curl -L -f "$DOWNLOAD_URL" | $ARCHIVER | dd bs=30M of=/dev/mmcblk1
sync
echo ""
echo "You may want to run now pine64_remove_boot0.sh to make the current device unbootable."
echo ""
echo "Done."