blob: 89b73eee38b20010a537b973650b5f2ed2dd922e [file] [log] [blame]
arf31f37f2012-09-05 08:57:46 -03001#!/bin/sh
2#
3# Squish a CM otapackage for distribution
4# cyanogen
5#
6
7OUT_TARGET_HOST=`uname -a | grep Darwin`
8if [ -z "$OUT_TARGET_HOST" ]
9then
10 OUT_TARGET_HOST=linux-x86
11 MD5=md5sum
12 XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
13 SED=sed
14else
15 OUT_TARGET_HOST=darwin-x86
16 MD5=md5
17 XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
18 SED=gsed
19fi
20
21if [ -z "$OUT" -o ! -d "$OUT" ]; then
22 echo "ERROR: $0 only works with a full build environment. $OUT should exist."
23 exit 1
24fi
25
26if [ "$TARGET_BUILD_TYPE" = "debug" ]; then
27 OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$USER.zip
28elif [ "$TARGET_BUILD_VARIANT" = "userdebug" ]; then
29 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
30elif [ "$TARGET_BUILD_VARIANT" = "user" ]; then
31 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
32else
33 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip
34fi
35if [ ! -f "$OTAPACKAGE" ]; then
36 echo "$OTAPACKAGE doesn't exist!";
37 exit 1
38fi
39
ar8f9ced82012-09-05 09:56:43 -030040OPTICHARGER=$ANDROID_BUILD_TOP/vendor/slim/tools/opticharger
arf31f37f2012-09-05 08:57:46 -030041QUIET=-q
42DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
arfaa54c12012-09-05 16:48:18 -030043DELETE_MEDIA="*.qmg"
ar96c40fa2012-09-07 12:09:28 -030044DELETE_APKS="Home.apk LiveWallpapers.apk VoiceDialer.apk SoundRecorder.apk VisualizationWallpapers.apk "
arf31f37f2012-09-05 08:57:46 -030045
46REPACK=$OUT/repack.d
47printf "Sanitizing environment..."
48rm -rf $REPACK
49mkdir -p $REPACK
50echo
51
52
53# Unpack the otapackage and opticharge all apks
54mkdir $REPACK/ota
55(
56cd $REPACK/ota
57printf "Unpacking $OTAPACKAGE..."
58unzip $QUIET $OTAPACKAGE
59echo
60
61# Move all apks to the same directory so xargs can
62# use also with framework-res.apk. This allow process
63# framework-res.apk in parallel with other apks
64mkdir -p $REPACK/parallel
65cd $REPACK/parallel
66cp $REPACK/ota/system/framework/framework-res.apk .
67cp $REPACK/ota/system/app/*.apk .
68
69# Do optimization in parallel
70find ./ -name \*.apk | $XARGS $OPTICHARGER
71
72# Move optimized apks to repack directory
73mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
74mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
75
76# Return to directory
77cd $REPACK/ota
78rm -rf $REPACK/parallel
79)
80
81# Fix build.prop
82$SED -i \
83 -e '/ro\.kernel\.android\.checkjni/d' \
84 -e '/ro\.build\.type/s/eng/user/' \
85 $REPACK/ota/system/build.prop
86
87
88# Delete unnecessary binaries
89( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
90
arfaa54c12012-09-05 16:48:18 -030091# Delete Offline charging mode files
92( cd $REPACK/ota/system/media; echo $DELETE_MEDIA | xargs rm -f; )
93
ar96c40fa2012-09-07 12:09:28 -030094# Delete Home Apk
95( cd $REPACK/ota/system/app; echo $DELETE_APKS | xargs rm -f; )
96
arfaa54c12012-09-05 16:48:18 -030097# No need for modem.bin
98rm -f $REPACK/ota/modem.bin
99
100# No need for media/video
101rm -rf $REPACK/ota/system/media/video
102
103# Delete compiled fonts
104rm -rf $REPACK/ota/system/fonts
105
106#make dir for fonts again
107mkdir $REPACK/ota/system/fonts
108
109# Add precompiled fonts
110mv -f $REPACK/ota/system/sfont/*.ttf $REPACK/ota/system/fonts/
111
ar96c40fa2012-09-07 12:09:28 -0300112# Add OTA app
113#mkdir $REPACK/ota/data/app
114#cp -f $OUT/data/app/com.acquariusoft.UpdateMe.apk $REPACK/ota/data/app/
115
arfaa54c12012-09-05 16:48:18 -0300116# No need for tts
117rm -rf $REPACK/ota/system/tts
118
arf31f37f2012-09-05 08:57:46 -0300119# No need for recovery
120rm -rf $REPACK/ota/recovery
121
122# Strip modules
123[ -d $REPACK/ota/system/lib/modules ] && \
124 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
125
arfaa54c12012-09-05 16:48:18 -0300126# Swap boot.img
ar51617412012-09-05 21:12:15 -0300127#DEVICEINFO=`sed -n -e'/ro\.product\.device/s/^.*=//p' $REPACK/ota/system/build.prop`
128#if [ "$DEVICEINFO" = "GT-I9000" ]; then
arfaa54c12012-09-05 16:48:18 -0300129 rm -f $REPACK/ota/boot.img
130 mv -f $REPACK/ota/system/slimkernel/boot.img $REPACK/ota/boot.img
ar51617412012-09-05 21:12:15 -0300131#fi
arfaa54c12012-09-05 16:48:18 -0300132
arf31f37f2012-09-05 08:57:46 -0300133# Determine what to name the new signed package
ar8716a412012-09-05 10:08:55 -0300134MODVERSION=`sed -n -e'/ro\.modversion/s/^.*=//p' $REPACK/ota/system/build.prop`
135OUTFILE=$OUT/$MODVERSION.zip
arf31f37f2012-09-05 08:57:46 -0300136echo MODVERSION: $MODVERSION
137
138# Pack it up and sign
139printf "Zipping package..."
140( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
141echo
142printf "Signing package..."
143SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
144java -Xmx1024m \
145 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
146 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
147 $REPACK/update.zip $OUTFILE
148echo
149printf "Cleaning up..."
150rm -rf $REPACK
151echo
152
153# Create a md5 checksum image of the repacked package
154(
155img=`basename $OUTFILE`
156cd `dirname $OUTFILE`
157$MD5 $img >$img.md5sum
158echo
159echo "Package complete: $OUTFILE"
160cat $img.md5sum
161echo
162)
163
164exit 0