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 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 7 | OUT_TARGET_HOST=`uname -a | grep Darwin` |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 8 | if [ -z "$OUT_TARGET_HOST" ] |
| 9 | then |
| 10 | OUT_TARGET_HOST=linux-x86 |
| 11 | MD5=md5sum |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 12 | XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`" |
| 13 | SED=sed |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 14 | else |
| 15 | OUT_TARGET_HOST=darwin-x86 |
| 16 | MD5=md5 |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 17 | XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`" |
| 18 | SED=gsed |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 19 | fi |
| 20 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 21 | if [ -z "$OUT" -o ! -d "$OUT" ]; then |
| 22 | echo "ERROR: $0 only works with a full build environment. $OUT should exist." |
| 23 | exit 1 |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 24 | fi |
| 25 | |
David Kohen | 61848e4 | 2011-02-06 20:29:33 +0200 | [diff] [blame] | 26 | if [ "$TARGET_BUILD_TYPE" = "debug" ]; then |
Ladios Jonquil | 1f76513 | 2011-09-25 02:11:08 +0800 | [diff] [blame] | 27 | OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$USER.zip |
David Kohen | 61848e4 | 2011-02-06 20:29:33 +0200 | [diff] [blame] | 28 | else |
Ladios Jonquil | 1f76513 | 2011-09-25 02:11:08 +0800 | [diff] [blame] | 29 | OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip |
David Kohen | 61848e4 | 2011-02-06 20:29:33 +0200 | [diff] [blame] | 30 | fi |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 31 | if [ ! -f "$OTAPACKAGE" ]; then |
| 32 | echo "$OTAPACKAGE doesn't exist!"; |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 36 | OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 37 | QUIET=-q |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 38 | DELETE_BINS="applypatch applypatch_static check_prereq recovery updater" |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 39 | |
| 40 | |
| 41 | # Some products want a squashfs for xbin for space |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 42 | case "$TARGET_PRODUCT" in |
| 43 | cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;; |
| 44 | *) WANT_SQUASHFS=0 ;; |
| 45 | esac |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 46 | |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 47 | if [ "$WANT_SQUASHFS" -eq 1 ]; then |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 48 | 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 Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 60 | fi |
| 61 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 62 | if [ "$fatal" -ne 0 ]; then |
| 63 | echo |
| 64 | echo " Unoptimized package is still available at" |
| 65 | echo " $OTAPACKAGE" |
| 66 | exit $fatal |
| 67 | fi |
Chris Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 68 | fi |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 69 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 70 | REPACK=$OUT/repack.d |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 71 | printf "Sanitizing environment..." |
| 72 | rm -rf $REPACK |
| 73 | mkdir -p $REPACK |
| 74 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 75 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 76 | |
| 77 | # Unpack the otapackage and opticharge all apks |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 78 | mkdir $REPACK/ota |
| 79 | ( |
| 80 | cd $REPACK/ota |
| 81 | printf "Unpacking $OTAPACKAGE..." |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 82 | unzip $QUIET $OTAPACKAGE |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 83 | echo |
| 84 | cd $REPACK/ota/system/framework |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 85 | $OPTICHARGER framework-res.apk |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 86 | cd $REPACK/ota/system/app |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 87 | find ./ -name \*.apk | $XARGS $OPTICHARGER |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 88 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 89 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 90 | |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 91 | if [ "$WANT_SQUASHFS" -eq 1 ]; then |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 92 | squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery" |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 93 | updater=$REPACK/ota/META-INF/com/google/android/updater-script |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 94 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 95 | # 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 Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 100 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 101 | # 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 Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 114 | |
| 115 | # Remove xbin stuff and fix up updater-script |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 116 | $SED -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 117 | fi |
| 118 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 119 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 120 | # Fix build.prop |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 121 | $SED -i \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 122 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 123 | -e '/ro\.build\.type/s/eng/user/' \ |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 124 | $REPACK/ota/system/build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 125 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 126 | |
| 127 | # Delete unnecessary binaries |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 128 | ( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 129 | |
Steve Kondik | 008c065 | 2010-07-11 04:34:44 -0400 | [diff] [blame] | 130 | # Delete leftover wireless driver |
Chris Soyars | 88f9e39 | 2010-11-26 21:30:27 -0500 | [diff] [blame] | 131 | # rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 132 | |
| 133 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 134 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 135 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 136 | # Strip modules |
Pat Thoyts | 8ed18b5 | 2011-08-03 16:14:31 +0100 | [diff] [blame] | 137 | [ -d $REPACK/ota/system/lib/modules ] && \ |
| 138 | find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 139 | |
| 140 | # Determine what to name the new signed package |
| 141 | if [ -z "$CYANOGEN_NIGHTLY" ]; then |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 142 | MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop` |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 143 | : ${MODVERSION:=nightly} |
| 144 | OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip |
Steve Kondik | cee37ef | 2010-07-16 18:03:19 -0400 | [diff] [blame] | 145 | else |
| 146 | OUTFILE=$OUT/update-squished.zip |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 147 | fi |
| 148 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 149 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 150 | printf "Zipping package..." |
| 151 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 152 | echo |
| 153 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 154 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Chris Soyars | 4422633 | 2010-08-21 00:30:40 -0400 | [diff] [blame] | 155 | java -Xmx512m \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 156 | -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 |
| 159 | echo |
| 160 | printf "Cleaning up..." |
| 161 | rm -rf $REPACK |
| 162 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 163 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 164 | # Create a md5 checksum image of the repacked package |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 165 | ( |
| 166 | img=`basename $OUTFILE` |
| 167 | cd `dirname $OUTFILE` |
| 168 | $MD5 $img >$img.md5sum |
| 169 | echo |
| 170 | echo "Package complete: $OUTFILE" |
| 171 | cat $img.md5sum |
| 172 | echo |
| 173 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 174 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 175 | exit 0 |