-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·362 lines (349 loc) · 10.1 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·362 lines (349 loc) · 10.1 KB
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
#!/bin/bash
## This script its the main script that will execute everything in the project ##
# load helper scripts WITHOUT loops
. vars.sh || exit 255
. get_info.sh || exit 255
. logger.sh || exit 255
. create_disk.sh || exit 255
. modify_trusty.sh || exit 255
. boot_debug.sh || exit 255
. boot_no_trusty.sh || exit 255
. boot_trusty.sh || exit 255
. clean_boot_hals.sh || exit 255
. clean_boot_hals_2.sh || exit 255
. create_disk.sh || exit 255
. create_metadata.sh || exit 255
. create_userdata.sh || exit 255
. make_vendor.sh || exit 255
. make_super.sh || exit 255
. mount_alos.sh || exit 255
. move_keymint.sh || exit 255
. move_trusty.sh || exit 255
. sed_keystore.sh || exit 255
. unpack_trusty.sh || exit 255
. update_fstab.sh || exit 255
. update_metadata.sh || exit 255
. update_super_disk.sh || exit 255
. update_userdata.sh || exit 255
. make_system_dlkm.sh || exit 255
. make_system_ext.sh || exit 255
. make_vendor_dlkm.sh || exit 255
. make_product.sh || exit 255
. colors.sh || exit 255
. unpack_alos_files.sh || exit 255
# Help menu
show_help() {
info "---------HELP MENU----------"
info "USAGE: $0 [-p] [-t]"
info_continue "-h" " shows this menu"
info_continue "-l" " will use the logger"
info_continue "-b" " builds the files locally"
info_continue "-t" " boot with trusty"
info_continue '-n' " boots without trusty"
info_continue "-d" " use debug boot"
info_continue "-v" " builds images"
info_continue "-p" " applies paches"
info_continue "-u" " update images"
info "---------------------------"
}
# Title function
title() {
echo ""
info " ▄▄▄▄ ▄▄ ▄▄▄▄▄ ▄▄▄▄▄▄▄ "
error "▄██▀▀██▄ ██ ▀▀ ▀▀ ▄███████▄ █████▀▀▀ "
success "███ ███ ██ ██ ██ ███▄███▄ ██ ████▄ ██ ██ ██ ███▄███▄ ███ ███ ▀████▄ "
info "███▀▀███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███▄▄▄███ ▀████ "
error "███ ███ ██ ▀██▀█ ██ ██ ██ ██▄ ██ ██ ██▄ ▀██▀█ ██ ██ ██ ▀█████▀ ███████▀ "
}
# Init scripts for the first time running it
init_first_time() {
QEMU=$(which qemu-system-aarch64 2>/dev/null)
if [ -z $QEMU ]; then
log_error "QEMU not installed, installing it"
case $MANAGER in
apt)
log_info "Installing qemu via apt"
sudo apt install qemu-system-arm qemu-efi-aarch64
;;
pacman)
log_info "Installing qemu via pacman"
sudo pacman -S qemu-system-aarch64
;;
yum)
log_info "Installing qemu via yum"
sudo yum install qemu
;;
dnf)
log_info "Installing qemu via dnf"
sudo dnf install qemu
;;
zypper)
log_info "Installing qemu via zypper"
# This commands are from the opensuse official page (https://software.opensuse.org/download/package?package=qemu-guest-agent&project=Virtualization)
sudo zypper addrepo https://download.opensuse.org/repositories/Virtualization/openSUSE_Slowroll/Virtualization.repo
sudo zypper refresh
sudo zypper install qemu-guest-agent
;;
snap)
log_error "SNAP package wont work at 100%, please install it from another package manager or download it manually"
;;
flatpak)
log_error "FLATPAK package wont work at 100%, please install it from another package manager or download it manually"
;;
*)
log_error "Unkown package manager"
;;
esac
fi
touch logs/.init_first_time
}
# Log functions
create_logs() {
if [ ! -d logs ]; then
mkdir logs
fi
if [ ! -f logs/script.log ]; then
touch logs/script.log
log_info "Hii, logs are created, enjoy the project!"
fi
}
make_logger() {
if [ "$LOGGER" = "1" ]; then
echo 'log_info() {\necho ""\necho ""\ninfo "$1"\necho "[INFO]: $1" >> logs/script.log\n}\nlog_error() {\necho ""\necho ""\nerror "$1"\necho "[ERROR]: $1" >> logs/script.log\n}\n log_green() {\necho ""\necho ""\nsuccess "$1"\necho "[SUCCESS]: $1" >> logs/script.log\n}' > logger.sh
else
echo 'log_info() {\necho ""\n}\nlog_error() {\necho ""\n}\nlog_success() {\necho ""\n}' > logger.sh
fi
}
# Main functions
use_debug_boot() {
log_info "Booting in debug mode"
if [ ! -f super_disk.img ] || [ ! -f boot_debug.sh ]; then
log_error "Images or script are missing in the project root folder"
exit 255
fi
boot_debug
}
no_trusty() {
log_info "Booting without trusty"
if [ ! -f super_disk.img ] || [ ! -f boot_no_trusty.sh ]; then
log_error "Images or script are missing in the project root folder"
exit 255
fi
boot_without_trusty
}
use_trusty() {
log_info "Booting with trusty"
if [ ! -f super_disk.img ] || [ ! -f boot_trusty.sh ]; then
log_error "Images or script are missing in the project root folder"
exit 255
fi
if [ $DOWNLOAD_PREMAKE = 1 ]; then
unpack_trusty
move_trusty
else
if [ ! -d trusty_source ]; then
read -p "This will download trusty source code, apply patches and build it because you choose no download the premake files, continue?" -n 1
mkdir trusty_source
cd trusty_source
repo init -u https://android.googlesource.com/trusty/manifest -b main --depth=1
repo sync
cd ..
fi
modify_trusty
trusty_source/trusty/vendor/google/aosp/scripts/build.py qemu-generic-arm64-test-debug
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/atf/qemu/debug/bl1.bin .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/atf/qemu/debug/bl2.bin .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/test-runner/external/trusty/bootloader/test-runner/test-runner.bin .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/atf/qemu/debug/fdts/tos_fw_config.bin .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/lk.bin .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/atf/qemu/debug/metadata.img .
cp trusty_source/build_root/build-qemu-generic-arm64-test-debug/atf/qemu/debug/RPMB_DATA .
mv test-runner.bin bl33.bin
mv lk.bin bl32.bin
move_keymint
read -p "Compilation completed, delete source code? [y/n]" ANSWER -n 1
case $ANSWER in
y|Y)
log_info "Deleting trusty source code"
rm -rf trusty_source
;;
n|N)
log_info "Not deleting trusty source code"
;;
*)
log_error "Answer unrecognized, not deleting trusty source code"
;;
esac
fi
boot_with_trusty
}
build_stuff() {
info "--BUILD MENU--"
info_continue "Select the number of the image you want to build"
info_continue "1)" "Disk (needs super)"
info_continue "2)" "Super (needs system, vendor, system_dlkm and vendor_dlkm)"
info_continue "3)" "System (ALOS gsi)"
info_continue "4)" "Vendor"
info_continue "5)" "System_dlkm"
info_continue "6)" "Vendor_dlkm"
info "Once the image finished building you can build other"
info "---------------"
read -n 1 IMAGE_SELECTION
case $IMAGE_SELECTION in
1)
if [ -f super_alos.img ]; then
log_info "Building disk"
create_disk
else
log_error "Super alos not found in the root dir, please build it"
fi
;;
2)
if [ ! -f cuttlefish/system_dlkm.img ] || [ ! -f cuttlefish/vendor_dlkm.img ] || [ ! -f comet/vendor.img ] || [ ! -f alos.img ]; then
log_error "Some files are missing for building super, check for the imgs in cuttlefish/, comet/ and root dir or build them"
else
log_info "Building super"
make_super
fi
;;
3)
log_info "Building system"
make_system
;;
4)
log_info "Building vendor"
make_vendor
;;
5)
log_info "Building system_dlkm"
make_system_dlkm
;;
6)
log_info "Building vendor_dlkm"
make_vendor_dlkm
;;
*)
log_error "Unkown option: $IMAGE_SELECTION, use number from 1-6"
exit 255
;;
esac
read -p "Do you want to build another one? [y/n]" BUILD_ANOTHER
case $BUILD_ANOTHER in
y|Y)
build_stuff
;;
n|N)
echo ""
;;
*)
log_error "Unkown option, assuming no"
;;
esac
}
update_stuff() {
log_info "Opening update menu"
info "--UPDATE MENU--"
info_continue "Select the number of the image you want to update"
info_continue "1)" " Super"
info_continue "2)" " Fstab"
info_continue "3)" " Metadata"
info_continue "4)" " Userdata"
info "Once the image finished building you can build other"
info "---------------"
read -n 1 UPDATE_SELECTION
case $UPDATE_SELECTION in
1)
if [ -f super_alos.img ]; then
log_info "Updating super in disk"
update_super_disk
else
log_error "Super Alos not found in root dir, please build it"
fi
;;
2)
log_info "Building fstab"
update_fstab
;;
3)
log_info "Updating metadata"
update_metadata
;;
4)
log_info "Updating Userdata"
update_userdata
;;
*)
log_error "Unkown option: "$UPDATE_SELECTION", use number from 1-6"
exit 255
;;
esac
read -p "Do you want to build another one? [y/n]" BUILD_ANOTHER
case $BUILD_ANOTHER in
y|Y)
update_stuff
;;
n|N)
echo ""
;;
*)
log_error "Unkown option, assuming no"
;;
esac
}
apply_patches() {
log_info "Applying patches"
clean_boot_hals
clean_boot_hals_2
sed_keystore
}
#########################################################
title
if [ -f logs/init_first_time ]; then
echo ""
else
init_first_time
fi
# Get user options
while getopts "plbtndvuh" OPTION; do
case "$OPTION" in
p) apply_patches
;;
l) DOWNLOAD_PREMAKE=1
;;
b) build_stuff
;;
t) use_trusty
;;
n) no_trusty
;;
d) use_debug_boot
;;
u) update_stuff
;;
l) LOGGER=0
;;
v) DOWNLOAD_PREMAKE=0
;;
h) show_help
;;
*) log_error "$OPTION"; exit 1
;;
esac
done
make_logger
if [ "$LOGGER" = 1 ]; then
if [ $OPTIND -eq 1 ]; then
log_error "No flags provided."
show_help
exit
fi
create_logs
echo "-----------INIT ALOS SCRIPT-----------" >> logs/script.log
date >> logs/script.log
else
if [ $OPTIND -eq 1 ]; then
error "No flags provided."
show_help
exit
fi
fi