blob: aaf22872e528e1653061d44d7042c73e7d644d53 [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
Chris Cosby2d0feb52010-07-16 16:28:46 -04007OUT_TARGET_HOST=`uname -a | grep Darwin`
Steve Kondikae76c842010-06-28 11:47:26 -04008if [ -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
Steve Kondikd5f3e152010-07-24 18:33:52 -040034case "$TARGET_PRODUCT" in
35 cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
36 *) WANT_SQUASHFS=0 ;;
37esac
Chris Cosby972e0032010-07-16 11:13:35 -040038
Steve Kondikd5f3e152010-07-24 18:33:52 -040039if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040040 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
Chris Cosby972e0032010-07-16 11:13:35 -040063printf "Sanitizing environment..."
64rm -rf $REPACK
65mkdir -p $REPACK
66echo
Steve Kondikae76c842010-06-28 11:47:26 -040067
Steve Kondikae76c842010-06-28 11:47:26 -040068
69# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040070mkdir $REPACK/ota
71(
72cd $REPACK/ota
73printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040074unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040075echo
76cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040077$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040078cd $REPACK/ota/system/app
79for i in *.apk; do $OPTICHARGER $i; done
80)
Steve Kondikae76c842010-06-28 11:47:26 -040081
Steve Kondikae76c842010-06-28 11:47:26 -040082
Steve Kondikd5f3e152010-07-24 18:33:52 -040083if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040084 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
Chris Cosby2d0feb52010-07-16 16:28:46 -040085 updater=$REPACK/ota/META-INF/com/google/android/updater-script
Chris Cosby972e0032010-07-16 11:13:35 -040086
Chris Cosby2d0feb52010-07-16 16:28:46 -040087 # Relocate su
88 cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
89 rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
90 mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
91 chmod -R 555 $REPACK/_xbin/*
Chris Cosby972e0032010-07-16 11:13:35 -040092
Chris Cosby2d0feb52010-07-16 16:28:46 -040093 # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
94 # Forgive me for the regex hell here.
95 ln -s ../bin/su $REPACK/_xbin/su
96 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'`
97 do
98 ln -s busybox $REPACK/_xbin/$link
99 done
100
101 # Create the squashfs with new and improved symlinkage!
102 mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
103 rm -rf $REPACK/ota/system/xbin/*
104 mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
105 chmod 444 $REPACK/ota/system/xbin/xbin.sqf
Chris Cosby972e0032010-07-16 11:13:35 -0400106
107 # Remove xbin stuff and fix up updater-script
Chris Cosby2d0feb52010-07-16 16:28:46 -0400108 sed -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
Steve Kondikae76c842010-06-28 11:47:26 -0400109fi
110
Chris Cosby972e0032010-07-16 11:13:35 -0400111
Steve Kondikae76c842010-06-28 11:47:26 -0400112# Fix build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400113sed -i \
114 -e '/ro\.kernel\.android\.checkjni/d' \
115 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -0400116 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400117
Steve Kondikae76c842010-06-28 11:47:26 -0400118
119# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -0400120( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400121
Steve Kondik008c0652010-07-11 04:34:44 -0400122# Delete leftover wireless driver
Chris Cosby2d0feb52010-07-16 16:28:46 -0400123rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400124
125# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400126rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400127
Chris Cosby972e0032010-07-16 11:13:35 -0400128# Strip modules
Chris Cosby2d0feb52010-07-16 16:28:46 -0400129find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -0400130
131# Determine what to name the new signed package
132if [ -z "$CYANOGEN_NIGHTLY" ]; then
Chris Cosby2d0feb52010-07-16 16:28:46 -0400133 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
Chris Cosby972e0032010-07-16 11:13:35 -0400134 : ${MODVERSION:=nightly}
135 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikcee37ef2010-07-16 18:03:19 -0400136else
137 OUTFILE=$OUT/update-squished.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400138fi
139
Steve Kondikae76c842010-06-28 11:47:26 -0400140# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400141printf "Zipping package..."
142( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
143echo
144printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400145SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Soyars44226332010-08-21 00:30:40 -0400146java -Xmx512m \
Chris Cosby972e0032010-07-16 11:13:35 -0400147 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
148 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
149 $REPACK/update.zip $OUTFILE
150echo
151printf "Cleaning up..."
152rm -rf $REPACK
153echo
Steve Kondikae76c842010-06-28 11:47:26 -0400154
Chris Cosby2d0feb52010-07-16 16:28:46 -0400155# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400156(
157img=`basename $OUTFILE`
158cd `dirname $OUTFILE`
159$MD5 $img >$img.md5sum
160echo
161echo "Package complete: $OUTFILE"
162cat $img.md5sum
163echo
164)
Steve Kondikae76c842010-06-28 11:47:26 -0400165
Chris Cosby972e0032010-07-16 11:13:35 -0400166exit 0