Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Squish a CM otapackage for distribution |
| 4 | # cyanogen |
| 5 | # |
| 6 | |
| 7 | OUT_TARGET_HOST=$(uname -a | grep Darwin) |
| 8 | if [ -z "$OUT_TARGET_HOST" ] |
| 9 | then |
| 10 | OUT_TARGET_HOST=linux-x86 |
| 11 | MD5=md5sum |
| 12 | else |
| 13 | OUT_TARGET_HOST=darwin-x86 |
| 14 | MD5=md5 |
| 15 | fi |
| 16 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 17 | if [ -z "$OUT" -o ! -d "$OUT" ]; then |
| 18 | echo "ERROR: $0 only works with a full build environment. $OUT should exist." |
| 19 | exit 1 |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 20 | fi |
| 21 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 22 | OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip |
| 23 | if [ ! -f "$OTAPACKAGE" ]; then |
| 24 | echo "$OTAPACKAGE doesn't exist!"; |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 28 | OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 29 | QUIET=-q |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 30 | DELETE_BINS="applypatch applypatch_static check_prereq recovery updater" |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 31 | |
| 32 | |
| 33 | # Some products want a squashfs for xbin for space |
| 34 | case "$TARGET_PRODUCT" in |
| 35 | cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;; |
| 36 | *) WANT_SQUASHFS=0 ;; |
| 37 | esac |
| 38 | |
| 39 | if [ "$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 Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 52 | fi |
| 53 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 54 | if [ "$fatal" -ne 0 ]; then |
| 55 | echo |
| 56 | echo " Unoptimized package is still available at" |
| 57 | echo " $OTAPACKAGE" |
| 58 | exit $fatal |
| 59 | fi |
Chris Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 60 | fi |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 61 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 62 | REPACK=$OUT/repack.d |
| 63 | SYSTEM=$REPACK/ota/system |
| 64 | printf "Sanitizing environment..." |
| 65 | rm -rf $REPACK |
| 66 | mkdir -p $REPACK |
| 67 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 68 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 69 | |
| 70 | # Unpack the otapackage and opticharge all apks |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 71 | mkdir $REPACK/ota |
| 72 | ( |
| 73 | cd $REPACK/ota |
| 74 | printf "Unpacking $OTAPACKAGE..." |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 75 | unzip $QUIET $OTAPACKAGE |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 76 | echo |
| 77 | cd $REPACK/ota/system/framework |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 78 | $OPTICHARGER framework-res.apk |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 79 | cd $REPACK/ota/system/app |
| 80 | for i in *.apk; do $OPTICHARGER $i; done |
| 81 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 82 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 83 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 84 | if [ "$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 Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 102 | fi |
| 103 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 104 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 105 | # Fix build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 106 | sed -i \ |
| 107 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 108 | -e '/ro\.build\.type/s/eng/user/' \ |
| 109 | $SYSTEM/build.prop |
| 110 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 111 | |
| 112 | # Delete unnecessary binaries |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 113 | ( cd $SYSTEM/bin; echo $DELETE_BINS | xargs rm -f; ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 114 | |
Steve Kondik | 008c065 | 2010-07-11 04:34:44 -0400 | [diff] [blame] | 115 | # Delete leftover wireless driver |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 116 | rm -rf $SYSTEM/lib/modules/*/kernel/drivers/net |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 117 | |
| 118 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 119 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 120 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 121 | # Strip modules |
| 122 | find $SYSTEM/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded |
| 123 | |
| 124 | # Determine what to name the new signed package |
| 125 | if [ -z "$CYANOGEN_NIGHTLY" ]; then |
| 126 | OUTFILE=$OUT/update-squished.zip |
| 127 | else |
| 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 Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 131 | fi |
| 132 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 133 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 134 | printf "Zipping package..." |
| 135 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 136 | echo |
| 137 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 138 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 139 | java -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 |
| 143 | echo |
| 144 | printf "Cleaning up..." |
| 145 | rm -rf $REPACK |
| 146 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 147 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 148 | ( |
| 149 | img=`basename $OUTFILE` |
| 150 | cd `dirname $OUTFILE` |
| 151 | $MD5 $img >$img.md5sum |
| 152 | echo |
| 153 | echo "Package complete: $OUTFILE" |
| 154 | cat $img.md5sum |
| 155 | echo |
| 156 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 157 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame^] | 158 | exit 0 |