forked from doozan/NookManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·208 lines (171 loc) · 7.31 KB
/
build.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
SWD="$( cd "$( dirname "$0" )" && pwd )"
download()
{
local file_url=$1
local file_dest=$2
case $file_dest in
*/) if [ ! -d "$file_dest" ]; then
mkdir -p "$file_dest"
fi
wget -nc -P "$file_dest" "$file_url";;
*) if [ ! -f "$file_dest" ]; then
wget -nc -O "$file_dest" "$file_url"
fi;;
esac
}
extract()
{
local file_src=$1
local file_dest=$2
if [ ! -f "$file_src" ]; then
return 1
fi
if [ ! -d "$file_dest" ]; then
mkdir -p "$file_dest"
filetype=${file_src/*./}
if [ "$filetype" == "tgz" ]; then
tar -xzvf "$file_src" -C "$file_dest"
elif [ "$filetype" == "zip" ]; then
unzip "$file_src" -d "$file_dest"
elif [ "$filetype" == "bz2" ]; then
tar -xjvf "$file_src" -C "$file_dest"
else
echo "Extension \"$filetype\" is unknown, cannot extract $file_src"
fi
fi
}
download_and_extract()
{
local file_url=$1
local file_dest=$2
local file_dir=$3
case $file_dest in
*/) file_dest=$file_dest$(basename "$file_url")
esac
download $file_url $file_dest
extract $file_dest $file_dir
}
DLDIR=$SWD/staging/downloads
BDIR=$SWD/staging/build
OUTDIR=$SWD/sdcard
mkdir -p $DLDIR
mkdir -p $BDIR
download_and_extract "http://images.barnesandnoble.com/PResources/download/Nook/source-code/nook2_1-2.tgz" "$DLDIR/" "$BDIR/nook_src"
download_and_extract "http://su.barnesandnoble.com/nook/nook2/1.2/aoW5Thnhd71GzQ7C3q6JFI2hXkaOufNIHjBYHo6i/nook_1_2_update.zip" "$DLDIR/" "$BDIR/nook_firmware"
download_and_extract "http://su.barnesandnoble.com/nook/nook2/1.1.2/byoyFa4tPqT3du0nSXTLrBeYy5CHbHS264o9Ujsh/nook_1_1_2_update.zip" "$DLDIR/" "$BDIR/nook_old_firmware"
download_and_extract "http://www.adbtoolkit.com/rooting/su/zip/su-2.3.6.1-ef-signed.zip" "$DLDIR/" "$BDIR/superuser"
download_and_extract "http://buildroot.uclibc.org/downloads/buildroot-2012.08.tar.bz2" "$DLDIR/" "$BDIR/buildroot"
download "https://github.com/CyanogenMod/android_frameworks_base/blob/jellybean/data/fonts/DroidSansFallback.ttf?raw=true" "$DLDIR/DroidSansFallback.ttf"
download "https://s3.amazonaws.com/github/downloads/yiselieren/ReLaunch/ReLaunch-1.3.8.apk" "$DLDIR/"
download "http://download.doozan.com/nook/NookTouchModManager-0.4.0.apk" "$DLDIR/"
download "http://pool.apk.bazaarandroid.com/moonglo/com-amazon-venezia-201000-634745-98e61fd37521387e2e0b61be64a518b0.apk" "$DLDIR/"
download "https://smali.googlecode.com/files/baksmali-1.4.0.jar" "$DLDIR/"
download "https://smali.googlecode.com/files/smali-1.4.0.jar" "$DLDIR/"
if [ ! -d "$BDIR/nook_rescue" ]; then
mkdir "$BDIR/nook_rescue"
dd if="$BDIR/nook_firmware/ramdisk-recovery.img" of="$BDIR/nook_rescue/rescue.gz" bs=64 skip=1
cd "$BDIR/nook_rescue/"
zcat rescue.gz | cpio -id
cd "$SWD"
fi
# copy custom buildroot settings to buildroot/custom
rsync -a --delete Buildroot/ "$BDIR/buildroot/buildroot-2012.08/custom"
cp Buildroot/buildroot-config "$BDIR/buildroot/buildroot-2012.08/.config"
# Create patched jars
if [ ! -d "$BDIR/patched-jars" ]; then
mkdir -p "$BDIR/patched-jars"
download "https://github.com/doozan/NookTouchPatches/raw/master/patches/1.2.0/android.policy.patch" "$BDIR/patched-jars/"
download "https://github.com/doozan/NookTouchPatches/raw/master/patches/1.2.0/services.patch" "$BDIR/patched-jars/"
dos2unix "$BDIR/patched-jars/android.policy.patch"
dos2unix "$BDIR/patched-jars/services.patch"
cp "$BDIR/nook_firmware/system/framework/android.policy.jar" "$BDIR/patched-jars/android.policy.orig.jar"
cp "$BDIR/nook_firmware/system/framework/services.jar" "$BDIR/patched-jars/services.orig.jar"
cd "$BDIR/patched-jars"
java -jar "$DLDIR/baksmali-1.4.0.jar" -o android.policy android.policy.orig.jar
java -jar "$DLDIR/baksmali-1.4.0.jar" -o services services.orig.jar
patch -p1 < android.policy.patch
patch -p1 < services.patch
unzip android.policy.orig.jar -d android.policy-bin
java -jar "$DLDIR/smali-1.4.0.jar" -o android.policy-bin/classes.dex android.policy
cd android.policy-bin
zip -9 ../android.policy.jar *
cd ..
unzip services.orig.jar -d services-bin
java -jar "$DLDIR/smali-1.4.0.jar" -o services-bin/classes.dex services
cd services-bin
zip -9 ../services.jar *
cd "$SWD"
fi
# Configure the nook sources as git repos so buildroot can checkout the source
if [ ! -d "$BDIR/nook_src/distro/u-boot/.git" ]; then
cd "$BDIR/nook_src/distro/u-boot"
git init
git add .
git commit -m "initial commit"
cd "$SWD"
fi
if [ ! -d "$BDIR/nook_src/distro/kernel/.git" ]; then
cd "$BDIR/nook_src/distro/kernel"
git init
git add .
git commit -m "initial commit"
cd "$SWD"
fi
# Run buildroot
cd "$BDIR/buildroot/buildroot-2012.08"
make
if [ "$?" -ne "0" ]; then exit; fi
mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n "NookManager" -d output/images/rootfs.cpio.gz output/images/uRamdisk
cd "$SWD"
# build to565
#"$BDIR/buildroot/buildroot-2012.08/output/host/usr/bin/arm-none-linux-gnueabi-gcc" -O2 -Wall -Wno-unused-parameter -o "misc/to565" "misc/to565.c"
rm -rf "$OUTDIR"
mkdir -p "$OUTDIR/files/data/app"
mkdir -p "$OUTDIR/files/system/app"
mkdir -p "$OUTDIR/files/system/bin"
mkdir -p "$OUTDIR/files/system/fonts"
mkdir -p "$OUTDIR/files/system/framework"
# Create the contents of the sdcard in $OUTDIR
cp "$BDIR/buildroot/buildroot-2012.08/output/images/u-boot.bin" "$OUTDIR"
cp "$BDIR/buildroot/buildroot-2012.08/output/images/uImage" "$OUTDIR"
cp "$BDIR/buildroot/buildroot-2012.08/output/images/uRamdisk" "$OUTDIR"
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d "$SWD/misc/boot.script" "$OUTDIR/boot.scr"
cp "$BDIR/nook_firmware/MLO" "$OUTDIR"
cp "$BDIR/nook_firmware/wvf.bin" "$OUTDIR"
cp "$BDIR/nook_firmware/cfg.bin" "$OUTDIR"
cp "$BDIR/nook_firmware/flash_spl.bin" "$OUTDIR"
cp "$SWD/misc/booting.pgm" "$OUTDIR"
cp -r "$SWD/NookManager/"* "$OUTDIR/"
# Copy PackageInstaller from the old firmware (Needed for 1.2.0)
cp "$BDIR/nook_old_firmware/system/app/PackageInstaller.apk" "$OUTDIR/files/system/app"
cp "$BDIR/superuser/system/app/Superuser.apk" "$OUTDIR/files/data/app/com.noshufou.android.su.apk"
cp "$BDIR/superuser/system/bin/su" "$OUTDIR/files/system/bin/"
cp "$DLDIR/DroidSansFallback.ttf" "$OUTDIR/files/system/fonts/"
cp "$DLDIR/ReLaunch-1.3.8.apk" "$OUTDIR/files/data/app/com.harasoft.relaunch.apk"
cp "$DLDIR/NookTouchModManager-0.4.0.apk" "$OUTDIR/files/data/app/org.nookmods.ntmm.apk"
cp "$DLDIR/com-amazon-venezia-201000-634745-98e61fd37521387e2e0b61be64a518b0.apk" "$OUTDIR/files/data/app/com.android.venezia.apk"
cp "$BDIR/patched-jars/android.policy.jar" "$OUTDIR/files/system/framework/"
cp "$BDIR/patched-jars/services.jar" "$OUTDIR/files/system/framework/"
# Create image
IMAGE_FILE=NookManager.img
dd if=/dev/zero of=$IMAGE_FILE bs=1MiB count=64
WHOLE_CARD=$(sudo losetup -f)
sudo losetup $WHOLE_CARD $IMAGE_FILE
BOOTFS_DEV=$(sudo losetup -f)
sudo parted $WHOLE_CARD mklabel msdos
sudo parted $WHOLE_CARD --align=minimal mkpart primary fat32 16384B 100%
sudo parted $WHOLE_CARD set 1 boot on
sudo losetup -o 16384 $BOOTFS_DEV $WHOLE_CARD
sudo mkdosfs -F 32 -n "NookManager" $BOOTFS_DEV
if [ ! -d "$BDIR/tmpmount" ]; then
mkdir "$BDIR/tmpmount"
fi
sudo mount -t vfat -o uid=$(id -ur) -o gid=$(id -gr) $BOOTFS_DEV "$BDIR/tmpmount"
rsync -a "$OUTDIR/" "$BDIR/tmpmount/"
sync
sudo umount "$BDIR/tmpmount"
sudo losetup -d $BOOTFS_DEV
sync
sudo losetup -d $WHOLE_CARD
echo "Build Complete. You can now flash $IMAGE_FILE to an SD card."