blob: c984b81fa925a41beb8fe341b1d54e1d324e69a2 [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
kufikugel47a7a0a2012-12-02 03:47:20 +010022 echo "ERROR: $0 only works with a full build environment. $OUT should exist."
23 exit 1
arf31f37f2012-09-05 08:57:46 -030024fi
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
mnazim64dcfc72012-12-26 17:04:31 -070036 echo "$OTAPACKAGE doesn't exist!";
37 exit 1
arf31f37f2012-09-05 08:57:46 -030038fi
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"
Lars Greissb85bb282013-11-11 20:06:56 +010044DELETE_APKS="LiveWallpapers.apk SpeechRecorder.apk VideoEditor.apk HoloSpiralWallpaper.apk MagicSmokeWallpapers.apk NoiseField.apk Galaxy4.apk OpenWnn.apk PinyinIME.apk"
Griffin Millender393de592014-10-02 15:20:55 -050045DELETE_PRIV_APKS="VoiceDialer.apk"
ar450af112012-09-10 15:45:03 -030046DELETE_GALLERY="Gallery2.apk"
krarvind958856b2013-02-11 01:15:55 +010047DELETE_FONTS="MTLmr3m.ttf"
arf31f37f2012-09-05 08:57:46 -030048
49REPACK=$OUT/repack.d
50printf "Sanitizing environment..."
51rm -rf $REPACK
52mkdir -p $REPACK
53echo
54
55
56# Unpack the otapackage and opticharge all apks
57mkdir $REPACK/ota
58(
59cd $REPACK/ota
60printf "Unpacking $OTAPACKAGE..."
61unzip $QUIET $OTAPACKAGE
62echo
63
64# Move all apks to the same directory so xargs can
65# use also with framework-res.apk. This allow process
66# framework-res.apk in parallel with other apks
67mkdir -p $REPACK/parallel
68cd $REPACK/parallel
69cp $REPACK/ota/system/framework/framework-res.apk .
70cp $REPACK/ota/system/app/*.apk .
Griffin Millender0c99eff2013-11-10 00:11:55 -060071for f in $REPACK/ota/system/priv-app/*.apk; do
72 cp $f ./priv-app-$(basename $f)
73done
74
arf31f37f2012-09-05 08:57:46 -030075
76# Do optimization in parallel
77find ./ -name \*.apk | $XARGS $OPTICHARGER
78
79# Move optimized apks to repack directory
80mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
Griffin Millender0c99eff2013-11-10 00:11:55 -060081for f in $REPACK/parallel/priv-app*.apk; do
82 mv $f $REPACK/ota/system/priv-app/$(basename $f | cut -d'-' -f3)
83done
arf31f37f2012-09-05 08:57:46 -030084mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
85
86# Return to directory
87cd $REPACK/ota
88rm -rf $REPACK/parallel
89)
90
91# Fix build.prop
92$SED -i \
93 -e '/ro\.kernel\.android\.checkjni/d' \
94 -e '/ro\.build\.type/s/eng/user/' \
95 $REPACK/ota/system/build.prop
96
97
98# Delete unnecessary binaries
99( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
100
arfaa54c12012-09-05 16:48:18 -0300101# Delete Offline charging mode files
102( cd $REPACK/ota/system/media; echo $DELETE_MEDIA | xargs rm -f; )
103
Lars Greissb9e5f412013-11-04 17:19:33 +0100104# Delete Home Apk's
ar96c40fa2012-09-07 12:09:28 -0300105( cd $REPACK/ota/system/app; echo $DELETE_APKS | xargs rm -f; )
106
Lars Greissb9e5f412013-11-04 17:19:33 +0100107# Delete priv-app Apk's
108( cd $REPACK/ota/system/priv-app; echo $DELETE_PRIV_APKS | xargs rm -f; )
109
arfaa54c12012-09-05 16:48:18 -0300110# No need for modem.bin
111rm -f $REPACK/ota/modem.bin
112
113# No need for media/video
114rm -rf $REPACK/ota/system/media/video
115
ar87dc6e22012-10-08 09:02:44 -0300116# Delete Unnecessary Fonts
117( cd $REPACK/ota/system/fonts; echo $DELETE_FONTS | xargs rm -f; )
118
arfaa54c12012-09-05 16:48:18 -0300119# Delete compiled fonts
ar87dc6e22012-10-08 09:02:44 -0300120#rm -rf $REPACK/ota/system/fonts
arfaa54c12012-09-05 16:48:18 -0300121
122#make dir for fonts again
ar87dc6e22012-10-08 09:02:44 -0300123#mkdir $REPACK/ota/system/fonts
arfaa54c12012-09-05 16:48:18 -0300124
125# Add precompiled fonts
ar87dc6e22012-10-08 09:02:44 -0300126#mv -f $REPACK/ota/system/sfont/*.ttf $REPACK/ota/system/fonts/
arfaa54c12012-09-05 16:48:18 -0300127
128# No need for tts
129rm -rf $REPACK/ota/system/tts
130
krarvind6cba84a2012-12-17 01:31:12 +0000131# No need for srec
132rm -rf $REPACK/ota/system/usr/srec
133
arf31f37f2012-09-05 08:57:46 -0300134# No need for recovery
135rm -rf $REPACK/ota/recovery
mnazim12b01672012-12-01 10:09:35 -0700136rm -rf $REPACK/ota/system/etc/recovery-resource.dat
arf31f37f2012-09-05 08:57:46 -0300137
138# Strip modules
139[ -d $REPACK/ota/system/lib/modules ] && \
140 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
141
ar450af112012-09-10 15:45:03 -0300142# Fix LCD Density for slim
143DEVICELCD=`sed -n -e'/ro\.sf\.lcd_density/s/^.*=//p' $OUT/system/build.prop`
144if [ "$DEVICELCD" = "240" ]; then
145 sed -i 's/ro.sf.lcd_density=240/ro.sf.lcd_density=182/g' $OUT/system/build.prop
146elif [ "$DEVICELCD" = "320" ]; then
Lars Greiss8f847bf2013-03-27 00:52:20 +0100147 sed -i 's/ro.sf.lcd_density=320/ro.sf.lcd_density=245/g' $OUT/system/build.prop
blk_jack0685f302013-05-09 03:02:49 -0400148elif [ "$DEVICELCD" = "480" ]; then
Lars Greiss9b1b41b2014-01-07 19:01:34 +0100149 sed -i 's/ro.sf.lcd_density=480/ro.sf.lcd_density=370/g' $OUT/system/build.prop
ar450af112012-09-10 15:45:03 -0300150elif [ "$DEVICELCD" = "213" ]; then
151 sed -i 's/ro.sf.lcd_density=213/ro.sf.lcd_density=182/g' $OUT/system/build.prop
152fi
arf87e5692012-09-28 22:54:05 -0300153
andi34128d6662014-08-23 12:36:38 +0200154# Device specific LCD Density fix
arf87e5692012-09-28 22:54:05 -0300155DEVICEID=`sed -n -e'/ro\.product\.device/s/^.*=//p' $OUT/system/build.prop`
156if [ "$DEVICEID" = "SGH-I717" ]; then
Lars Greiss1d9660f2013-03-28 01:38:33 +0100157 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=268/g' $OUT/system/build.prop
ara4656a72012-10-06 08:38:48 -0300158elif [ "$DEVICEID" = "GT-N7000" ]; then
Lars Greiss1d9660f2013-03-28 01:38:33 +0100159 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=268/g' $OUT/system/build.prop
krarvind2be3c8d2013-01-23 02:54:56 +0000160elif [ "$DEVICEID" = "mako" ]; then
Lars Greiss1d9660f2013-03-28 01:38:33 +0100161 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=268/g' $OUT/system/build.prop
Griffin Millender1374d4d2013-07-31 17:16:42 -0500162elif [ "$DEVICEID" = "flo" ]; then
163 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=286/g' $OUT/system/build.prop
Griffin Millender595699c2013-10-24 17:48:44 -0500164elif [ "$DEVICEID" = "deb" ]; then
165 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=286/g' $OUT/system/build.prop
OmarEinea86ddb7e2014-08-16 06:57:00 +0300166elif [ "$DEVICEID" = "amami" ]; then
167 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=286/g' $OUT/system/build.prop
PerLyckec978ecc2014-09-30 15:17:36 +0200168elif [ "$DEVICEID" = "togari" ]; then
169 sed -i 's/ro.sf.lcd_density=245/ro.sf.lcd_density=300/g' $OUT/system/build.prop
arf87e5692012-09-28 22:54:05 -0300170fi
ar450af112012-09-10 15:45:03 -0300171cp -f $OUT/system/build.prop $REPACK/ota/system/build.prop
172
173# Delete Gallery2 for 5MP cameras
174CAMERARESOLUTION=`sed -n -e'/ro\.camera\.res/s/^.*=//p' $REPACK/ota/system/build.prop`
arde2f5172012-09-20 15:34:22 -0300175#if [ "$CAMERARESOLUTION" = "5MP" ];then
176# rm -f $REPACK/ota/system/app/Gallery2.apk
177#fi
ar450af112012-09-10 15:45:03 -0300178
arfaa54c12012-09-05 16:48:18 -0300179# Swap boot.img
ar450af112012-09-10 15:45:03 -0300180PREBUILTKERNEL=$OUT/system/slimkernel/boot.img
181if [ -e "$PREBUILTKERNEL" ];then
arfaa54c12012-09-05 16:48:18 -0300182 rm -f $REPACK/ota/boot.img
183 mv -f $REPACK/ota/system/slimkernel/boot.img $REPACK/ota/boot.img
ar02dbdde2012-09-08 10:03:38 -0300184fi
arfaa54c12012-09-05 16:48:18 -0300185
arf31f37f2012-09-05 08:57:46 -0300186# Determine what to name the new signed package
ar8716a412012-09-05 10:08:55 -0300187MODVERSION=`sed -n -e'/ro\.modversion/s/^.*=//p' $REPACK/ota/system/build.prop`
188OUTFILE=$OUT/$MODVERSION.zip
arf31f37f2012-09-05 08:57:46 -0300189echo MODVERSION: $MODVERSION
190
191# Pack it up and sign
192printf "Zipping package..."
193( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
194echo
195printf "Signing package..."
196SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
197java -Xmx1024m \
198 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
199 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
200 $REPACK/update.zip $OUTFILE
201echo
202printf "Cleaning up..."
203rm -rf $REPACK
204echo
205
206# Create a md5 checksum image of the repacked package
207(
208img=`basename $OUTFILE`
209cd `dirname $OUTFILE`
210$MD5 $img >$img.md5sum
211echo
212echo "Package complete: $OUTFILE"
213cat $img.md5sum
214echo
215)
216
217exit 0