blob: 063b8e0d3808b00dbcb8a7f93cddcbf9821e0dad [file] [log] [blame]
Steve Kondikae76c842010-06-28 11:47:26 -04001#!/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
12else
13 OUT_TARGET_HOST=darwin-x86
14 MD5=md5
15fi
16
17OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
18if [ ! -f "$OTAPACKAGE" ]; then
19 echo "$OTAPACKAGE doesn't exist!";
20 exit 1
21fi
22
23XBIN=$OUT/system/xbin
24OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040025QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040026DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby5bebc222010-07-15 15:44:43 -040027if [ -z "$NO_SQUASHFS" -a `which mksquashfs` = "" ]; then
28 NO_SQUASHFS=true
29else
30 if mksquashfs -version | grep -q 'version 4'; then :; else
31 echo "mksquashfs must be at least version 4 for this build"
32 exit 1
33 fi
34
35fi
Steve Kondikae76c842010-06-28 11:47:26 -040036
37WORK=/tmp/repack
38rm -rf $WORK
39mkdir -p $WORK
40
41if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
42then
43 # Create the xbin squashfs
44 cp -a $XBIN $WORK/xbin/
ctsof095b8a2010-07-03 08:16:59 +000045 chmod -R 755 $WORK/xbin/*
Chris Cosby5bebc222010-07-15 15:44:43 -040046 rm -f $WORK/xbin/su
ctsof095b8a2010-07-03 08:16:59 +000047 ln -s $WORK/bin/su $WORK/xbin/su
Chris Cosby5bebc222010-07-15 15:44:43 -040048 mksquashfs $WORK/xbin/* $WORK/xbin.sqf -force-uid 1000 -force-gid 1000
Steve Kondikae76c842010-06-28 11:47:26 -040049fi
50
51# Unpack the otapackage and opticharge all apks
52mkdir $WORK/ota
53cd $WORK/ota
Pat Thoyts304457f2010-07-11 02:42:36 -040054unzip $QUIET $OTAPACKAGE
Steve Kondikae76c842010-06-28 11:47:26 -040055cd system/framework
56$OPTICHARGER framework-res.apk
57cd ../app
58for i in *.apk; do
59 $OPTICHARGER $i;
60done
61
62cd $WORK/ota/system
63
Steve Kondikc47804f2010-07-07 09:06:39 -040064if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
Steve Kondikae76c842010-06-28 11:47:26 -040065then
66 # Relocate su and put xbin.sqf where it belongs
67 rm -f bin/su
68 mv xbin/su bin/su
69 rm -rf xbin/*
70 mv $WORK/xbin.sqf xbin/
71fi
72
73# Fix build.prop
Pat Thoyts304457f2010-07-11 02:42:36 -040074sed -n -e '/ro\.kernel\.android\.checkjni/d' \
75 -e '/ro\.build\.type/s/eng/user/' \
76 -e 'p' \
77 build.prop > build.prop.new
Steve Kondikae76c842010-06-28 11:47:26 -040078mv build.prop.new build.prop
79
80# Delete unnecessary binaries
81for i in $DELETE_BINS; do
82 rm -f bin/$i
83done
84
Steve Kondik008c0652010-07-11 04:34:44 -040085# Delete leftover wireless driver
86rm -rf lib/modules/*/kernel/drivers/net
87
88# Strip modules
89find lib/modules -name "*.ko" -exec arm-eabi-strip --strip-unneeded {} \;
90
Steve Kondikae76c842010-06-28 11:47:26 -040091# Find the CM version
Pat Thoyts304457f2010-07-11 02:42:36 -040092MODVERSION=`sed -ne '/ro\.modversion/s/^.*CyanogenMod-//p' build.prop`
Steve Kondikae76c842010-06-28 11:47:26 -040093
94# No need for recovery
95cd $WORK/ota
96rm -rf recovery
97
98# Remove xbin stuff and fix up updater-script
Steve Kondikc47804f2010-07-07 09:06:39 -040099if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
Steve Kondikae76c842010-06-28 11:47:26 -0400100then
101 sed -e "s/system\/xbin\/su/system\/bin\/su/g" META-INF/com/google/android/updater-script | grep -v xbin > updater-script.new
Steve Kondik7cfb49f2010-07-09 01:34:30 -0400102 mv updater-script.new META-INF/com/google/android/updater-script
Steve Kondikae76c842010-06-28 11:47:26 -0400103fi
104
Steve Kondikae76c842010-06-28 11:47:26 -0400105# Pack it up and sign
Pat Thoyts304457f2010-07-11 02:42:36 -0400106zip $QUIET -r update.zip .
Steve Kondikae76c842010-06-28 11:47:26 -0400107echo "Signing package.."
108SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
109java -Xmx2048m -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 update.zip update_signed.zip
110
ctsocff00cd2010-07-03 06:15:31 +0000111if [ "$CYANOGEN_NIGHTLY" != "" ]
112then
ctso7e2391a2010-07-03 06:31:37 +0000113 OUTFILE=$OUT/update-squished.zip
ctsocff00cd2010-07-03 06:15:31 +0000114else
ctso7e2391a2010-07-03 06:31:37 +0000115 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
ctsocff00cd2010-07-03 06:15:31 +0000116fi
ctso7e2391a2010-07-03 06:31:37 +0000117mv update_signed.zip $OUTFILE
118$MD5 $OUTFILE > $OUTFILE.md5sum
Steve Kondikae76c842010-06-28 11:47:26 -0400119echo "Package complete: $OUT/update-cm-$MODVERSION-signed.zip";
ctso7e2391a2010-07-03 06:31:37 +0000120cat $OUTFILE.md5sum
Steve Kondikae76c842010-06-28 11:47:26 -0400121