├── .gitignore ├── LICENSE ├── README.md └── bin ├── common.sh ├── create_local_emulator_package.sh ├── create_local_product_package.sh ├── flash_local_product_out.sh ├── flash_product_zip.sh ├── sync_remote_emulator_images.sh └── sync_remote_product_out.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | 3 | packages 4 | 5 | avd/* 6 | !avd/whaleshark.ini 7 | !avd/whaleshark.avd 8 | avd/whaleshark.avd/* 9 | !avd/whaleshark.avd/config.ini 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2023] [Alexander Wolz] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tool Collection for AOSP and AAOS builds 2 | 3 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/alexanderwolz/android-build-tools) 4 | ![GitHub](https://img.shields.io/github/license/alexanderwolz/android-build-tools) 5 | ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/alexanderwolz/android-build-tools) 6 | ![GitHub all releases](https://img.shields.io/github/downloads/alexanderwolz/android-build-tools/total?color=informational) 7 | 8 | 9 | ## 🧑‍💻 About 10 | 11 | This repository contains tools to synch and flash Android images. 12 | 13 | See also [android_device_whaleshark_tangorpro](https://github.com/alexanderwolz/android_device_whaleshark_tangorpro) for a Google Pixel Tablet based AAOS image. 14 | 15 | And [android_device_whaleshark_emulator](https://github.com/alexanderwolz/android_device_whaleshark_emulator) for an ARM64-based AAOS Emulator image. 16 | 17 | 18 | ## 🪄 Environment 19 | 20 | A ```.env```-file must be place in the root folder of this repository containing following properties (examples): 21 | 22 | ``` 23 | SSH_HOST="server.de" 24 | SSH_USER="root" 25 | SSH_PORT="22" 26 | REMOTE_AOSP_ROOT="/home/$USER/aosp" 27 | LOCAL_AOSP_ROOT="/home/$USER/aosp" 28 | ``` 29 | 30 | References to folders should be absolute. 31 | You can also add ```SSH_KEY="~/.ssh/id_rsa"``` if your SSH is set up with key-pairs, otherwise it will ask for password. 32 | 33 | ## 🛠️ Scripts 34 | 35 | 36 | ### **bin/create_local_product_package.sh** 37 | 38 | This scripts creates a zip package that can be flashed to Android devices. Use the script like this: 39 | 40 | ``` 41 | bash bin/create_local_product_package.sh 42 | bash bin/create_local_product_package.sh $DEVICE_NAME 43 | ``` 44 | 45 | ### **bin/flash_local_product_out.sh** 46 | 47 | This scripts flashes all existing images from ```ANDROID_PRODUCT_OUT``` to a connected Android device. 48 | 49 | ``` 50 | bash bin/flash_local_product_out.sh 51 | bash bin/flash_local_product_out.sh $DEVICE_NAME 52 | ``` 53 | 54 | 55 | ### **bin/flash_product_zip.sh** 56 | 57 | This scripts flashes a given product zip to a connected Android device. 58 | 59 | ``` 60 | bash bin/flash_product_zip.sh $ZIP_FILE 61 | ``` 62 | 63 | 64 | ### **bin/sync_remote_product_out.sh** 65 | 66 | This script synchronizes the product files of a given target in ```$ANDROID_PRODUCT_OUT``` on a remote server to ```localhost```. *SSH* and *rsync* must be setup on both ends. 67 | 68 | Use the script like this: 69 | 70 | ``` 71 | bash bin/sync_remote_product_out.sh 72 | bash bin/sync_remote_product_out.sh $DEVICE_NAME 73 | ``` 74 | 75 | 76 | ### **bin/flash_local_product_out.sh** 77 | 78 | Use the script like this: 79 | 80 | ``` 81 | bash bin/flash_local_product_out.sh -h 82 | bash bin/flash_local_product_out.sh $DEVICE_NAME 83 | ``` 84 | 85 | This script has been tested with images built for Google Pixel Tablet (tangorpro) 86 | 87 | 88 | ### **bin/sync_remote_emulator_images.sh** 89 | 90 | This script synchronizes emulator image files of a given target in ```$ANDROID_PRODUCT_OUT``` on a remote server to ```localhost``` according to the ```ANDROID_SDK```-location. *SSH* and *rsync* must be setup on both ends. 91 | 92 | Use the script like this: 93 | 94 | ``` 95 | bash bin/sync_remote_emulator_images.sh 96 | bash bin/sync_remote_emulator_images.sh $DEVICE_NAME 97 | ``` 98 | -------------------------------------------------------------------------------- /bin/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | 5 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 6 | PARENT_DIR="$(dirname "$SCRIPT_DIR")" 7 | ENV_FILE_NAME=".env" 8 | ENV_FILE="$PARENT_DIR/$ENV_FILE_NAME" 9 | 10 | if [ -f $ENV_FILE ]; then 11 | source $ENV_FILE 12 | else 13 | echo "Please create env file '$ENV_FILE'" 14 | echo "" 15 | exit 1 16 | fi 17 | 18 | if [ -z $SSH_HOST ]; then 19 | echo "Please set '\$SSH_HOST' in $ENV_FILE" 20 | echo "" 21 | exit 1 22 | fi 23 | 24 | if [ -z $SSH_USER ]; then 25 | echo "Please set '\$SSH_USER' in $ENV_FILE" 26 | echo "" 27 | exit 1 28 | fi 29 | 30 | if [ -z $REMOTE_AOSP_ROOT ]; then 31 | echo "Please set '\$REMOTE_AOSP_ROOT' in $ENV_FILE" 32 | echo "" 33 | exit 1 34 | fi 35 | 36 | if [ -z $LOCAL_AOSP_ROOT ]; then 37 | echo "Please set '\$LOCAL_AOSP_ROOT' in $ENV_FILE" 38 | echo "" 39 | exit 1 40 | fi 41 | 42 | if [ ! -z $SSH_KEY ]; then 43 | SSH_OPTS+=" -i $SSH_KEY" 44 | fi 45 | 46 | if [ ! -z $SSH_PORT ]; then 47 | SSH_OPTS+=" -p $SSH_PORT" 48 | fi 49 | 50 | REMOTE="$SSH_USER@$SSH_HOST" 51 | SSH_OPTS="ssh$SSH_OPTS" 52 | SSH_CMD="$SSH_OPTS $REMOTE" 53 | 54 | function setLocalAOSPHome() { 55 | test -e $LOCAL_AOSP_ROOT/build/envsetup.sh > /dev/null 56 | if [ $? -eq 0 ]; then 57 | echo "this is an AOSP root folder" 58 | LOCAL_AOSP_HOME=$LOCAL_AOSP_ROOT 59 | else 60 | local LOCAL_AOSP_HOMES=($(ls $LOCAL_AOSP_ROOT)) 61 | chooseLocalAOSPHome "${LOCAL_AOSP_HOMES[@]}" || exit 1 62 | fi 63 | } 64 | 65 | function chooseLocalAOSPHome() { 66 | local AOSP_HOMES=("$@") 67 | if [ ${#AOSP_HOMES[@]} == 0 ]; then 68 | echo "\$LOCAL_AOSP_ROOT is not an AOSP root folder or does not contain subfolders" 69 | echo "" 70 | exit 1 71 | fi 72 | if [ ${#AOSP_HOMES[@]} == 1 ]; then 73 | LOCAL_AOSP_HOME=$LOCAL_AOSP_ROOT/"${AOSP_HOMES[0]}" 74 | echo "There is only one local AOSP subfolder available, using '$LOCAL_AOSP_HOME'" 75 | else 76 | echo "" 77 | echo "There are several local AOSP subfolders, please choose one:" 78 | for INDEX in "${!AOSP_HOMES[@]}"; do 79 | let AOSP_HOME_INDEX=${INDEX}+1 80 | echo "$AOSP_HOME_INDEX. ${AOSP_HOMES[$INDEX]}" 81 | done 82 | echo "" 83 | echo "please choose an AOSP folder:" 84 | read INPUT 85 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 86 | if [ "$INPUT" -lt "1" ]; then 87 | echo "You can't choose zero, except you are Chuck Norris :)" 88 | echo "" 89 | exit 1 90 | fi 91 | if [ "$INPUT" -gt "${#AOSP_HOMES[@]}" ]; then 92 | echo "There are only ${#AOSP_HOMES[@]} folders to choose from." 93 | echo "" 94 | exit 1 95 | fi 96 | local INDEX="$((INPUT-1))" #its a valid number, so use the index 97 | LOCAL_AOSP_HOME=$LOCAL_AOSP_ROOT/"${AOSP_HOMES[$INDEX]}" 98 | else 99 | LOCAL_AOSP_HOME="$LOCAL_AOSP_ROOT/$INPUT" 100 | fi 101 | echo "" 102 | fi 103 | 104 | if [ -z $LOCAL_AOSP_HOME ]; then 105 | echo "Something's wrong, try again" 106 | echo "" 107 | exit 1 108 | fi 109 | } 110 | 111 | function setRemoteProductParent() { 112 | $SSH_CMD "test -e $REMOTE_AOSP_ROOT/build/envsetup.sh" > /dev/null 113 | if [ $? -eq 0 ]; then 114 | REMOTE_AOSP_HOME=$REMOTE_AOSP_ROOT 115 | LOCAL_AOSP_HOME=$LOCAL_AOSP_ROOT 116 | else 117 | local REMOTE_AOSP_HOMES=($($SSH_CMD ls $REMOTE_AOSP_ROOT)) 118 | chooseRemoteAOSPHome "${REMOTE_AOSP_HOMES[@]}" || exit 1 119 | LOCAL_AOSP_HOME=$LOCAL_AOSP_ROOT/$(basename $REMOTE_AOSP_HOME) 120 | fi 121 | REMOTE_PRODUCT_PARENT_FOLDER="$REMOTE_AOSP_HOME/out/target/product" 122 | } 123 | 124 | function chooseRemoteAOSPHome() { 125 | local AOSP_HOMES=("$@") 126 | if [ ${#AOSP_HOMES[@]} == 0 ]; then 127 | echo "\$REMOTE_AOSP_ROOT is not an AOSP root folder or does not contain subfolders" 128 | echo "" 129 | exit 1 130 | fi 131 | if [ ${#AOSP_HOMES[@]} == 1 ]; then 132 | REMOTE_AOSP_HOME=$REMOTE_AOSP_ROOT/"${AOSP_HOMES[0]}" 133 | echo "There is only one AOSP subfolder available at $SSH_HOST, using '$REMOTE_AOSP_HOME'" 134 | else 135 | echo "" 136 | echo "There are several AOSP subfolders at $SSH_HOST, please choose one:" 137 | for INDEX in "${!AOSP_HOMES[@]}"; do 138 | let AOSP_HOME_INDEX=${INDEX}+1 139 | echo "$AOSP_HOME_INDEX. ${AOSP_HOMES[$INDEX]}" 140 | done 141 | echo "" 142 | echo "please choose an AOSP folder:" 143 | read INPUT 144 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 145 | if [ "$INPUT" -lt "1" ]; then 146 | echo "You can't choose zero, except you are Chuck Norris :)" 147 | echo "" 148 | exit 1 149 | fi 150 | if [ "$INPUT" -gt "${#AOSP_HOMES[@]}" ]; then 151 | echo "There are only ${#AOSP_HOMES[@]} folders to choose from." 152 | echo "" 153 | exit 1 154 | fi 155 | local INDEX="$((INPUT-1))" #its a valid number, so use the index 156 | REMOTE_AOSP_HOME=$REMOTE_AOSP_ROOT/"${AOSP_HOMES[$INDEX]}" 157 | else 158 | REMOTE_AOSP_HOME="$REMOTE_AOSP_ROOT/$INPUT" 159 | fi 160 | echo "" 161 | fi 162 | 163 | if [ -z $REMOTE_AOSP_HOME ]; then 164 | echo "Something's wrong, try again" 165 | echo "" 166 | exit 1 167 | fi 168 | } 169 | 170 | function chooseDevice() { 171 | local DEVICE_NAMES=("$@") 172 | if [ ${#DEVICE_NAMES[@]} == 0 ]; then 173 | echo "There are no devices available at $REMOTE_PRODUCT_PARENT_FOLDER" 174 | echo "" 175 | exit 1 176 | fi 177 | if [ ${#DEVICE_NAMES[@]} == 1 ]; then 178 | DEVICE_NAME="${DEVICE_NAMES[0]}" 179 | echo "There is only one device available, using '$DEVICE_NAME'" 180 | else 181 | echo "" 182 | echo "There are several devices, please choose one:" 183 | for INDEX in "${!DEVICE_NAMES[@]}"; do 184 | let DEVICE_INDEX=${INDEX}+1 185 | echo "$DEVICE_INDEX. ${DEVICE_NAMES[$INDEX]}" 186 | done 187 | echo "" 188 | echo "please choose a device:" 189 | read INPUT 190 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 191 | if [ "$INPUT" -lt "1" ]; then 192 | echo "You can't choose zero, except you are Chuck Norris :)" 193 | echo "" 194 | exit 1 195 | fi 196 | if [ "$INPUT" -gt "${#DEVICE_NAMES[@]}" ]; then 197 | echo "There are only ${#DEVICE_NAMES[@]} devices to choose from." 198 | echo "" 199 | exit 1 200 | fi 201 | local INDEX="$((INPUT-1))" #its a valid number, so use the index 202 | DEVICE_NAME="${DEVICE_NAMES[$INDEX]}" 203 | else 204 | DEVICE_NAME=$INPUT 205 | fi 206 | echo "" 207 | fi 208 | 209 | if [ -z $DEVICE_NAME ]; then 210 | echo "Something's wrong, try again" 211 | echo "" 212 | exit 1 213 | fi 214 | } 215 | 216 | function getConnectedAndroidDevices() { 217 | local CONNECTED_FASTBOOT_DEVICES=($(fastboot devices | awk '{print $1}' | tr -d '[:blank:]')) 218 | local CONNECTED_ADB_DEVICES=($(adb devices | tail -n +2 | awk '{print $1}')) 219 | CONNECTED_DEVICES=() 220 | 221 | for DEVICE in "${CONNECTED_FASTBOOT_DEVICES[@]}" 222 | do 223 | CONNECTED_DEVICES+=$DEVICE 224 | done 225 | 226 | for DEVICE in "${CONNECTED_ADB_DEVICES[@]}" 227 | do 228 | CONNECTED_DEVICES+=$DEVICE 229 | done 230 | } 231 | -------------------------------------------------------------------------------- /bin/create_local_emulator_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | 5 | function add() { 6 | local ELEMENT=$ANDROID_PRODUCT_OUT/$1 7 | if [ -f $ELEMENT ] || [ -d $ELEMENT ]; then 8 | if [ ! -z $2 ]; then 9 | cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$2" 10 | else 11 | cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$1" 12 | fi 13 | else 14 | echo "Skipping - No such file: $1" 15 | fi 16 | } 17 | 18 | echo "" 19 | echo "---------------------------------------------------------------" 20 | echo "Create emulator package Tool" 21 | echo "---------------------------------------------------------------" 22 | 23 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 24 | source "$SCRIPT_DIR/common.sh" || exit 1 25 | 26 | if [ -z $ANDROID_HOME ]; then 27 | echo "\$ANDROID_HOME is not set" 28 | echo "" 29 | exit 1 30 | fi 31 | 32 | ## -- APIS 33 | 34 | APIS=($(ls $ANDROID_HOME/system-images)) 35 | 36 | if [ ${#APIS[@]} == 0 ]; then 37 | echo "\$ANDROID_HOME does not contain any system images" 38 | echo "" 39 | exit 1 40 | fi 41 | 42 | if [ ${#APIS[@]} == 1 ]; then 43 | API=${APIS[0]} 44 | else 45 | echo "" 46 | echo "There are several apis, please choose one:" 47 | for INDEX in "${!APIS[@]}"; do 48 | let API_INDEX=${INDEX}+1 49 | echo "$API_INDEX. ${APIS[$INDEX]}" 50 | done 51 | echo "" 52 | echo "please choose an api:" 53 | read INPUT 54 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 55 | if [ "$INPUT" -lt "1" ]; then 56 | echo "You can't choose zero, except you are Chuck Norris :)" 57 | echo "" 58 | exit 1 59 | fi 60 | if [ "$INPUT" -gt "${#APIS[@]}" ]; then 61 | echo "There are only ${#APIS[@]} apis to choose from." 62 | echo "" 63 | exit 1 64 | fi 65 | INDEX="$((INPUT-1))" #its a valid number, so use the index 66 | API="${APIS[$INDEX]}" 67 | else 68 | API=$INPUT 69 | fi 70 | echo "" 71 | fi 72 | 73 | ## -- products 74 | 75 | PRODUCTS=($(ls $ANDROID_HOME/system-images/$API)) 76 | 77 | if [ ${#PRODUCTS[@]} == 0 ]; then 78 | echo "$API does not contain any products" 79 | echo "" 80 | exit 1 81 | fi 82 | 83 | if [ ${#PRODUCTS[@]} == 1 ]; then 84 | PRODUCT=${PRODUCTS[0]} 85 | else 86 | echo "" 87 | echo "There are several products, please choose one:" 88 | for INDEX in "${!PRODUCTS[@]}"; do 89 | let API_INDEX=${INDEX}+1 90 | echo "$API_INDEX. ${PRODUCTS[$INDEX]}" 91 | done 92 | echo "" 93 | echo "please choose a product:" 94 | read INPUT 95 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 96 | if [ "$INPUT" -lt "1" ]; then 97 | echo "You can't choose zero, except you are Chuck Norris :)" 98 | echo "" 99 | exit 1 100 | fi 101 | if [ "$INPUT" -gt "${#PRODUCTS[@]}" ]; then 102 | echo "There are only ${#PRODUCTS[@]} products to choose from." 103 | echo "" 104 | exit 1 105 | fi 106 | INDEX="$((INPUT-1))" #its a valid number, so use the index 107 | PRODUCT="${PRODUCTS[$INDEX]}" 108 | else 109 | PRODUCT=$PRODUCTS 110 | fi 111 | echo "" 112 | fi 113 | 114 | ## -- architectures 115 | 116 | ARCHS=($(ls $ANDROID_HOME/system-images/$API/$PRODUCT)) 117 | 118 | if [ ${#ARCHS[@]} == 0 ]; then 119 | echo "$API/$PRODUCT does not contain any architectures" 120 | echo "" 121 | exit 1 122 | fi 123 | 124 | if [ ${#ARCHS[@]} == 1 ]; then 125 | ARCH=${ARCHS[0]} 126 | else 127 | echo "" 128 | echo "There are several architectures, please choose one:" 129 | for INDEX in "${!ARCHS[@]}"; do 130 | let ARCH_INDEX=${INDEX}+1 131 | echo "$ARCH_INDEX. ${ARCHS[$INDEX]}" 132 | done 133 | echo "" 134 | echo "please choose an architecture:" 135 | read INPUT 136 | if [[ $INPUT ]] && [ $INPUT -eq $INPUT 2>/dev/null ]; then 137 | if [ "$INPUT" -lt "1" ]; then 138 | echo "You can't choose zero, except you are Chuck Norris :)" 139 | echo "" 140 | exit 1 141 | fi 142 | if [ "$INPUT" -gt "${#ARCHS[@]}" ]; then 143 | echo "There are only ${#ARCHS[@]} architectures to choose from." 144 | echo "" 145 | exit 1 146 | fi 147 | INDEX="$((INPUT-1))" #its a valid number, so use the index 148 | ARCH="${ARCHS[$INDEX]}" 149 | else 150 | ARCH=$ARCHS 151 | fi 152 | echo "" 153 | fi 154 | 155 | 156 | 157 | 158 | 159 | EMULATOR_RELATIVE_PATH="system-images/$API/$PRODUCT/$ARCH" 160 | EMULATOR_HOME="$ANDROID_HOME/$EMULATOR_RELATIVE_PATH" 161 | BUILD_PROPERTIES_FILE="$EMULATOR_HOME/build.prop" 162 | 163 | if [ ! -f $BUILD_PROPERTIES_FILE ]; then 164 | echo "Missing file $BUILD_PROPERTIES_FILE" 165 | exit 1 166 | fi 167 | 168 | BUILD_PROPERTIES=$(cat $BUILD_PROPERTIES_FILE) || exit 1 169 | 170 | API_LEVEL=$(cat $BUILD_PROPERTIES_FILE | grep ro.build.version.sdk= | cut -d'=' -f2) || exit 1 171 | BUILD_FLAVOR=$(cat $BUILD_PROPERTIES_FILE | grep ro.build.flavor= | cut -d'=' -f2) || exit 1 172 | PRODUCT_NAME=$(cat $BUILD_PROPERTIES_FILE | grep ro.build.product= | cut -d'=' -f2) || exit 1 173 | ANDROID_VERSION=$(cat $BUILD_PROPERTIES_FILE | grep ro.system.build.version.release= | cut -d'=' -f2) || exit 1 174 | BUILD_TYPE=$(cat $BUILD_PROPERTIES_FILE | grep ro.system.build.type= | cut -d'=' -f2) || exit 1 175 | BUILD_ID=$(cat $BUILD_PROPERTIES_FILE | grep ro.system.build.id= | cut -d'=' -f2) || exit 1 176 | 177 | 178 | echo "---------------------------------------------------------------" 179 | echo "Emulator: $PRODUCT" 180 | echo "Android: $API" 181 | echo "Arch: $ARCH" 182 | echo "Build: $BUILD_FLAVOR" 183 | echo "---------------------------------------------------------------" 184 | 185 | echo "" 186 | while true; do 187 | read -p "Do you wish to create emulator package? [y/n] " selection 188 | case $selection in 189 | [y]*) break ;; 190 | [n]*) exit ;; 191 | *) echo "Please answer y or n." ;; 192 | esac 193 | done 194 | 195 | NOW=$(date +"%Y%m%d-%H%M%S") 196 | BEGIN=$(date -u +%s) 197 | 198 | 199 | PACKAGE_ROOT=$PARENT_DIR"/packages" 200 | PACKAGE_DIR=$PACKAGE_ROOT"/"$BUILD_FLAVOR"_android"$ANDROID_VERSION"_"$NOW 201 | PACKAGE_DIR_ZIP=$PACKAGE_DIR.zip 202 | EMULATOR_RELATIVE_PATH="system-images/$API/$PRODUCT/$ARCH" 203 | 204 | mkdir -p $PACKAGE_DIR"/"$EMULATOR_RELATIVE_PATH || exit 1 205 | 206 | echo "Copying images .." 207 | cp -rf $EMULATOR_HOME/* $PACKAGE_DIR"/"$EMULATOR_RELATIVE_PATH 208 | 209 | echo "Zipping all content .." 210 | pushd $PACKAGE_DIR > /dev/null 211 | zip -r $PACKAGE_DIR_ZIP . || exit 1 212 | popd > /dev/null 213 | 214 | # echo "Cleaning up .." 215 | # rm -rf $PACKAGE_DIR 216 | 217 | 218 | DURATION=$(($(date -u +%s)-$BEGIN)) 219 | echo "---------------------------------------------------------------" 220 | echo "Package can be found at ../packages/$(basename $PACKAGE_DIR_ZIP)" 221 | echo "---------------------------------------------------------------" 222 | echo "Finished - took $(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds" 223 | echo "---------------------------------------------------------------" 224 | echo "" #newline -------------------------------------------------------------------------------- /bin/create_local_product_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | 5 | function add() { 6 | local ELEMENT=$ANDROID_PRODUCT_OUT/$1 7 | if [ -f $ELEMENT ] || [ -d $ELEMENT ]; then 8 | if [ ! -z $2 ]; then 9 | cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$2" 10 | else 11 | cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$1" 12 | fi 13 | else 14 | echo "Skipping - No such file: $1" 15 | fi 16 | } 17 | 18 | echo "" 19 | echo "---------------------------------------------------------------" 20 | echo "Create product package Tool" 21 | echo "---------------------------------------------------------------" 22 | 23 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 24 | source "$SCRIPT_DIR/common.sh" || exit 1 25 | 26 | setLocalAOSPHome 27 | 28 | DEVICE_NAMES=($(ls $LOCAL_AOSP_HOME)) 29 | if [ ${#DEVICE_NAMES[@]} == 0 ]; then 30 | echo "There are no devices available at $LOCAL_AOSP_HOME" 31 | echo "" 32 | exit 1 33 | fi 34 | 35 | if [ ! -z $1 ]; then 36 | DEVICE_NAME=$1 37 | else 38 | echo "---------------------------------------------------------------" 39 | echo "Reading product device list .." 40 | chooseDevice "${DEVICE_NAMES[@]}" || exit 1 41 | fi 42 | 43 | ANDROID_PRODUCT_OUT="$LOCAL_AOSP_HOME/$DEVICE_NAME" 44 | export ANDROID_PRODUCT_OUT 45 | 46 | echo "---------------------------------------------------------------" 47 | echo "Using product: $DEVICE_NAME" 48 | echo "---------------------------------------------------------------" 49 | 50 | echo "" 51 | while true; do 52 | read -p "Do you wish to create package for '$DEVICE_NAME'? [y/n] " selection 53 | case $selection in 54 | [y]*) break ;; 55 | [n]*) exit ;; 56 | *) echo "Please answer y or n." ;; 57 | esac 58 | done 59 | 60 | BUILD_PROPERTIES_FILE="$ANDROID_PRODUCT_OUT/system/build.prop" 61 | 62 | if [ ! -f $BUILD_PROPERTIES_FILE ]; then 63 | echo "Missing file $BUILD_PROPERTIES_FILE" 64 | exit 1 65 | fi 66 | 67 | BUILD_PROPERTIES=$(cat $BUILD_PROPERTIES_FILE) || exit 1 68 | 69 | API_LEVEL=$(echo "$BUILD_PROPERTIES" | grep ro.build.version.sdk= | cut -d'=' -f2) || exit 1 70 | BUILD_FLAVOR=$(echo "$BUILD_PROPERTIES" | grep ro.build.flavor= | cut -d'=' -f2) || exit 1 71 | PRODUCT_NAME=$(echo "$BUILD_PROPERTIES"| grep ro.build.product= | cut -d'=' -f2) || exit 1 72 | ANDROID_VERSION=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.version.release= | cut -d'=' -f2) || exit 1 73 | BUILD_TYPE=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.type= | cut -d'=' -f2) || exit 1 74 | BUILD_ID=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.id= | cut -d'=' -f2) || exit 1 75 | 76 | NOW=$(date +"%Y%m%d-%H%M%S") 77 | BEGIN=$(date -u +%s) 78 | 79 | PACKAGE_ROOT=$PARENT_DIR"/packages" 80 | PACKAGE_DIR=$PACKAGE_ROOT"/"$BUILD_FLAVOR"_android"$ANDROID_VERSION"_"$NOW 81 | PACKAGE_IMAGE_DIR=$PACKAGE_DIR"/images-"$BUILD_FLAVOR"_android"$ANDROID_VERSION 82 | 83 | PACKAGE_IMAGE_ZIP=$PACKAGE_IMAGE_DIR.zip 84 | PACKAGE_DIR_ZIP=$PACKAGE_DIR.zip 85 | 86 | mkdir -p $PACKAGE_IMAGE_DIR || exit 1 87 | 88 | echo "Checking files .." 89 | 90 | FLASH_FILE=$PACKAGE_DIR/flash.sh 91 | cp $SCRIPT_DIR/flash_product_zip.sh $FLASH_FILE 92 | sed -i '' -e "s/ZIP_FILE=\$1/ZIP_FILE=$(basename $PACKAGE_IMAGE_ZIP)/g" $FLASH_FILE 93 | chmod +x $FLASH_FILE 94 | 95 | BOOTLOADER="$ANDROID_PRODUCT_OUT/bootloader.img" 96 | if [ -f $BOOTLOADER ]; then 97 | echo "Adding bootloader.img" 98 | cp $BOOTLOADER $PACKAGE_DIR || exit 1 99 | fi 100 | 101 | add system/build.prop build.prop 102 | #add abl.img 103 | add android-info.txt 104 | #add bl1.img 105 | #add bl2.img 106 | #add bl31.img 107 | add boot.img 108 | add dtbo.img 109 | add fastboot-info.txt 110 | #add gsa.img 111 | add init_boot.img 112 | #add ldfw.img 113 | #add pbl.img 114 | add product.img 115 | add pvmfw.img 116 | add super_empty.img 117 | add system_dlkm.img 118 | add system_ext.img 119 | add system_other.img 120 | add system.img 121 | #add tzsw.img 122 | add vbmeta_system.img 123 | add vbmeta_vendor.img 124 | add vbmeta.img 125 | add vendor_boot.img 126 | add vendor_dlkm.img 127 | add vendor_kernel_boot.img 128 | add vendor.img 129 | add vendor/ #TODO merge this into image 130 | 131 | echo "Zipping images .." 132 | pushd $PACKAGE_IMAGE_DIR > /dev/null 133 | zip -r $PACKAGE_IMAGE_ZIP . || exit 1 134 | popd > /dev/null 135 | 136 | #zip -r -j $PACKAGE_IMAGE_ZIP $PACKAGE_IMAGE_DIR/* || exit 1 137 | rm -rf $PACKAGE_IMAGE_DIR || exit 1 138 | 139 | echo "Zipping all content .." 140 | zip -j $PACKAGE_DIR_ZIP $PACKAGE_DIR/* || exit 1 141 | 142 | #echo "Cleaning up .." 143 | #rm -rf $PACKAGE_DIR 144 | 145 | 146 | DURATION=$(($(date -u +%s)-$BEGIN)) 147 | echo "---------------------------------------------------------------" 148 | echo "Package can be found at ../packages/$(basename $PACKAGE_DIR_ZIP)" 149 | echo "---------------------------------------------------------------" 150 | echo "Finished - took $(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds" 151 | echo "---------------------------------------------------------------" 152 | echo "" #newline 153 | -------------------------------------------------------------------------------- /bin/flash_local_product_out.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | 5 | function printHelpMenu(){ 6 | echo "" 7 | echo "usage: [options] [device-name]" 8 | echo "----------------------------" 9 | echo " -b flash bootloader" 10 | echo " -f flash images" 11 | echo " -v sync vendor partition" 12 | echo "----------------------------" 13 | echo " -h print this menu" 14 | echo "" 15 | } 16 | 17 | echo "" 18 | echo "---------------------------------------------------------------" 19 | echo "Flash Tool" 20 | echo "---------------------------------------------------------------" 21 | 22 | #copied from The Android Open Source Project 23 | if ! [ $($(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 3301 ]; then 24 | echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html" 25 | exit 1 26 | fi 27 | 28 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 29 | source "$SCRIPT_DIR/common.sh" || exit 1 30 | 31 | FLASH_BOOTLOADER=0 32 | FLASH_IMAGES=0 33 | SYNCH_VENDOR=0 34 | 35 | while getopts b?f?h?v opt; do 36 | case $opt in 37 | b) 38 | FLASH_BOOTLOADER=1 39 | ;; 40 | f) 41 | FLASH_IMAGES=1 42 | ;; 43 | h) 44 | printHelpMenu 45 | exit 0 46 | ;; 47 | v) 48 | SYNCH_VENDOR=1 49 | ;; 50 | esac 51 | done 52 | 53 | if [ $OPTIND -eq 1 ]; then 54 | # no specific arguments, so flash images and vendor! 55 | FLASH_IMAGES=1 56 | SYNCH_VENDOR=1 57 | fi 58 | 59 | shift $((OPTIND - 1)) 60 | [ "${1:-}" = "--" ] && shift 61 | 62 | if [ "$FLASH_BOOTLOADER" -eq 1 ]; then 63 | echo "Option: Flashing bootloader" 64 | fi 65 | 66 | if [ "$FLASH_IMAGES" -eq 1 ]; then 67 | echo "Option: Flashing base images" 68 | fi 69 | 70 | if [ "$SYNCH_VENDOR" -eq 1 ]; then 71 | echo "Option: Synching vendor partition" 72 | fi 73 | 74 | echo "---------------------------------------------------------------" 75 | getConnectedAndroidDevices 76 | 77 | if [ ${#CONNECTED_DEVICES[@]} == 0 ]; then 78 | echo "There are no connected devices!" 79 | exit 1 80 | fi 81 | 82 | echo "Connected Android devices:" 83 | for DEVICE in "${CONNECTED_DEVICES[@]}" 84 | do 85 | echo " - $DEVICE" 86 | done 87 | 88 | if [ ${#CONNECTED_DEVICES[@]} == 1 ]; then 89 | DEVICE_ID="${CONNECTED_DEVICES[0]}" 90 | fi 91 | 92 | if [[ ${#CONNECTED_DEVICES[@]} -gt 1 ]]; then 93 | echo "Please choose a device id!" 94 | exit 1 95 | fi 96 | 97 | setLocalAOSPHome 98 | 99 | $(fastboot devices | grep $DEVICE_ID > /dev/null) 100 | IS_NOT_FASTBOOT=$? 101 | 102 | DEVICE_NAMES=($(ls $LOCAL_AOSP_HOME)) 103 | if [ ${#DEVICE_NAMES[@]} == 0 ]; then 104 | echo "There are no devices available at $LOCAL_AOSP_HOME" 105 | echo "" 106 | exit 1 107 | fi 108 | 109 | if [ ! -z $1 ]; then 110 | DEVICE_NAME=$1 111 | else 112 | echo "---------------------------------------------------------------" 113 | echo "Reading product device list from $LOCAL_AOSP_HOME .." 114 | chooseDevice "${DEVICE_NAMES[@]}" || exit 1 115 | fi 116 | 117 | ANDROID_PRODUCT_OUT="$LOCAL_AOSP_HOME/$DEVICE_NAME" 118 | export ANDROID_PRODUCT_OUT 119 | 120 | echo "---------------------------------------------------------------" 121 | echo "Using product: $DEVICE_NAME" 122 | echo "Using device: $DEVICE_ID" 123 | echo "---------------------------------------------------------------" 124 | 125 | echo "" 126 | while true; do 127 | read -p "Do you wish to flash '$DEVICE_NAME' on device '$DEVICE_ID'? [y/n] " selection 128 | case $selection in 129 | [y]*) break ;; 130 | [n]*) exit ;; 131 | *) echo "Please answer y or n." ;; 132 | esac 133 | done 134 | 135 | if [[ "$FLASH_BOOTLOADER" -eq 1 || "$FLASH_IMAGES" -eq 1 ]]; then 136 | if [ "$IS_NOT_FASTBOOT" -eq 1 ]; then 137 | echo "Restarting to fastboot.." 138 | adb reboot bootloader || exit 1 139 | else 140 | echo "Device $DEVICE_ID is already on fastboot" 141 | fi 142 | fi 143 | 144 | if [ "$FLASH_BOOTLOADER" -eq 1 ]; then 145 | BOOTLOADER="$ANDROID_PRODUCT_OUT/bootloader.img" 146 | if [ -f $BOOTLOADER ]; then 147 | fastboot flash bootloader $BOOTLOADER 148 | fastboot reboot-bootloader 149 | sleep 5 150 | else 151 | echo "There is no bootloader image in $ANDROID_PRODUCT_OUT" 152 | exit 1 153 | fi 154 | fi 155 | 156 | if [ "$FLASH_IMAGES" -eq 1 ]; then 157 | echo Flashing files from $ANDROID_PRODUCT_OUT 158 | fastboot flashing unlock 159 | fastboot -w flashall 160 | fi 161 | 162 | 163 | if [ "$SYNCH_VENDOR" -eq 1 ]; then 164 | # now comes the tricky part with vendor files.. 165 | 166 | if [ "$IS_NOT_FASTBOOT" -eq 0 ]; then 167 | echo "Restarting to normal bootup.." 168 | fastboot reboot || exit 1 169 | sleep 5 170 | fi 171 | 172 | echo "waiting for device to come up .." 173 | adb -s $DEVICE_ID wait-for-device 174 | 175 | echo "setting adb root .." 176 | adb -s $DEVICE_ID root 177 | 178 | VERITY_MODE=$(adb -s $DEVICE_ID shell getprop ro.boot.veritymode) 179 | if [ "$VERITY_MODE" == "enabled" ]; then 180 | echo "disabling verity .." 181 | adb disable-verity 182 | sleep 3 183 | 184 | echo "rebooting .." 185 | adb -s $DEVICE_ID reboot 186 | 187 | echo "waiting for device to come up .." 188 | adb -s $DEVICE_ID wait-for-device 189 | 190 | echo "setting adb root .." 191 | adb -s $DEVICE_ID root 192 | 193 | sleep 2 194 | else 195 | echo "Verity is already disabled, skipping" 196 | fi 197 | 198 | echo "Remounting .." 199 | adb -s $DEVICE_ID remount 200 | if [ "$?" -ne 0 ]; then 201 | echo "Committing checkpoint .." 202 | adb -s $DEVICE_ID shell vdc checkpoint commitChanges 203 | adb -s $DEVICE_ID remount 204 | 205 | echo "rebooting .." 206 | adb -s $DEVICE_ID reboot 207 | 208 | echo "waiting for device to come up .." 209 | adb -s $DEVICE_ID wait-for-device 210 | 211 | echo "setting adb root .." 212 | adb -s $DEVICE_ID root 213 | 214 | echo "Try remount again .." 215 | adb -s $DEVICE_ID remount 216 | fi 217 | 218 | echo "Syncing vendor partition .." 219 | adb -s $DEVICE_ID sync vendor 220 | 221 | echo "Rebooting .." 222 | adb -s $DEVICE_ID reboot 223 | fi 224 | 225 | echo "done" -------------------------------------------------------------------------------- /bin/flash_product_zip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 5 | 6 | #copied from The Android Open Source Project 7 | if ! [ $($(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 3301 ]; then 8 | echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html" 9 | exit 1 10 | fi 11 | 12 | echo "" 13 | echo "---------------------------------------------------------------" 14 | echo "Flashing tool" 15 | echo "---------------------------------------------------------------" 16 | 17 | ZIP_FILE=$1 18 | 19 | if [ -z $ZIP_FILE ]; then 20 | echo "Please specify zip file" 21 | exit 1 22 | fi 23 | 24 | while true; do 25 | read -p "Do you wish to flash? [y/n] " selection 26 | case $selection in 27 | [y]*) break ;; 28 | [n]*) exit ;; 29 | *) echo "Please answer y or n." ;; 30 | esac 31 | done 32 | 33 | if ! [ $($(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 3301 ]; then 34 | echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html" 35 | exit 1 36 | fi 37 | 38 | adb reboot bootloader 39 | if [ "$?" -ne 0 ]; then 40 | exit 1 41 | fi 42 | 43 | if [ -f "$SCRIPT_DIR/bootloader.img" ]; then 44 | fastboot flash bootloader "$SCRIPT_DIR/bootloader.img" 45 | fastboot reboot-bootloader 46 | sleep 5 47 | fi 48 | 49 | fastboot -w update $ZIP_FILE 50 | 51 | 52 | 53 | # now comes the tricky part with vendor files.. 54 | 55 | echo "waiting for device to come up .." 56 | adb wait-for-device 57 | 58 | echo "setting adb root .." 59 | adb root 60 | 61 | VERITY_MODE=$(adb shell getprop ro.boot.veritymode) 62 | if [ "$VERITY_MODE" == "enabled" ] || [ "$VERITY_MODE" = "enforcing" ]; then 63 | echo "disabling verity .." 64 | adb disable-verity 65 | sleep 3 66 | 67 | echo "rebooting .." 68 | adb reboot 69 | 70 | echo "waiting for device to come up .." 71 | adb wait-for-device 72 | 73 | echo "setting adb root .." 74 | adb root 75 | 76 | sleep 2 77 | else 78 | echo "Verity is already disabled, skipping" 79 | fi 80 | 81 | echo "Remounting .." 82 | adb remount 83 | if [ "$?" -ne 0 ]; then 84 | echo "Committing checkpoint .." 85 | adb shell vdc checkpoint commitChanges 86 | adb remount 87 | 88 | echo "rebooting .." 89 | adb reboot 90 | 91 | echo "waiting for device to come up .." 92 | adb wait-for-device 93 | 94 | echo "setting adb root .." 95 | adb root 96 | 97 | echo "Try remount again .." 98 | adb remount 99 | fi 100 | 101 | #extracting vendor from zip to tmp folder 102 | ANDROID_PRODUCT_OUT_TMP="$SCRIPT_DIR/.product_out_tmp" 103 | rm -rf $ANDROID_PRODUCT_OUT_TMP 104 | mkdir -p $ANDROID_PRODUCT_OUT_TMP 105 | unzip $ZIP_FILE "vendor/*" -d "$ANDROID_PRODUCT_OUT_TMP" > /dev/null || exit 1 106 | export ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT_TMP 107 | 108 | echo "Syncing vendor partition .." 109 | adb sync vendor 110 | 111 | echo "Rebooting .." 112 | adb reboot || exit 1 113 | 114 | rm -rf $ANDROID_PRODUCT_OUT_TMP 115 | 116 | echo "done" -------------------------------------------------------------------------------- /bin/sync_remote_emulator_images.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | 5 | echo "" 6 | echo "---------------------------------------------------------------" 7 | echo "Synching Emulator Images Tool" 8 | echo "---------------------------------------------------------------" 9 | 10 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 11 | source "$SCRIPT_DIR/common.sh" || exit 1 12 | 13 | if [ ! $ANDROID_HOME ]; then 14 | echo "Please set \$ANDROID_HOME variable (points to sdk folder)" 15 | exit 1 16 | fi 17 | 18 | setRemoteProductParent 19 | 20 | echo "Reading device list from $SSH_HOST .." 21 | DEVICE_NAMES=($($SSH_OPTS $SSH_USER@$SSH_HOST ls $REMOTE_PRODUCT_PARENT_FOLDER)) 22 | if [ ${#DEVICE_NAMES[@]} == 0 ]; then 23 | echo "There are no devices available at $REMOTE_PRODUCT_PARENT_FOLDER" 24 | echo "" 25 | exit 1 26 | fi 27 | 28 | if [ ! -z $1 ]; then 29 | DEVICE_NAME=$1 30 | else 31 | chooseDevice "${DEVICE_NAMES[@]}" || exit 1 32 | echo "---------------------------------------------------------------" 33 | fi 34 | 35 | if [[ ${DEVICE_NAMES[@]} =~ $DEVICE_NAME ]]; then 36 | echo "Synching AOSP device '$DEVICE_NAME' in $REMOTE_AOSP_HOME from $SSH_HOST .." 37 | echo "---------------------------------------------------------------" 38 | else 39 | echo "Device $DEVICE does not exist" 40 | echo "" 41 | exit 1 42 | fi 43 | 44 | TARGET="$REMOTE_PRODUCT_PARENT_FOLDER/$DEVICE_NAME" 45 | 46 | BUILD_PROPERTIES=$($SSH_CMD cat $TARGET/system/build.prop) 47 | 48 | API_LEVEL=$(echo "$BUILD_PROPERTIES" | grep ro.build.version.sdk= | cut -d'=' -f2) || exit 1 49 | # TODO: switch to ro.system.product.cpu.abilist ?? 50 | ARCH=$(echo "$BUILD_PROPERTIES" | grep ro.product.cpu.abi= | cut -d'=' -f2) || exit 1 51 | BUILD_FLAVOR=$(echo "$BUILD_PROPERTIES" | grep ro.build.flavor= | cut -d'=' -f2) || exit 1 52 | TARGET_NAME=$(echo "$BUILD_FLAVOR" | cut -d'_' -f1)|| exit 1 53 | SYSIMG_DIR="$ANDROID_HOME/system-images/android-$API_LEVEL/$TARGET_NAME/$ARCH" 54 | 55 | echo "Product '$TARGET_NAME' has API level $API_LEVEL for arch $ARCH" 56 | echo "Using system folder $SYSIMG_DIR" 57 | 58 | echo "" 59 | while true; do 60 | read -p "Do you wish to synch '$TARGET_NAME' ($DEVICE_NAME)? [y/n] " selection 61 | case $selection in 62 | [y]*) break ;; 63 | [n]*) exit ;; 64 | *) echo "Please answer y or n." ;; 65 | esac 66 | done 67 | 68 | BEGIN=$(date -u +%s) 69 | 70 | mkdir -p $SYSIMG_DIR 71 | 72 | #source props missing 73 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/kernel-ranchu" $SYSIMG_DIR"/kernel-ranchu-64" || exit 1 74 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/ramdisk-qemu.img" $SYSIMG_DIR"/ramdisk.img" || exit 1 75 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/system-qemu.img" $SYSIMG_DIR"/system.img" || exit 1 76 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/VerifiedBootParams.textproto" $SYSIMG_DIR"/VerifiedBootParams.textproto" || exit 1 77 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/advancedFeatures.ini" $SYSIMG_DIR"/advancedFeatures.ini" || exit 1 78 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/system/build.prop" $SYSIMG_DIR"/build.prop" || exit 1 79 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/encryptionkey.img" $SYSIMG_DIR"/encryptionkey.img" || exit 1 80 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/userdata.img" $SYSIMG_DIR"/userdata.img" || exit 1 81 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/vendor-qemu.img" $SYSIMG_DIR"/vendor.img" || exit 1 82 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/data" $SYSIMG_DIR || exit 1 83 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/product-qemu.img" $SYSIMG_DIR"/product.img" || exit 1 84 | rsync -avh -e "$SSH_OPTS" --delete $REMOTE:$TARGET"/system_ext-qemu.img" $SYSIMG_DIR"/system_ext.img" || exit 1 85 | 86 | DURATION=$(($(date -u +%s)-$BEGIN)) 87 | 88 | echo "" 89 | echo "---------------------------------------------------------------" 90 | echo "Images can be found at $SYSIMG_DIR" 91 | echo "---------------------------------------------------------------" 92 | echo "Finished Sync - took $(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds" 93 | echo "---------------------------------------------------------------" 94 | echo "" #newline -------------------------------------------------------------------------------- /bin/sync_remote_product_out.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2023 Alexander Wolz 3 | 4 | function printHelpMenu(){ 5 | echo "" 6 | echo "usage: [options] [device-name]" 7 | echo "----------------------------" 8 | echo " -a sync everything" 9 | echo "----------------------------" 10 | echo " -h print this menu" 11 | echo "" 12 | } 13 | 14 | 15 | echo "" 16 | echo "---------------------------------------------------------------" 17 | echo "Synching Tool" 18 | echo "---------------------------------------------------------------" 19 | 20 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 21 | source "$SCRIPT_DIR/common.sh" || exit 1 22 | 23 | while getopts a?h opt; do 24 | case $opt in 25 | a) 26 | SYNC_ALL=1 27 | echo "!! Syncing everything !!" 28 | echo "---------------------------------------------------------------" 29 | ;; 30 | h) 31 | printHelpMenu 32 | exit 0 33 | ;; 34 | esac 35 | done 36 | 37 | shift $((OPTIND - 1)) 38 | [ "${1:-}" = "--" ] && shift 39 | 40 | setRemoteProductParent 41 | 42 | echo "Reading device list from $SSH_HOST .." 43 | DEVICE_NAMES=($($SSH_OPTS $SSH_USER@$SSH_HOST ls $REMOTE_PRODUCT_PARENT_FOLDER)) 44 | if [ ${#DEVICE_NAMES[@]} == 0 ]; then 45 | echo "There are no devices available at $REMOTE_PRODUCT_PARENT_FOLDER" 46 | echo "" 47 | exit 1 48 | fi 49 | 50 | if [ ! -z $1 ]; then 51 | DEVICE_NAME=$1 52 | else 53 | chooseDevice "${DEVICE_NAMES[@]}" || exit 1 54 | echo "" 55 | echo "---------------------------------------------------------------" 56 | fi 57 | 58 | if [[ ${DEVICE_NAMES[@]} =~ $DEVICE_NAME ]]; then 59 | echo "Synching AOSP device '$DEVICE_NAME' in $REMOTE_AOSP_HOME from $SSH_HOST .." 60 | echo "Using local folder $LOCAL_AOSP_HOME" 61 | echo "---------------------------------------------------------------" 62 | else 63 | echo "Device $DEVICE does not exist" 64 | echo "" 65 | exit 1 66 | fi 67 | 68 | echo "" 69 | while true; do 70 | read -p "Do you wish to synch '$DEVICE_NAME'? [y/n] " selection 71 | case $selection in 72 | [y]*) break ;; 73 | [n]*) exit ;; 74 | *) echo "Please answer y or n." ;; 75 | esac 76 | done 77 | 78 | REMOTE_PRODUCT_FOLDER="$REMOTE_PRODUCT_PARENT_FOLDER/$DEVICE_NAME" 79 | 80 | BEGIN=$(date -u +%s) 81 | 82 | mkdir -p $LOCAL_AOSP_HOME 83 | 84 | if [ ! -z $SYNC_ALL ]; then 85 | #copy everything from $ANDROID_PRODUCT_OUT 86 | rsync -avh -e "$SSH_OPTS" --delete "$SSH_USER@$SSH_HOST":$REMOTE_PRODUCT_FOLDER $LOCAL_AOSP_HOME 87 | else 88 | #copy everything from $ANDROID_PRODUCT_OUT except exclude folders 89 | rsync -avh -e "$SSH_OPTS" --delete --exclude apex --exclude symbols --exclude obj --exclude obj_arm --exclude obj_x86 \ 90 | "$SSH_USER@$SSH_HOST":$REMOTE_PRODUCT_FOLDER $LOCAL_AOSP_HOME 91 | fi 92 | 93 | DURATION=$(($(date -u +%s)-$BEGIN)) 94 | echo "---------------------------------------------------------------" 95 | echo "AOSP product can be found at $LOCAL_AOSP_HOME/$DEVICE_NAME" 96 | echo "---------------------------------------------------------------" 97 | echo "Finished Sync - took $(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds" 98 | echo "---------------------------------------------------------------" 99 | echo "" #newline 100 | --------------------------------------------------------------------------------