blob: 2f2c1a8a3e7bcb65cd13ffe78b57bbcf130ca15b [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
Chris Cosby972e0032010-07-16 11:13:35 -040026OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
27if [ ! -f "$OTAPACKAGE" ]; then
28 echo "$OTAPACKAGE doesn't exist!";
29 exit 1
30fi
31
Steve Kondikae76c842010-06-28 11:47:26 -040032OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040033QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040034DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040035
36
37# Some products want a squashfs for xbin for space
Steve Kondikd5f3e152010-07-24 18:33:52 -040038case "$TARGET_PRODUCT" in
39 cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
40 *) WANT_SQUASHFS=0 ;;
41esac
Chris Cosby972e0032010-07-16 11:13:35 -040042
Steve Kondikd5f3e152010-07-24 18:33:52 -040043if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040044 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 Cosby5bebc222010-07-15 15:44:43 -040056 fi
57
Chris Cosby972e0032010-07-16 11:13:35 -040058 if [ "$fatal" -ne 0 ]; then
59 echo
60 echo " Unoptimized package is still available at"
61 echo " $OTAPACKAGE"
62 exit $fatal
63 fi
Chris Cosby5bebc222010-07-15 15:44:43 -040064fi
Steve Kondikae76c842010-06-28 11:47:26 -040065
Chris Cosby972e0032010-07-16 11:13:35 -040066REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040067printf "Sanitizing environment..."
68rm -rf $REPACK
69mkdir -p $REPACK
70echo
Steve Kondikae76c842010-06-28 11:47:26 -040071
Steve Kondikae76c842010-06-28 11:47:26 -040072
73# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040074mkdir $REPACK/ota
75(
76cd $REPACK/ota
77printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040078unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040079echo
80cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040081$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040082cd $REPACK/ota/system/app
Takuo Kitame9db76662010-10-29 09:55:59 +090083find ./ -name \*.apk | $XARGS $OPTICHARGER
Chris Cosby972e0032010-07-16 11:13:35 -040084)
Steve Kondikae76c842010-06-28 11:47:26 -040085
Steve Kondikae76c842010-06-28 11:47:26 -040086
Steve Kondikd5f3e152010-07-24 18:33:52 -040087if [ "$WANT_SQUASHFS" -eq 1 ]; then
Chris Cosby972e0032010-07-16 11:13:35 -040088 squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
Chris Cosby2d0feb52010-07-16 16:28:46 -040089 updater=$REPACK/ota/META-INF/com/google/android/updater-script
Chris Cosby972e0032010-07-16 11:13:35 -040090
Chris Cosby2d0feb52010-07-16 16:28:46 -040091 # 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 Cosby972e0032010-07-16 11:13:35 -040096
Chris Cosby2d0feb52010-07-16 16:28:46 -040097 # 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 Cosby972e0032010-07-16 11:13:35 -0400110
111 # Remove xbin stuff and fix up updater-script
Takuo Kitame9db76662010-10-29 09:55:59 +0900112 $SED -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
Steve Kondikae76c842010-06-28 11:47:26 -0400113fi
114
Chris Cosby972e0032010-07-16 11:13:35 -0400115
Steve Kondikae76c842010-06-28 11:47:26 -0400116# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +0900117$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -0400118 -e '/ro\.kernel\.android\.checkjni/d' \
119 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -0400120 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -0400121
Steve Kondikae76c842010-06-28 11:47:26 -0400122
123# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -0400124( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -0400125
Steve Kondik008c0652010-07-11 04:34:44 -0400126# Delete leftover wireless driver
Chris Cosby2d0feb52010-07-16 16:28:46 -0400127rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
Steve Kondikae76c842010-06-28 11:47:26 -0400128
129# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -0400130rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -0400131
Chris Cosby972e0032010-07-16 11:13:35 -0400132# Strip modules
Chris Cosby2d0feb52010-07-16 16:28:46 -0400133find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -0400134
135# Determine what to name the new signed package
136if [ -z "$CYANOGEN_NIGHTLY" ]; then
Chris Cosby2d0feb52010-07-16 16:28:46 -0400137 MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
Chris Cosby972e0032010-07-16 11:13:35 -0400138 : ${MODVERSION:=nightly}
139 OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
Steve Kondikcee37ef2010-07-16 18:03:19 -0400140else
141 OUTFILE=$OUT/update-squished.zip
Steve Kondikae76c842010-06-28 11:47:26 -0400142fi
143
Steve Kondikae76c842010-06-28 11:47:26 -0400144# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400145printf "Zipping package..."
146( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
147echo
148printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400149SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Chris Soyars44226332010-08-21 00:30:40 -0400150java -Xmx512m \
Chris Cosby972e0032010-07-16 11:13:35 -0400151 -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
154echo
155printf "Cleaning up..."
156rm -rf $REPACK
157echo
Steve Kondikae76c842010-06-28 11:47:26 -0400158
Chris Cosby2d0feb52010-07-16 16:28:46 -0400159# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400160(
161img=`basename $OUTFILE`
162cd `dirname $OUTFILE`
163$MD5 $img >$img.md5sum
164echo
165echo "Package complete: $OUTFILE"
166cat $img.md5sum
167echo
168)
Steve Kondikae76c842010-06-28 11:47:26 -0400169
Chris Cosby972e0032010-07-16 11:13:35 -0400170exit 0