#!/bin/bash # LineageOS build helper script, credit to @AOSPA, @YumeMichi # red = errors, cyan = warnings, green = confirmations, blue = informational # plain for generic text, bold for titles, reset flag at each end of line # plain blue should not be used for readability reasons - use plain cyan instead CLR_RST=$(tput sgr0) ## reset flag #CLR_RED=$CLR_RST$(tput setaf 1) # red, plain CLR_GRN=$CLR_RST$(tput setaf 2) # green, plain #CLR_BLU=$CLR_RST$(tput setaf 4) # blue, plain CLR_CYA=$CLR_RST$(tput setaf 6) # cyan, plain CLR_BLD=$(tput bold) ## bold flag CLR_BLD_RED=$CLR_RST$CLR_BLD$(tput setaf 1) # red, bold CLR_BLD_GRN=$CLR_RST$CLR_BLD$(tput setaf 2) # green, bold CLR_BLD_BLU=$CLR_RST$CLR_BLD$(tput setaf 4) # blue, bold #CLR_BLD_CYA=$CLR_RST$CLR_BLD$(tput setaf 6) # cyan, bold # Set defaults LINEAGE_BUILD_VARIANT="userdebug" LINEAGE_VERSION_MAJOR="20" LINEAGE_VERSION_MINOR="0" LINEAGE_BUILD_DATE=$(date -u +%Y%m%d) LINEAGE_BUILD_TYPE="X" LINEAGE_EXTRAVERSION="" function checkExit() { if [ $? -ne 0 ]; then EXIT_CODE=$? echo "${CLR_BLD_RED}Build failed!${CLR_RST}" echo -e "" exit $EXIT_CODE fi } # Output usage help function showHelpAndExit { echo -e "${CLR_BLD_BLU}Usage: $0 [options]${CLR_RST}" echo -e "" echo -e "${CLR_BLD_BLU}Options:${CLR_RST}" echo -e "${CLR_BLD_BLU} -h, --help Display this help message${CLR_RST}" echo -e "${CLR_BLD_BLU} -c, --clean Wipe the tree before building${CLR_RST}" echo -e "${CLR_BLD_BLU} -i, --installclean Dirty build - Use 'installclean'${CLR_RST}" echo -e "${CLR_BLD_BLU} -r, --repo-sync Sync before building${CLR_RST}" echo -e "${CLR_BLD_BLU} -b, --build-id LineageOS unofficial build id${CLR_RST}" echo -e "${CLR_BLD_BLU} -t, --build-type Specify build type${CLR_RST}" echo -e "${CLR_BLD_BLU} -j, --jobs Specify jobs/threads to use${CLR_RST}" echo -e "${CLR_BLD_BLU} -m, --module Build a specific module${CLR_RST}" echo -e "${CLR_BLD_BLU} -g, --gms Build with GMS${CLR_RST}" echo -e "${CLR_BLD_BLU} -s, --sign-keys Specify path to sign key mappings${CLR_RST}" echo -e "${CLR_BLD_BLU} -p, --pwfile Specify path to sign key password file${CLR_RST}" echo -e "${CLR_BLD_BLU} -z, --imgzip Generate fastboot flashable image zip from signed target_files${CLR_RST}" exit 1 } # Setup getopt. long_opts="help,clean,installclean,repo-sync,build-id:,build-type:,jobs:,module:,gms,sign-keys:,pwfile:,imgzip" getopt_cmd=$(getopt -o hcir:b:t:j:m:gs:p:z --long "$long_opts" \ -n "$(basename "$0")" -- "$@") || { echo -e "${CLR_BLD_RED}\nError: Getopt failed. Extra args\n${CLR_RST}" showHelpAndExit exit 1 } eval set -- "$getopt_cmd" while true; do case "$1" in -h | --help | h | help) showHelpAndExit ;; -c | --clean | c | clean) FLAG_CLEAN_BUILD=y ;; -i | --installclean | i | installclean) FLAG_INSTALLCLEAN_BUILD=y ;; -r | --repo-sync | r | repo-sync) FLAG_SYNC=y ;; -b | --build-id | b | build-id) LINEAGE_BUILD_ID="$2" shift ;; -t | --build-type | t | build-type) LINEAGE_BUILD_VARIANT="$2" shift ;; -j | --jobs | j | jobs) JOBS="$2" shift ;; -m | --module | m | module) MODULES+=("$2") echo "$2" shift ;; -g | --gms | g | gms) FLAG_GMS="y" ;; -s | --sign-keys | s | sign-keys) KEY_MAPPINGS="$2" shift ;; -p | --pwfile | p | pwfile) PWFILE="$2" shift ;; -z | --imgzip | img | imgzip) FLAG_IMG_ZIP=y ;; --) shift break ;; esac shift done # Mandatory argument if [ $# -eq 0 ]; then echo -e "${CLR_BLD_RED}Error: No device specified${CLR_RST}" showHelpAndExit fi export DEVICE="$1" shift # Make sure we are running on 64-bit before carrying on with anything ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/') if [ "$ARCH" != "64" ]; then echo -e "${CLR_BLD_RED}error: unsupported arch (expected: 64, found: $ARCH)${CLR_RST}" exit 1 fi # Set up paths #cd $(dirname $0) DIR_ROOT=$(pwd) # Make sure everything looks sane so far if [ ! -d "$DIR_ROOT/vendor/lineage" ]; then echo -e "${CLR_BLD_RED}error: insane root directory ($DIR_ROOT)${CLR_RST}" exit 1 fi # Setup LineageOS build id if specified if [ "$LINEAGE_BUILD_ID" ]; then LINEAGE_EXTRAVERSION="-$LINEAGE_BUILD_ID" export TARGET_UNOFFICIAL_BUILD_ID=$LINEAGE_BUILD_ID fi # Initializationizing! echo -e "${CLR_BLD_BLU}Setting up the environment${CLR_RST}" echo -e "" # shellcheck source=/dev/null . build/envsetup.sh echo -e "" # Use the thread count specified by user CMD="" if [ "$JOBS" ]; then CMD+="-j$JOBS" fi # Pick the default thread count (allow overrides from the environment) if [ -z "$JOBS" ]; then if [ "$(uname -s)" = 'Darwin' ]; then JOBS=$(sysctl -n machdep.cpu.core_count) else JOBS=$(grep