forked from makinbacon21/switchroot-script-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ_Builder.sh
391 lines (337 loc) · 12.5 KB
/
Q_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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/bin/bash
# get current working directory
CWD=$(pwd)
if [ -z "$BUILDBASE" ];
then
BUILDBASE=~
fi
# arguments
for arg in "$@"
do
if [ "$arg" == "--verbose" ] || [ "$arg" == "-v" ];
then
echo "Verbose mode enabled."
VERBOSE=true
set -x
fi
if [ "$arg" == "--nosync" ] || [ "$arg" == "-n" ];
then
echo "No-Sync mode enabled."
NOSYNC=true
fi
if [ "$arg" == "--clean" ] || [ "$arg" == "-c" ];
then
echo "Clean mode enabled."
if [ $NOSYNC ];
then
echo "Clean and No-Sync modes are incompatible...assuming Clean."
NOSYNC=false
fi
CLEAN=true
fi
done
cd $BUILDBASE
# get threads for tasks
JOBS=$(($(nproc) + 1))
# rom type?
while true; do
read -p "Do ya want icosa (i) or foster_tab (m) or android tv (t)?" imt
case $imt in
[Ii]* ) FOSTERTYPE=i; break;;
[Mm]* ) FOSTERTYPE=m; break;;
[Tt]* ) FOSTERTYPE=t; break;;
* ) echo "Please answer yes or no.";;
esac
done
# oc coreboot?
while true; do
read -p "Do ya want an 1862 MHz memory OC (y/n)?" yn
case $yn in
[Yy]* ) MEMOC=y; break;;
[Nn]* ) MEMOC=n; break;;
* ) echo "Please answer yes or no.";;
esac
done
# oc patch?
while true; do
read -p "Do ya want a 2091 MHz CPU OC (y/n)?" yn
case $yn in
[Yy]* ) CPUOC=y; break;;
[Nn]* ) CPUOC=n; break;;
* ) echo "Please answer yes or no.";;
esac
done
# joycon-swap?
while true; do
read -p "Do ya want the joycon trigger patch (y/n)?" yn
case $yn in
[Yy]* ) JCPATCH=y; break;;
[Nn]* ) JCPATCH=n; break;;
* ) echo "Please answer yes or no.";;
esac
done
# root?
while true; do
read -p "Do ya want your device rooted (patch for Magisk) (y/n)?" yn
case $yn in
[Yy]* ) MAGISK=y; break;;
[Nn]* ) MAGISK=n; break;;
* ) echo "Please answer yes or no.";;
esac
done
# prompt for root and install necessary packages
sudo apt update
sudo apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf
> imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses5-dev
> libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc
> zip zlib1g-dev python python3 binfmt-support qemu qemu-user-static repo default-jdk gradle
sudo apt upgrade
# check to see if git is configured, if not prompt user
if [[ "$(git config --list)" != *"user.email"* ]];
then
read -p "Enter your git email address: " GITEMAIL
read -p "Enter your name: " GITNAME
git config --global user.email $GITEMAIL
git config --global user.name $GITNAME
fi
# clean build?
if [ ! -z $CLEAN ];
then
rm -rf $BUILDBASE/android
fi
if [ ! -d $BUILDBASE/android ];
then
# download and unzip latest platform tools
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
unzip platform-tools-latest-linux.zip -d ~
cd $BUILDBASE
# check for platform tools in PATH, add if missing
if ! grep -q "PATH=\"\$HOME/platform-tools:\$PATH\"" ~/.profile ;
then
echo "if [ -d \"\$HOME/platform-tools\" ] ; then" >> ~/.profile
echo " PATH=\"\$HOME/platform-tools:\$PATH\"" >> ~/.profile
echo "fi" >> ~/.profile
fi
# create directories and get repo
mkdir -p ~/bin
mkdir -p $BUILDBASE/android/lineage
# check for missing case sensitivity (assume WSL) and fix if not
if [ -d ~/Bin ];
then
cd $CWD
powershell.exe -File "./wsl_cs.ps1" -Buildbase "$BUILDBASE"
fi
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
# check for bin in PATH, add if missing
if ! grep -q "PATH=\"\$HOME/bin:\$PATH\"" ~/.profile ;
then
echo "if [ -d \"\$HOME/bin\" ] ; then" >> ~/.profile
echo " PATH=\"\$HOME/bin:\$PATH\"" >> ~/.profile
echo "fi" >> ~/.profile
fi
# initialize repo, sync
cd $BUILDBASE/android/lineage
repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
repo sync --force-sync -j${JOBS}
cd ./.repo
git clone https://gitlab.com/switchroot/android/manifest.git -b lineage-17.1 local_manifests
repo sync --force-sync -j${JOBS}
elif [ -z $NOSYNC ];
then
cd $BUILDBASE/android/lineage
repo forall -c 'git reset --hard'
repo forall -c 'git clean -fdd'
cd .repo/local_manifests
git pull
cd $BUILDBASE/android/lineage
repo sync --force-sync -j${JOBS}
# update stuff (used for clean too but kinda unnecessary)
cd $BUILDBASE/android/lineage
source build/envsetup.sh
# repopicks
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py -t nvidia-enhancements-q
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py -t icosa-bt-lineage-17.1
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py -t nvidia-shieldtech-q
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py -t nvidia-beyonder-q
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py 300860
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py 287339
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py 302339
${BUILDBASE}/android/lineage/vendor/lineage/build/tools/repopick.py 284553
# bionic intrinsics patch
cd $BUILDBASE/android/lineage/bionic
patch -p1 < $BUILDBASE/android/lineage/.repo/local_manifests/patches/bionic_intrinsics.patch
# beyonder fix patch
cd $BUILDBASE/android/lineage/device/nvidia/foster_tab
patch -p1 < $BUILDBASE/android/lineage/.repo/local_manifests/patches/device_nvidia_foster_tab-beyonder.patch
# mouse patch
cd $BUILDBASE/android/lineage/frameworks/native
patch -p1 < $BUILDBASE/android/lineage/.repo/local_manifests/patches/frameworks_native-mouse.patch
# icosa firmware patch
cd $BUILDBASE/android/lineage/vendor/firmware
git am < $BUILDBASE/android/lineage/.repo/local_manifests/patches/vendor_firmware_icosa.patch
# art hack patch
cd $BUILDBASE/android/lineage/art
patch -p1 < $BUILDBASE/android/lineage/.repo/local_manifests/patches/art-hack.patch
# atv resolution patch
cd $BUILDBASE/android/lineage/device/lineage
patch -p1 < $BUILDBASE/android/lineage/.repo/local_manifests/patches/atv-res.patch
# cpu oc patch
if [ $CPUOC = "y" ];
then
cd $BUILDBASE/android/lineage/kernel/nvidia/linux-4.9/kernel/kernel-4.9
patch -p1 < $CWD/patches/oc-android10.patch
cd $BUILDBASE/android/lineage/device/nvidia/foster
patch -p1 < $CWD/patches/oc_profiles.patch
fi
# joycon patch
if [ $JCPATCH = "y" ];
then
cd $BUILDBASE/android/lineage/hardware/nintendo/joycond
patch -p1 < $CWD/patches/joycond10.patch
fi
# patch to support old TWRP
cd $BUILDBASE/android/lineage/device/nvidia/foster
git revert 0e1c660d -n
fi
# reset back to lineage directory
cd $BUILDBASE/android/lineage
# ccache
export USE_CCACHE=1
export CCACHE_EXEC="/usr/bin/ccache"
export WITHOUT_CHECK_API=true
ccache -M 50G
### Rebuild (clean)
mkdir -p $BUILDBASE/android/lineage/out/target/product/$OUTPUTFILE/vendor/lib/modules
source build/envsetup.sh
# check rom type and assign gapps type and rom type
if [ $FOSTERTYPE = "i" ];
then
TYPE="pico"
OUTPUTFILE="icosa"
lunch lineage_icosa-userdebug
elif [ $FOSTERTYPE = "m" ];
then
TYPE="pico"
OUTPUTFILE="foster_tab"
lunch lineage_foster_tab-userdebug
else
TYPE="tvmini"
OUTPUTFILE="foster"
lunch lineage_foster-userdebug
fi
make -j${JOBS} bacon
## This script copies the build output to the output dir
## so it can be used by hekate
cd ${BUILDBASE}
ZIP_FILE=$(ls -rt ${BUILDBASE}/android/lineage/out/target/product/$OUTPUTFILE/lineage-17.1-*-UNOFFICIAL-$OUTPUTFILE.zip | tail -1)
## Copy to output
echo "Creating switchroot install dir..."
mkdir -p $BUILDBASE/android/output/switchroot/install
echo "Creating switchroot android dir..."
mkdir -p $BUILDBASE/android/output/switchroot/android
echo "Downloading hekate..."
LATEST_HEKATE=$(curl -sL https://github.com/CTCaer/hekate/releases/latest | grep -o '/CTCaer/hekate/releases/download/.*/hekate_ctcaer.*zip')
curl -L -o ./hekate.zip https://github.com/$LATEST_HEKATE
unzip -u ./hekate.zip -d $BUILDBASE/android/output/
echo "Creating bootloader config dir..."
mkdir -p $BUILDBASE/android/output/bootloader/ini
echo "Copying build zip to SD Card..."
cp $ZIP_FILE $BUILDBASE/android/output/
echo "Copying build combined kernel and ramdisk..."
cp $BUILDBASE/android/lineage/out/target/product/$OUTPUTFILE/boot.img $BUILDBASE/android/output/switchroot/install/
echo "Copying build dtb..."
cp $BUILDBASE/android/lineage/out/target/product/$OUTPUTFILE/obj/KERNEL_OBJ/arch/arm64/boot/dts/tegra210-icosa.dtb $BUILDBASE/android/output/switchroot/install/
echo "Downloading twrp..."
curl -L -o $BUILDBASE/android/output/switchroot/install/twrp.img https://github.com/PabloZaiden/switchroot-android-build/raw/master/external/twrp.img
echo "Downloading coreboot.rom..."
# oc coreboot check
if [ $MEMOC == "y" ];
then
curl -L -o $BUILDBASE/android/output/switchroot/android/coreboot.rom https://github.com/PabloZaiden/switchroot-android-build/raw/5591127dc4b9ef3ed1afb0bb677d05108705caa5/external/coreboot-oc.rom
else
curl -L -o $BUILDBASE/android/output/switchroot/android/coreboot.rom https://github.com/PabloZaiden/switchroot-android-build/raw/5591127dc4b9ef3ed1afb0bb677d05108705caa5/external/coreboot.rom
fi
echo "Downloading 00-android.ini..."
curl -L -o $BUILDBASE/android/output/bootloader/ini/00-android.ini https://gitlab.com/ZachyCatGames/shitty-pie-guide/-/raw/master/res/00-android.ini?inline=false
echo "Downloading boot scripts..."
curl -L -o $BUILDBASE/android/output/switchroot/android/common.scr https://gitlab.com/switchroot/bootstack/switch-uboot-scripts/-/jobs/artifacts/master/raw/common.scr?job=build
curl -L -o $BUILDBASE/android/output/switchroot/android/boot.scr https://gitlab.com/switchroot/bootstack/switch-uboot-scripts/-/jobs/artifacts/master/raw/sd.scr?job=build
echo "Downloading Pico Open GApps..."
# get base URL for pico gapps
BASE_GAPPS_URL=$(curl -L https://sourceforge.net/projects/opengapps/rss?path=/arm64 \
| grep -Po "https:\/\/.*10\.0-${TYPE}.*zip\/download" \
| head -n 1 \
| sed "s/\/download//" \
| sed "s/files\///" \
| sed "s/projects/project/" \
| sed "s/sourceforge/downloads\.sourceforge/")
TIMESTAMP=$(echo $(( $(date '+%s%N') / 1000000000)))
FULL_GAPPS_URL=$(echo $BASE_GAPPS_URL"?use_mirror=autoselect&ts="$TIMESTAMP)
curl -L -o $BUILDBASE/android/output/opengapps_${TYPE}.zip $FULL_GAPPS_URL
## Patch zip file to accept any bootloader version
OUTPUT_ZIP_FILE=$(ls -rt ${BUILDBASE}/android/output/lineage-17.1-*-UNOFFICIAL-${OUTPUTFILE}.zip | tail -1)
mkdir -p ./META-INF/com/google/android/
unzip -p $OUTPUT_ZIP_FILE META-INF/com/google/android/updater-script > ./META-INF/com/google/android/updater-script.original
sed -E 's/getprop\(\"ro\.bootloader\"\)/true || getprop\(\"ro\.bootloader\"\)/g' < ./META-INF/com/google/android/updater-script.original > ./META-INF/com/google/android/updater-script
rm ./META-INF/com/google/android/updater-script.original
zip -u $OUTPUT_ZIP_FILE META-INF/com/google/android/updater-script
rm -rf ./META-INF/com/google/android/
# Magisk pre-rooting
if [ $MAGISK = "y" ];
then
cd $BUILDBASE
# get android sdk cmd tools
if [ -z "$ANDROID_SDK_ROOT" ];
then
wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
if [ -d cmdline-tools ];
then
echo "A" | unzip commandlinetools-linux-6858069_latest.zip
else
unzip commandlinetools-linux-6858069_latest.zip
fi
export ANDROID_SDK_ROOT="$BUILDBASE/cmdline-tools"
export PATH="$BUILDBASE/cmdline-tools:$BUILDBASE/cmdline-tools/bin:$PATH"
fi
# get android ndk
if [ ! -d cmdline-tools/ndk ];
then
wget https://dl.google.com/android/repository/android-ndk-r21d-linux-x86_64.zip
unzip android-ndk-r21d-linux-x86_64.zip
mkdir cmdline-tools/ndk/
mkdir cmdline-tools/ndk/magisk
cp android-ndk-r21d/* cmdline-tools/ndk/magisk/
fi
# register sdk licenses
yes | sdkmanager --sdk_root=$ANDROID_SDK_ROOT --licenses
# reset and pull Magisk
if [ -d Magisk ];
then
cd Magisk
git reset --hard
git pull --force
else
git clone https://github.com/topjohnwu/Magisk.git
cd Magisk
fi
if [ -z $VERBOSE ]
then
./build.py -v all
else
./build.py all
fi
# unpack magisk zip and move all required files to x86 folder
cd out
unzip magisk-release.zip
cp common/* x86/
cp $BUILDBASE/android/output/switchroot/install/boot.img x86/
cd x86
# patch and replace boot.img
bash ./boot-patch.sh boot.img
rm $BUILDBASE/android/output/switchroot/install/boot.img
mv new-boot.img $BUILDBASE/android/output/switchroot/install/boot.img
# zip patched boot.img into lineage zip
cd $BUILDBASE/android/output/switchroot/install/
zip -u $OUTPUT_ZIP_FILE boot.img
fi