blob: d06db57a6f2de785579d109f6e13970e5394b38d [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
Chris Cosby972e0032010-07-16 11:13:35 -040017if [ -z "$OUT" -o ! -d "$OUT" ]; then
18 echo "ERROR: $0 only works with a full build environment. $OUT should exist."
19 exit 1
Steve Kondikae76c842010-06-28 11:47:26 -040020fi
21
Chris Cosby972e0032010-07-16 11:13:35 -040022OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
23if [ ! -f "$OTAPACKAGE" ]; then
24 echo "$OTAPACKAGE doesn't exist!";
25 exit 1
26fi
27
Steve Kondikae76c842010-06-28 11:47:26 -040028OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040029QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040030DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040031
32
33# Some products want a squashfs for xbin for space
34case "$TARGET_PRODUCT" in
35 cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
36 *) WANT_SQUASHFS=0 ;;
37esac
38
39if [ "$WANT_SQUASHFS" -eq 1 ]; then
40 fatal=0
41 MKSQUASHFS_VER_REQ=4
42 if type mksquashfs >/dev/null 2>&1; then
43 if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
44 echo
45 echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
46 fatal=1
47 fi
48 else
49 echo
50 echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
51 fatal=1
Chris Cosby5bebc222010-07-15 15:44:43 -040052 fi
53
Chris Cosby972e0032010-07-16 11:13:35 -040054 if [ "$fatal" -ne 0 ]; then
55 echo
56 echo " Unoptimized package is still available at"
57 echo " $OTAPACKAGE"
58 exit $fatal
59 fi
Chris Cosby5bebc222010-07-15 15:44:43 -040060fi
Steve Kondikae76c842010-06-28 11:47:26 -040061
Chris Cosby972e0032010-07-16 11:13:35 -040062REPACK=$OUT/repack.d
63SYSTEM=$REPACK/ota/system
64printf "Sanitizing environment..."
65rm -rf $REPACK
66mkdir -p $REPACK
67echo
Steve Kondikae76c842010-06-28 11:47:26 -040068
Steve Kondikae76c842010-06-28 11:47:26 -040069
70# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040071mkdir $REPACK/ota
72(
73cd $REPACK/ota
74printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040075unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040076echo
77cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040078$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040079cd $REPACK/ota/system/app
80for i in *.apk; do $OPTICHARGER $i; done
81)
Steve Kondikae76c842010-06-28 11:47:26 -040082
Steve Kondikae76c842010-06-28 11:47:26 -040083
Chris Cosby972e0032010-07-16 11:13:35 -040084if [ "$WANT_SQUASHFS" -eq 1 ]; then
85 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
86
87 # Create the xbin squashfs
88 cp -a $SYSTEM/xbin $REPACK/xbin/
89 rm -f $REPACK/xbin/su
90 chmod -R 555 $REPACK/xbin/*
91 ln -s ../bin/su $REPACK/xbin/su
92
93 # Relocate su and put xbin.sqf where it belongs
94 rm -f $SYSTEM/bin/su
95 mv $SYSTEM/xbin/su $SYSTEM/bin/su
96 rm -rf $SYSTEM/xbin/*
97 mksquashfs $REPACK/xbin/* $SYSTEM/xbin/xbin.sqf $squash_opts
98 chmod 444 $SYSTEM/xbin/xbin.sqf
99
100 # Remove xbin stuff and fix up updater-script
101 sed -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $REPACK/ota/META-INF/com/google/android/updater-script
Steve Kondikae76c842010-06-28 11:47:26 -0400102fi
103
Chris Cosby972e0032010-07-16 11:13:35 -0400104
Steve Kondikae76c842010-06-28 11:47:26 -0400105# Fix build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400106sed -i \
107 -e '/ro\.kernel\.android\.checkjni/d' \
108 -e '/ro\.build\.type/s/eng/user/' \
109 $SYSTEM/build.prop
110
Steve Kondikae76c842010-06-28 11:47:26 -0400111
112# Delete unnecessary binaries
Chris Cosby972e0032010-07-16 11:13:35 -0400113( cd $SYSTEM/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400114
Steve Kondik008c0652010-07-11 04:34:44 -0400115# Delete leftover wireless driver
Chris Cosby972e0032010-07-16 11:13:35 -0400116rm -rf $SYSTEM/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400117
118# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400119rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400120
Chris Cosby972e0032010-07-16 11:13:35 -0400121# Strip modules
122find $SYSTEM/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
123
124# Determine what to name the new signed package
125if [ -z "$CYANOGEN_NIGHTLY" ]; then
126 OUTFILE=$OUT/update-squished.zip
127else
128 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $SYSTEM/build.prop`
129 : ${MODVERSION:=nightly}
130 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400131fi
132
Steve Kondikae76c842010-06-28 11:47:26 -0400133# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400134printf "Zipping package..."
135( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
136echo
137printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400138SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Cosby972e0032010-07-16 11:13:35 -0400139java -Xmx2048m \
140 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
141 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
142 $REPACK/update.zip $OUTFILE
143echo
144printf "Cleaning up..."
145rm -rf $REPACK
146echo
Steve Kondikae76c842010-06-28 11:47:26 -0400147
Chris Cosby972e0032010-07-16 11:13:35 -0400148(
149img=`basename $OUTFILE`
150cd `dirname $OUTFILE`
151$MD5 $img >$img.md5sum
152echo
153echo "Package complete: $OUTFILE"
154cat $img.md5sum
155echo
156)
Steve Kondikae76c842010-06-28 11:47:26 -0400157
Chris Cosby972e0032010-07-16 11:13:35 -0400158exit 0