blob: e2665bb9f9fdb7fd5043146cf03a12da916eeaf2 [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
Chris Cosby972e0032010-07-16 11:13:35 -040034
Wes Garnera5982b22010-07-20 13:39:05 -050035if [ -n "$WANT_SQUASHFS" ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040036 fatal=0
37 MKSQUASHFS_VER_REQ=4
38 if type mksquashfs >/dev/null 2>&1; then
39 if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
40 echo
41 echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
42 fatal=1
43 fi
44 else
45 echo
46 echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
47 fatal=1
Chris Cosby5bebc222010-07-15 15:44:43 -040048 fi
49
Chris Cosby972e0032010-07-16 11:13:35 -040050 if [ "$fatal" -ne 0 ]; then
51 echo
52 echo " Unoptimized package is still available at"
53 echo " $OTAPACKAGE"
54 exit $fatal
55 fi
Chris Cosby5bebc222010-07-15 15:44:43 -040056fi
Steve Kondikae76c842010-06-28 11:47:26 -040057
Chris Cosby972e0032010-07-16 11:13:35 -040058REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040059printf "Sanitizing environment..."
60rm -rf $REPACK
61mkdir -p $REPACK
62echo
Steve Kondikae76c842010-06-28 11:47:26 -040063
Steve Kondikae76c842010-06-28 11:47:26 -040064
65# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040066mkdir $REPACK/ota
67(
68cd $REPACK/ota
69printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040070unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040071echo
72cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040073$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040074cd $REPACK/ota/system/app
75for i in *.apk; do $OPTICHARGER $i; done
76)
Steve Kondikae76c842010-06-28 11:47:26 -040077
Steve Kondikae76c842010-06-28 11:47:26 -040078
Wes Garnera5982b22010-07-20 13:39:05 -050079if [ -n "$WANT_SQUASHFS" ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040080 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
Chris Cosby2d0feb52010-07-16 16:28:46 -040081 updater=$REPACK/ota/META-INF/com/google/android/updater-script
Chris Cosby972e0032010-07-16 11:13:35 -040082
Chris Cosby2d0feb52010-07-16 16:28:46 -040083 # Relocate su
84 cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
85 rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
86 mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
87 chmod -R 555 $REPACK/_xbin/*
Chris Cosby972e0032010-07-16 11:13:35 -040088
Chris Cosby2d0feb52010-07-16 16:28:46 -040089 # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
90 # Forgive me for the regex hell here.
91 ln -s ../bin/su $REPACK/_xbin/su
92 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'`
93 do
94 ln -s busybox $REPACK/_xbin/$link
95 done
96
97 # Create the squashfs with new and improved symlinkage!
98 mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
99 rm -rf $REPACK/ota/system/xbin/*
100 mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
101 chmod 444 $REPACK/ota/system/xbin/xbin.sqf
Chris Cosby972e0032010-07-16 11:13:35 -0400102
103 # Remove xbin stuff and fix up updater-script
Chris Cosby2d0feb52010-07-16 16:28:46 -0400104 sed -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
Steve Kondikae76c842010-06-28 11:47:26 -0400105fi
106
Chris Cosby972e0032010-07-16 11:13:35 -0400107
Steve Kondikae76c842010-06-28 11:47:26 -0400108# Fix build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400109sed -i \
110 -e '/ro\.kernel\.android\.checkjni/d' \
111 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -0400112 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400113
Steve Kondikae76c842010-06-28 11:47:26 -0400114
115# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -0400116( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400117
Steve Kondik008c0652010-07-11 04:34:44 -0400118# Delete leftover wireless driver
Chris Cosby2d0feb52010-07-16 16:28:46 -0400119rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400120
121# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400122rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400123
Chris Cosby972e0032010-07-16 11:13:35 -0400124# Strip modules
Chris Cosby2d0feb52010-07-16 16:28:46 -0400125find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -0400126
127# Determine what to name the new signed package
128if [ -z "$CYANOGEN_NIGHTLY" ]; then
Chris Cosby2d0feb52010-07-16 16:28:46 -0400129 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
Chris Cosby972e0032010-07-16 11:13:35 -0400130 : ${MODVERSION:=nightly}
131 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikcee37ef2010-07-16 18:03:19 -0400132else
133 OUTFILE=$OUT/update-squished.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400134fi
135
Steve Kondikae76c842010-06-28 11:47:26 -0400136# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400137printf "Zipping package..."
138( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
139echo
140printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400141SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Cosby972e0032010-07-16 11:13:35 -0400142java -Xmx2048m \
143 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
144 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
145 $REPACK/update.zip $OUTFILE
146echo
147printf "Cleaning up..."
148rm -rf $REPACK
149echo
Steve Kondikae76c842010-06-28 11:47:26 -0400150
Chris Cosby2d0feb52010-07-16 16:28:46 -0400151# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400152(
153img=`basename $OUTFILE`
154cd `dirname $OUTFILE`
155$MD5 $img >$img.md5sum
156echo
157echo "Package complete: $OUTFILE"
158cat $img.md5sum
159echo
160)
Steve Kondikae76c842010-06-28 11:47:26 -0400161
Chris Cosby972e0032010-07-16 11:13:35 -0400162exit 0