blob: d59b4bc9aaa475ecbc938529d3a24fadde349caa (
plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#!/bin/sh
#
# Squish a CM otapackage for distribution
# cyanogen
#
OUT_TARGET_HOST=`uname -a | grep Darwin`
if [ -z "$OUT_TARGET_HOST" ]
then
OUT_TARGET_HOST=linux-x86
MD5=md5sum
XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
SED=sed
else
OUT_TARGET_HOST=darwin-x86
MD5=md5
XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
SED=gsed
fi
if [ -z "$OUT" -o ! -d "$OUT" ]; then
echo "ERROR: $0 only works with a full build environment. $OUT should exist."
exit 1
fi
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
if [ ! -f "$OTAPACKAGE" ]; then
echo "$OTAPACKAGE doesn't exist!";
exit 1
fi
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
QUIET=-q
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
# Some products want a squashfs for xbin for space
case "$TARGET_PRODUCT" in
cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
*) WANT_SQUASHFS=0 ;;
esac
if [ "$WANT_SQUASHFS" -eq 1 ]; then
fatal=0
MKSQUASHFS_VER_REQ=4
if type mksquashfs >/dev/null 2>&1; then
if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
echo
echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
fatal=1
fi
else
echo
echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
fatal=1
fi
if [ "$fatal" -ne 0 ]; then
echo
echo " Unoptimized package is still available at"
echo " $OTAPACKAGE"
exit $fatal
fi
fi
REPACK=$OUT/repack.d
printf "Sanitizing environment..."
rm -rf $REPACK
mkdir -p $REPACK
echo
# Unpack the otapackage and opticharge all apks
mkdir $REPACK/ota
(
cd $REPACK/ota
printf "Unpacking $OTAPACKAGE..."
unzip $QUIET $OTAPACKAGE
echo
cd $REPACK/ota/system/framework
$OPTICHARGER framework-res.apk
cd $REPACK/ota/system/app
find ./ -name \*.apk | $XARGS $OPTICHARGER
)
if [ "$WANT_SQUASHFS" -eq 1 ]; then
squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
updater=$REPACK/ota/META-INF/com/google/android/updater-script
# Relocate su
cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
chmod -R 555 $REPACK/_xbin/*
# Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
# Forgive me for the regex hell here.
ln -s ../bin/su $REPACK/_xbin/su
for link in `sed -n -e's/,//g' -e'/symlink(.*busybox/,/xbin.*);/p' $updater | tr '"' '\n' | sed -n -e'\,/system/xbin/,s,/system/xbin/,,p'`
do
ln -s busybox $REPACK/_xbin/$link
done
# Create the squashfs with new and improved symlinkage!
mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
rm -rf $REPACK/ota/system/xbin/*
mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
chmod 444 $REPACK/ota/system/xbin/xbin.sqf
# Remove xbin stuff and fix up updater-script
$SED -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
fi
# Fix build.prop
$SED -i \
-e '/ro\.kernel\.android\.checkjni/d' \
-e '/ro\.build\.type/s/eng/user/' \
$REPACK/ota/system/build.prop
# Delete unnecessary binaries
( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
# Delete leftover wireless driver
# rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
# No need for recovery
rm -rf $REPACK/ota/recovery
# Strip modules
find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
# Determine what to name the new signed package
if [ -z "$CYANOGEN_NIGHTLY" ]; then
MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
: ${MODVERSION:=nightly}
OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
else
OUTFILE=$OUT/update-squished.zip
fi
# Pack it up and sign
printf "Zipping package..."
( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
echo
printf "Signing package..."
SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
java -Xmx512m \
-jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
-w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
$REPACK/update.zip $OUTFILE
echo
printf "Cleaning up..."
rm -rf $REPACK
echo
# Create a md5 checksum image of the repacked package
(
img=`basename $OUTFILE`
cd `dirname $OUTFILE`
$MD5 $img >$img.md5sum
echo
echo "Package complete: $OUTFILE"
cat $img.md5sum
echo
)
exit 0
|