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 |
| 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 |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 63 | printf "Sanitizing environment..." |
| 64 | rm -rf $REPACK |
| 65 | mkdir -p $REPACK |
| 66 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 67 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 68 | |
| 69 | # Unpack the otapackage and opticharge all apks |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 70 | mkdir $REPACK/ota |
| 71 | ( |
| 72 | cd $REPACK/ota |
| 73 | printf "Unpacking $OTAPACKAGE..." |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 74 | unzip $QUIET $OTAPACKAGE |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 75 | echo |
| 76 | cd $REPACK/ota/system/framework |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 77 | $OPTICHARGER framework-res.apk |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 78 | cd $REPACK/ota/system/app |
| 79 | for i in *.apk; do $OPTICHARGER $i; done |
| 80 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 81 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 82 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 83 | if [ "$WANT_SQUASHFS" -eq 1 ]; then |
| 84 | 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] | 85 | updater=$REPACK/ota/META-INF/com/google/android/updater-script |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 86 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 87 | # Relocate su |
| 88 | cp -a $REPACK/ota/system/xbin $REPACK/_xbin/ |
| 89 | rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su |
| 90 | mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su |
| 91 | chmod -R 555 $REPACK/_xbin/* |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 92 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 93 | # Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem). |
| 94 | # Forgive me for the regex hell here. |
| 95 | ln -s ../bin/su $REPACK/_xbin/su |
| 96 | 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'` |
| 97 | do |
| 98 | ln -s busybox $REPACK/_xbin/$link |
| 99 | done |
| 100 | |
| 101 | # Create the squashfs with new and improved symlinkage! |
| 102 | mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts |
| 103 | rm -rf $REPACK/ota/system/xbin/* |
| 104 | mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf |
| 105 | chmod 444 $REPACK/ota/system/xbin/xbin.sqf |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 106 | |
| 107 | # Remove xbin stuff and fix up updater-script |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 108 | 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] | 109 | fi |
| 110 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 111 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 112 | # Fix build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 113 | sed -i \ |
| 114 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 115 | -e '/ro\.build\.type/s/eng/user/' \ |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 116 | $REPACK/ota/system/build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 117 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 118 | |
| 119 | # Delete unnecessary binaries |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 120 | ( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 121 | |
Steve Kondik | 008c065 | 2010-07-11 04:34:44 -0400 | [diff] [blame] | 122 | # Delete leftover wireless driver |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 123 | rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 124 | |
| 125 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 126 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 127 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 128 | # Strip modules |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 129 | 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] | 130 | |
| 131 | # Determine what to name the new signed package |
| 132 | if [ -z "$CYANOGEN_NIGHTLY" ]; then |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 133 | 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] | 134 | : ${MODVERSION:=nightly} |
| 135 | OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip |
Steve Kondik | cee37ef | 2010-07-16 18:03:19 -0400 | [diff] [blame^] | 136 | else |
| 137 | OUTFILE=$OUT/update-squished.zip |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 138 | fi |
| 139 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 140 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 141 | printf "Zipping package..." |
| 142 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 143 | echo |
| 144 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 145 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 146 | java -Xmx2048m \ |
| 147 | -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \ |
| 148 | -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \ |
| 149 | $REPACK/update.zip $OUTFILE |
| 150 | echo |
| 151 | printf "Cleaning up..." |
| 152 | rm -rf $REPACK |
| 153 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 154 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 155 | # Create a md5 checksum image of the repacked package |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 156 | ( |
| 157 | img=`basename $OUTFILE` |
| 158 | cd `dirname $OUTFILE` |
| 159 | $MD5 $img >$img.md5sum |
| 160 | echo |
| 161 | echo "Package complete: $OUTFILE" |
| 162 | cat $img.md5sum |
| 163 | echo |
| 164 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 165 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 166 | exit 0 |