├── README.mkdn ├── build-rom.sh ├── jenkins-setup-gce.sh ├── merge-aosp-tag-arrow.sh ├── merge-aosp-tag-legacy.sh ├── merge-aosp-tag.sh ├── merge-caf-tag-ginkgo.sh ├── merge-caf-tag.sh └── ubuntu-setup.sh /README.mkdn: -------------------------------------------------------------------------------- 1 | Scripts 2 | ========= 3 | 4 | Usage: `source script-name.sh` 5 | OR `curl -L https://github.com/ghostrider-reborn/scripts/raw/master/script-name.sh | bash` 6 | 7 | Bunch of homemade bash scripts which I often use to make my life easier :) 8 | Feel free to fork it for your own use, and I'm open to PRs if you'd like to improve something or fix issues! 9 | 10 | * `build-rom.sh`: Builds any android ROM for any device, and uploads it to transfer.sh 11 | 12 | * `ubuntu-setup.sh`: Sets up an Ubuntu 18.04+ server or PC for android builds 13 | 14 | * `merge-aosp-tag.sh`: Merges the specified AOSP tag in a ROM source in all repos that are not tracked directly from AOSP 15 | 16 | * `merge-caf-tag.sh`: Merges the specified CAF tag in a ROM source in all repos that are not tracked directly from CAF 17 | 18 | * `jenkins-setup-gce.sh`: Set up jenkins at port 80 (HTTP port) in a GCE instance running Ubuntu 19 | 20 | * `merge-aosp-tag-legacy.sh`: Merge specified AOSP tag in [AOSP-LEGACY](https://github.com/AOSP-LEGACY) ROM source; enhanced version of `merge-aosp-tag.sh` 21 | 22 | * `merge-aosp-tag-arrow.sh`: Merge specified AOSP tag in [ArrowOS](https://github.com/ArrowOS) ROM source; enhanced version of `merge-aosp-tag.sh` 23 | 24 | * `merge-caf-tag-ginkgo.sh`: Merge specified CAF QSSI or vendor tag in [caf-ginkgo](https://github.com/caf-ginkgo) ROM source; enhanced rewritten version of `merge-caf-tag.sh`. Also automatically pushes succesfully merged repos. 25 | -------------------------------------------------------------------------------- /build-rom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to build any android ROM for any device and upload it to Google Drive or transfer.sh. 4 | # Not recommended for retarded build butts. 5 | # 6 | # Usage (in root of source): 7 | # ./build-rom.sh [options] 8 | # 9 | # See below for options. 10 | # 11 | 12 | # Set defaults 13 | MAKE_TARGET="bacon" 14 | CCACHE_DIR="$HOME/.ccache" 15 | 16 | # Spit out usage info when there are no arguments 17 | if [[ $# -eq 0 ]]; then 18 | echo -e "\nUsage: ./build-rom.sh [options]\n" 19 | echo "Options:" 20 | echo " -l, --lunch-command The lunch command e.g. lineage_A6020-userdebug" 21 | echo " -m, --make-target Compilation target name e.g. bacon or bootimage" 22 | echo " Default: bacon" 23 | echo " -n, --custom-target Set this if you are compiling something other" 24 | echo " than the flashable ROM zip, e.g. bootimage" 25 | echo " -c, --clean Perform a clean build" 26 | echo " -s, --sync Sync the sources (repo sync) before building" 27 | echo " -o, --out Full or relative path to the output directory" 28 | echo " Default: /out" 29 | echo " -C, --ccache-dir Full or relative path to the ccache directory" 30 | echo " Default: $HOME/.ccache" 31 | echo "" 32 | exit 0 33 | fi 34 | 35 | # Parse arguments 36 | while [[ "$#" -gt 0 ]]; do case $1 in 37 | -l|--lunch) LUNCH="$2"; shift;; 38 | -m|--make-target) MAKE_TARGET="$2"; shift;; 39 | -n|--custom-target) CUSTOM=1;; 40 | -c|--clean) CLEAN=1;; 41 | -s|--sync) SYNC=1;; 42 | -o|--out) OUTDIR="$2"; shift;; 43 | -C|--ccache-dir) CCACHE_DIR="$2"; shift;; 44 | *) echo "Unknown parameter passed: $1"; exit 1;; 45 | esac; shift; done 46 | 47 | # Abort if lunch command isn't specified 48 | if [[ -z $LUNCH ]]; then echo "ERROR: Lunch command not specified! Aborting ..."; exit 1; fi 49 | 50 | # Get the device name from the lunch command 51 | DEVICE=$(sed -e "s/^.*_//" -e "s/-.*//" <<< "$LUNCH") 52 | 53 | # Limit java's RAM usage to half if system has <16GB RAM 54 | memsize=$(($(grep MemTotal /proc/meminfo | awk '{print $2}')/(1024 * 1024))) 55 | if [ $memsize -lt 16 ]; then 56 | export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx$((memsize/2))g" 57 | export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx$((memsize/2))g" 58 | fi 59 | 60 | # Enable CCACHE 61 | export USE_CCACHE=1 62 | export CCACHE_NOCOMPRESS=true 63 | ccache -M 500G &>/dev/null 64 | 65 | # Set the ccache and build output directories 66 | export CCACHE_DIR 67 | if [[ -n $OUTDIR ]]; then export OUTDIR_COMMON_BASE=$OUTDIR 68 | else OUTDIR=$(pwd)/out; fi 69 | 70 | # Spit out some build info 71 | echo -e "\nDevice: $DEVICE \nROM Source directory: $(pwd) \nCCACHE directory: $CCACHE_DIR \nOutput directory: $OUTDIR \nMake target: $MAKE_TARGET \n" 72 | 73 | # Do a quick repo sync if specified 74 | if [[ -n $SYNC ]]; then 75 | echo -e "Syncing sources ...\n" 76 | if ! schedtool -B -n 1 -e ionice -n 1 "$(command -v repo)" sync -c -f --force-sync --optimized-fetch --no-tags --no-clone-bundle --prune -j8; then 77 | echo -e "\nError occured while syncing! Continuing with the build ...\n" 78 | fi 79 | fi 80 | 81 | # Do cleanup if user has specified it 82 | if [[ -n $CLEAN ]]; then echo -e "Clearing output directory ...\n"; rm -rf out; fi 83 | 84 | # Aaaand... begin compilation! 85 | source build/envsetup.sh 86 | echo -e "\nStarting build ...\n" 87 | SECONDS=0 # Reset bash timer 88 | lunch "$LUNCH" 89 | if mka "$MAKE_TARGET"; then 90 | if [[ -z $CUSTOM ]]; then 91 | echo -e "\nBuild completed succesfully in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) :-) \n" 92 | 93 | zipdir=$(get_build_var PRODUCT_OUT) 94 | zippath=$(ls "$zipdir"/*2019*.zip | tail -n -1) 95 | 96 | # Upload the ROM to google drive if it's available, else upload to transfer.sh 97 | if [ -x "$(command -v gdrive)" ]; then 98 | echo -e "Uploading ROM to Google Drive using gdrive CLI ..." 99 | # In some cases when the gdrive CLI is not set up properly, upload fails. 100 | # In that case upload it to transfer.sh itself 101 | if ! gdrive upload --share "$zippath"; then 102 | echo -e "\nAn error occured while uploading to Google Drive." 103 | echo "Uploading ROM zip to transfer.sh..." 104 | echo "ROM zip uploaded succesfully: $(curl -sT "$zippath" https://transfer.sh/"$(basename "$zippath")")" 105 | fi 106 | else 107 | echo "Uploading ROM zip to transfer.sh..." 108 | echo "ROM zip uploaded succesfully: $(curl -sT "$zippath" https://transfer.sh/"$(basename "$zippath")")" 109 | fi 110 | echo -e "\n Good bye!" 111 | exit 0 112 | else echo -e "\n $MAKE_TARGET compiled succesfully in $((SECONDS / 60)) minute(s) and $((SECONDS % 60)) second(s) :-) Good bye! \n"; fi 113 | else echo -e "\nERROR OCCURED DURING COMPILATION :'( EXITING ... \n"; exit 1; fi 114 | -------------------------------------------------------------------------------- /jenkins-setup-gce.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to set up Jenkins on an Ubuntu 16.04/above GCE 4 | # instance, on port 80 (http port) using firewalld 5 | # 6 | # Make sure you edit the firewall rules to allow port 80 7 | # traffic (i.e. add the default-allow-http tag) 8 | # 9 | # Usage: 10 | # ./jenkins-setup-gce.sh 11 | # 12 | 13 | echo -e "Installing OpenJDK 8 dependency..." 14 | sudo apt update &>/dev/null 15 | sudo apt install -y openjdk-8-jdk &>/dev/null 16 | echo "Done." 17 | 18 | echo -e "\nInstalling Jenkins and firewalld..." 19 | wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - &>/dev/null 20 | sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' 21 | sudo apt update &>/dev/null 22 | sudo apt install -y jenkins firewalld &>/dev/null 23 | sudo service jenkins start 24 | echo "Done." 25 | 26 | echo -e "\nSetting up jenkins on port 80..." 27 | sudo systemctl mask ebtables &>/dev/null 28 | sudo systemctl disable ebtables &>/dev/null 29 | sudo firewall-cmd --permanent --add-port=8080/tcp &>/dev/null 30 | sudo firewall-cmd --permanent --add-port=80/tcp &>/dev/null 31 | sudo firewall-cmd --zone=public --change-interface=ens4 --permanent &>/dev/null 32 | sudo firewall-cmd --zone=public --add-forward-port=port=80:proto=tcp:toport=8080 --permanent &>/dev/null 33 | sudo firewall-cmd --reload &>/dev/null 34 | echo "Done." 35 | 36 | echo -e "\nSUCCESS! Jenkins is now available at port 80\n" 37 | 38 | -------------------------------------------------------------------------------- /merge-aosp-tag-arrow.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # AOSP tag merge script for ArrowOS 4 | # Author: Adithya R (ghostrider-reborn) 5 | # 6 | # Usage (from source root): 7 | # ./manifest/merge-tag.sh 8 | 9 | # Colors 10 | red=$'\e[1;31m' 11 | grn=$'\e[1;32m' 12 | blu=$'\e[1;34m' 13 | end=$'\e[0m' 14 | 15 | REMOTE="arrow" 16 | BRANCH="arrow-13.1" 17 | 18 | BLACKLIST="packages/apps/DeskClock" 19 | 20 | # verify tag 21 | if [ -z "$1" ]; then 22 | echo -e "Unspecified tag!\nUsage: ./merge.sh " 23 | exit 1 24 | else 25 | TAG="$1" 26 | fi 27 | 28 | if ! wget -q --spider https://android.googlesource.com/platform/manifest/+/refs/tags/$TAG; then 29 | echo "Invalid tag: $TAG!" 30 | exit 1 31 | fi 32 | 33 | # fetch all existing repos 34 | echo "${blu}Fetching list of repos to be merged...$end" 35 | REPOS=$(repo forall -v -c "if [ \"\$REPO_REMOTE\" = \"$REMOTE\" ]; then echo \$REPO_PATH; fi") 36 | echo $REPOS 37 | 38 | # save root dir 39 | src_root=$(pwd) 40 | 41 | # initialize some files 42 | for file in failed success unchanged; do 43 | rm -f $file 44 | touch $file 45 | done 46 | 47 | # main 48 | for repo in $REPOS; do echo; 49 | if [[ $BLACKLIST =~ $repo ]]; then 50 | echo -e "$repo is in blacklist, skipped" 51 | continue 52 | fi 53 | 54 | if ! grep -q -e "path=\"$repo\"" -e "name=\"$repo\"" manifest/default.xml; then 55 | echo "${red}$repo not found in AOSP manifest, skipping..." 56 | continue 57 | fi 58 | 59 | # this is where the fun begins 60 | echo "${blu}Merging ${repo}..." 61 | name=$(grep "path=\"$repo\"" manifest/default.xml | sed -e 's/.*name="//' -e 's/".*//') 62 | if [[ -z $name ]]; then 63 | name=$(grep "name=\"$repo\"" manifest/default.xml | sed -e 's/.*name="//' -e 's/".*//') 64 | fi 65 | 66 | git -C $repo checkout -q $BRANCH &> /dev/null || echo "${red}$repo checkout failed!" 67 | git -C $repo reset --hard $REMOTE/$BRANCH &> /dev/null 68 | 69 | if ! git -C $repo fetch -q https://android.googlesource.com/$name $TAG &> /dev/null; then 70 | echo "${red}$repo fetch failed!" 71 | else 72 | if ! git -C $repo merge FETCH_HEAD -q -m "Merge tag '$TAG' into $BRANCH" &> /dev/null; then 73 | echo "$repo" >> $src_root/failed 74 | echo "${red}$repo merge failed!" 75 | else 76 | if [[ $(git -C $repo rev-parse HEAD) != $(git -C $repo rev-parse $REMOTE/$BRANCH) ]] && [[ $(git -C $repo diff HEAD $REMOTE/$BRANCH) ]]; then 77 | echo "$repo" >> $src_root/success 78 | echo "${grn}$repo merged succesfully!" 79 | else 80 | echo "${end}$repo unchanged" 81 | echo "$repo" >> $src_root/unchanged 82 | git -C $repo reset --hard $REMOTE/$BRANCH &> /dev/null 83 | fi 84 | fi 85 | fi 86 | done 87 | 88 | if [ -s success ]; then 89 | #echo -e "${grn}\nPushing succeeded repos:$end" 90 | echo -e "${grn}\nMerge succeeded in:$end" 91 | for repo in $(cat success); do 92 | echo $repo 93 | #git -C $repo push -q &> /dev/null || echo "${red}$repo push failed!" 94 | done 95 | fi 96 | 97 | if [ -s failed ]; then 98 | echo -e "$red \nThese repos failed merging:$end" 99 | cat failed 100 | fi 101 | 102 | echo $end 103 | -------------------------------------------------------------------------------- /merge-aosp-tag-legacy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script to merge latest AOSP tag in AOSP-LEGACY source 3 | # Can be adapted to other AOSP-based ROMs as well 4 | # 5 | # After completion, you'll get the following files in the ROM source dir: 6 | # success - repos where merge succeeded 7 | # failed - repos where merge failed 8 | # 9 | # Also supports auto-pushing of repos where merge succeeded 10 | # 11 | # Usage: Just run the script in root of ROM source 12 | # 13 | 14 | # Colors 15 | red=$'\e[1;31m' 16 | grn=$'\e[1;32m' 17 | blu=$'\e[1;34m' 18 | end=$'\e[0m' 19 | 20 | # Assumes user is running the script in root of source 21 | ROM_PATH=$(pwd) 22 | 23 | # ROM-specific constants 24 | BRANCH=ten 25 | REMOTE_NAME=legacy 26 | REPO_XML_PATH="snippets/legacy.xml" 27 | 28 | # Blacklisted repos - don't try to merge 29 | blacklist="manifest \ 30 | hardware/qcom/display \ 31 | hardware/qcom/media \ 32 | hardware/qcom/audio \ 33 | hardware/qcom/bt \ 34 | hardware/qcom/wlan \ 35 | hardware/ril \ 36 | prebuilts/r8" 37 | 38 | # Get merge tag from user 39 | read -p "Enter the AOSP tag you want to merge: " TAG 40 | 41 | # Set the base URL for all repositories to be pulled from 42 | AOSP="https://android.googlesource.com" 43 | 44 | reset_branch () { 45 | git checkout $BRANCH &> /dev/null 46 | git fetch $REMOTE_NAME $BRANCH &> /dev/null 47 | git reset --hard $REMOTE_NAME/$BRANCH &> /dev/null 48 | } 49 | 50 | # Logic kanged from some similar script 51 | repos="$(grep "remote=\"$REMOTE_NAME\"" $ROM_PATH/.repo/manifests/$REPO_XML_PATH | awk '{print $2}' | awk -F '"' '{print $2}')" 52 | 53 | for files in success failed; do 54 | rm $files 2> /dev/null 55 | touch $files 56 | done 57 | 58 | for REPO in $repos; do 59 | if [[ $blacklist =~ $REPO ]]; then 60 | echo -e "\n$REPO is in blacklist, skipping" 61 | else 62 | case $REPO in 63 | build/make) repo_url="$AOSP/platform/build" ;; 64 | *) repo_url="$AOSP/platform/$REPO" ;; esac 65 | 66 | if wget -q --spider $repo_url; then 67 | echo -e "$blu \nMerging $REPO $end" 68 | cd $REPO 69 | reset_branch 70 | git fetch -q $repo_url $TAG &> /dev/null 71 | if git merge FETCH_HEAD -q -m "Merge tag '$TAG' into $BRANCH" &> /dev/null; then 72 | if [[ $(git rev-parse HEAD) != $(git rev-parse $REMOTE_NAME/$BRANCH) ]] && [[ $(git diff HEAD $REMOTE_NAME/$BRANCH) ]]; then 73 | echo "$REPO" >> $ROM_PATH/success 74 | echo "${grn}Merging $REPO succeeded :) $end" 75 | else 76 | echo "$REPO - unchanged" 77 | git reset --hard $REMOTE_NAME/$BRANCH &> /dev/null 78 | fi 79 | else 80 | echo "$REPO" >> $ROM_PATH/failed 81 | echo "${red}$REPO merging failed :( $end" 82 | fi 83 | cd $ROM_PATH 84 | fi 85 | fi 86 | done 87 | 88 | echo -e "$red \nThese repos failed merging: \n $end" 89 | cat failed 90 | echo -e "$grn \nThese repos succeeded merging: \n $end" 91 | cat success 92 | 93 | echo $red 94 | read -p "Do you want to push the succesfully merged repos? (Y/N): " PUSH 95 | echo $end 96 | 97 | if [[ $PUSH == "Y" ]] || [[ $PUSH == "y" ]]; then 98 | # Push succesfully merged repos 99 | for REPO in $(cat success); do 100 | cd $REPO 101 | echo -e "Pushing $REPO ..." 102 | git push -q $REMOTE_NAME HEAD:$BRANCH &> /dev/null 103 | cd $ROM_PATH 104 | done 105 | fi 106 | 107 | echo -e "\n${blu}All done :) $end" 108 | -------------------------------------------------------------------------------- /merge-aosp-tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to merge specified AOSP tag in repos tracked by Google's repo tool (git-repo) 4 | # 5 | # Usage (in root of ROM source): 6 | # repo forall -c $(pwd)/merge_aosp_tag.sh [] 7 | # 8 | 9 | TAG=$1 10 | AOSP_REMOTE=$2 11 | if [ -n "$3" ]; then ADDNL_REMOTE=$3, else ADDNL_REMOTE="k"; fi 12 | 13 | ### 14 | ### TODO: Whitelisted repos support 15 | ### 16 | 17 | if [[ $REPO_REMOTE != "$AOSP_REMOTE" && $REPO_REMOTE != "$ADDNL_REMOTE" ]]; then 18 | 19 | # Workaround for build/make as it lies in "platform/build" repo in AOSP 20 | if [[ $REPO_PATH = "build/make" ]]; then REPO_PATH="build"; fi 21 | 22 | # Check if it is a repo which is forked from AOSP 23 | if wget -q --spider https://android.googlesource.com/platform/$REPO_PATH; then 24 | # Find branch name from manifest & checkout 25 | branch=$(sed 's|refs\/heads\/||' <<< "$REPO_RREV") 26 | git checkout -q "$branch" 27 | 28 | # Fetch the tag from AOSP 29 | git fetch -q https://android.googlesource.com/platform/$REPO_PATH "$TAG" 30 | 31 | # Store the current hash value of HEAD 32 | hash=$(git rev-parse HEAD) 33 | 34 | # Merge and inform user on succesful merge, by comparing hash 35 | if git merge -q --no-ff -m "Merge tag '$TAG' into $branch" FETCH_HEAD; then 36 | if [[ $(git rev-parse HEAD) != "$hash" ]] && [[ $(git diff HEAD "$REPO_REMOTE"/"$branch") ]]; then 37 | echo -e "\n\e[34m$REPO_PATH merged succesfully\e[0m\n" 38 | else git reset --hard "$REPO_REMOTE"/"$branch"; fi 39 | else 40 | echo -e "\n\e[31m$REPO_PATH has merge errors\e[0m\n" 41 | fi 42 | fi 43 | fi 44 | -------------------------------------------------------------------------------- /merge-caf-tag-ginkgo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # CAF tag merge script for caf-ginkgo 3 | 4 | # Colors 5 | red=$'\e[1;31m' 6 | grn=$'\e[1;32m' 7 | blu=$'\e[1;34m' 8 | end=$'\e[0m' 9 | 10 | REMOTE="ginkgo" 11 | BRANCH="11.0" 12 | VENDOR="trinket" 13 | 14 | # fetch tag from user 15 | read -p "Enter the CAF tag you wanna merge: " TAG 16 | echo 17 | 18 | # check if the tag is QSSI or vendor 19 | if [[ $TAG = *"QSSI"* ]]; then 20 | QSSI=true 21 | echo "${blu}QSSI tag detected!" 22 | else 23 | QSSI=false 24 | echo "${blu}Vendor tag detected!" 25 | fi 26 | 27 | # fetch all existing repos 28 | echo "${blu}Fetching list of repos to be merged..." 29 | repo forall -c "if [ \"\$REPO_REMOTE\" = \"$REMOTE\" ]; then echo \$REPO_PATH; fi" > .temp 2> /dev/null 30 | 31 | # save current dir 32 | cur_dir=$(pwd) 33 | 34 | # initialize some files 35 | for file in failed success unchanged; do 36 | rm -f $file 37 | touch $file 38 | done 39 | 40 | # main 41 | for path in $(cat .temp); do 42 | echo 43 | 44 | if $QSSI && ! grep -q $path manifest/default.xml; then 45 | echo "${red}$path not found in QSSI manifest! Skipping..." 46 | continue 47 | fi 48 | 49 | if ! grep -q $path manifest/$VENDOR.xml; then 50 | echo "${red}$path not found in vendor manifest! Skipping..." 51 | continue 52 | fi 53 | 54 | echo "${blu}Merging ${path}..." 55 | name=$(grep "path=\"$path\"" manifest/$VENDOR.xml manifest/default.xml | sed -e 's/.*name="//' -e 's/".*//') 56 | 57 | cd $path 58 | 59 | if [[ $(git status --porcelain) = *" M "* ]]; then 60 | # save uncommitted changes that could be important 61 | git checkout -q -b "staging-$(date -%s)" &> /dev/null 62 | git commit -a -q -m "Staging $(date)" &> /dev/null 63 | fi 64 | 65 | # reset HEAD to our branch 66 | git checkout -q $BRANCH &> /dev/null 67 | git fetch -q $REMOTE $BRANCH &> /dev/null 68 | git reset --hard $REMOTE/$BRANCH &> /dev/null 69 | 70 | git fetch -q https://source.codeaurora.org/quic/la/$name $TAG &> /dev/null 71 | if git merge FETCH_HEAD -q -m "Merge tag '$TAG' into $BRANCH" &> /dev/null; then 72 | if [[ $(git rev-parse HEAD) != $(git rev-parse $REMOTE/$BRANCH) ]] && [[ $(git diff HEAD $REMOTE/$BRANCH) ]]; then 73 | echo "$path" >> $cur_dir/success 74 | echo "${grn}Merging $path succeeded!" 75 | else 76 | echo "${end}$path - unchanged" 77 | echo "$path" >> $cur_dir/unchanged 78 | git reset --hard $REMOTE/$BRANCH &> /dev/null 79 | fi 80 | else 81 | echo "$path" >> $cur_dir/failed 82 | echo "${red}$path merging failed!" 83 | fi 84 | 85 | cd $cur_dir 86 | done 87 | 88 | echo -e "$grn \nPushing succeeded repos: $end" 89 | for repo in $(cat success); do 90 | cd $repo 91 | echo $repo 92 | git push -q &> /dev/null 93 | cd $cur_dir 94 | done 95 | 96 | echo -e "$red \nThese repos failed merging: $end" 97 | cat failed 98 | 99 | rm -f .temp 100 | echo $end 101 | -------------------------------------------------------------------------------- /merge-caf-tag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Basic shell script to merge specified CAF tag in repos tracked by Google's repo tool 4 | # 5 | # Usage (in root of ROM source): 6 | # repo forall -c bash $(pwd)/merge-caf-tag.sh [] 7 | # 8 | 9 | TAG=$1 10 | CAF_REMOTE=$2 11 | if [ -n "$3" ]; then ADDNL_REMOTE=$3, else ADDNL_REMOTE="k"; fi 12 | 13 | if [[ $REPO_REMOTE != "$CAF_REMOTE" ]] && [[ $REPO_PATH != "manifest" ]]; then 14 | # Workaround for build/make as it lies in "platform/build" repo in AOSP/CAF 15 | if [[ $REPO_PATH = "build/make" ]]; then REPO_PATH="build"; fi 16 | 17 | # Check if it is a repo which is forked from CAF 18 | if wget -q --spider "$GIT_LINK"/platform/$REPO_PATH; then 19 | # Find branch name from manifest & checkout 20 | branch=$(sed 's|refs\/heads\/||' <<< "$REPO_RREV") 21 | git checkout -q "$branch" 22 | 23 | # Fetch the tag from CAF 24 | git fetch -q "https://source.codeaurora.org/quic/la/platform/$REPO_PATH" "$TAG" 25 | 26 | # Store the current hash value of HEAD 27 | hash="$(git rev-parse HEAD)" 28 | 29 | # Merge and inform user on succesful merge, by comparing hash 30 | if git merge -q -m "Merge tag '$TAG' into $branch" FETCH_HEAD &> /dev/null; then 31 | if [[ $(git rev-parse HEAD) != "$hash" ]] && [[ $(git diff HEAD "$REPO_REMOTE/$branch") ]]; then 32 | echo -e "\n\e[34m$REPO_PATH merged succesfully\e[0m\n" 33 | fi 34 | else 35 | echo -e "\n\e[31m$REPO_PATH has merge errors\e[0m\n" 36 | fi 37 | fi 38 | fi 39 | -------------------------------------------------------------------------------- /ubuntu-setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to set up an Ubuntu 20.04+ server 4 | # (with minimum 16GB RAM, 8 threads CPU) for android ROM compiling 5 | # 6 | # Sudo access is mandatory to run this script 7 | # 8 | # IMPORTANT NOTICE: This script sets my personal git config, update 9 | # it with your details before you run this script! 10 | # 11 | # Usage: 12 | # ./ubuntu-setup.sh 13 | # 14 | 15 | # Go to home dir 16 | orig_dir=$(pwd) 17 | cd $HOME 18 | 19 | echo -e "Installing and updating APT packages...\n" 20 | sudo apt update -qq 21 | sudo apt full-upgrade -y -qq 22 | sudo apt install -y -qq git-core gnupg flex bc bison build-essential zip curl zlib1g-dev gcc-multilib \ 23 | g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev jq \ 24 | lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig imagemagick \ 25 | python2 python3 python3-pip python3-dev python-is-python3 schedtool ccache libtinfo5 \ 26 | libncurses5 lzop tmux libssl-dev neofetch patchelf dos2unix git-lfs default-jdk \ 27 | libxml-simple-perl ripgrep rclone 28 | sudo apt autoremove -y -qq 29 | sudo apt purge snapd -y -qq 30 | pip3 install thefuck 31 | echo -e "\nDone." 32 | 33 | echo -e "\nInstalling git-repo..." 34 | wget -q https://storage.googleapis.com/git-repo-downloads/repo 35 | chmod a+x repo 36 | sudo install repo /usr/local/bin/repo 37 | rm repo 38 | echo -e "Done." 39 | 40 | echo -e "\nInstalling Android SDK platform tools..." 41 | wget -q https://dl.google.com/android/repository/platform-tools-latest-linux.zip 42 | unzip -qq platform-tools-latest-linux.zip 43 | rm platform-tools-latest-linux.zip 44 | echo -e "Done." 45 | 46 | # echo -e "\nInstalling Google Drive CLI..." 47 | # wget -q https://raw.githubusercontent.com/usmanmughalji/gdriveupload/master/gdrive 48 | # chmod a+x gdrive 49 | # sudo install gdrive /usr/local/bin/gdrive 50 | # rm gdrive 51 | # echo -e "Done." 52 | 53 | if [[ $SHELL = *zsh* ]]; then 54 | sh_rc=".zshrc" 55 | else 56 | sh_rc=".bashrc" 57 | fi 58 | 59 | echo -e "\nInstalling apktool and JADX..." 60 | mkdir -p bin 61 | wget -q https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.10.0.jar -O bin/apktool.jar 62 | echo 'alias apktool="java -jar $HOME/bin/apktool.jar"' >> $sh_rc 63 | 64 | wget -q https://github.com/skylot/jadx/releases/download/v1.5.1/jadx-1.5.1.zip -O jadx.zip 65 | unzip -qq jadx.zip -d jadx 66 | rm jadx.zip 67 | echo 'export PATH="$HOME/jadx/bin:$PATH"' >> $sh_rc 68 | echo -e "Done." 69 | 70 | echo -e "\nSetting up shell environment..." 71 | 72 | cat <<'EOF' >> $sh_rc 73 | 74 | # Super-fast repo sync 75 | repofastsync() { time schedtool -B -e ionice -n 0 `which repo` sync -c --force-sync --optimized-fetch --no-tags --no-clone-bundle --retry-fetches=5 -j$(nproc --all) "$@"; } 76 | 77 | # List lib dependencies of any lib/bin 78 | list_blob_deps() { readelf -d $1 | grep "\(NEEDED\)" | sed -r "s/.*\[(.*)\]/\1/"; } 79 | alias deps="list_blob_deps" 80 | 81 | export TZ='Asia/Kolkata' 82 | export USE_CCACHE=1 83 | export CCACHE_EXEC=/usr/bin/ccache 84 | 85 | function msg() { 86 | echo -e "\e[1;32m$1\e[0m" 87 | } 88 | 89 | function helptree() { 90 | if [[ -z $1 && -z $2 ]]; then 91 | msg "Usage: helptree " 92 | return 93 | fi 94 | kernel_version="$( cat Makefile | grep VERSION | head -n 1 | sed "s|.*=||1" | sed "s| ||g" )" 95 | kernel_patchlevel="$( cat Makefile | grep PATCHLEVEL | head -n 1 | sed "s|.*=||1" | sed "s| ||g" )" 96 | version=$kernel_version.$kernel_patchlevel 97 | if [[ $version != "4.14" && $version != "5.4" ]]; then 98 | msg "Kernel $version not supported! Only msm-5.4 and msm-4.14 are supported as of now." 99 | return 100 | fi 101 | if [[ -z $3 ]]; then 102 | spec=all 103 | else 104 | spec=$3 105 | fi 106 | if [[ $2 = "add" ]]; then 107 | tree_status="Adding" 108 | commit_status="Import from" 109 | else 110 | tree_status="Updating" 111 | commit_status="Merge" 112 | if [[ $spec = "all" ]]; then 113 | msg "Merging kernel as of $1.." 114 | git fetch https://git.codelinaro.org/clo/la/kernel/msm-$version $1 && 115 | git merge FETCH_HEAD -m "Merge tag '$1' of msm-$version" 116 | fi 117 | fi 118 | if [[ $spec = "wifi" || $spec = "all" ]]; then 119 | for i in qcacld-3.0 qca-wifi-host-cmn fw-api; do 120 | msg "$tree_status $i subtree as of $1..." 121 | git subtree $2 -P drivers/staging/$i -m "$i: $commit_status tag '$1'" \ 122 | https://git.codelinaro.org/clo/la/platform/vendor/qcom-opensource/wlan/$i $1 123 | done 124 | fi 125 | if [[ $spec = "techpack" || $spec = "all" ]]; then 126 | msg "$tree_status audio-kernel subtree as of $1..." 127 | git subtree $2 -P techpack/audio -m "techpack: audio: $commit_status tag '$1'" \ 128 | https://git.codelinaro.org/clo/la/platform/vendor/opensource/audio-kernel $1 129 | if [[ $version = "5.4" ]]; then 130 | msg "$tree_status camera-kernel subtree as of $1..." 131 | git subtree $2 -P techpack/camera -m "techpack: camera: $commit_status tag '$1'" \ 132 | https://git.codelinaro.org/clo/la/platform/vendor/opensource/camera-kernel $1 133 | msg "$tree_status dataipa subtree as of $1..." 134 | git subtree $2 -P techpack/dataipa -m "techpack: dataipa: $commit_status tag '$1'" \ 135 | https://git.codelinaro.org/clo/la/platform/vendor/opensource/dataipa $1 136 | msg "$tree_status datarmnet subtree as of $1..." 137 | git subtree $2 -P techpack/datarmnet -m "techpack: datarmnet: $commit_status tag '$1'" \ 138 | https://git.codelinaro.org/clo/la/platform/vendor/qcom/opensource/datarmnet $1 139 | msg "$tree_status datarmnet-ext subtree as of $1..." 140 | git subtree $2 -P techpack/datarmnet-ext -m "techpack: datarmnet-ext: $commit_status tag '$1'" \ 141 | https://git.codelinaro.org/clo/la/platform/vendor/qcom/opensource/datarmnet-ext $1 142 | msg "$tree_status display-drivers subtree as of $1..." 143 | git subtree $2 -P techpack/display -m "techpack: display: $commit_status tag '$1'" \ 144 | https://git.codelinaro.org/clo/la/platform/vendor/opensource/display-drivers $1 145 | msg "$tree_status video-driver subtree as of $1..." 146 | git subtree $2 -P techpack/video -m "techpack: video: $commit_status tag '$1'" \ 147 | https://git.codelinaro.org/clo/la/platform/vendor/opensource/video-driver $1 148 | elif [[ $version = "4.14" ]]; then 149 | if [[ $2 = "add" ]] || [ -d "techpack/data" ]; then 150 | msg "$tree_status data-kernel as of $1..." 151 | git subtree $2 -P techpack/data -m "techpack: data: $commit_status tag '$1'" \ 152 | https://git.codelinaro.org/clo/la/platform/vendor/qcom-opensource/data-kernel $1 153 | fi 154 | fi 155 | fi 156 | } 157 | 158 | function addtree() { 159 | if [[ -z $1 ]]; then 160 | msg "Usage: addtree [optional: spec]" 161 | return 162 | fi 163 | helptree $1 add $2 164 | } 165 | 166 | function updatetree() { 167 | if [[ -z $1 ]]; then 168 | msg "Usage: updatetree [optional: spec]" 169 | return 170 | fi 171 | helptree $1 pull $2 172 | } 173 | 174 | export PATH="$HOME/.local/bin:$HOME/bin:$PATH" 175 | 176 | eval $(thefuck --alias) 177 | 178 | function f() { 179 | if [ -z "$2" ]; then find | grep $1 180 | elif [ "$1" = "-i" ]; then 181 | if [ ! -z "$3" ]; then find $3 | grep -i $2 182 | else find | grep -i $2; fi 183 | else find $2 | grep $1; fi 184 | } 185 | 186 | # alias gup="gdrive upload --share" 187 | function gup() { 188 | [ -z "$1" ] && echo "Error: File not specified!" && return 189 | rclone copy -P $1 gdrive: && rclone link gdrive:$(basename $1) 190 | } 191 | 192 | #### FILL IN PIXELDRAIN API KEY #### 193 | PD_API_KEY= 194 | #################################### 195 | function pdup() { 196 | [ -z "$1" ] && echo "Error: File not specified!" && return 197 | ID=$(curl --progress-bar -T "$1" -u :$PD_API_KEY https://pixeldrain.com/api/file/ | cat | grep -Po '(?<="id":")[^"]*') 198 | echo -e "\nhttps://pixeldrain.com/u/$ID" 199 | } 200 | 201 | alias nnano=nano 202 | alias Nano=nano 203 | alias rgb="rg --binary" 204 | alias wgetc="wget --content-disposition" 205 | 206 | EOF 207 | 208 | # Add android sdk to path 209 | cat <<'EOF' >> .profile 210 | 211 | # Add Android SDK platform tools to path 212 | if [ -d "$HOME/platform-tools" ] ; then 213 | PATH="$HOME/platform-tools:$PATH" 214 | fi 215 | EOF 216 | 217 | # Unlimited history file 218 | sed -i 's/HISTSIZE=.*/HISTSIZE=-1/g' $sh_rc 219 | sed -i 's/HISTFILESIZE=.*/HISTFILESIZE=-1/g' $sh_rc 220 | 221 | echo -e "Done." 222 | 223 | # Increase tmux scrollback buffer size 224 | echo "set-option -g history-limit 6000" >> .tmux.conf 225 | 226 | # Increase maximum ccache size 227 | ccache -M 50G 228 | 229 | ### 230 | ### IMPORTANT !!! REPLACE WITH YOUR PERSONAL DETAILS IF NECESSARY 231 | ### 232 | # Configure git 233 | echo -e "\nSetting up Git..." 234 | 235 | if [[ $USER == "adithya" ]]; then 236 | git config --global user.email "gh0strider.2k18.reborn@gmail.com" 237 | git config --global user.name "Adithya R" 238 | git config --global review.gerrit.aospa.co.username "ghostrider-reborn" 239 | git config --global review.gerrit.libremobileos.com.username "ghostrider-reborn" 240 | git config --global review.review.lineageos.org.username "ghostrider-reborn" 241 | echo "export ARROW_GERRIT_USER=ghostrider_reborn" >> $sh_rc 242 | fi 243 | 244 | if [[ $USER == "panda" ]]; then 245 | git config --global user.name "Jyotiraditya Panda" 246 | git config --global user.email "jyotiraditya@aospa.co" 247 | fi 248 | 249 | git config --global alias.cp 'cherry-pick' 250 | git config --global alias.c 'commit' 251 | git config --global alias.f 'fetch' 252 | git config --global alias.m 'merge' 253 | git config --global alias.rb 'rebase' 254 | git config --global alias.rs 'reset' 255 | git config --global alias.ck 'checkout' 256 | git config --global alias.rsh 'reset --hard' 257 | git config --global alias.logp 'log --pretty=oneline --abbrev-commit' 258 | git config --global alias.mlog 'merge --log=100' 259 | git config --global credential.helper 'cache --timeout=99999999' 260 | git config --global url."git@github.com:".insteadOf "https://github.com/" 261 | git config --global push.autoSetupRemote true 262 | echo "Done." 263 | 264 | # Done! 265 | echo -e "\nALL DONE. Now sync sauces & start baking!" 266 | echo -e "Please relogin or run \`source ~/$sh_rc && source ~/.profile\` for environment changes to take effect." 267 | 268 | # Go back to original dir 269 | cd "$orig_dir" 270 | --------------------------------------------------------------------------------