forked from PitchBlackRecoveryProject/vendor_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb_build.sh
executable file
·137 lines (123 loc) · 4.46 KB
/
pb_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Copyright (C) 2018-2020, Mohd Faraz <[email protected]>
# PitchBlack Recovery Project <[email protected]>
#
# Custom build script
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Please maintain this if you use this script or any part of it
#
BUILD_START=$(date +"%s")
blue='\033[0;34m'
cyan='\033[0;36m'
green='\e[0;32m'
yellow='\033[0;33m'
red='\033[0;31m'
nocol='\033[0m'
purple='\e[0;35m'
white='\e[0;37m'
DATE=$(date +%Y%m%d-%H%M)
VERSION=$(cat $(pwd)/bootable/recovery/variables.h | egrep "define\s+PB_MAIN_VERSION" | awk '{print $3}' | tr -d '"')
PB_VENDOR=vendor/utils
PB_WORK=$OUT
PB_WORK_DIR=$OUT/zip
RECOVERY_IMG=$OUT/recovery.img
RECOVERY_RAM=$OUT/ramdisk-recovery.cpio
CURR_W=$(pwd)
cd ${OUT}/../../../../
AB_OTA="false"
AB_OTA=$AB_OTA_UPDATER
unset AB_OTA_UPDATER
export PB_DEVICE=$(cut -d'_' -f2-3 <<<$TARGET_PRODUCT)
function get_build_var()
{
SOONG_BASH_UI=build/soong/soong_ui.bash
if [ -f $SOONG_BASH_UI ]; then
(build/soong/soong_ui.bash --dumpvar-mode $1)
return
fi
(CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
command make --no-print-directory -f build/core/config.mk dumpvar-$1)
}
PBRP_BUILD_TYPE=UNOFFICIAL
if [ -z $BETA_BUILD ]; then
PB_BETA=$(get_build_var BETA_BUILD)
else
PB_BETA=${BETA_BUILD}
fi
if [ "$PB_OFFICIAL_CH" == "true" ]; then
PBRP_BUILD_TYPE=OFFICIAL
elif [ "$PB_BETA" == "true" ]; then
PBRP_BUILD_TYPE=BETA
else
PBRP_BUILD_TYPE=UNOFFICIAL
fi
if [ "$PBRP_BUILD_TYPE" != "UNOFFICIAL" ]; then
python3 $PB_VENDOR/pb_devices.py verify all $PB_DEVICE
if [[ "$?" != "0" ]]; then
PBRP_BUILD_TYPE=UNOFFICIAL
echo -e "${red}Error Device is not OFFICIAL${nocol}"
exit 1;
fi
fi
cd $CURR_W
if [ "$PB_GO" != "true" ]; then
ZIP_NAME=PBRP-$PB_DEVICE-$VERSION-$DATE-$PBRP_BUILD_TYPE
else
echo -e "${red}PitchBlack Go Variant has been depreciated and has been removed. Remove PB_GO flag to build normally.{nocol}"
exit 1;
fi
echo -e "${red}**** Making Zip ****${nocol}"
if [ -d "$PB_WORK_DIR" ]; then
rm -rf "$PB_WORK_DIR"
rm -rf "$PB_WORK"/*.zip
fi
if [ ! -d "PB_WORK_DIR" ]; then
mkdir "$PB_WORK_DIR"
fi
echo -e "${blue}**** Copying Tools ****${nocol}"
cp -R "$PB_VENDOR/PBRP" "$PB_WORK_DIR"
echo -e "${green}**** Copying Updater Scripts ****${nocol}"
mkdir -p "$PB_WORK_DIR/META-INF/com/google/android"
cp -R "$PB_VENDOR/updater/update-script" "$PB_WORK_DIR/META-INF/com/google/android/"
cp -R "$PB_VENDOR/updater/update-binary" "$PB_WORK_DIR/META-INF/com/google/android/update-binary"
cp -R "$PB_VENDOR/updater/awk" "$PB_WORK_DIR/META-INF/"
if [[ -f "$PB_WORK/recovery/root/sbin/keycheck" ]]; then
cp "$PB_WORK/recovery/root/sbin/keycheck" "$PB_WORK_DIR/META-INF/"
fi
if [[ "$AB_OTA" = "true" ]]; then
sed -i "s|AB_DEVICE=false|AB_DEVICE=true|g" "$PB_WORK_DIR/META-INF/com/google/android/update-binary"
fi
echo -e "${cyan}**** Copying Recovery Image ****${nocol}"
mkdir -p "$PB_WORK_DIR/TWRP"
cp "$PB_VENDOR/updater/magiskboot" "$PB_WORK_DIR"
cp "$RECOVERY_IMG" "$PB_WORK_DIR/TWRP/"
echo -e "${green}**** Compressing Files into ZIP ****${nocol}"
cd $PB_WORK_DIR
zip -r ${ZIP_NAME}.zip *
BUILD_RESULT_STRING="BUILD SUCCESSFUL"
BLINKBLUE="\033[0;5;34m";
echo -e ${BLINKBLUE};
cat ${OUT}/../../../../vendor/utils/.pb.1;
echo -e "${nocol}";
echo
BUILD_END=$(date +"%s")
#DIFF=$(($BUILD_END - $BUILD_START + ( ($HOURS * 60) + ($MINS * 60) + $SECS)))
if [[ "${BUILD_RESULT_STRING}" = "BUILD SUCCESSFUL" ]]; then
mv ${PB_WORK_DIR}/${ZIP_NAME}.zip ${PB_WORK_DIR}/../${ZIP_NAME}.zip
echo -e "$cyan****************************************************************************************$nocol"
echo -e "$cyan*$nocol${green} ${BUILD_RESULT_STRING}$nocol"
echo -e "$cyan*$nocol${green} RECOVERY LOCATION: ${OUT}/recovery.img$nocol"
echo -e "$purple*$nocol${green} RECOVERY SIZE: $(ls -lh ${OUT}/recovery.img | awk '{print $5}')$nocol"
echo -e "$cyan*$nocol${green} ZIP LOCATION: ${PB_WORK}/${ZIP_NAME}.zip$nocol"
echo -e "$purple*$nocol${green} ZIP SIZE: $( du -h ${PB_WORK}/${ZIP_NAME}.zip | awk '{print $1}' )$nocol"
echo -e "$cyan****************************************************************************************$nocol"
fi