summaryrefslogtreecommitdiffstats
path: root/tools/squisher
blob: 063b8e0d3808b00dbcb8a7f93cddcbf9821e0dad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
#
# Squish a CM otapackage for distribution
# cyanogen
#

OUT_TARGET_HOST=$(uname -a | grep Darwin)
if [ -z "$OUT_TARGET_HOST" ]
then
   OUT_TARGET_HOST=linux-x86
   MD5=md5sum
else
   OUT_TARGET_HOST=darwin-x86
   MD5=md5
fi

OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
if [ ! -f "$OTAPACKAGE" ]; then
   echo "$OTAPACKAGE doesn't exist!";
   exit 1
fi

XBIN=$OUT/system/xbin
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
QUIET=-q
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
if [ -z "$NO_SQUASHFS" -a `which mksquashfs` = "" ]; then
	NO_SQUASHFS=true 
else
	if mksquashfs -version | grep -q 'version 4'; then :; else
		echo "mksquashfs must be at least version 4 for this build"
		exit 1
	fi

fi

WORK=/tmp/repack
rm -rf $WORK
mkdir -p $WORK

if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
then
   # Create the xbin squashfs
   cp -a $XBIN $WORK/xbin/
   chmod -R 755 $WORK/xbin/*
   rm -f $WORK/xbin/su
   ln -s $WORK/bin/su $WORK/xbin/su
   mksquashfs $WORK/xbin/* $WORK/xbin.sqf -force-uid 1000 -force-gid 1000
fi

# Unpack the otapackage and opticharge all apks
mkdir $WORK/ota
cd $WORK/ota
unzip $QUIET $OTAPACKAGE
cd system/framework
$OPTICHARGER framework-res.apk
cd ../app
for i in *.apk; do
   $OPTICHARGER $i;
done

cd $WORK/ota/system

if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
then
   # Relocate su and put xbin.sqf where it belongs
   rm -f bin/su
   mv xbin/su bin/su
   rm -rf xbin/*
   mv $WORK/xbin.sqf xbin/
fi

# Fix build.prop
sed -n -e '/ro\.kernel\.android\.checkjni/d' \
    -e '/ro\.build\.type/s/eng/user/' \
    -e 'p' \
    build.prop > build.prop.new
mv build.prop.new build.prop

# Delete unnecessary binaries
for i in $DELETE_BINS; do
   rm -f bin/$i
done

# Delete leftover wireless driver
rm -rf lib/modules/*/kernel/drivers/net

# Strip modules
find lib/modules -name "*.ko" -exec arm-eabi-strip --strip-unneeded {} \;

# Find the CM version
MODVERSION=`sed -ne '/ro\.modversion/s/^.*CyanogenMod-//p' build.prop`

# No need for recovery
cd $WORK/ota
rm -rf recovery

# Remove xbin stuff and fix up updater-script
if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
then
   sed -e "s/system\/xbin\/su/system\/bin\/su/g" META-INF/com/google/android/updater-script | grep -v xbin > updater-script.new
   mv updater-script.new META-INF/com/google/android/updater-script
fi

# Pack it up and sign
zip $QUIET -r update.zip .
echo "Signing package.."
SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
java -Xmx2048m -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 update.zip update_signed.zip

if [ "$CYANOGEN_NIGHTLY" != "" ]
then
    OUTFILE=$OUT/update-squished.zip
else
    OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
fi
mv update_signed.zip $OUTFILE
$MD5 $OUTFILE > $OUTFILE.md5sum
echo "Package complete: $OUT/update-cm-$MODVERSION-signed.zip";
cat $OUTFILE.md5sum