-
Notifications
You must be signed in to change notification settings - Fork 18
/
replace-android-image
executable file
·59 lines (46 loc) · 1.22 KB
/
replace-android-image
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
#!/bin/bash
# Wait until the adb shell is unavailable, meaning the device is rebooting
wait_for_reboot() {
while test -n "$(adb shell echo '1' 2>/dev/null)"
do
echo -n ".";
sleep 3;
done
echo
}
#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
}
SYSTEM_IMAGE=$1
if [ ! -f "$SYSTEM_IMAGE" ]; then
echo "Usage: $0 system.img"
exit
fi
wait_for_device
adb shell "ls /data"
if file $SYSTEM_IMAGE | grep -v ": Linux rev 1.0 ext4" >/dev/null; then
echo "Converting from sparse ext4 image to mountable ext4 image"
simg2img $SYSTEM_IMAGE tmp.img >/dev/null
resize2fs -M tmp.img >/dev/null 2>&1
mv tmp.img $SYSTEM_IMAGE
fi
echo Pushing android system image...
adb push $SYSTEM_IMAGE /data/system.img >/dev/null 2>&1 &
SIZE=$(stat -t $SYSTEM_IMAGE |awk '{print $2}')
S=0
while test $S -lt $SIZE
do
sleep 1
S=$(adb shell stat -t /data/system.img | awk '{print $2}')
printf "%0.2d%%\r" $[100*$S/$SIZE]
done
echo "Done, rebooting to Halium"
adb shell "ls /data"
#adb reboot
# vim: expandtab: ts=4: sw=4