-
Notifications
You must be signed in to change notification settings - Fork 28
/
update.sh
executable file
·152 lines (126 loc) · 3.79 KB
/
update.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
#!/bin/bash
set -e
usage() {
echo "Usage: $0 -c <new_copperhead_factory_dir> -d <device_type> [--no-tor]"
exit 1
}
# Use GNU getopt to capture arguments as it allows us to have long options
# which the bash builtin getopts doesn't support. We also still support the
# old # positional arguments for now, but don't advertise them in the usage().
TEMP=$(getopt -o 'hc:d:T::' --long 'help,copperhead:,device:,no-tor::' -- "$@")
[ $? -ne 0 ] && usage
eval set -- "$TEMP"; unset TEMP
# Set defaults
NO_TOR=0
# Parse the args
while true; do
case "$1" in
'-c'|'--copperhead')
COPPERHEAD_DIR=$2
shift 2;
continue
;;
'-d'|'--device')
DEVICE=$2
shift 2
continue
;;
'-T'|'--no-tor')
NO_TOR=1
shift
continue
;;
'-h'|'--help')
usage
;;
'-*')
echo "Unknown option: $1" >&2
exit 1
;;
'--')
shift
break
;;
*)
POSITIONAL="$POSITIONAL $1"
shift
continue
;;
esac
done
set +e
# Backwards compatibility for positional arguments
[ -z $COPPERHEAD_DIR ] && [ -n $1 ] && COPPERHEAD_DIR=$1 && shift
[ -z $DEVICE ] && [ -n $1 ] && DEVICE=$1 && shift
set -e
export COPPERHEAD_DIR
export DEVICE
export NO_TOR
# Bail out if no Copperhead directory was provided or no device defined
[ -z ${COPPERHEAD_DIR} ] && usage
[ -z ${DEVICE} ] && usage
SUPERBOOT_DIR=$PWD/helper-repos/super-bootimg
SIMG2IMG_DIR=$PWD/helper-repos/android-simg2img
#if [ ! -f "./packages/gapps-delta.tar.xz" ]
#then
# echo "You have to have a gapps-delta zip from a previous install :("
# exit 1
#fi
if [ ! -f "./extras/${DEVICE}/updater-script" ]
then
echo "./extras/${DEVICE}/updater-script not found. Device unsupported?"
exit 1
fi
cd $COPPERHEAD_DIR
mkdir -p images
cd images
if [ ! -f "boot.img" ]
then
unzip ../*.zip
fi
cd ../..
./fetch-apks.sh
./install-su.sh $COPPERHEAD_DIR $SUPERBOOT_DIR
./apply-gapps-delta.sh $COPPERHEAD_DIR $SIMG2IMG_DIR
./re-sign.sh $COPPERHEAD_DIR $SIMG2IMG_DIR $SUPERBOOT_DIR
# We need to extract raw system, vendor images
$SIMG2IMG_DIR/simg2img ./images/system-signed.img ./images/system-signed.raw
$SIMG2IMG_DIR/simg2img ./images/vendor-signed.img ./images/vendor-signed.raw
mkdir -p update
cp ./images/system-signed.raw ./update/
cp ./images/vendor-signed.raw ./update/
cp ./images/boot-signed.img ./update/
cp ./images/recovery-signed.img ./update/
python ./extras/${DEVICE}/convert-factory.py $COPPERHEAD_DIR/radio-*.img $COPPERHEAD_DIR/bootloader-*.img ./update
cd update
mkdir -p META-INF/com/google/android/
mkdir -p META-INF/com/android/
cp ../extras/${DEVICE}/updater-script META-INF/com/google/android/updater-script
cp ../extras/${DEVICE}/update-binary META-INF/com/google/android/
cp ../extras/${DEVICE}/metadata META-INF/com/android
# XXX: bootloader.. not sure how to do that..
zip -r ../${DEVICE}-update.zip .
cd ..
java -jar ./extras/blobs/signapk.jar -w ./keys/releasekey.x509.pem ./keys/releasekey.pk8 ${DEVICE}-update.zip ${DEVICE}-update-signed.zip
echo
echo "Now please reboot your device into recovery:"
echo " 1. Reboot into Fastboot with Power + Volume Down"
echo " 2. Use Volume Down to select Recovery, and press Power"
echo " 3. Briefly tap Power + Volume-Up to get past the broken android logo."
echo -n "[Hit Enter to continue...]"
read junk
echo "Now select 'Apply Update from ADB' with Volume Down, and press Power."
echo -n "[Hit Enter to continue...]"
read junk
if [ -z "$(adb devices | grep sideload)" ]
then
echo
echo "You need to unplug and replug your device after starting sideload.."
echo -n "[Hit Enter to continue...]"
read junk
# A sleep is needed to ensure the device is successfully detected after plugging back in
sleep 5
fi
adb sideload ${DEVICE}-update-signed.zip
echo
echo "All done! Yay! Select Reboot into System and press power."