forked from plasma-phone-packaging/pm-flashtool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpm-flash
More file actions
executable file
·126 lines (107 loc) · 3.58 KB
/
pm-flash
File metadata and controls
executable file
·126 lines (107 loc) · 3.58 KB
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 -ex
# The job of flashtool is to,
# - detect which device is connected
# - download files for specific device
# - install the recovery
# - install the Plasma rootfs
# - reboot
CACHEDIR=cache
#wait until we get a working adb shell, meaning the device is in normal or recovery mode
wait_for_device() {
while test -z "$(adb shell echo '1' 2>/dev/null)"
do
echo -n ".";
sleep 3;
done
echo
}
confirm()
{
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
download()
{
# If no device name was supplied just bail out
if [ $# -eq 0 ]; then
echo "No device name was supplied to download, this is fatal error"
exit 1
fi
# Cleanup
mkdir -p $CACHEDIR/ && pushd $CACHEDIR/
echo "Downloading latest rootfs ... "
if [ "$2" == "neon" ]; then
ROOTFS_VERSION=`curl https://images.plasma-mobile.org/rootfs_stamp 2> /dev/null`
wget -c "https://images.plasma-mobile.org/rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz" -P rootfs
ln -sf rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz pm-rootfs-latest.tar.gz
fi
if [ "$2" == "arch" ]; then
ROOTFS_VERSION=`curl https://images.plasma-mobile.org/arch_rootfs_stamp 2> /dev/null`
wget -c "https://images.plasma-mobile.org/arch-rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz" -P rootfs
ln -sf rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz pm-rootfs-latest.tar.gz
fi
if [ "$2" == "edge" ]; then
ROOTFS_VERSION=`curl https://images.plasma-mobile.org/edge_rootfs_stamp 2> /dev/null`
wget -c "https://images.plasma-mobile.org/edge-rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz" -P rootfs
ln -sf rootfs/pm-rootfs-$ROOTFS_VERSION.tar.gz pm-rootfs-latest.tar.gz
fi
echo "[done]"
# This will change in future
echo "Downloading the latest boot, recovery, and system images ... "
HALIUM_VERSION=`curl https://images.plasma-mobile.org/halium/$1/halium_stamp 2> /dev/null`
wget -c "https://images.plasma-mobile.org/halium/$1/recovery.img" -P $1
wget -c "https://images.plasma-mobile.org/halium/$1/$HALIUM_VERSION/system.img" -P $1/$HALIUM_VERSION
wget -c "https://images.plasma-mobile.org/halium/$1/$HALIUM_VERSION/boot.img" -P $1/$HALIUM_VERSION
rm -f $1/latest
ln -sf $HALIUM_VERSION $1/latest
echo "[done]"
popd
}
flash-phone()
{
# If no device name was supplied just bail out
if [ $# -eq 0 ]; then
echo "No device name was supplied to flash-phone, this is fatal error"
exit 1
fi
echo -n "Flashing recovery image ... "
fastboot flash recovery $CACHEDIR/$1/recovery.img 2> /dev/null
echo -n "[done]"
fastboot boot $CACHEDIR/$1/recovery.img
wait_for_device
./rootstock-touch-install `readlink -f $CACHEDIR/pm-rootfs-latest.tar.gz` $CACHEDIR/$1/latest/system.img $CACHEDIR/$1/latest/boot.img
}
echo "Waiting for device to be in the fastboot mode"
fastboot getvar product
DEVICE_NAME=`fastboot getvar product 2>&1 | head -1 | awk -F': ' '{print $2}'`
confirm "Connected device is $DEVICE_NAME, is that correct? [y/N]" || exit 1
PLATFORM="neon"
echo "Continuing ..."
while getopts "cp:" opt; do
case $opt in
c)
echo "Option provided to use cache, not downloading files again"
NOCACHE=1
;;
p)
PLATFORM="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [ -z "$NOCACHE" ]; then
download $DEVICE_NAME $PLATFORM
fi
flash-phone $DEVICE_NAME