Skip to content

Commit 446c6f4

Browse files
committed
Add simple experimental android upgrader script
1 parent a6ba43e commit 446c6f4

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
if [[ "$(id -u)" -ne "0" ]]; then
6+
echo "This script requires root."
7+
exit 1
8+
fi
9+
10+
echo "Pine A64/Pinebook Android upgrader (experimental)!"
11+
echo "(C) 2017. Kamil Trzciński (https://ayufan.eu)."
12+
echo ""
13+
14+
usage() {
15+
echo "Usage:"
16+
echo "$ $0 <device> <system> [version]"
17+
echo ""
18+
echo "Systems:"
19+
echo " - android-7.0 (https://github.com/ayufan-pine64/android-7.0/releases)"
20+
echo " - android-7.1 (https://github.com/ayufan-pine64/android-7.0/releases)"
21+
echo ""
22+
echo "Version:"
23+
echo " - latest will be used if version is not defined"
24+
exit 1
25+
}
26+
27+
if [[ $# -ne 2 ]] && [[ $# -ne 3 ]]; then
28+
usage
29+
fi
30+
31+
if [[ "$2" != "android-7.0" ]] || [[ "$2" != "android-7.1" ]]; then
32+
usage
33+
fi
34+
35+
REPO="ayufan-pine64/$2"
36+
if [[ "$(cat /etc/pine64_model)" -eq "pinebook" ]]; then
37+
PREFIX="$2-pine-a64-pinebook-v"
38+
else
39+
PREFIX="$2-pine-a64-v"
40+
fi
41+
SUFFIX="-r[0-9]*.img.gz"
42+
ARCHIVER="gzip -d"
43+
44+
VERSION="$3"
45+
46+
if [[ -z "$VERSION" ]]; then
47+
VERSION=$(curl -f -sS https://api.github.com/repos/$REPO/releases/latest | jq -r ".tag_name")
48+
if [ -z "$VERSION" ]; then
49+
echo "Latest release was not for $2."
50+
echo "Please go to: https://github.com/$REPO/releases/latest"
51+
exit 1
52+
fi
53+
54+
echo "Using latest release: $VERSION from https://github.com/$REPO/releases."
55+
fi
56+
57+
NAME="$PREFIX$VERSION$SUFFIX"
58+
NAME_SAFE="${NAME//./\\.}"
59+
VERSION_SAFE="${VERSION//./\\.}"
60+
61+
echo "Looking for download URL..."
62+
DOWNLOAD_URL=$(curl -f -sS https://api.github.com/repos/$REPO/releases | \
63+
jq -r ".[].assets | .[].browser_download_url" | \
64+
( grep -o "https://github\.com/$REPO/releases/download/$VERSION_SAFE/$NAME_SAFE" || true))
65+
66+
if [[ -z "$DOWNLOAD_URL" ]]; then
67+
echo "The download URL for $NAME not found".
68+
echo "Look at https://github.com/$REPO/releases for correct versions."
69+
exit 1
70+
fi
71+
72+
echo "Doing this will overwrite all data stored on eMMC."
73+
74+
while true; do
75+
echo "Type YES to continue or Ctrl-C to abort."
76+
read CONFIRM
77+
if [[ "$CONFIRM" == "YES" ]]; then
78+
break
79+
fi
80+
done
81+
82+
echo ""
83+
echo "Using $DOWNLOAD_URL..."
84+
echo "Umounting..."
85+
umount -f $1* || true
86+
echo ""
87+
88+
START=16 # 8k
89+
END=4337664 # 2,220,883,968
90+
91+
echo "Downloading and upgrade $1..."
92+
curl -L -f "$DOWNLOAD_URL" | $ARCHIVER | \
93+
tail -c "+$((START*512))" | \
94+
dd bs=8k seek="$((START/16))" count="$(((END-START)/16))" "of=$1"
95+
sync
96+
echo ""
97+
98+
echo "Done."

0 commit comments

Comments
 (0)