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 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 26 | OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip |
| 27 | if [ ! -f "$OTAPACKAGE" ]; then |
| 28 | echo "$OTAPACKAGE doesn't exist!"; |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 32 | OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 33 | QUIET=-q |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 34 | DELETE_BINS="applypatch applypatch_static check_prereq recovery updater" |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 35 | |
| 36 | |
| 37 | # Some products want a squashfs for xbin for space |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 38 | case "$TARGET_PRODUCT" in |
| 39 | cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;; |
| 40 | *) WANT_SQUASHFS=0 ;; |
| 41 | esac |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 42 | |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 43 | if [ "$WANT_SQUASHFS" -eq 1 ]; then |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 44 | fatal=0 |
| 45 | MKSQUASHFS_VER_REQ=4 |
| 46 | if type mksquashfs >/dev/null 2>&1; then |
| 47 | if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else |
| 48 | echo |
| 49 | echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build." |
| 50 | fatal=1 |
| 51 | fi |
| 52 | else |
| 53 | echo |
| 54 | echo "ERROR: $TARGET_PRODUCT requires mksquashfs." |
| 55 | fatal=1 |
Chris Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 56 | fi |
| 57 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 58 | if [ "$fatal" -ne 0 ]; then |
| 59 | echo |
| 60 | echo " Unoptimized package is still available at" |
| 61 | echo " $OTAPACKAGE" |
| 62 | exit $fatal |
| 63 | fi |
Chris Cosby | 5bebc22 | 2010-07-15 15:44:43 -0400 | [diff] [blame] | 64 | fi |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 65 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 66 | REPACK=$OUT/repack.d |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 67 | printf "Sanitizing environment..." |
| 68 | rm -rf $REPACK |
| 69 | mkdir -p $REPACK |
| 70 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 71 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 72 | |
| 73 | # Unpack the otapackage and opticharge all apks |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 74 | mkdir $REPACK/ota |
| 75 | ( |
| 76 | cd $REPACK/ota |
| 77 | printf "Unpacking $OTAPACKAGE..." |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 78 | unzip $QUIET $OTAPACKAGE |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 79 | echo |
| 80 | cd $REPACK/ota/system/framework |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 81 | $OPTICHARGER framework-res.apk |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 82 | cd $REPACK/ota/system/app |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 83 | find ./ -name \*.apk | $XARGS $OPTICHARGER |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 84 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 85 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 86 | |
Steve Kondik | d5f3e15 | 2010-07-24 18:33:52 -0400 | [diff] [blame] | 87 | if [ "$WANT_SQUASHFS" -eq 1 ]; then |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 88 | 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] | 89 | updater=$REPACK/ota/META-INF/com/google/android/updater-script |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 90 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 91 | # Relocate su |
| 92 | cp -a $REPACK/ota/system/xbin $REPACK/_xbin/ |
| 93 | rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su |
| 94 | mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su |
| 95 | chmod -R 555 $REPACK/_xbin/* |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 96 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 97 | # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem). |
| 98 | # Forgive me for the regex hell here. |
| 99 | ln -s ../bin/su $REPACK/_xbin/su |
| 100 | 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'` |
| 101 | do |
| 102 | ln -s busybox $REPACK/_xbin/$link |
| 103 | done |
| 104 | |
| 105 | # Create the squashfs with new and improved symlinkage! |
| 106 | mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts |
| 107 | rm -rf $REPACK/ota/system/xbin/* |
| 108 | mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf |
| 109 | chmod 444 $REPACK/ota/system/xbin/xbin.sqf |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 110 | |
| 111 | # Remove xbin stuff and fix up updater-script |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 112 | $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] | 113 | fi |
| 114 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 115 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 116 | # Fix build.prop |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 117 | $SED -i \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 118 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 119 | -e '/ro\.build\.type/s/eng/user/' \ |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 120 | $REPACK/ota/system/build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 121 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 122 | |
| 123 | # Delete unnecessary binaries |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 124 | ( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 125 | |
Steve Kondik | 008c065 | 2010-07-11 04:34:44 -0400 | [diff] [blame] | 126 | # Delete leftover wireless driver |
Chris Soyars | 88f9e39 | 2010-11-26 21:30:27 -0500 | [diff] [blame] | 127 | # rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 128 | |
| 129 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 130 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 131 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 132 | # Strip modules |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 133 | 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] | 134 | |
| 135 | # Determine what to name the new signed package |
| 136 | if [ -z "$CYANOGEN_NIGHTLY" ]; then |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 137 | 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] | 138 | : ${MODVERSION:=nightly} |
| 139 | OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip |
Steve Kondik | cee37ef | 2010-07-16 18:03:19 -0400 | [diff] [blame] | 140 | else |
| 141 | OUTFILE=$OUT/update-squished.zip |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 142 | fi |
| 143 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 144 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 145 | printf "Zipping package..." |
| 146 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 147 | echo |
| 148 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 149 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Chris Soyars | 4422633 | 2010-08-21 00:30:40 -0400 | [diff] [blame] | 150 | java -Xmx512m \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 151 | -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \ |
| 152 | -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \ |
| 153 | $REPACK/update.zip $OUTFILE |
| 154 | echo |
| 155 | printf "Cleaning up..." |
| 156 | rm -rf $REPACK |
| 157 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 158 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 159 | # Create a md5 checksum image of the repacked package |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 160 | ( |
| 161 | img=`basename $OUTFILE` |
| 162 | cd `dirname $OUTFILE` |
| 163 | $MD5 $img >$img.md5sum |
| 164 | echo |
| 165 | echo "Package complete: $OUTFILE" |
| 166 | cat $img.md5sum |
| 167 | echo |
| 168 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 169 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 170 | exit 0 |