-
Notifications
You must be signed in to change notification settings - Fork 34
/
pb_deploy.sh
executable file
·347 lines (295 loc) · 13.6 KB
/
pb_deploy.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
#
# Custom Deploy Script for PBRP
#
# Copyright (C) 2019 - 2020, Manjot Sidhu <[email protected]>
# Rokib Hasan Sagar <[email protected]>
# Mohd Faraz <[email protected]>
# PitchBlack Recovery Project <[email protected]>
#
# 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
#
# Required Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST) VENDOE/OEM(such as xiaomi) CODENAME(such as rolex)
test $# -lt 3 && echo -e "Give Proper arguments\nRequired Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST) VENDOE/OEM(such as xiaomi) CODENAME(such as rolex)" && exit 1;
DEPLOY_TYPE=$1
VENDOR=$2
CODENAME=$3
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'
if [ ! -d "$(pwd)/out/target/product/${CODENAME}/" ]; then
echo -e "${red}Plz Run in the Root of the compilation enviromnent\n${nocol}"
exit 1;
fi
curl https://raw.githubusercontent.com/PitchBlackRecoveryProject/vendor_utils/pb/pb_devices.json > /tmp/pb_devices.json
maintainer=$(python3 vendor/utils/pb_devices.py verify $VENDOR $CODENAME true)
# GitHub Username & Repository Name
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
GH_USER=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f1)
GH_REPO=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f2)
GH_SHA=$(echo ${GITHUB_SHA})
elif [[ "$CIRCLECI" == "true" ]]; then
GH_USER=$(echo ${CIRCLE_PROJECT_USERNAME})
GH_REPO=$(echo ${CIRCLE_PROJECT_REPONAME})
GH_SHA=$(echo ${CIRCLE_SHA1})
else
GH_USER=PitchBlackRecoveryProject
GH_REPO=android_device_${VENDOR}_${CODENAME}-pbrp
GH_SHA=$(cd $(pwd)/device/${VENDOR}/${CODENAME} && git rev-list --branches | head -1)
fi
if [ -z ${GH_BOT_TOKEN} ] || [ -z ${BOT_API} ]; then
echo "Make sure all ENV variables (GH_BOT_TOKEN/BOT_API) are available"
exit -1;
fi
UPLOAD_PATH=$(pwd)/out/target/product/${CODENAME}/upload/
# Version
TWRP_V=$(cat $(pwd)/bootable/recovery/variables.h | egrep "define\s+TW_MAIN_VERSION_STR" | awk '{print $3}' | tr -d '"')
VERSION=$(cat $(pwd)/bootable/recovery/variables.h | egrep "define\s+PB_MAIN_VERSION" | awk '{print $3}' | tr -d '"')
pb_sticker="https://thumbs.gfycat.com/NauticalMellowAlpineroadguidetigerbeetle-mobile.mp4"
# Validate and Prepare for deploy
if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then
# Official Deploy = SF + GHR + WP + TG (Main Channel)
DEPLOY_TYPE_NAME="Official"
RELEASE_TAG=${VERSION}
BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-OFFICIAL.zip 2>/dev/null)
elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then
# Beta Deploy = SF + GHR + WP + TG (Beta Group)
DEPLOY_TYPE_NAME="Beta"
RELEASE_TAG=${VERSION}-beta
BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-BETA.zip 2>/dev/null)
elif [[ "$DEPLOY_TYPE" == "TEST" ]]; then
# Test Deploy = GHR + TG (Device Maintainers Chat)
DEPLOY_TYPE_NAME="Test"
RELEASE_TAG=${VERSION}-test
BUILDFILE=$(find $(pwd)/out/target/product/${CODENAME}/PBRP*-UNOFFICIAL.zip 2>/dev/null)
else
echo -e "Wrong Build Type Given, Required Build Type: OFFICIAL/BETA/TEST" && exit 1
fi
function get_device_name () {
local DEVICE=$(cat /tmp/pb_devices.json | grep $1 -A 3 | grep name | awk -F[\"] '{print $4}')
echo "$DEVICE"
}
function get_vendor () {
echo "$(echo ${1} | cut -d' ' -f1)"
}
# Common Props
BUILD_IMG=$(find $(pwd)/out/target/product/${CODENAME}/recovery.img 2>/dev/null)
MD5=$(md5sum $BUILDFILE | awk '{print $1}')
FILE_SIZE=$( du -h $BUILDFILE | awk '{print $1}' )
BUILD_DATE=$(echo "$BUILDFILE" | awk -F'[-]' '{print $4}')
BUILD_DATETIME="$(echo "$BUILDFILE" | awk -F'[-]' '{print $4}')-$(echo "$BUILDFILE" | awk -F'[-]' '{print $5}')"
TARGET_DEVICE=$(cat /tmp/pb_devices.json | grep ${CODENAME} -A 3 | grep name | awk -F[\"] '{print $4}')
BUILD_NAME=$(echo ${BUILDFILE} | awk -F['/'] '{print $NF}')
DEVICES=$(cat /tmp/pb_devices.json | grep ${CODENAME} -A 3 | grep unified | awk -F[\"] '{ for (i=4; i<NF; i=i+2) print $i }')
# Release Links
gh_link="https://github.com/${GH_USER}/${GH_REPO}/releases/download/${RELEASE_TAG}/${BUILD_NAME}"
sf_link="https://sourceforge.net/projects/pbrp/files/${CODENAME}/$(echo $BUILDFILE | awk -F'[/]' '{print $NF}')/download"
wp_link="https://pitchblackrecovery.com/$(echo $CODENAME | sed "s:_:-:g")"
# Format for TG
FORMAT="PitchBlack Recovery for <b>$TARGET_DEVICE</b> (<code>${CODENAME}</code>)\n\n<b>Info</b>\n\nPitchBlack V${VERSION} <b>${DEPLOY_TYPE_NAME}</b>\nBased on TWRP ${TWRP_V}\n<b>Build Date</b>: <code>${BUILD_DATE:0:4}/${BUILD_DATE:4:2}/${BUILD_DATE:6}</code>\n\n<b>Maintainer</b>: ${maintainer}\n"
if [[ ! -z $CHANGELOG ]]; then
FORMAT=${FORMAT}"\n<b>Changelog</b>:\n"${CHANGELOG}"\n"
fi
FORMAT=${FORMAT}"\n<b>MD5</b>: <code>$MD5</code>\n"
BUTTONS=
#Special format for unifieds
if [ ! -z "$DEVICES" ]; then
UNIFORMAT="PitchBlack Recovery for <b>$(get_vendor $(get_device_name $(echo $DEVICES | cut -d' ' -f1)))</b>"
TAGS=
for i in $DEVICES; do
TARGET_DEVICE=$(cat /tmp/pb_devices.json | grep -i ${i} -A 1 | grep name | awk -F[\"] '{print $4}' | cut -d' ' -f2-)
UNIFORMAT="${UNIFORMAT} <b>$TARGET_DEVICE</b> /"
TAGS="${TAGS}#${i} "
wp_link="https://pitchblackrecovery.com/$(echo $i | sed "s:_:-:g")"
BUTTONS="${BUTTONS}$i|$wp_link!"
done
UNIFORMAT="${UNIFORMAT:0:-1} (<code>${CODENAME}</code>)\n\n<b>Info</b>\n\nPitchBlack V${VERSION} <b>${DEPLOY_TYPE_NAME}</b>\nBased on TWRP ${TWRP_V}\n<b>Build Date</b>: <code>${BUILD_DATE:0:4}/${BUILD_DATE:4:2}/${BUILD_DATE:6}</code>\n\n<b>Maintainer</b>: ${maintainer}\n"
if [[ ! -z $CHANGELOG ]]; then
UNIFORMAT=${UNIFORMAT}"\n<b>Changelog</b>:\n"${CHANGELOG}"\n"
fi
UNIFORMAT=${UNIFORMAT}"\n<b>MD5</b>: <code>$MD5</code>\n\n${TAGS}\n"
FORMAT=$UNIFORMAT
fi
# Deploy on SourceForge
function sf_deploy() {
echo -e "${green}Deploying on SourceForge!\n${nocol}"
# Install sshpass if not installed
chksspb=$(which sshpass 2>/dev/null)
if [[ "$chksspb" != "/usr/bin/sshpass" ]]; then
echo
printf "Sshpass is required but not installed!\n\nInstalling sspass...\n"
echo
ID_LIKE="$(cut -d'=' -f2 <<<$(grep ID_LIKE= /etc/os-release))"
echo
if [ "$ID_LIKE" == "arch" ]; then
sudo pacman -S sshpass --noconfirm
elif [ "$ID_LIKE" = "debian" ]; then
sudo apt-get install sshpass -y
fi
else true;
fi
echo
# SF Details
echo
echo "Build detected for :" $CODENAME
echo "PitchBlack version :" $pbv
echo "Build Date :" $BUILD_DATE
echo "Build Location :" $BUILDFILE
echo "MD5 :" $MD5
echo
if [ -z $SFUserName ]; then
echo -e "${green}Enter SF Username${nocol}"
read SFUserName
fi
if [ -z $SFPassword ]; then
echo -e "${green}Enter SF Password${nocol}"
read -s SFPassword
fi
cd $(pwd)/vendor/utils;
# Check for Official
python3 pb_devices.py verify "$VENDOR" "$CODENAME"
if [[ "$?" == "0" ]]; then
sshpass -p "${SFPassword}" sftp -o StrictHostKeyChecking=no ${SFUserName}@frs.sourceforge.net <<-EOF
cd /home/frs/project/pbrp/
mkdir ${CODENAME}
cd ${CODENAME}
put ${BUILDFILE}
exit
EOF
if [ "$?" == "0" ]; then
echo -e "${green} Deployed On SOURCEFORGE SUCCESSFULLY\n${nocol}"
cd ../../
return 0
else
echo -e "${red} FAILED TO UPLOAD TO SOURCEFORGE\n${nocol}"
cd ../../
return 1
fi
else
echo -e "${red} Device is not Official\n${nocol}"
cd ../../
return 2
fi
}
# Deploy on GitHub Releases
function gh_deploy() {
# Prepare Upload directory for Github Releases
mkdir ${UPLOAD_PATH}
# Copy Required Files
if [[ ! -z ${BUILDFILE} ]]; then
cp $BUILDFILE $UPLOAD_PATH
fi
cp $BUILD_IMG $UPLOAD_PATH
# If Samsung's Odin TAR available, copy it to our upload dir
BUILD_FILE_TAR=$(find $(pwd)/out/target/product/${CODENAME}/*.tar 2>/dev/null)
if [[ ! -z ${BUILD_FILE_TAR} ]]; then
echo "Samsung's Odin Tar available: $BUILD_FILE_TAR"
cp ${BUILD_FILE_TAR} ${UPLOAD_PATH}
fi
# Final Release
ghr -t ${GH_BOT_TOKEN} -u ${GH_USER} -r ${GH_REPO} -n "$(echo $DEPLOY_TYPE_NAME) Release for $(echo $CODENAME)" -b "PBRP $(echo $RELEASE_TAG)" -c ${GH_SHA} -delete ${RELEASE_TAG} ${UPLOAD_PATH}
return "$?"
}
# Deploy Official Build on Official Telegram Channel
function tg_official_deploy() {
echo -e "${green}Deploying to Telegram!\n${nocol}"
if [ -z "$DEVICES" ]; then
python3 vendor/utils/scripts/telegram.py -c @pitchblackrecovery -AN "$pb_sticker" -C "$FORMAT" -D "Download|${wp_link}!Download - SF|${sf_link}!Download - GHR|${gh_link}!Chat|https://t.me/pbrpcom!Channel|https://t.me/pitchblackrecovery" -m "HTML"
else
python3 vendor/utils/scripts/telegram.py -c @pitchblackrecovery -AN "$pb_sticker" -C "$FORMAT" -D "${BUTTONS}Chat|https://t.me/pbrpcom!Channel|https://t.me/pitchblackrecovery" -m "HTML"
fi
echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}"
return 0
}
# Deploy Beta Build on Official PBRP Testing Group
function tg_beta_deploy() {
echo -e "${green}Deploying to Telegram!\n${nocol}"
if [ -z "$DEVICES" ]; then
python3 vendor/utils/scripts/telegram.py -c "-1001270222037" -AN "$pb_sticker" -C "$FORMAT" -D "Download|$wp_link!Download - SF|${sf_link}!Download - GHR|${gh_link}!Beta Chat|https://t.me/pbrp_testers!Channel|https://t.me/joinchat/AAAAAEu2DNXX-P7RgFWBcw" -m "HTML"
else
python3 vendor/utils/scripts/telegram.py -c "-1001270222037" -AN "$pb_sticker" -C "$FORMAT" -D "${BUTTONS}Beta Chat|https://t.me/pbrp_testers!Channel|https://t.me/joinchat/AAAAAEu2DNXX-P7RgFWBcw" -m "HTML"
fi
echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}"
return 0
}
# Deploy Test Build on Official PBRP Device Maintainers Group
function tg_test_deploy() {
echo -e "${green}Deploying to Telegram Device Maintainers Chat!\n${nocol}"
if [ -z ${BUILDFILE} ]; then
TEST_LINK="https://github.com/${GH_USER}/${GH_REPO}/releases/download/${RELEASE_TAG}/recovery.img"
else
TEST_LINK="https://github.com/${GH_USER}/${GH_REPO}/releases/download/${RELEASE_TAG}/$(echo $BUILDFILE | awk -F'[/]' '{print $NF}')"
fi
MAINTAINER_MSG="PitchBlack Recovery for \`${VENDOR}\` \`${CODENAME}\` is available Only For Testing Purpose\n\n"
if [[ ! -z $MAINTAINER ]]; then MAINTAINER_MSG=${MAINTAINER_MSG}"Maintainer: ${MAINTAINER}\n\n"; fi
if [[ ! -z $CHANGELOG ]]; then MAINTAINER_MSG=${MAINTAINER_MSG}"Changelog:\n"${CHANGELOG}"\n\n"; fi
MAINTAINER_MSG=${MAINTAINER_MSG}"Go to ${TEST_LINK} to download it."
if [[ $USE_SECRET_BOOTABLE == 'true' ]]; then
python3 vendor/utils/scripts/telegram.py -c "-1001465331122" -M "$MAINTAINER_MSG" -m "HTML"
else
python3 vendor/utils/scripts/telegram.py -c "-1001228903553" -M "$MAINTAINER_MSG" -m "HTML"
fi
echo -e "${green}Deployed to Telegram SUCCESSFULLY!\n${nocol}"
return 0
}
# Deploy on PBRP Database for WP
# NOTE: Must be called after sf_deploy
function wp_deploy() {
echo -e "${green}Deploying to PBRP Database!\n${nocol}"
curl -i -X POST 'https://us-central1-pbrp-prod.cloudfunctions.net/release' -H "Authorization: Bearer ${GCF_AUTH_KEY}" -H "Content-Type: application/json" --data "{\"codename\": \"$CODENAME\", \"vendor\":\"$VENDOR\", \"md5\": \"$MD5\", \"size\": \"$FILE_SIZE\", \"sf_link\": \"$sf_link\", \"gh_link\": \"$gh_link\",\"version\": \"$VERSION\", \"build_type\": \"$DEPLOY_TYPE\"}"
echo -e "${green}Deployed to PBRP Database SUCCESSFULLY!\n${nocol}"
return 0
}
if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then
zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-OFFICIAL.zip 2>/dev/null | wc -l)
elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then
zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-BETA.zip 2>/dev/null | wc -l)
else
zipcounter=$(find $(pwd)/out/target/product/$CODENAME/PBRP*-UNOFFICIAL.zip 2>/dev/null | wc -l)
fi
recoveryimgcheck=$(find $(pwd)/out/target/product/$CODENAME/recovery.img 2>/dev/null | wc -l)
bootimgcheck=$(find $(pwd)/out/target/product/$CODENAME/boot.img 2>/dev/null | wc -l)
if [[ "$recoveryimgcheck" > "0" || "$bootimgcheck" > "0" ]]; then
if [[ "$zipcounter" > "1" ]]; then
printf "${red}More than one zips dected! Remove old build...\n${nocol}"
else
# Time for Deployment!
if [[ "$DEPLOY_TYPE" == "OFFICIAL" ]]; then
# Official Deploy = SF + GHR + WP + TG (Main Channel)
if ! sf_deploy; then echo -e "Error in SourceForge Deployment." && exit 1; fi
if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi
if ! wp_deploy; then echo -e "Error in PBRP Website Deployment." && exit 1; fi
if ! tg_official_deploy; then echo -e "Error in Telegram Official Deployment." && exit 1; fi
elif [[ "$DEPLOY_TYPE" == "BETA" ]]; then
# Beta Deploy = SF + GHR + WP + TG (Beta Group)
if ! sf_deploy; then echo -e "Error in SourceForge Deployment." && exit 1; fi
if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi
if ! wp_deploy; then echo -e "Error in PBRP Website Deployment." && exit 1; fi
if ! tg_beta_deploy; then echo -e "Error in Telegram Beta Deployment." && exit 1; fi
elif [[ "$DEPLOY_TYPE" == "TEST" ]]; then
# Test Deploy = GHR + TG (Device Maintainers Chat)
if ! gh_deploy; then echo -e "Error in GitHub Releases Deployment." && exit 1; fi
if ! tg_test_deploy; then echo -e "Error in Telegram Test Deployment." && exit 1; fi
else
echo -e "Wrong Arguments Given, Required Arguments: BUILD_TYPE(OFFICIAL/BETA/TEST)" && exit 1
fi
fi
else
echo
printf "${red}No build found\n${nocol}"
echo
fi