-
Notifications
You must be signed in to change notification settings - Fork 3
/
builder.sh
executable file
·293 lines (272 loc) · 8.17 KB
/
builder.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
nitrogen_dir=nitrogenEx
nitrogen_build_dir=nitrogenEx-builds
compiler_dir=../Linaro-4.9.4
compiler_prefix=bin/arm-eabi-
cross_compiler=$compiler_dir/$compiler_prefix
if ! [ -d ~/.ccache ]; then
echo -e "${bldred}No ccache directory, creating...${txtrst}"
mkdir ~/.ccache
fi
if ! [ -d ~/.ccache/$nitrogen_dir ]; then
echo -e "${bldred}No ccache/$nitrogen_dir directory, creating...${txtrst}"
mkdir ~/.ccache/$nitrogen_dir
fi
if ! [ -d ../$nitrogen_build_dir ]; then
echo -e "${bldred}No $nitrogen_build_dir directory, creating...${txtrst}"
mkdir ~/$nitrogen_build_dir
mkdir ~/$nitrogen_build_dir/build_files
fi
if ! [ -d ../$compiler_dir ]; then
echo -e "${bldred}No $compiler_dir directory, creating...${txtrst}"
git clone https://github.com/nitrogen-devs/android_toolchain_linaro.git $compiler_dir
fi
# Bash Color
green='\033[01;32m'
red='\033[01;31m'
blink_red='\033[05;31m'
restore='\033[0m'
clear
# Resources
THREAD=$(cat /proc/cpuinfo | grep 'model name' | sed -e 's/.*: //' | wc -l)
KERNEL="zImage-dtb"
DEFCONFIG="hammerhead_defconfig"
# Kernel Details
BASE_NEX_VER="NitrogenEX"
kversion="1.0";
VER=".$kversion"
NEX_VER="$BASE_NEX_VER$VER"
# Vars
export CCACHE_DIR=~/.ccache/nitrogenex
export LOCALVERSION=.`echo $NEX_VER`
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=$cross_compiler
# Paths
KERNEL_DIR=`pwd`
REPACK_DIR="android/kernel-packer"
ZIP_MOVE=~/$nitrogen_build_dir/3.4.0.`echo $NEX_VER`.zip
ZIMAGE_DIR="arch/arm/boot"
# Functions
function clean_all {
rm -rf $REPACK_DIR/kernel/$KERNEL
rm -rf $REPACK_DIR/META-INF/com/google/android/updater-script
make clean && make mrproper
}
function make_kernel {
make $DEFCONFIG
make -j$THREAD 2<&1 | tee builder.log
if [ -f $ZIMAGE_DIR/$KERNEL ]; then
cp -vr $ZIMAGE_DIR/$KERNEL $REPACK_DIR/kernel/$KERNEL
fi
}
function make_updater {
(cat << EOF) > $REPACK_DIR/META-INF/com/google/android/updater-script
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print("-----------------------------------------------");
ui_print("* * *** *** **** **** **** *** * * *** * *");
ui_print("** * * * * * * * * * ** * * * *");
ui_print("* ** * * **** * * * ** *** * ** *** *");
ui_print("* * * * * * * * * * * * * * * *");
ui_print("* * *** * * * **** **** *** * * *** * *");
ui_print("- By Mr.MEX --------------------- Linux 3.4.0 -");
ui_print("- Extreme version: $kversion -");
ui_print("- For: Google Nexus 5 (HAMMERHEAD) -");
ui_print("-----------------------------------------------");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print("- Installing... -------------------------------");
ui_print("- Mount /system... -");
run_program("/sbin/busybox", "mount", "/system");
ui_print("- Done! -");
ui_print("- Mount /data... -");
run_program("/sbin/busybox", "mount", "/data");
ui_print("- Done! -");
ui_print("- Extract files to /tmp... -");
package_extract_dir("kernel", "/tmp");
ui_print("- Done! -");
ui_print("- Extract files to /system... -");
package_extract_dir("system", "/system");
ui_print("- Done! -");
ui_print("- Setting permirrions... -");
set_perm(0, 0, 0755, "/system/etc/init.d/98kernelconfig");
set_perm(0, 0, 0644, "/system/vendor/firmware/fw_bcmdhd.bin");
set_perm(0, 0, 0644, "/system/vendor/firmware/fw_bcmdhd_apsta.bin");
set_perm(0, 0, 0777, "/tmp/init.nitrogen.rc");
set_perm(0, 0, 0777, "/tmp/init.supolicy.sh");
set_perm(0, 0, 0777, "/tmp/installer.sh");
set_perm(0, 0, 0777, "/tmp/mkbootimg");
set_perm(0, 0, 0777, "/tmp/unpackbootimg");
ui_print("- Done! -");
ui_print("- Copy boot.img to /tmp... -");
run_program("/sbin/busybox", "dd", "if=/dev/block/platform/msm_sdcc.1/by-name/boot", "of=/tmp/boot.img");
ui_print("- Done! -");
ui_print("- Unpack boot.img... -");
run_program("/tmp/unpackbootimg", "-i", "/tmp/boot.img", "-o", "/tmp/");
ui_print("- Done! -");
ui_print("- Running installer script... -");
ui_print("- Copy ramdisk -");
ui_print("- Unpacking ramdisk -");
ui_print("- Patching init.hammerhead.rc -");
ui_print("- Copy files -");
ui_print("- Delete old ramdisk -");
ui_print("- Building new ramdisk -");
ui_print("- Cleanup -");
ui_print("- Killing thermal and mpdecision -");
ui_print("- Building new boot.img -");
run_program("/tmp/installer.sh");
ui_print("- Done! -");
ui_print("- Flasing new boot.img... -");
run_program("/sbin/busybox", "dd", "if=/tmp/newboot.img", "of=/dev/block/platform/msm_sdcc.1/by-name/boot");
ui_print("- Done! -");
ui_print("- Unmount /system... -");
unmount("/data");
ui_print("- Done! -");
ui_print("- Unmount /data... -");
unmount("/system");
ui_print("- Done! -");
ui_print("-----------------------------------------------");
ui_print(" ");
ui_print(" ");
ui_print(" ");
ui_print("- Nitrogen Extreme Kernel ---------------------");
ui_print("- -");
ui_print("- Installation complete! -");
ui_print("- -");
ui_print("-----------------------------------------------");
ui_print(" ");
ui_print(" ");
ui_print(" ");
EOF
}
function make_zip {
cd $REPACK_DIR
if [ -f kernel/$KERNEL ]; then
zip -9 -r `echo $NEX_VER`.zip .
if [ -f `echo $NEX_VER`.zip ]; then
mv `echo $NEX_VER`.zip $ZIP_MOVE
else
echo -e "No zip!"
fi
else
echo -e "No $KERNEL !"
fi
cd $KERNEL_DIR
}
function cleanup {
rm -rf $REPACK_DIR/kernel/$KERNEL
rm -rf $REPACK_DIR/META-INF/com/google/android/updater-script
rm -rf `echo $NEX_VER`.zip
}
DATE_START=$(date +"%s")
echo -e "${green}"
echo "Kernel Creation Script:"
echo
echo "---------------"
echo "Kernel Version:"
echo "---------------"
echo -e "${red}"; echo -e "${blink_red}"; echo "$NEX_VER"; echo -e "${restore}";
echo -e "${green}"
echo "-----------------"
echo "Making Kernel:"
echo "-----------------"
echo -e "${restore}"
while read -p "Please choose your option:
1. Clean build
2. Dirty build
3. Abort
:> " cchoice
do
case "$cchoice" in
1 )
echo -e "${green}"
echo
echo "[..........Cleaning up..........]"
echo
echo -e "${restore}"
clean_all
echo -e "${green}"
echo
echo "[....Building `echo $NEX_VER`....]"
echo
echo -e "${restore}"
make_kernel
make_updater
echo -e "${green}"
echo
echo "[....Make `echo $NEX_VER`.zip....]"
echo
echo -e "${restore}"
make_zip
echo -e "${green}"
echo
echo "[.....Moving `echo $NEX_VER`.....]"
echo
echo -e "${restore}"
cleanup
break
;;
2 )
echo -e "${green}"
echo
echo "[....Building `echo $NEX_VER`....]"
echo
echo -e "${restore}"
make_kernel
make_updater
echo -e "${green}"
echo
echo "[....Make `echo $NEX_VER`.zip....]"
echo
echo -e "${restore}"
make_zip
echo -e "${green}"
echo
echo "[.....Moving `echo $NEX_VER`.....]"
echo
echo -e "${restore}"
cleanup
break
;;
3 )
break
;;
* )
echo -e "${red}"
echo
echo "Invalid try again!"
echo
echo -e "${restore}"
;;
esac
done
echo -e "${green}"
echo "-------------------"
echo "Build Completed in:"
echo "-------------------"
echo -e "${restore}"
DATE_END=$(date +"%s")
DIFF=$(($DATE_END - $DATE_START))
echo "Time: $(($DIFF / 60)) minute(s) and $(($DIFF % 60)) seconds."
echo