├── .gitignore ├── README.md ├── README_CN.md ├── aosp.sh ├── lang.sh └── my_env.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | android 3 | test.sh 4 | t.sh 5 | ROM 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AOSP setup 2 | [中文](./README_CN.md) 3 | Quick start my aosp sync up 4 | ``` 5 | git clone https://github.com/stuartore/aosp-setup.git && cd aosp-setup 6 | ./aosp.sh 7 | ``` 8 | 9 | ### Custom 10 | ``` 11 | ./aosp.sh ${ROM_manifest_url} 12 | 13 | # example 14 | ./aosp.sh https://github.com/xxxxxxx/manifest.git 15 | ``` 16 | ### Mirror 17 | ``` 18 | # set github & aosp mirror for synchonization 19 | ./aosp.sh --mirror 20 | 21 | # keep mirror when sync source 22 | ./aosp.sh -k 23 | ./aosp.sh --keep-mirror 24 | ``` 25 | 26 | ### Auto Build 27 | ``` 28 | ./aosp.sh --auto_build {brand}/{device_code} 29 | 30 | # example 31 | ./aosp.sh --auto_build xiaomi/psyche 32 | ``` 33 | > Debug: Still uer to fix error & mannual handle 34 | 35 | + LineageOS 36 | + ArrowOS 37 | + Pixel Experience 38 | + RisingOS 39 | + Crdroid 40 | + AlphaDroid 41 | + Evolution-X 42 | + Project-Elixir 43 | + Paranoid Android (AOSPA) 44 | + PixysOS 45 | + SuperiorOS 46 | + PixelPlusUI 47 | 48 | #### Get script status 49 | Get running status on Wechat,[`Click me`](https://wxpusher.zjiecode.com/wxuser/?type=1&id=83609#/follow). 50 | ``` 51 | # eg. You need to copy UID on wechat official account 52 | ./aosp.sh --auto_build --with_push UID_xxxxx 53 | ``` 54 | + Thanks to @zjiecode and his `wxpusher` 55 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # AOSP setup 2 | 快速开始AOSP编译 3 | ``` 4 | git clone https://github.com/stuartore/aosp-setup.git && aosp-setup 5 | ./aosp.sh 6 | ``` 7 | > 配置环境并拉取源码 8 | 9 | ### 自定义 10 | ``` 11 | ./aosp.sh ${ROM_manifest_url} 12 | 13 | # 例子 14 | ./aosp.sh https://github.com/xxxxxxx/manifest.git 15 | 16 | # Xiaomi 12X已适配自动编译,VPS服务器编译示例 17 | ./aosp.sh -k https://github.com/xxxxxxx/manifest.git --auto_build 18 | ``` 19 | 20 | ### 镜像 21 | ``` 22 | # 设置github 和(或)aosp同步镜像 23 | ./aosp.sh --mirror 24 | 25 | # 保留原有镜像配置 26 | ./aosp.sh --keep-mirror 27 | ``` 28 | 29 | ### 自动编译 30 | ``` 31 | ./aosp.sh --auto_build 品牌/设备代号 32 | 33 | # 例子 34 | ./aosp.sh --auto_build xiaomi/psyche 35 | ``` 36 | > 实验性:仍然需要用户处理和修复出错 37 | 38 | + LineageOS 39 | + ArrowOS 40 | + Pixel Experience 41 | + Crdroid 42 | + AlphaDroid 43 | + Evolution-X 44 | + Project-Elixir 45 | + Paranoid Android (AOSPA) 46 | + PixysOS 47 | + SuperiorOS 48 | + PixelPlusUI 49 | 50 | #### 运行状态推送 51 | 无人值守,[`点我`](https://wxpusher.zjiecode.com/wxuser/?type=1&id=83609#/follow) 52 | ``` 53 | # 例子, 可能需要在公众号右下方获取UID_xxxx 54 | ./aosp.sh --auto_build --with_push UID_xxxxx 55 | ``` 56 | + 感谢@zjiecode和`wxpusher` 57 | -------------------------------------------------------------------------------- /aosp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source $(dirname $0)/lang.sh 4 | 5 | #1 which rom 6 | #2 branch 7 | AOSP_SETUP_ROOT=$(pwd) 8 | 9 | declare -i env_run_last_return 10 | declare -i env_run_time 11 | 12 | # generated to avoid install deps repeatedly. EDIT env_run_time=3 or higher to skip install deps 13 | env_run_last_return=0 14 | env_run_time=0 15 | aosp_source_dir_working= 16 | aosp_setup_dir_check_ok=0 17 | 18 | # use pkg manager 19 | str_to_arr(){ 20 | # arg 1: string 21 | # arg 2: split symbol 22 | OLD_IFS="$IFS" 23 | IFS="$2" 24 | str_to_arr_result=($1) 25 | IFS="$OLD_IFS" 26 | } 27 | 28 | # use pkg manager 29 | pkg_mgr(){ 30 | pkg_cmd_list=(apt pacman dnf eopkg zypper) 31 | for pkg_cmd in "${pkg_cmd_list[@]}"; do if [[ "$(command -v ${pkg_cmd})" != "" ]]; then pkg_cmd=${pkg_cmd}; break; fi; done 32 | echo $pkg_cmd 33 | } 34 | 35 | ######################### PATCH & FIX UNIT ######################### 36 | patch_when_low_ram(){ 37 | # a patch that fix build on low ram PC less than 25Gb 38 | # at least 25GB recommended 39 | 40 | get_pc_ram_raw=($(free -m | grep ${pc_mem_str})) 41 | get_pc_ram=${get_pc_ram_raw[1]} 42 | declare -i pc_ram 43 | pc_ram=$get_pc_ram 44 | 45 | get_pc_swap_ram_raw=($(free -m | sed -n '2p')) 46 | get_pc_swap_ram=${get_pc_swap_ram_raw[1]} 47 | declare -i pc_sawp_ram=0 48 | pc_sawp_ram=$get_pc_swap_ram 49 | 50 | # need to patch when ram less than 25Gb 51 | declare -i pc_ram_patch 52 | pc_ram_patch=0 53 | if [[ $pc_ram -lt 25600 ]] && [[ $pc_sawp_ram -lt 30000 ]];then 54 | echo -e "\n\033[1;32m=>\033[0m ${auto_add_ram_str_1} ${pc_ram}${auto_add_ram_str_2} $pc_sawp_ram" 55 | pc_ram_patch=1 56 | else 57 | echo -e "\n\033[1;32m=>\033[0m RAM: ${pc_sawp_ram}Mb" 58 | fi 59 | 60 | if [[ $pc_ram_patch == 1 ]];then 61 | # zram swap patch 62 | if [[ ! -f /usr/local/sbin/zram-swap.sh ]];then 63 | git clone https://github.com/foundObjects/zram-swap.git ~/zram-swap 64 | cd ~/zram-swap && sudo ./install.sh 65 | fi 66 | cd $AOSP_SETUP_ROOT 67 | sudo /usr/local/sbin/zram-swap.sh stop 68 | sudo sed -i 's/#_zram_fixedsize="2G"/_zram_fixedsize="64G"/g' /etc/default/zram-swap 69 | sudo /usr/local/sbin/zram-swap.sh start 70 | # remove directory because do not need patch another time 71 | sudo rm -rf ~/zram-swap 72 | fi 73 | 74 | # more patch for cmd.BuiltTool("metalava"). locate line and add java mem when running. 75 | metalava_patch_file=${aosp_source_dir_working}/build/soong/java/droidstubs.go 76 | echo -e "\033[1;32m=>\033[0m ${patch_out_of_mem_str} $metalava_patch_file" 77 | if [[ -f $metalava_patch_file ]];then 78 | declare -i locate_metalava_0 79 | declare -i locate_metalava_1 80 | locate_metalava_0=$(grep 'cmd.BuiltTool("metalava")' -ns $metalava_patch_file | awk -F ':' '{print $1}') 81 | locate_metalava_1=$(grep 'Flag(config.JavacVmFlags).' -ns $metalava_patch_file | awk -F ':' '{print $1}') 82 | declare -i locate_metalava_3=$locate_metalava_1-$locate_metalava_0 83 | # make sure codes in the same method 84 | if [[ $locate_metalava_3 -le 6 ]];then 85 | # the second line declare the mem 86 | if [[ ! $(grep 'Flag("-J-Xmx' -l $metalava_patch_file) ]];then 87 | sed -i '/Flag(config.JavacVmFlags)./a Flag("-J-XmxMEMm")\.' $metalava_patch_file 88 | fi 89 | sed -i 's/Flag("-J-Xmx.*/Flag("-J-Xmx8192m")\./' $metalava_patch_file 90 | fi 91 | echo -e "\n\033[1;32m=>\033[0m ${patch_out_of_mem_info_str}\n" 92 | else 93 | echo -e "\n\033[1;33m=>\033[0m ${try_fix_out_of_mem_str}\n" 94 | fi 95 | } 96 | 97 | ssh_enlong_patch(){ 98 | if [[ $run_on_vm -eq 1 ]];then 99 | sudo sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 30/g' /etc/ssh/sshd_config 100 | sudo sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 86400/g' /etc/ssh/sshd_config 101 | 102 | # try: fix git early eof 103 | git config --global http.postBuffer 1048576000 104 | git config --global core.compression -1 105 | git config --global http.lowSpeedLimit 0 106 | git config --global http.lowSpeedTime 999999 107 | 108 | sudo systemctl restart sshd 109 | fi 110 | } 111 | 112 | git_fix_openssl(){ 113 | # now ubuntu 114 | sudo apt-get update 115 | sudo apt-get install build-essential fakeroot dpkg-dev libcurl4-openssl-dev 116 | sudo apt-get build-dep git 117 | 118 | mkdir ~/git-openssl 119 | cd ~/git-openssl 120 | apt-get source git 121 | cd git-* 122 | sed -i 's/libcurl4-gnutls-dev/libcurl4-openssl-dev/g' debian/control 123 | sed -i '/TEST =test/ d' debian/rules 124 | sudo dpkg-buildpackage -rfakeroot -b 125 | } 126 | 127 | ccache_fix(){ 128 | # Only ccache fix when build failed 129 | # Custom Ccache 130 | custom_ccache_dir= 131 | 132 | if [[ ! $(grep 'Generated ccache config' $HOME/.bashrc) ]];then 133 | default_ccache_dir=/home/$USER/.aosp_ccache 134 | if [[ $custom_ccache_dir == "" ]];then 135 | custom_ccache_dir=$default_ccache_dir 136 | fi 137 | mkdir -p /home/$USER/.ccache 138 | mkdir -p $custom_ccache_dir 139 | sudo mount --bind /home/$USER/.ccache $custom_ccache_dir 140 | sudo chmod -R 777 $custom_ccache_dir 141 | 142 | sed -i '$a \ 143 | # Generated ccache config \ 144 | export USE_CCACHE=1 \ 145 | export CCACHE_EXEC=\/usr\/bin\/ccache \ 146 | export CCACHE_DIR='"$custom_ccache_dir"' \ 147 | ccache -M 50G -F 0' $HOME/.bashrc 148 | fi 149 | } 150 | 151 | lineage_sdk_patch(){ 152 | cd $aosp_source_dir_working 153 | rom_spec_str=$rom_spec_str 154 | 155 | git clone https://github.com/LineageOS/android_packages_resources_devicesettings.git -b lineage-20.0 packages/resources/devicesettings 156 | git clone https://github.com/LineageOS/android_hardware_lineage_interfaces -b lineage-20.0 hardware/lineage/interfaces 157 | git clone https://github.com/LineageOS/android_hardware_lineage_livedisplay.git -b lineage-20.0 hardware/lineage/livedisplay 158 | 159 | # add trust usb & trust usb defaults 160 | rom_build_soong_bp=vendor/${rom_spec_str}/build/soong/Android.bp 161 | 162 | if [[ ! $(grep 'name: "trust_usb_control_defaults"' $rom_build_soong_bp) ]];then 163 | sed -i '1a \ 164 | trust_usb_control { \ 165 | name: "trust_usb_control_defaults", \ 166 | soong_config_variables: { \ 167 | target_trust_usb_control_path: { \ 168 | cppflags: ["-DUSB_CONTROL_PATH=\\"%s\\""], \ 169 | }, \ 170 | target_trust_usb_control_enable: { \ 171 | cppflags: ["-DUSB_CONTROL_ENABLE=\\"%s\\""], \ 172 | }, \ 173 | target_trust_usb_control_disable: { \ 174 | cppflags: ["-DUSB_CONTROL_DISABLE=\\"%s\\""], \ 175 | }, \ 176 | }, \ 177 | }' $rom_build_soong_bp 178 | fi 179 | 180 | if [[ ! $(grep 'name: "trust_usb_control"' $rom_build_soong_bp) ]];then 181 | sed -i '1a \ 182 | \/\/ aosp-setup: lineage sdk patch \ 183 | soong_config_module_type { \ 184 | name: "trust_usb_control", \ 185 | module_type: "cc_defaults", \ 186 | config_namespace: "lineageGlobalVars", \ 187 | value_variables: [ \ 188 | "target_trust_usb_control_path", \ 189 | "target_trust_usb_control_enable", \ 190 | "target_trust_usb_control_disable", \ 191 | ], \ 192 | properties: ["cppflags"], \ 193 | }' $rom_build_soong_bp 194 | fi 195 | 196 | cd $AOSP_SETUP_ROOT 197 | } 198 | 199 | dt_str_patch(){ 200 | # patch device tree string 201 | # 1 - device tree directory 202 | if [[ ! $1 =~ '/' ]];then echo -e "\033[1;33m=>\033[0m ${dt_bringup_name_error_str}";return;fi 203 | 204 | cd $aosp_source_dir_working 205 | 206 | rom_spec_str=$rom_spec_str 207 | 208 | dt_dir=device/$(dirname ${1})/$(basename ${1}) 209 | cd $dt_dir 210 | dt_device_name="$(grep 'PRODUCT_DEVICE' *.mk --max-count=1 | sed 's/[[:space:]]//g' | sed 's/.*:=//g')" 211 | dt_main_mk=$(grep 'PRODUCT_DEVICE :=' *.mk --max-count=1 | sed 's/[[:space:]]//g' | sed 's/:PRODUCT_DEVICE.*//g' | head -1) 212 | dt_old_str=$(echo $dt_main_mk | sed 's/_.*//g') 213 | dt_new_main_mk="${rom_spec_str}_${dt_device_name}.mk" 214 | 215 | if [[ ! $(grep 'revision="android-15' ../../../.repo/manifests/default.xml) ]] && [[ $(pwd) != "psyche" ]] ;then 216 | sed -i 's/'"${dt_old_str}"'/'"${rom_spec_str}"'/g' AndroidProducts.mk 217 | sed -i 's/'"${dt_old_str}"'/'"${rom_spec_str}"'/g' $dt_main_mk 218 | sed -i 's/vendor\/'"${dt_old_str}"'/vendor\/'"${rom_spec_str}"'/g' BoardConfig*.mk 219 | 220 | 221 | if [[ -f $dt_main_mk ]] && [[ ! -f $dt_new_main_mk ]];then 222 | mv $dt_main_mk $dt_new_main_mk 223 | fi 224 | if [[ -f ${dt_old_str}.dependencies ]] && [[ ! -f ${rom_spec_str}.dependencies ]];then 225 | mv ${dt_old_str}.dependencies ${rom_spec_str}.dependencies 226 | fi 227 | 228 | # handle parts. if there are multiple name for device settings, user need to check mannually 229 | if [[ -f ../../../packages/resources/devicesettings/Android.bp ]] && [[ -f parts/Android.bp ]];then 230 | if [[ $(grep settings.resource ../../../packages/resources/devicesettings/Android.bp | grep -c 'name:') -eq 1 ]];then 231 | old_parts_settings_str="$(grep settings.resources parts/Android.bp | sed 's/[[:space:]]//g')" 232 | new_parts_settings_str="$(grep name: ../../../packages/resources/devicesettings/Android.bp | sed 's/[[:space:]]//g' | sed 's/name://g')" 233 | sed -i 's/'"${old_parts_settings_str}"'/'"${new_parts_settings_str}"'/g' parts/Android.bp 234 | fi 235 | fi 236 | fi 237 | 238 | cd $AOSP_SETUP_ROOT 239 | } 240 | 241 | other_fix(){ 242 | # fix Disallowed PATH Tool error 243 | disallowed_tg_file=${aosp_source_dir}/build/sonng/ui/path/config.go 244 | 245 | # build continue after build error 246 | m api-stubs-docs-non-updatable-update-current-api && m framework-bluetooth.stubs.source-update-current-api && m system-api-stubs-docs-non-updatable-update-current-api && m test-api-stubs-docs-non-updatable-update-current-api 247 | 248 | } 249 | 250 | so_deps(){ 251 | so_deps_list=($(readelf -a $1 | grep NEEDED | sed 's/.*Shared\ library://g' | sed 's/\[//g' | sed 's/\]//g' | sed 's/[[:space:]]//g' | sort)) 252 | echo -e "\033[1;32m=>\033[0m Dep \033[4m$(basename $1)\033[0m\n" 253 | for so_dep in "${so_deps_list[@]}" 254 | do 255 | if [[ $(find "$(dirname $1)/.." -iname $so_dep) ]];then 256 | echo -e "\033[1;32m$so_dep\033[0m" 257 | 258 | else 259 | echo -e "$so_dep" 260 | fi 261 | done 262 | echo 263 | } 264 | 265 | setup_patches(){ 266 | # check repo 267 | repo_check 268 | 269 | # low RAM patch less than 25Gb 270 | patch_when_low_ram 271 | } 272 | 273 | ########################## ERROR HANDLING UNIT ############################ 274 | # All error fix function under AOSP Source Dir (aosp_source_dir_working) 275 | 276 | lineage_sdk_dump_error(){ 277 | # fix error for aleady defined Android.bp 278 | #sh -c "$(cat out/error.log | grep 'already defined' | sed 's/Android.bp.*/Android.bp/g' | sed 's/.*hardware/hardware/g' | sed 's/^/rm &/g')" 279 | echo 280 | } 281 | 282 | sysprop_dump_error_handle(){ 283 | # It's maybe not perfect 284 | sysprop_dump_in_log=($(grep = out/error.log | grep -v 'Command:' | grep '\.')) 285 | sysprop_real_dump_list=($(grep = out/error.log | grep -v 'Command:' | grep '\.' | sed 's/=.*//g' | uniq)) 286 | 287 | } 288 | 289 | stubs_api_error_handle(){ 290 | source build/envsetup.sh 291 | m api-stubs-docs-non-updatable-update-current-api && m framework-bluetooth.stubs.source-update-current-api && m system-api-stubs-docs-non-updatable-update-current-api && m test-api-stubs-docs-non-updatable-update-current-api 292 | } 293 | 294 | allow_list_error_handle(){ 295 | # file: build/soong/scripts/check_boot_jars/package_allowed_list.txt 296 | 297 | # base hals 298 | if [[ ! $(grep 'aosp-setup adds' build/soong/scripts/check_boot_jars/package_allowed_list.txt) ]];then 299 | sh -c "$(echo ''' 300 | # aosp-setup adds 301 | com\.oplus\.os 302 | com\.oplus\.os\..* 303 | oplus\.content\.res 304 | oplus\.content\.res\..* 305 | vendor\.lineage\.livedisplay 306 | vendor\.lineage\.livedisplay\..* 307 | vendor\.lineage\.touch 308 | vendor\.lineage\.touch\..* 309 | ink\.kaleidoscope 310 | ink\.kaleidoscope\..* 311 | ''' >> build/soong/scripts/check_boot_jars/package_allowed_list.txt)" 312 | fi 313 | 314 | # some individual hal 315 | allow_hal="$(cat out/error.log | sed 's/build\/soong\/scripts\/check_boot_jars\/package_allowed_list.txt.*//g' | sed 's/.*whose\ package\ name//g' | sed 's/is\ empty.*//g' | sed 's/"//g' | sed 's/[[:space:]]//g')" 316 | 317 | allow_hal_1="$(echo $allow_hal | sed 's/\./\\./g')" 318 | allow_hal_2="$(echo ${allow_hal_1}\\..*)" 319 | echo $allow_hal_1 >> build/soong/scripts/check_boot_jars/package_allowed_list.txt 320 | echo $allow_hal_2 >> build/soong/scripts/check_boot_jars/package_allowed_list.txt 321 | } 322 | 323 | handle_build_error(){ 324 | 325 | #error: found duplicate sysprop assignments: 326 | #persist.sys.sf.native_mode=258 327 | #persist.sys.sf.native_mode=2 328 | 329 | # out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/aligned/framework-minus-apex.jar contains class file ink.kaleidoscope.ParallelSpaceManager$$ExternalSyntheticLambda0, whose package name "ink.kaleidoscope" is empty or not in the allow list build/soong/scripts/check_boot_jars/package_allowed_list.txt of packages allowed on the bootclasspath 330 | 331 | if [[ -f aosh.sh ]] && [[ -f lang.sh ]];then 332 | cd ${aosp_source_dir_working} 333 | fi 334 | local default_error_log=out/error.log 335 | 336 | local failed_cmd=$(grep Command out/error.log | sed 's/Command://g') 337 | if [[ $(grep 'Read-only file system' $default_error_log) ]] && [[ $(grep 'ccache:' $default_error_log) ]];then 338 | local error_type="ccache_readonly_error" 339 | elif [[ $(grep 'duplicate sysprop' $default_error_log) ]];then 340 | local error_type="sysprop_dump_error" 341 | elif [[ $(grep 'update-current-api' $default_error_log) ]];then 342 | local error_type="stubs_update_api_error" 343 | elif [[ $(grep 'package_allowed_list.txt' $default_error_log) ]];then 344 | local error_type="allow_list_error" 345 | else 346 | local error_type="unhandled" 347 | fi 348 | 349 | case $error_type in 350 | "ccache_readonly_error") 351 | # It seems user still need to run command mannually 352 | ccache_fix 353 | sudo mount --bind /home/$USER/.ccache $custom_ccache_dir 354 | ;; 355 | # typeattribute/ expandtypeattribute 356 | "sysprop_dump_error") 357 | sysprop_dump_error_handle 358 | ;; 359 | "stubs_update_api_error") 360 | stubs_api_error_handle 361 | ;; 362 | "allow_list_error") 363 | allow_list_error_handle 364 | ;; 365 | "unhandled") 366 | exit 1 367 | esac 368 | } 369 | 370 | ######################### MIRROR UNIT (OK) ######################### 371 | select_mirror(){ 372 | if [[ $(which git) == "" ]];then echo -e '\nPlease install git';exit 1;fi 373 | sel_github_list=( 374 | 'https://mirror.ghproxy.com/https://github.com' 375 | 'https://githubfast.com' 376 | 'https://github.moeyy.xyz/https://github.com' 377 | 'https://ghproxy.net/https://github.com' 378 | 'https://kkgithub.com' 379 | 'https://gitdl.cn/https://github.com' 380 | 'https://ghp.ci/https://github.com' 381 | 'https://github.store' 382 | 'https://slink.ltd/https://github.com' 383 | 'https://github.site' 384 | 'https://gitclone.com' 385 | ) 386 | sel_aosp_list=('tuna tsinghua' 'ustc' 'beijing bfsu' 'nanfang sci (not)' 'google') 387 | 388 | git_aosp_repo_mirror_reset "github" "aosp" 389 | while (( "$#" )) 390 | do 391 | case "$1" in 392 | "github") 393 | ## handle github.com 394 | echo -e "\n${choose_git_mirror_str}" 395 | select gm in "${sel_github_list[@]}" 396 | do 397 | if [[ $gm != "" ]];then 398 | echo -e "\033[1;32m=>\033[0m ${sel_is_str} $gm" 399 | git config --global url."${gm}".insteadof https://github.com 400 | case $gm in 401 | 'https://kkgithub.com') 402 | git config --global url.https://raw.kkgithub.com.insteadof https://raw.githubusercontent.com 403 | ;; 404 | 'https://gitdl.cn/https://github.com') 405 | git config --global url.https://gitdl.cn/https://raw.githubusercontent.com.insteadof https://raw.githubusercontent.com 406 | ;; 407 | 'https://ghproxy.net/https://github.com') 408 | git config --global url.https://ghproxy.net/https://raw.githubusercontent.com.insteadof https://raw.githubusercontent.com 409 | ;; 410 | 'https://github.store') 411 | git config --global url.https://raw.github.store.insteadof https://raw.githubusercontent.com 412 | ;; 413 | 'https://github.site') 414 | git config --global url.https://raw.github.site.insteadof https://raw.githubusercontent.com 415 | ;; 416 | *) 417 | # create random raw github mirror list 418 | ramdom_raw_github_mirror_list=( 419 | 'https://mirror.ghproxy.com/https://raw.githubusercontent.com' 420 | 'https://fastly.jsdelivr.net/gh' 421 | 'https://github.moeyy.xyz/https://raw.githubusercontent.com' 422 | 'https://ghproxy.net/https://raw.githubusercontent.com' 423 | 'https://raw.github.store' 424 | 'https://github.site' 425 | ) 426 | declare -i raw_github_list_num=${#ramdom_raw_github_mirror_list[@]} 427 | raw_github_gen_i_raw=$(expr $RANDOM % $raw_github_list_num) 428 | # sometimes RANDOM could be null, auto select 0 if this happends 429 | if [[ $raw_github_gen_i_raw == "" ]];then 430 | declare -i raw_github_gen_i=0 431 | else 432 | declare -i raw_github_gen_i=$raw_github_gen_i_raw 433 | fi 434 | ramdom_raw_github_mirror=${ramdom_raw_github_mirror_list[${raw_github_gen_i}]} 435 | git config --global url."${ramdom_raw_github_mirror}".insteadof https://raw.githubusercontent.com 436 | ;; 437 | esac 438 | else 439 | echo -e "\033[1;32m=>\033[0m don't use github mirror" 440 | fi 441 | break 442 | done 443 | ;; 444 | "aosp") 445 | ## handle AOSP 446 | echo -e "\n${choose_aosp_mirror_str}\n" 447 | select aos in "${sel_aosp_list[@]}" 448 | do 449 | case $aos in 450 | 'tuna tsinghua') 451 | aom='https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/' 452 | ;; 453 | 'ustc') 454 | select ustc_pro in "git" "https" "http" 455 | do 456 | aom="${ustc_pro}://mirrors.ustc.edu.cn/aosp/" 457 | break 458 | done 459 | ;; 460 | 'beijing bfsu') 461 | aom='https://mirrors.bfsu.edu.cn/git/AOSP/' 462 | ;; 463 | 'nanfang sci (not)') 464 | aom='https://mirrors.sustech.edu.cn/AOSP/' 465 | ;; 466 | *) 467 | aom='https://android.googlesource.com' 468 | ;; 469 | esac 470 | echo -e "\033[1;32m=>\033[0m ${sel_is_str} $aom" 471 | git config --global url."${aom}".insteadof https://android.googlesource.com 472 | break 473 | done 474 | ;; 475 | esac 476 | shift 477 | done 478 | } 479 | 480 | git_aosp_repo_mirror_reset(){ 481 | 482 | while (( "$#" )); do 483 | case $1 in 484 | "github") 485 | local insteadof_git_list=($(git config --global --list | grep insteadof | grep github | sed 's/insteadof=.*/insteadof/g' | sort)) 486 | for insteadof_git in "${insteadof_git_list[@]}" 487 | do 488 | git config --global --unset ${insteadof_git} 489 | done 490 | ;; 491 | "aosp") 492 | local insteadof_aosp_list=($(git config --global --list | grep insteadof | grep android | sed 's/insteadof=.*/insteadof/g' | sort)) 493 | for insteadof_aosp in "${insteadof_aosp_list[@]}" 494 | do 495 | git config --global --unset ${insteadof_aosp} 496 | done 497 | ;; 498 | esac 499 | shift 500 | done 501 | 502 | # REPO URL 503 | export REPO_URL='https://gerrit.googlesource.com/git-repo' 504 | } 505 | 506 | mirror_unit_main(){ 507 | # for aosp | git mirrors 508 | if [[ $keep_mirror_arg -eq 0 ]];then 509 | echo -e "${use_mirror_str}" 510 | select use_mirror_sel in "Yes" "No" 511 | do 512 | case $use_mirror_sel in 513 | "Yes") 514 | sel_mirror_list=$(echo $sel_mirror_list_str | sort) 515 | eval "select_mirror ${sel_mirror_list[@]}" 516 | export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo' 517 | ;; 518 | "No" | *) 519 | git_aosp_repo_mirror_reset "github" "aosp" 520 | echo -e "\033[1;36m=>\033[0m ${skip_mirror_str}" 521 | ;; 522 | esac 523 | break 524 | done 525 | else 526 | echo -e "\033[1;32m=>\033[0m ${keep_mirror_str}" 527 | fi 528 | } 529 | 530 | ######################### DEPS UNIT ######################### 531 | ubuntu_deps(){ 532 | sudo apt update -y 533 | sudo apt install software-properties-common -y 534 | 535 | lsb_release="$(lsb_release -d | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//')" 536 | 537 | other_pkgs="lsb-core ncurses-dev android-platform-tools-base pngcrush python-all-dev schedtool " 538 | 539 | case $lsb_release in 540 | "Mint 18"* | "Ubuntu 16"*) 541 | other_pkgs+="libesd0-dev" 542 | ;; 543 | "Ubuntu 2"* | "Pop!_OS 2"*) 544 | other_pkgs+="libncurses5 curl python-is-python3" 545 | ;; 546 | "Debian GNU/Linux 10"* | "Debian GNU/Linux 11"*) 547 | other_pkgs+="libncurses5" 548 | ;; 549 | "Deepin 2"*) 550 | # Deepin absent for common: ncurses-dev android-platform-tools-base pngcrush python-all-dev schedtool 551 | # Deepin could find: libncurses-dev android-sdk-platform-tools-common 552 | other_pkgs="libncurses-dev android-sdk-platform-tools-common" 553 | ;; 554 | *) 555 | other_pkgs+="libncurses5" 556 | ;; 557 | esac 558 | 559 | LATEST_MAKE_VERSION="4.3" 560 | 561 | sudo apt install -y adb autoconf automake axel bc bison build-essential \ 562 | ccache clang cmake curl expat fastboot flex g++ \ 563 | g++-multilib gawk gcc gcc-multilib git git-lfs gnupg gperf \ 564 | htop imagemagick lib32ncurses5-dev lib32z1-dev libtinfo5 libc6-dev libcap-dev \ 565 | libexpat1-dev libgmp-dev '^liblz4-.*' '^liblzma.*' libmpc-dev libmpfr-dev libncurses5-dev \ 566 | libsdl1.2-dev libssl-dev libtool libxml2 libxml2-utils libavcodec-dev libavformat-dev '^lzma.*' lzop \ 567 | maven ncftp patch patchelf pkg-config \ 568 | pngquant python2.7 python3 python3-pyelftools python-all-dev re2c squashfs-tools subversion \ 569 | texinfo unzip w3m xsltproc zip zlib1g-dev lzip p7zip p7zip-full \ 570 | libxml-simple-perl libswitch-perl apt-utils rsync zip ${other_pkgs} 571 | 572 | sudo systemctl restart udev 573 | } 574 | 575 | arch_deps(){ 576 | sudo sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf 577 | 578 | if [[ ! $(grep '# aosp-setup add ustc archlinuxcn' /etc/pacman.conf) ]];then 579 | sudo sed -i '$a \ 580 | \ 581 | # aosp-setup add ustc archlinuxcn \ 582 | [archlinuxcn] \ 583 | SigLevel = Optional TrustAll \ 584 | Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch \ 585 | ' /etc/pacman.conf 586 | fi 587 | 588 | if [[ -f /usr/bin/repo ]];then sudo rm -f /usr/bin/repo;fi 589 | if [[ $env_run_time -le 2 ]];then 590 | sudo pacman-key --lsign-key "farseerfc@archlinux.org" 591 | sudo pacman -Sy --noconfirm archlinuxcn-keyring 592 | fi 593 | sudo pacman -Syy --noconfirm --needed git git-lfs multilib-devel fontconfig ttf-droid yay ccache make yay patch pkg-config maven gradle python-pyelftools 594 | packages=(ncurses5-compat-libs lib32-ncurses5-compat-libs aosp-devel xml2 lineageos-devel python-pip python-setuptools p7zip) 595 | yay -Sy --noconfirm --norebuild --noredownload ${packages[@]} 596 | sudo pacman -S --noconfirm --needed android-tools # android-udev 597 | } 598 | 599 | fedora_deps(){ 600 | sudo dnf install -y \ 601 | android-tools autoconf213 bison bzip2 ccache clang curl flex gawk gcc-c++ git git-lfs p7zip glibc-devel glibc-static libstdc++-static libX11-devel make mesa-libGL-devel ncurses-devel openssl patch zlib-devel ncurses-devel.i686 readline-devel.i686 libX11-devel.i686 mesa-libGL-devel.i686 glibc-devel.i686 libstdc++.i686 libXrandr.i686 zip perl-Digest-SHA python2 python3-pyelftools wget lzop openssl openssl-devel java-1.8.0-openjdk-devel ImageMagick schedtool lzip vboot-utils vim ccache libxcrypt-compat libfreetype.so.6 freetype-devel 602 | 603 | # The package libncurses5 is not available, so we need to hack our way by symlinking the required library. 604 | sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5 605 | sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libtinfo.so.5 606 | sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5 607 | sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.5 608 | 609 | sudo udevadm control --reload-rules 610 | } 611 | 612 | opensuse_deps(){ 613 | sudo zypper in mirrorsorcerer 614 | sudo systemctl enable --now mirrorsorcerer 615 | 616 | sudo zypper install android-tools autoconf213 bc bison bzip2 ccache clang curl flex gawk gpg2 gperf gcc-c++ git git-lfs glibc-devel ImageMagick java-11-openjdk java-1_8_0-openjdk java-1_8_0-openjdk-devel liblz4-1 libncurses5 libncurses6 libpopt0 libressl-devel libstdc++6 libX11-6 libxml2-tools libxslt1 libX11-devel libXrandr2 lzip lzop kernel-devel maven make megatools Mesa-libGL1 Mesa-libGL-devel mokutil nano neofetch ncurses5-devel ncurses-devel openssl opi patch perl-Digest-SHA1 python python-rpm-generators python3-pyelftools readline-devel schedtool screenfetch sha3sum squashfs vim wget wireguard-tools xf86-video-intel zip zlib-devel 617 | 618 | # Devel Basis (https://darryldias.me/2020/devel-basis-on-opensuse-sle/) 619 | sudo zypper install -t pattern devel_basis 620 | 621 | # The package libncurses5 is not available, so we need to hack our way by symlinking the required library. 622 | sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5 623 | sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libtinfo.so.5 624 | sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5 625 | sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.5 626 | 627 | # libxcrypt-compat 628 | sudo ln -s /usr/lib64/libcrypt.so.2 /usr/lib64/libcrypt.so.1 629 | 630 | } 631 | 632 | solus_deps(){ 633 | sudo eopkg it -c system.devel 634 | sudo eopkg it openjdk-8-devel curl-devel git gnupg gperf libgcc-32bit libxslt-devel lzop ncurses-32bit-devel ncurses-devel readline-32bit-devel rsync schedtool sdl1-devel squashfs-tools unzip wxwidgets-devel zip zlib-32bit-devel lzip ccache 635 | 636 | sudo usysconf run -f 637 | } 638 | 639 | ######################### BUILD DEVICE(POST ENV) ENV UNIT ##################### 640 | aosp_setup_check(){ 641 | # This function must run before sync to ensure non-English directory not exist for android source 642 | if [[ $1 -eq 1 ]];then clear;return;fi 643 | 644 | # check directory do not have non-English words 645 | aosp_setup_dir_str="$(echo $AOSP_SETUP_ROOT | sed 's/[a-zA-Z]//g' | sed 's/[:doirt:]//g')" 646 | spec_symbol_list=('~' '`' '!' '@' '#' '$' '%' '^' '&' '-' '+' '=' '[' ']' '\' '|' '/' ':' '<' '>' '?') 647 | 648 | for spec_symbol in "${spec_symbol_list[@]}" 649 | do 650 | aosp_setup_dir_str="$(echo ${aosp_setup_dir_str} | sed 's|\'"$spec_symbol"'||g')" 651 | done 652 | if [[ "${aosp_setup_dir_str}" != "" ]];then 653 | sed -i '16s/aosp_setup_dir_check_ok=.*/aosp_setup_dir_check_ok=0/g' $(dirname $0)/${BASH_SOURCE} 654 | echo -e "\033[1;33m=>\033[0m Found non-English direcotory string [\033[36m${aosp_setup_dir_str}\033[0m]\n\033[1;33m=>\033[0m Suggestions: rename it in Eng." 655 | exit 656 | else 657 | sed -i '16s/aosp_setup_dir_check_ok=.*/aosp_setup_dir_check_ok=1/g' $(dirname $0)/${BASH_SOURCE} 658 | fi 659 | 660 | # Install deps for setup configuration 661 | if [[ "$(command -v curl)" == "" ]] || [[ "$(command -v git)" == "" ]];then 662 | case $pkg_cmd in 663 | "apt") 664 | sudo apt-get update -yq && sudo apt-get install curl git -yq 665 | ;; 666 | "pacman") 667 | sudo pacman -Syy && sudo pacman -Sy curl git 668 | ;; 669 | "dnf") 670 | sudo dnf update -y && sudo dnf install -y curl git 671 | ;; 672 | "eopkg") 673 | sudo eopkg update -y && sudo eopkg install -y curl git 674 | ;; 675 | "zypper") 676 | sudo zypper --non-interactive update && sudo zypper install --non-interactive curl git 677 | ;; 678 | esac 679 | fi 680 | 681 | clear 682 | } 683 | 684 | repo_check(){ 685 | ### handle git-repo 686 | ## Decline handle git-repo because scripts do it 687 | 688 | if [[ "$(command -v repo)" == "" ]];then 689 | repo_tg_path=/usr/bin/repo 690 | sudo curl https://storage.googleapis.com/git-repo-downloads/repo -o $repo_tg_path --silent 691 | sudo chown ${USER}:${USER} $repo_tg_path || chown ${USER}:${USER} $repo_tg_path 692 | sudo chmod a+x $repo_tg_path || chmod a+x $repo_tg_path 693 | sudo chmod 0755 $repo_tg_path || chmod 0755 $repo_tg_path 694 | echo -e "\033[1;32m=>\033[0m ${repo_added_str}" 695 | fi 696 | 697 | touch $HOME/.bashrc 698 | if [[ ! $(grep '# android sync-helper' $HOME/.bashrc) ]];then 699 | cat <> $HOME/.bashrc 700 | # android sync-helper 701 | export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo' 702 | readonly REPO_URL 703 | BASHEOF 704 | fi 705 | 706 | ### handle repo bin path 707 | touch $HOME/.profile 708 | if [[ ! $(grep '# android sync-helper' $HOME/.profile) ]];then 709 | cat <> $HOME/.profile 710 | # android sync-helper 711 | if [ -d "$HOME/bin" ] ; then 712 | PATH="$HOME/bin:$PATH" 713 | fi 714 | PROFILEEOF 715 | fi 716 | 717 | ### handle disconnect ssh issue 718 | # sudo sed -i 's/^export TMOUT=.*/export TMOUT=0/' /etc/profile && sudo sed -i "/#ClientAliveInterval/a\ClientAliveInterval 60" /etc/ssh/sshd_config && sudo sed -i "/#ClientAliveInterval/d" /etc/ssh/sshd_config && sudo sed -i '/ClientAliveCountMax/ s/^#//' /etc/ssh/sshd_config &&sudo /bin/systemctl restart sshd.service 719 | } 720 | 721 | git_config_user_info(){ 722 | # git config 723 | # 1 - user.name 724 | # 2 - user.email 725 | 726 | if [[ $(git config user.name) != "" ]] && [[ $(git config user.email) != "" ]];then 727 | return 728 | else 729 | echo -e "\n==> Config git " 730 | fi 731 | 732 | # with arg 733 | if [[ $1 != "" ]];then 734 | git config --global user.name "$1" 735 | else 736 | read -p 'Your name: ' git_name 737 | git config --global user.name "${git_name}" 738 | fi 739 | 740 | if [[ $2 != "" ]] && [[ $2 =~ "@" ]];then 741 | git config --global user.email "$2" 742 | else 743 | read -p 'Your email: ' git_email 744 | git config --global user.email "${git_email}" 745 | fi 746 | } 747 | 748 | setup_build_deps(){ 749 | # lineageos: bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev 750 | # Ubuntu versions older than 20.04 (focal), libwxgtk3.0-dev 751 | # Ubuntu versions older than 16.04 (xenial), libwxgtk2.8-dev 752 | 753 | case $pkg_cmd in 754 | "apt") 755 | ubuntu_deps 756 | ;; 757 | "pacman") 758 | arch_deps 759 | ;; 760 | "dnf") 761 | fedora_deps 762 | ;; 763 | "eopkg") 764 | solus_deps 765 | ;; 766 | "zypper") 767 | opensuse_deps 768 | ;; 769 | esac 770 | 771 | check_machine_type 772 | cd $AOSP_SETUP_ROOT 773 | } 774 | 775 | check_machine_type(){ 776 | if [[ $run_on_vm -eq 0 ]];then 777 | on_physical_machine 778 | else 779 | on_cloud_vm_machine 780 | fi 781 | } 782 | 783 | on_physical_machine(){ 784 | # This function is mainly for setup adb tools* on physical machine 785 | 786 | # skip setup adb tools if run on vm 787 | if [[ $run_on_vm -eq 1 ]];then return;fi 788 | 789 | # adb path 790 | if [[ $(grep 'add Android SDK platform' -ns $HOME/.bashrc) == "" ]];then 791 | sed -i '$a \ 792 | # add Android SDK platform tools to path \ 793 | if [ -d "$HOME/platform-tools" ] ; then \ 794 | PATH="$HOME/platform-tools:$PATH" \ 795 | fi' $HOME/.bashrc 796 | fi 797 | 798 | # adb udev rules 799 | if [[ ! -f /etc/udev/rules.d/51-android.rules ]];then 800 | sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/main/51-android.rules 801 | fi 802 | sudo chmod 644 /etc/udev/rules.d/51-android.rules 803 | sudo chown root /etc/udev/rules.d/51-android.rules 804 | } 805 | 806 | on_cloud_vm_machine(){ 807 | # skip setup adb tools if run on vm 808 | if [[ $run_on_vm -eq 0 ]];then return;fi 809 | 810 | # ssh 811 | ssh_enlong_patch 812 | 813 | # check ssh-key 814 | if [[ ! -f /home/${USER}/.ssh/id_ed25519.pub ]];then 815 | echo 'n' | ssh-keygen -t ed25519 -f /home/${USER}/.ssh/id_ed25519 -N '' -q -C "${USER}@VM-${USER}" 816 | fi 817 | sudo chown -R ${USER}:${USER} /home/${USER}/.ssh 818 | sudo chmod -R 700 /home/${USER}/.ssh 819 | 820 | # add login info for profile 821 | touch /home/${USER}/.profile 822 | if [[ ! $(grep '>>> Your-key' /home/${USER}/.profile) ]];then 823 | cat>>/home/${USER}/.profile<>> Your-key" 825 | cat /home/${USER}/.ssh/id_ed25519.pub 826 | BASHINFO 827 | fi 828 | } 829 | 830 | env_install_mode(){ 831 | # config install android build dependencies 832 | if [[ $only_env_mode -eq 1 ]];then 833 | echo "OnlyEnv" 834 | elif [[ $env_run_time -lt 3 ]] || [[ $env_run_last_return -gt 0 ]];then 835 | env_run_time+=1 836 | sed -i '14s/env_run_time=./env_run_time='"${env_run_time}"'/g' $(dirname $0)/${BASH_SOURCE} 837 | echo "Need" 838 | else 839 | echo "NoNeed" 840 | fi 841 | } 842 | 843 | android_env_setup(){ 844 | # setup(install) build deps 845 | mirror_unit_main 846 | git_config_user_info "${custom_git_username}" "${custom_git_email}" 847 | case $1 in 848 | "Need" | "OnlyEnv") 849 | setup_build_deps && env_run_return=$? && sed -i '13s/env_run_last_return=./env_run_last_return='"${env_run_return}"'/g' $(dirname $0)/${BASH_SOURCE} 850 | esac 851 | setup_patches 852 | if [[ $1 == "OnlyEnv" ]];then exit 0;fi 853 | } 854 | 855 | ######################### PRE SYNC & SYNC UNIT ######################### 856 | rom_manifest_config(){ 857 | if [[ $1 != "" ]];then 858 | if [[ $1 =~ "manifest" ]] || [[ $1 =~ "android" ]] && [[ ! $1 =~ "device" ]] && [[ ! $1 =~ "vendor" ]] && [[ ! $1 =~ "kernel" ]];then 859 | ROM_MANIFEST=${aosp_manifest_url} 860 | fi 861 | else 862 | 863 | #echo -e "\n${sel_rom_source_str}" 864 | rom_sources=("LineageOS" "ArrowOS" "Pixel Experience" "RisingOS-Revived" "Crdroid" "AlphaDroid" "Evolution-X" "Project-Elixir" "Paranoid Android (AOSPA)" "PixysOS" "SuperiorOS" "PixelPlusUI") 865 | select aosp_source in "${rom_sources[@]}" 866 | do 867 | case $aosp_source in 868 | "LineageOS") 869 | ROM_MANIFEST='https://github.com/LineageOS/android.git' 870 | ;; 871 | "ArrowOS") 872 | ROM_MANIFEST='https://github.com/ArrowOS/android_manifest.git' 873 | ;; 874 | "Pixel Experience") 875 | ROM_MANIFEST='https://github.com/PixelExperience/manifest.git' 876 | ;; 877 | "RisingOS-Revived") 878 | ROM_MANIFEST='https://github.com/RisingOS-Revived/android.git' 879 | ;; 880 | "Crdroid") 881 | ROM_MANIFEST='https://github.com/crdroidandroid/android.git' 882 | ;; 883 | "AlphaDroid") 884 | ROM_MANIFEST='https://github.com/AlphaDroid-Project/manifest.git' 885 | ;; 886 | "Evolution-X") 887 | ROM_MANIFEST='https://github.com/Evolution-X/manifest.git' 888 | ;; 889 | "Project-Elixir") 890 | ROM_MANIFEST='https://github.com/Project-Elixir/manifest.git' 891 | ;; 892 | "Paranoid Android (AOSPA)") 893 | ROM_MANIFEST='https://github.com/AOSPA/manifest.git' 894 | ;; 895 | "PixysOS") 896 | ROM_MANIFEST='https://github.com/PixysOS/manifest.git' 897 | ;; 898 | "SuperiorOS") 899 | ROM_MANIFEST='https://github.com/SuperiorOS/manifest.git' 900 | ;; 901 | "PixelPlusUI") 902 | ROM_MANIFEST='https://github.com/PixelPlusUI/manifest.git' 903 | ;; 904 | esac 905 | break 906 | done 907 | fi 908 | echo ${ROM_MANIFEST} 909 | } 910 | 911 | repo_sync_fail_handle(){ 912 | # 1 - failed repo directory list 913 | 914 | if [[ ! -f build/envsetup.sh ]];then 915 | if [[ $aosp_source_dir != "" ]];then 916 | aosp_source_dir_working=$aosp_source_dir 917 | fi 918 | if [[ ${aosp_source_dir_working} != "" ]];then 919 | if [[ ! -d .repo ]] && [[ -d $aosp_source_dir_working ]];then 920 | cd $aosp_source_dir_working 921 | fi 922 | else 923 | return 1 924 | fi 925 | fi 926 | 927 | if [[ ${1} == "" ]];then 928 | echo -e "\033[1;32m=>\033[0m ${repo_failed_usr_str}" 929 | echo " ${repo_failed_usr_eg_str}" 930 | read -p '=>' repo_fail_str 931 | else 932 | repo_fail_str="" 933 | while [[ ${1} =~ '/' ]] 934 | do 935 | # do not pass a dangerous direcotory 936 | if [[ ${1:0:1} == '/' ]];then continue;fi 937 | repo_fail_str="${repo_fail_str} ${1}" 938 | shift 939 | done 940 | fi 941 | 942 | declare -i repo_fail_num=0 943 | while [[ repo_fail_num -lt 4 ]] 944 | do 945 | let repo_fail_num++ 946 | 947 | echo -e "\033[1;32m=>\033[0m ${repo_failed_usr_str}" 948 | echo " ${repo_failed_usr_eg_str}" 949 | read -p '=>' repo_fail_str 950 | 951 | repo_fail_list=($(echo ${repo_fail_str} | sort)) 952 | 953 | # handle by log 954 | #declare -i repo_line_a=$(grep -n repos: t.log | awk -F ':' '{print $1}') && let repo_line_a++ 955 | #declare -i repo_line_b=$(grep -n 'Try re-running' t.log | awk -F ':' '{print $1}') && let repo_line_b-- 956 | #repo_fail_list=($(sed -n ''"${repo_line_a}"','"${repo_line_b}"'p' t.log | sort)) 957 | 958 | # recheck in aosp source directory - because remove is a dangerous command 959 | if [[ ! -d build ]] || [[ ! -d bootable ]];then return 0;fi 960 | 961 | for repo_fail in "${repo_fail_list[@]}" 962 | do 963 | eval "$(grep "${repo_fail}" .repo/manifest* -r | sed 's/ /\n/g' | grep name | grep -v '/')" 964 | if [[ -d .repo/project-objects/${name}.git ]];then 965 | rm -rf .repo/project-objects/${name}.git 966 | else 967 | repo_fail_in_po_list=($(find .repo/project-objects/ -maxdepth 2 -iname "*$(echo ${repo_fail} | sed 's/\//_/g')*")) 968 | if [[ ! ${#repo_fail_in_po_list[@]} -eq 0 ]];then 969 | echo "rm -rf ${repo_fail_in_po_list[@]}" 970 | fi 971 | fi 972 | rm -rf .repo/projects/${repo_fail}.git 973 | rm -rf ${repo_fail} 974 | done 975 | 976 | return 977 | 978 | # synchronize again 979 | # don't use --force-remove-dirty --prune 980 | repo sync -c --no-repo-verify --no-clone-bundle --optimized-fetch --prune -j$(nproc --all) && break 981 | repo_fail_str="" 982 | done 983 | } 984 | 985 | handle_sync(){ 986 | # aosp source 987 | str_to_arr $1 '/' 988 | declare -i url_all_num 989 | url_all_num=${#str_to_arr_result[@]} 990 | os_str_num=url_all_num-2 991 | manifest_str_num=url_all_num-1 992 | rom_str=${str_to_arr_result[${os_str_num}]} 993 | manifest_str="$(echo ${str_to_arr_result[${manifest_str_num}]} | sed 's/.git$//g')" 994 | 995 | echo -e "\n\033[1;4;32m---------- ${rom_info_str} ------------\033[0m" 996 | echo -e "\033[1;33mROM\033[0m: $rom_str" 997 | echo -e "\033[1;33mmanifest\033[0m: $manifest_str" 998 | echo -e "\033[1;4;32m-----------------------------\033[0m" 999 | 1000 | aosp_source_dir=android/${rom_str} 1001 | mkdir -p $aosp_source_dir 1002 | sed -i '15s|aosp_source_dir_working=.*|aosp_source_dir_working='"${aosp_source_dir}"'|g' $(dirname $0)/${BASH_SOURCE} 1003 | 1004 | custom_json="$(dirname $0)/${rom_str}.json" 1005 | if [[ ! -f $custom_json ]];then 1006 | curl https://api.github.com/repos/${rom_str}/${manifest_str}/branches -o $custom_json 1007 | fi 1008 | 1009 | if [[ $2 != "" ]];then 1010 | custom_branch=$2 1011 | else 1012 | if [[ $(echo $rom_str | tr A-Z a-z) == "lineageos" ]];then 1013 | custom_branches=($(cat $custom_json | grep name | sed 's/"name"://g' | sed 's/"//g' | sed 's/,//g' | sed 's/[[:space:]]//g' | grep "lineage") lineage-19.1 lineage-20.0 lineage-21.0 lineage-22.0) 1014 | else 1015 | custom_branches=($(cat $custom_json | grep name | sed 's/"name"://g' | sed 's/"//g' | sed 's/,//g' | sed 's/[[:space:]]//g')) 1016 | fi 1017 | 1018 | if [[ ${#custom_branches[@]} -eq 1 ]];then 1019 | custom_branch=${custom_branches[0]} 1020 | else 1021 | echo -e "\n${rom_branch_str}" 1022 | select custom_branch_sel in "${custom_branches[@]}" 1023 | do 1024 | custom_branch=$custom_branch_sel 1025 | break 1026 | done 1027 | fi 1028 | fi 1029 | 1030 | # source bashrc everytime sync source 1031 | source $HOME/.bashrc 1032 | 1033 | cd $aosp_source_dir 1034 | echo -e "\n\033[1;32m=>\033[0m ${enter_to_sync_str}\033[1;3;34m$(pwd)\033[0m" 1035 | 1036 | if [[ -d .repo/project-objects ]];then 1037 | repo_init_need=0 1038 | else 1039 | if [[ -d .repo ]];then 1040 | declare -i repo_init_dir_size 1041 | repo_init_dir_raw=$(du -sm .repo | sed 's/[[:space:]]*.repo//g') 1042 | repo_init_dir_size=$repo_init_dir_raw 1043 | if [[ $repo_init_dir_size -lt 4 ]];then 1044 | rm -rf .repo 1045 | export REPO_INIT_NEED=1 1046 | else 1047 | export REPO_INIT_NEED=0 1048 | fi 1049 | else 1050 | export REPO_INIT_NEED=1 1051 | fi 1052 | fi 1053 | 1054 | if [[ $REPO_INIT_NEED -eq 1 ]];then yes | repo init --depth=1 -u https://github.com/${rom_str}/${manifest_str} -b $custom_branch --git-lfs;fi 1055 | 1056 | # update repo 1057 | declare -i repo_launcher_main_version=$(grep 'VERSION =' .repo/repo/repo -w | sed 's/[[:space:]]//g' | sed 's/VERSION=//g' | sed 's/(//g' | sed 's/)//g' | sed 's/,.*//g') 1058 | declare -i repo_launcher_sub_version=$(grep 'VERSION =' .repo/repo/repo -w | sed 's/[[:space:]]//g' | sed 's/VERSION=//g' | sed 's/(//g' | sed 's/)//g' | sed 's/.*,//g') 1059 | declare -i repo_main_version=$(grep 'VERSION =' $(which repo) -w | sed 's/[[:space:]]//g' | sed 's/VERSION=//g' | sed 's/(//g' | sed 's/)//g' | sed 's/,.*//g') 1060 | declare -i repo_sub_version=$(grep 'VERSION =' $(which repo) -w | sed 's/[[:space:]]//g' | sed 's/VERSION=//g' | sed 's/(//g' | sed 's/)//g' | sed 's/.*,//g') 1061 | if [[ $repo_launcher_main_version -gt $repo_main_version ]];then 1062 | sudo rm -f $(which repo) 1063 | sudo cp -f .repo/repo/repo /usr/bin/repo 1064 | sudo chmod a+x /usr/bin/repo 1065 | elif [[ $repo_launcher_main_version -eq $repo_main_version ]];then 1066 | if [[ $repo_launcher_sub_version -gt $repo_sub_version ]];then 1067 | sudo rm -f $(which repo) 1068 | sudo cp -f .repo/repo/repo /usr/bin/repo 1069 | sudo chmod a+x /usr/bin/repo 1070 | fi 1071 | fi 1072 | 1073 | # repo sync by default & handle sync when failed 1074 | if [[ $skip_aosp_sync == 1 ]] && [[ $env_run_time -ge 3 ]] && [[ -d out/target/product ]];then 1075 | echo -e "\033[1;32m=>\033[0m ${skip_aosp_sync_str1} \033[1;33m${rom_str}\033[0m ${skip_aosp_sync_str2}" 1076 | else 1077 | repo sync -c --no-repo-verify --no-clone-bundle --optimized-fetch --prune -j$(nproc --all) || repo_sync_fail_handle 1078 | fi 1079 | 1080 | if [[ $? -eq 0 ]] && [[ -f build/envsetup.sh ]];then 1081 | export rom_spec_str="$(basename "$(dirname $(find vendor -maxdepth 3 -type d -name '*config' -exec sh -c 'test -e "{}/common.mk" -o -e "{}/version.mk"' \; -print))")" 1082 | case $rom_spec_str in 1083 | "rising") 1084 | rom_spec_str="lineage" 1085 | ;; 1086 | esac 1087 | cd $AOSP_SETUP_ROOT 1088 | return 0 1089 | else 1090 | cd $AOSP_SETUP_ROOT 1091 | return 1 1092 | fi 1093 | } 1094 | 1095 | ################# POST TASK UNIT ################# 1096 | 1097 | track_info_for_build(){ 1098 | if [[ ! $(grep '# aosp-setup: track' $HOME/.profile) ]];then 1099 | cat>>$HOME/.profile< Process inactive" 1109 | fi 1110 | PROFILEINFO 1111 | fi 1112 | } 1113 | 1114 | # Prepare sources 1115 | git_check_dir(){ 1116 | if [[ ! -d $3 ]];then 1117 | mkdir -p $(dirname $3) 1118 | git clone --depth=1 $1 -b $2 $3 1119 | else 1120 | echo -e "\033[1;32m=>\033[0m Found $3" 1121 | fi 1122 | } 1123 | 1124 | custom_deps(){ 1125 | # 1 - brand/device 1126 | # 2 - device deps org from 1127 | local build_brand="$(dirname $1)" 1128 | local build_device="$(basename $1)" 1129 | 1130 | if [[ ! $2 == "" ]];then 1131 | rom_org=$2 1132 | else 1133 | local rom_org="$(echo ${rom_str} | tr A-Z a-z)" 1134 | fi 1135 | 1136 | case $rom_org in 1137 | lineageos | crdroidandroid | aospa) 1138 | custom_rom_org="${rom_org}" 1139 | ;; 1140 | arrowos | pixelexperience | evolution-x | pixysos | superioros | pixelplusui) 1141 | custom_rom_org="${rom_org}-devices" 1142 | ;; 1143 | risingtechoss) 1144 | custom_rom_org='risingoss-devices' 1145 | ;; 1146 | alphadroid-project) 1147 | custom_rom_org='alphadroid-devices' 1148 | ;; 1149 | project-elixir) 1150 | custom_rom_org='projectelixir-devices' 1151 | ;; 1152 | *) 1153 | custom_rom_org="pixelexperience-devices" 1154 | ;; 1155 | esac 1156 | 1157 | cd $aosp_source_dir_working 1158 | custom_deps_tmp_dir=aosp-setup_tmp 1159 | mkdir -p $custom_deps_tmp_dir 1160 | 1161 | # device 1162 | if [[ ! -d device/${build_brand}/${build_device} ]];then 1163 | local device_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${build_device}.json 1164 | if [[ ! -f $device_search_json ]];then 1165 | curl https://api.github.com/search/repositories?q=${build_brand}+${build_device}+user:${custom_rom_org} -o $device_search_json 1166 | fi 1167 | device_clone_url=$(grep device_${build_brand}_${build_device} $device_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g') 1168 | # device - if no device, then select pixelexperience-devices 1169 | if [[ $device_clone_url == "" ]];then 1170 | custom_rom_org=pixelexperience-devices 1171 | local device_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${build_device}.json 1172 | if [[ ! -f $device_search_json ]];then 1173 | curl https://api.github.com/search/repositories?q=${build_brand}+${build_device}+user:${custom_rom_org} -o $device_search_json 1174 | fi 1175 | device_clone_url=$(grep device_${build_brand}_${build_device} $device_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g') 1176 | fi 1177 | 1178 | echo "device/${build_brand}/${build_device}: $device_clone_url" 1179 | if [[ ! -d device/${build_brand}/${build_device} ]];then 1180 | git clone --depth=1 $device_clone_url device/${build_brand}/${build_device} 1181 | fi 1182 | fi 1183 | 1184 | device_common_name="$(grep device/${build_brand} device/${build_brand}/${build_device}/*.mk | grep common -m 1 | grep '.mk' | sed 's/device\/'"${build_brand}"'\/'"${build_device}"'\///g' | sed 's/.*device\/'"${build_brand}"'\///g' | sed 's/\/.*//g')" 1185 | if [[ $device_common_name == "" ]];then 1186 | declare -i device_use_common=0 1187 | else 1188 | declare -i device_use_common=1 1189 | if [[ ! -d device/${build_brand}/${device_common_name} ]];then 1190 | local device_common_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${device_common_name}.json 1191 | if [[ ! -f $device_common_search_json ]];then 1192 | curl https://api.github.com/search/repositories?q=device+${build_brand}+${device_common_name}+user:${custom_rom_org} -o $device_common_search_json 1193 | fi 1194 | device_common_clone_url="$(grep device_${build_brand}_${device_common_name} $device_common_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1195 | echo "device/${build_brand}/${device_common_name}: $device_common_clone_url" 1196 | if [[ ! -d device/${build_brand}/${device_common_name} ]];then 1197 | git clone --depth=1 $device_common_clone_url device/${build_brand}/${device_common_name} 1198 | fi 1199 | fi 1200 | fi 1201 | 1202 | 1203 | # kernel 1204 | local kernel_path=$(grep "TARGET_KERNEL_SOURCE" device/${build_brand} -rnsw -m 1 | grep -v '#' | head -1 | sed 's/[[:space:]]//g' | sed 's/.*:=//g') 1205 | local kernel_name="$(basename $kernel_path)" 1206 | if [[ ! -d kernel/${build_brand}/${kernel_name} ]];then 1207 | if [[ ${kernel_name} == ${build_device} ]];then 1208 | # use same kernel whose name the same with device name 1209 | # default kernel 1210 | local kernel_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${build_device}_kernel.json 1211 | if [[ ! -f $kernel_search_json ]];then 1212 | curl https://api.github.com/search/repositories?q=kernel_${build_brand}_${build_device}+user:${custom_rom_org} -o $kernel_search_json 1213 | fi 1214 | kernel_clone_url="$(grep kernel_${build_brand}_${build_device} $kernel_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1215 | echo "kernel/${build_brand}/${build_device}: $kernel_clone_url" 1216 | git clone --depth=1 $kernel_clone_url kernel/${build_brand}/${build_device} 1217 | else 1218 | # common kernel 1219 | local kernel_common_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${build_device}_kernel_common.json 1220 | if [[ ! -f $kernel_common_search_json ]];then 1221 | curl https://api.github.com/search/repositories?q=kernel_${build_brand}_${kernel_name}+user:${custom_rom_org} -o $kernel_common_search_json 1222 | fi 1223 | kernel_common_clone_url="$(grep kernel_${build_brand}_${kernel_name} $kernel_common_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1224 | echo "kernel/${build_brand}/${kernel_name}: $kernel_common_clone_url" 1225 | git clone --depth=1 $kernel_common_clone_url kernel/${build_brand}/${kernel_name} 1226 | fi 1227 | fi 1228 | 1229 | # vendor 1230 | if [[ ! -d vendor/${build_brand}/${build_device} ]];then 1231 | case $custom_rom_org in 1232 | pixelexperience-devices) 1233 | vendor_base_url="https://gitlab.pixelexperience.org/android/vendor-blobs/" 1234 | vendor_clone_url="https://gitlab.pixelexperience.org/android/vendor-blobs/vendor/${build_brand}/${build_device}.git" 1235 | echo "vendor/${build_brand}/${build_device}: $vendor_clone_url" 1236 | git clone --depth=1 $vendor_clone_url vendor/${build_brand}/${build_device} 1237 | 1238 | if [[ $device_use_common -eq 1 ]];then 1239 | vendor_common_clone_url="https://gitlab.pixelexperience.org/android/vendor-blobs/vendor_${build_brand}_${device_common_name}.git" 1240 | echo "vendor/${build_brand}/${device_common_name}: $vendor_common_clone_url" 1241 | git clone --depth=1 $vendor_common_clone_url vendor/${build_brand}/${device_common_name} 1242 | fi 1243 | ;; 1244 | *) 1245 | local vendor_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${build_device}_vendor.json 1246 | if [[ ! -f $vendor_search_json ]];then 1247 | curl https://api.github.com/search/repositories?q=vendor_${build_brand}_${build_device}+user:${custom_rom_org} -o $vendor_search_json 1248 | fi 1249 | vendor_clone_url="$(grep vendor_${build_brand}_${build_device} $vendor_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1250 | if [[ ! -d vendor/${build_brand}/${build_device} ]] && [[ ! -d vendor/${build_brand}/${device_common_name} ]];then 1251 | if [[ $vendor_clone_url == "" ]];then 1252 | echo "NO vendor. Please config: --device-org unknown" 1253 | exit 1 1254 | else 1255 | echo "vendor/${build_brand}/${device_common_name}: $vendor_clone_url" 1256 | git clone --depth=1 $vendor_clone_url vendor/${build_brand}/${build_device} 1257 | 1258 | local vendor_common_search_json=$custom_deps_tmp_dir/${custom_rom_org}_${build_brand}_${device_common_name}_vendor.json 1259 | if [[ ! -f $vendor_common_search_json ]];then 1260 | curl https://api.github.com/search/repositories?q=vendor_${build_brand}_${device_common_name}+user:${custom_rom_org} -o $vendor_common_search_json 1261 | fi 1262 | if [[ $device_use_common -eq 1 ]];then 1263 | vendor_common_clone_url="$(grep vendor_${build_brand}_${device_common_name} $kernel_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1264 | echo "vendor/${build_brand}/${device_common_name}: $vendor_common_clone_url" 1265 | git clone --depth=1 $vendor_common_clone_url vendor/${build_brand}/${device_common_name} 1266 | fi 1267 | fi 1268 | fi 1269 | ;; 1270 | esac 1271 | fi 1272 | 1273 | # firmware 1274 | # hardware 1275 | if [[ ! -d hardware/${build_brand} ]];then 1276 | local hardware_search_json=$custom_deps_tmp_dir/$(echo ${custom_rom_org} | sed 's/-devices//g')_${build_brand}_${build_device}_hardware.json 1277 | if [[ ! -f $hardware_search_json ]];then 1278 | curl https://api.github.com/search/repositories?q=hardware_${build_brand}+user:$(echo ${custom_rom_org} | sed 's/-devices//g') -o $hardware_search_json 1279 | fi 1280 | hardware_clone_url="$(grep hardware_${build_brand} $hardware_search_json | grep "clone_url" -m 1 | head -1 | sed 's/[[:space:]]//g' | sed 's/"//g' | sed 's/,//g' | sed 's/.*clone_url://g')" 1281 | echo "hardware/${build_brand}: $hardware_clone_url" 1282 | git clone --depth=1 $hardware_clone_url hardware/${build_brand} 1283 | fi 1284 | 1285 | # Other 1286 | 1287 | # Remove json tmp dir if device/vendor/kernel exists 1288 | if [[ -d device/${build_brand}/${build_device} ]] && [[ -d kernel/${build_brand}/${kernel_name} ]] && [[ -d vendor/${build_brand}/${build_device} ]] && [[ -d hardware/${build_brand} ]];then 1289 | rm -rf $custom_deps_tmp_dir 1290 | fi 1291 | 1292 | cd $AOSP_SETUP_ROOT 1293 | } 1294 | 1295 | psyche_deps(){ 1296 | if [[ $aosp_source_dir != "" ]];then 1297 | aosp_source_dir_working=$aosp_source_dir 1298 | fi 1299 | 1300 | if [[ ${aosp_source_dir_working} != "" ]];then 1301 | cd ${aosp_source_dir_working} 1302 | mkdir -p device/xiaomi vendor/xiaomi kernel/xiaomi 1303 | if [[ $(grep 'revision="android-15' .repo/manifests/default.xml) ]];then 1304 | dt_branch='fifteen' 1305 | elif [[ $(grep 'revision="android-14' .repo/manifests/default.xml) ]];then 1306 | dt_branch='fourteen' 1307 | elif [[ $(grep 'revision="android-13' .repo/manifests/default.xml) ]];then 1308 | dt_branch='thirteen' 1309 | else 1310 | # Use thirteen branch on un-handled occasion 1311 | dt_branch='thirteen' 1312 | fi 1313 | 1314 | # clone device tree 1315 | git_check_dir https://gitcode.com/stuartore/device_xiaomi_psyche.git ${dt_branch} device/xiaomi/psyche 1316 | 1317 | source build/envsetup.sh 1318 | cd $AOSP_SETUP_ROOT 1319 | fi 1320 | } 1321 | 1322 | auto_build(){ 1323 | # 1 - brand/codename . eg: xiaomi/psyche 1324 | if [[ $aosp_source_dir != "" ]];then 1325 | aosp_source_dir_working=$aosp_source_dir 1326 | fi 1327 | 1328 | # set defailt device xiaomi/psyche 1329 | local brand_device=xiaomi/psyche 1330 | if [[ -n $1 ]] && [[ $1 =~ '/' ]];then brand_device=$1;fi 1331 | local build_brand=${brand_device%%/*} 1332 | local build_device=${brand_device#*/} 1333 | case $brand_device in 1334 | "xiaomi/psyche") 1335 | psyche_deps 1336 | ;; 1337 | "oneplus/guacamole") 1338 | guacamole_deps 1339 | ;; 1340 | *) 1341 | # debug pull source 1342 | echo "Device Search is debugging ... Continue ?" 1343 | read -t 10 device_unknown_continue 1344 | case $device_unknown_continue in 1345 | Yes | yes | y | Y | YES) 1346 | custom_deps $brand_device $user_device_org 1347 | ;; 1348 | *) 1349 | exit 1350 | ;; 1351 | esac 1352 | esac 1353 | 1354 | if [[ ${aosp_source_dir_working} != "" ]];then 1355 | dt_str_patch ${brand_device} 1356 | 1357 | cd ${aosp_source_dir_working} 1358 | AOSP_BUILD_ROOT=$(pwd) 1359 | 1360 | export rom_spec_for_build==$rom_spec_str 1361 | 1362 | # build command 1363 | if [[ $(grep 'revision="android-15' .repo/manifests/default.xml) ]] || [[ $(grep 'revision="android-14' .repo/manifests/default.xml) ]];then 1364 | # rom spec for android 15, android 14 1365 | case "$(basename "$(dirname $(find vendor -maxdepth 3 -type d -name '*config' -exec sh -c 'test -e "{}/common.mk" -o -e "{}/version.mk"' \; -print))")" in 1366 | "rising") 1367 | rom_spec_for_build="rising" 1368 | ;; 1369 | esac 1370 | 1371 | case $rom_spec_for_build in 1372 | "rising") 1373 | build_rom_cmd="riseup ${build_device} userdebug" 1374 | build_rom_cmd1="rise fb" 1375 | ;; 1376 | "afterlife") 1377 | build_rom_cmd="goafterlife ${build_device}" 1378 | ;; 1379 | "superior") 1380 | build_rom_cmd="breakfast ${build_device} && m bacon" 1381 | ;; 1382 | "evolution") 1383 | build_rom_cmd="lunch ${rom_spec_str}_${build_device}-userdebug && m evolution" 1384 | ;; 1385 | "pixys") 1386 | build_rom_cmd="lunch ${rom_spec_str}_${build_device}-ap2a-userdebug && m pixysrelease" 1387 | ;; 1388 | *) 1389 | build_rom_cmd="lunch ${rom_spec_str}_${build_device}-userdebug && mka bacon" 1390 | ;; 1391 | esac 1392 | # default for android 13 1393 | else 1394 | local rom_spec_for_build=$rom_spec_str 1395 | case $rom_spec_for_build in 1396 | "evolution" | "pixys" | "xd") 1397 | build_rom_cmd="lunch ${rom_spec_str}_${build_device}-user && mka ${rom_spec_str}" 1398 | ;; 1399 | *) 1400 | build_rom_cmd="lunch ${rom_spec_str}_${build_device}-user && mka bacon" 1401 | ;; 1402 | esac 1403 | source build/envsetup.sh 1404 | fi 1405 | fi 1406 | 1407 | # build rom: most rom use one command, while some rom not 1408 | wxpush_sucess_str="wxpusher_status ${pusher_script_success_str} 'Build Passed' >/dev/null 2>&1 && trap - SIGINT EXIT" 1409 | wxpush_error_str="wxpusher_status ${pusher_script_error_str} "$(base64 < out/error.log)" >/dev/null 2>&1 " 1410 | 1411 | trap "${wxpush_error_str}" EXIT 1412 | if [[ "$build_rom_cmd1" != "" ]];then 1413 | eval "$build_rom_cmd" 1414 | eval "$build_rom_cmd1" && eval ${wxpush_sucess_str} 1415 | else 1416 | eval "$build_rom_cmd" && eval ${wxpush_sucess_str} 1417 | fi 1418 | 1419 | cd $AOSP_SETUP_ROOT 1420 | } 1421 | 1422 | post_tasks(){ 1423 | if [[ $post_task_str == "" ]];then return;fi 1424 | 1425 | post_task_list=($(echo $post_task_str | sort)) 1426 | for post_task in "${post_task_list[@]}" 1427 | do 1428 | if [[ $post_task =~ "auto_build" ]];then 1429 | post_end_task=$post_task 1430 | continue 1431 | fi 1432 | eval "$(echo $post_task | sed 's/POSTSPACE/ /g')" 1433 | done 1434 | eval "$(echo $post_end_task | sed 's/POSTSPACE/ /g')" 1435 | } 1436 | 1437 | wxpusher_status(){ 1438 | # need vars: 1439 | # 1. with_wxpusher 0/1 1440 | # 2. wxpusher log 1441 | # 3. wxpusher_uid 1442 | # 4. wxpusher_username (optional. the same with git username) 1443 | 1444 | if [[ $with_wxpusher -eq 0 ]] || [[ ! $wxpusher_uid =~ "UID_" ]];then return;fi 1445 | 1446 | local wxpusher_username="$(git config user.name)" 1447 | #wxpusher_uid="" 1448 | local script_status=$1 1449 | local wxpusher_log=$2 1450 | 1451 | URL="https://wxpusher.zjiecode.com/api/send/message" 1452 | 1453 | # 定义JSON数据 1454 | # 定义JSON数据 1455 | JSON_DATA=$(cat <${wxpusher_username},你好

你的脚本已${script_status}运行,base64日志为(请复制解码):\n

${wxpusher_log}



你可以选择上方点击查看解码

", 1459 | "summary":"编译运行状态:${script_status}", 1460 | "contentType":2, 1461 | "uids":[ 1462 | "${wxpusher_uid}" 1463 | ], 1464 | "url":"https://www.toolhelper.cn/EncodeDecode/Base64", 1465 | "verifyPay":false, 1466 | "verifyPayType":0 1467 | } 1468 | EOF 1469 | ) 1470 | 1471 | # 使用curl发送POST请求 1472 | curl -X POST \ 1473 | -H "Content-Type: application/json" \ 1474 | -d "$JSON_DATA" \ 1475 | $URL 1476 | 1477 | 1478 | } 1479 | ################# INSTRUCTION UNIT ################# 1480 | instructions_help(){ 1481 | if [[ $LANG =~ "zh_CN" ]];then 1482 | cat<\033[0m ${sync_sucess_str}" || echo -e "\033[1;32m=>\033[0m ${repo_error_str}" 1730 | 1731 | # post tasks 1732 | post_tasks 1733 | } 1734 | 1735 | main 1736 | -------------------------------------------------------------------------------- /lang.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | lang_en(){ 4 | pc_mem_str='Mem' 5 | pc_swap_mem_str='Swap' 6 | 7 | split_half_line_str='================' 8 | 9 | # repo added 10 | repo_added_str='git-repo url added' 11 | repo_error_str='If you receive \033[33mrepo error\033[0m related to itself . Run it next time' 12 | 13 | # mirror str 14 | use_mirror_str='Do you wanna use git & AOSP mirror ?' 15 | choose_git_mirror_str='Choose \033[1;33mgithub\033[0m mirror ?' 16 | choose_aosp_mirror_str='Choose \033[1;33mAndroid source\033[0m mirror ?' 17 | sel_is_str='select mirror is ' 18 | keep_mirror_str='keep mirror configuration' 19 | skip_mirror_str='Skip use mirror' 20 | 21 | # source synchonize str 22 | sel_rom_source_str='Which \033[1;33mROM source\033[0m do you wanna sync ?' 23 | rom_info_str='INFO' 24 | rom_branch_str='Which branch you wanna sync ?' 25 | enter_to_sync_str='Enter ' 26 | auto_add_ram_str_1='Automaticly add RAM (now ' 27 | auto_add_ram_str_2='Mb) patch. SWAP RAM:' 28 | patch_out_of_mem_str='patching' 29 | patch_out_of_mem_info_str='Fixed Ran out of memory error on low ram pc' 30 | try_fix_out_of_mem_str='Try fix memory error next run because not sync completely' 31 | sync_sucess_str='sync source \033[32msuccess\033[0m.' 32 | repo_failed_usr_str='Enter directory(-ies) sync failed' 33 | repo_failed_usr_eg_str='eg, bootable/recovery frameworks/av' 34 | repo_sync_mannual_str='Please repo sync mannually, then continue' 35 | 36 | # fix sepolicy str 37 | fix_sepolicy_str='fixed last used prebuilt sepolicy error' 38 | 39 | # dt bringup str 40 | dt_bringup_name_error_str="Device tree bringup skip. eg. --dt_bringup xiaomi/raphael" 41 | 42 | # error handle str 43 | error_handle_mannually_str="Please mannually handle the error" 44 | 45 | # upload rom str 46 | upload_user_str='Upload to gitlab repo ? [Y/n]' 47 | upload_git_repo_str='Gitlab/Github etc. repository address' 48 | upload_add_sshkey_str='Please add key to your Gitlab/Github Settings' 49 | upload_rom_info_str='Please choose witch archive to upload' 50 | upload_check_str='Enter to continue' 51 | upload_never_str="Won't upload" 52 | upload_auto_check_str="\033[1;32mAuto Continue\033[0m \033[1;33m(2minutes)\033[0m" 53 | 54 | # pusher 55 | pusher_script_success_str='Passed' 56 | pusher_script_error_str='Error' 57 | } 58 | 59 | lang_zh(){ 60 | pc_mem_str='内存' 61 | pc_swap_mem_str='交换' 62 | 63 | split_half_line_str='================' 64 | 65 | # repo added 66 | repo_added_str='已添加git-repo\n' 67 | repo_error_str='如果你遇到\033[33mrepo\033[0m相关错误,请在下一次运行本程序' 68 | 69 | # mirror str 70 | use_mirror_str='你想使用Git或AOSP镜像吗 ?' 71 | choose_git_mirror_str='请选择\033[1;33mGithub\033[0m镜像 ?' 72 | choose_aosp_mirror_str='请选择\033[1;33m安卓源码\033[0m镜像?' 73 | sel_is_str='选择了' 74 | keep_mirror_str='保留原有镜像配置' 75 | skip_mirror_str='选择了跳过使用镜像' 76 | 77 | # source synchonize str 78 | sel_rom_source_str='请问你想同步哪一个\033[1;33mROM\033[0m源码?' 79 | rom_info_str='信息' 80 | rom_branch_str='请选择你想同步的分支?' 81 | enter_to_sync_str='进入' 82 | auto_add_ram_str_1='自动增加RAM (现在' 83 | auto_add_ram_str_2='Mb) 补丁。交换空间' 84 | patch_out_of_mem_str='修补了' 85 | patch_out_of_mem_info_str='修补了在低内存设备上编译时内存不足的错误' 86 | try_fix_out_of_mem_str='下次运行修复内存不足错误,因为源码没有同步完全' 87 | sync_sucess_str='源码已同步\033[32m成功\033[0m.' 88 | repo_failed_usr_str='请输入同步失败目录' 89 | repo_failed_usr_eg_str='例: bootable/recovery frameworks/av' 90 | repo_sync_mannual_str='请手动完成同步再继续' 91 | 92 | # fix sepolicy str 93 | fix_sepolicy_str='修复了最近使用的预编译sepolicy错误' 94 | 95 | # dt bringup str 96 | dt_bringup_name_error_str="跳过设备树Bringup. 例: --dt_bringup xiaomi/raphael" 97 | 98 | # error handle str 99 | error_handle_mannually_str="请手动处理错误" 100 | 101 | # upload rom str 102 | upload_user_str='上传到远程仓库 ? [Y/n]' 103 | upload_git_repo_str='Gitlab/Github等仓库地址' 104 | upload_add_sshkey_str='请将密钥添加到你的Gitlab/Github设置' 105 | upload_rom_info_str='请选择需要上传的压缩包' 106 | upload_check_str='回车以继续' 107 | upload_never_str='不上传' 108 | upload_auto_check_str="\033[1;32m自动继续\033[0m \033[1;33m(2分钟)\033[0m" 109 | 110 | # pusher 111 | pusher_script_success_str='成功' 112 | pusher_script_error_str='失败' 113 | } 114 | 115 | case $LANG in 116 | "zh_CN"*) 117 | lang_zh 118 | ;; 119 | *) 120 | lang_en 121 | ;; 122 | esac 123 | -------------------------------------------------------------------------------- /my_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # env | only used to pull android pull source (default git configuration doesn't matter) 4 | # 配置 | 仅用于AOSP源码拉取(默认GIT配置不影响运行) 5 | your_git_username="example" 6 | your_git_email="example@example.com" 7 | git_android_manifest="https://github.com/Project-Mist-OS/manifest" 8 | git_android_branch="15" 9 | # only if get status on wechat (wxpusher) | 使用微信推送请配置UID_xxx (公众号wxpusher获取) 10 | wxpusher_uid="" 11 | --------------------------------------------------------------------------------