blob: 61a3663b373b2c3f1b354b0c9b74efbf6abee62d [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
27 OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
28else
29 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
30fi
Chris Cosby972e0032010-07-16 11:13:35 -040031if [ ! -f "$OTAPACKAGE" ]; then
32 echo "$OTAPACKAGE doesn't exist!";
33 exit 1
34fi
35
Steve Kondikae76c842010-06-28 11:47:26 -040036OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040037QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040038DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040039
40
41# Some products want a squashfs for xbin for space
Steve Kondikd5f3e152010-07-24 18:33:52 -040042case "$TARGET_PRODUCT" in
43 cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
44 *) WANT_SQUASHFS=0 ;;
45esac
Chris Cosby972e0032010-07-16 11:13:35 -040046
Steve Kondikd5f3e152010-07-24 18:33:52 -040047if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040048 fatal=0
49 MKSQUASHFS_VER_REQ=4
50 if type mksquashfs >/dev/null 2>&1; then
51 if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
52 echo
53 echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
54 fatal=1
55 fi
56 else
57 echo
58 echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
59 fatal=1
Chris Cosby5bebc222010-07-15 15:44:43 -040060 fi
61
Chris Cosby972e0032010-07-16 11:13:35 -040062 if [ "$fatal" -ne 0 ]; then
63 echo
64 echo " Unoptimized package is still available at"
65 echo " $OTAPACKAGE"
66 exit $fatal
67 fi
Chris Cosby5bebc222010-07-15 15:44:43 -040068fi
Steve Kondikae76c842010-06-28 11:47:26 -040069
Chris Cosby972e0032010-07-16 11:13:35 -040070REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040071printf "Sanitizing environment..."
72rm -rf $REPACK
73mkdir -p $REPACK
74echo
Steve Kondikae76c842010-06-28 11:47:26 -040075
Steve Kondikae76c842010-06-28 11:47:26 -040076
77# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040078mkdir $REPACK/ota
79(
80cd $REPACK/ota
81printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040082unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040083echo
84cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040085$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040086cd $REPACK/ota/system/app
Takuo Kitame9db76662010-10-29 09:55:59 +090087find ./ -name \*.apk | $XARGS $OPTICHARGER
Chris Cosby972e0032010-07-16 11:13:35 -040088)
Steve Kondikae76c842010-06-28 11:47:26 -040089
Steve Kondikae76c842010-06-28 11:47:26 -040090
Steve Kondikd5f3e152010-07-24 18:33:52 -040091if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040092 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
Chris Cosby2d0feb52010-07-16 16:28:46 -040093 updater=$REPACK/ota/META-INF/com/google/android/updater-script
Chris Cosby972e0032010-07-16 11:13:35 -040094
Chris Cosby2d0feb52010-07-16 16:28:46 -040095 # Relocate su
96 cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
97 rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
98 mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
99 chmod -R 555 $REPACK/_xbin/*
Chris Cosby972e0032010-07-16 11:13:35 -0400100
Chris Cosby2d0feb52010-07-16 16:28:46 -0400101 # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
102 # Forgive me for the regex hell here.
103 ln -s ../bin/su $REPACK/_xbin/su
104 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'`
105 do
106 ln -s busybox $REPACK/_xbin/$link
107 done
108
109 # Create the squashfs with new and improved symlinkage!
110 mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
111 rm -rf $REPACK/ota/system/xbin/*
112 mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
113 chmod 444 $REPACK/ota/system/xbin/xbin.sqf
Chris Cosby972e0032010-07-16 11:13:35 -0400114
115 # Remove xbin stuff and fix up updater-script
Takuo Kitame9db76662010-10-29 09:55:59 +0900116 $SED -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
Steve Kondikae76c842010-06-28 11:47:26 -0400117fi
118
Chris Cosby972e0032010-07-16 11:13:35 -0400119
Steve Kondikae76c842010-06-28 11:47:26 -0400120# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +0900121$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -0400122 -e '/ro\.kernel\.android\.checkjni/d' \
123 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -0400124 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400125
Steve Kondikae76c842010-06-28 11:47:26 -0400126
127# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -0400128( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400129
Steve Kondik008c0652010-07-11 04:34:44 -0400130# Delete leftover wireless driver
Chris Soyars88f9e392010-11-26 21:30:27 -0500131# rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400132
133# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400134rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400135
Chris Cosby972e0032010-07-16 11:13:35 -0400136# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +0100137[ -d $REPACK/ota/system/lib/modules ] && \
138 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -0400139
140# Determine what to name the new signed package
141if [ -z "$CYANOGEN_NIGHTLY" ]; then
Chris Cosby2d0feb52010-07-16 16:28:46 -0400142 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
Chris Cosby972e0032010-07-16 11:13:35 -0400143 : ${MODVERSION:=nightly}
144 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikcee37ef2010-07-16 18:03:19 -0400145else
146 OUTFILE=$OUT/update-squished.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400147fi
148
Steve Kondikae76c842010-06-28 11:47:26 -0400149# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400150printf "Zipping package..."
151( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
152echo
153printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400154SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Soyars44226332010-08-21 00:30:40 -0400155java -Xmx512m \
Chris Cosby972e0032010-07-16 11:13:35 -0400156 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
157 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
158 $REPACK/update.zip $OUTFILE
159echo
160printf "Cleaning up..."
161rm -rf $REPACK
162echo
Steve Kondikae76c842010-06-28 11:47:26 -0400163
Chris Cosby2d0feb52010-07-16 16:28:46 -0400164# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400165(
166img=`basename $OUTFILE`
167cd `dirname $OUTFILE`
168$MD5 $img >$img.md5sum
169echo
170echo "Package complete: $OUTFILE"
171cat $img.md5sum
172echo
173)
Steve Kondikae76c842010-06-28 11:47:26 -0400174
Chris Cosby972e0032010-07-16 11:13:35 -0400175exit 0