blob: b51193686a8ac40df12812cba91ff727c8a49748 [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
Takuo Kitame9db76662010-10-29 09:55:59 +090012 XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
13 SED=sed
Steve Kondikae76c842010-06-28 11:47:26 -040014else
15 OUT_TARGET_HOST=darwin-x86
16 MD5=md5
Takuo Kitame9db76662010-10-29 09:55:59 +090017 XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
18 SED=gsed
Steve Kondikae76c842010-06-28 11:47:26 -040019fi
20
Chris Cosby972e0032010-07-16 11:13:35 -040021if [ -z "$OUT" -o ! -d "$OUT" ]; then
22 echo "ERROR: $0 only works with a full build environment. $OUT should exist."
23 exit 1
Steve Kondikae76c842010-06-28 11:47:26 -040024fi
25
David Kohen61848e42011-02-06 20:29:33 +020026if [ "$TARGET_BUILD_TYPE" = "debug" ]; then
Ladios Jonquil1f765132011-09-25 02:11:08 +080027 OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$USER.zip
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000028elif [ "$TARGET_BUILD_VARIANT" = "userdebug" ]; then
29 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020030else
Ladios Jonquil1f765132011-09-25 02:11:08 +080031 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020032fi
Chris Cosby972e0032010-07-16 11:13:35 -040033if [ ! -f "$OTAPACKAGE" ]; then
34 echo "$OTAPACKAGE doesn't exist!";
35 exit 1
36fi
37
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000038OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040039QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040040DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040041
42
43# Some products want a squashfs for xbin for space
Steve Kondikd5f3e152010-07-24 18:33:52 -040044case "$TARGET_PRODUCT" in
45 cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
46 *) WANT_SQUASHFS=0 ;;
47esac
Chris Cosby972e0032010-07-16 11:13:35 -040048
Steve Kondikd5f3e152010-07-24 18:33:52 -040049if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040050 fatal=0
51 MKSQUASHFS_VER_REQ=4
52 if type mksquashfs >/dev/null 2>&1; then
53 if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
54 echo
55 echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
56 fatal=1
57 fi
58 else
59 echo
60 echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
61 fatal=1
Chris Cosby5bebc222010-07-15 15:44:43 -040062 fi
63
Chris Cosby972e0032010-07-16 11:13:35 -040064 if [ "$fatal" -ne 0 ]; then
65 echo
66 echo " Unoptimized package is still available at"
67 echo " $OTAPACKAGE"
68 exit $fatal
69 fi
Chris Cosby5bebc222010-07-15 15:44:43 -040070fi
Steve Kondikae76c842010-06-28 11:47:26 -040071
Chris Cosby972e0032010-07-16 11:13:35 -040072REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040073printf "Sanitizing environment..."
74rm -rf $REPACK
75mkdir -p $REPACK
76echo
Steve Kondikae76c842010-06-28 11:47:26 -040077
Steve Kondikae76c842010-06-28 11:47:26 -040078
79# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040080mkdir $REPACK/ota
81(
82cd $REPACK/ota
83printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040084unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040085echo
86cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040087$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040088cd $REPACK/ota/system/app
Takuo Kitame9db76662010-10-29 09:55:59 +090089find ./ -name \*.apk | $XARGS $OPTICHARGER
Chris Cosby972e0032010-07-16 11:13:35 -040090)
Steve Kondikae76c842010-06-28 11:47:26 -040091
Steve Kondikae76c842010-06-28 11:47:26 -040092
Steve Kondikd5f3e152010-07-24 18:33:52 -040093if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040094 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
Chris Cosby2d0feb52010-07-16 16:28:46 -040095 updater=$REPACK/ota/META-INF/com/google/android/updater-script
Chris Cosby972e0032010-07-16 11:13:35 -040096
Chris Cosby2d0feb52010-07-16 16:28:46 -040097 # Relocate su
98 cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
99 rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
100 mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
101 chmod -R 555 $REPACK/_xbin/*
Chris Cosby972e0032010-07-16 11:13:35 -0400102
Chris Cosby2d0feb52010-07-16 16:28:46 -0400103 # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
104 # Forgive me for the regex hell here.
105 ln -s ../bin/su $REPACK/_xbin/su
106 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'`
107 do
108 ln -s busybox $REPACK/_xbin/$link
109 done
110
111 # Create the squashfs with new and improved symlinkage!
112 mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
113 rm -rf $REPACK/ota/system/xbin/*
114 mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
115 chmod 444 $REPACK/ota/system/xbin/xbin.sqf
Chris Cosby972e0032010-07-16 11:13:35 -0400116
117 # Remove xbin stuff and fix up updater-script
Takuo Kitame9db76662010-10-29 09:55:59 +0900118 $SED -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
Steve Kondikae76c842010-06-28 11:47:26 -0400119fi
120
Chris Cosby972e0032010-07-16 11:13:35 -0400121
Steve Kondikae76c842010-06-28 11:47:26 -0400122# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +0900123$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -0400124 -e '/ro\.kernel\.android\.checkjni/d' \
125 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -0400126 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400127
Steve Kondikae76c842010-06-28 11:47:26 -0400128
129# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -0400130( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400131
Steve Kondik008c0652010-07-11 04:34:44 -0400132# Delete leftover wireless driver
Chris Soyars88f9e392010-11-26 21:30:27 -0500133# rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400134
135# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400136rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400137
Chris Cosby972e0032010-07-16 11:13:35 -0400138# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +0100139[ -d $REPACK/ota/system/lib/modules ] && \
140 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -0400141
142# Determine what to name the new signed package
143if [ -z "$CYANOGEN_NIGHTLY" ]; then
Chris Cosby2d0feb52010-07-16 16:28:46 -0400144 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
Chris Cosby972e0032010-07-16 11:13:35 -0400145 : ${MODVERSION:=nightly}
146 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikcee37ef2010-07-16 18:03:19 -0400147else
148 OUTFILE=$OUT/update-squished.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400149fi
150
Steve Kondikae76c842010-06-28 11:47:26 -0400151# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400152printf "Zipping package..."
153( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
154echo
155printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400156SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Soyars44226332010-08-21 00:30:40 -0400157java -Xmx512m \
Chris Cosby972e0032010-07-16 11:13:35 -0400158 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
159 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
160 $REPACK/update.zip $OUTFILE
161echo
162printf "Cleaning up..."
163rm -rf $REPACK
164echo
Steve Kondikae76c842010-06-28 11:47:26 -0400165
Chris Cosby2d0feb52010-07-16 16:28:46 -0400166# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400167(
168img=`basename $OUTFILE`
169cd `dirname $OUTFILE`
170$MD5 $img >$img.md5sum
171echo
172echo "Package complete: $OUTFILE"
173cat $img.md5sum
174echo
175)
Steve Kondikae76c842010-06-28 11:47:26 -0400176
Chris Cosby972e0032010-07-16 11:13:35 -0400177exit 0