-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcr.sh
More file actions
131 lines (107 loc) · 4.15 KB
/
cr.sh
File metadata and controls
131 lines (107 loc) · 4.15 KB
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
#!/bin/bash
# If something explodes, the script stops.
# Not that you'd know how to fix it anyway.
set -e
# Load .env — assuming you actually bothered to create it
if [ -f .env ]; then
set -o allexport
source .env
set +o allexport
else
echo ".env is missing. Make it, genius. This script can't read your mind."
exit 1
fi
# Check required variables — because apparently you forget things
if [ -z "$TG_BOT_TOKEN" ] || [ -z "$TG_CHAT_ID" ] || [ -z "$PIXELDRAIN_API_KEY" ]; then
echo "Some environment variables are missing. Fix your damn .env."
exit 1
fi
# Telegram helper — nothing magical, stop staring
send_telegram_message() {
curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMessage" \
--data-urlencode "chat_id=$TG_CHAT_ID" \
--data-urlencode "text=$1" \
--data-urlencode "parse_mode=Markdown" > /dev/null
}
# If the script dies, we complain dramatically
handle_exit() {
code=$?
if [ $code -ne 0 ]; then
send_telegram_message "*Build Failed*
Exit code: \`$code\` — something blew up. Shockingly, your fault? Probably."
fi
}
trap handle_exit EXIT
send_telegram_message "*Build Started for RMX1971*
If something catches fire, I'll let you know."
BUILD_START_TIME=$(date +%s)
export BUILD_USERNAME=dain
export BUILD_HOSTNAME=crave
echo "Wiping part of out/. It was full of garbage, like your debugging skills."
rm -rf out/target/product/RMX1971/system \
out/target/product/RMX1971/product .repo/local_manifests
echo "Cleanup done."
echo "Initializing crDroidAndroid repo… try not to curse at it."
repo init -u https://github.com/crdroidandroid/android.git -b 15.0 --git-lfs
git clone https://github.com/dain09/local_manifest -b cr .repo/local_manifests
echo "Syncing sources… this will take forever. Go touch grass."
if [ -f "/opt/crave/resync.sh" ]; then
/opt/crave/resync.sh
else
repo sync -c -j$(nproc --all) --force-sync --no-tags --no-clone-bundle
fi
echo "Patch time… prepare for disappointment."
cd frameworks/base
if git log --oneline | grep -qi "dt2w\|double.*tap\|mute"; then
echo "Patch already applied. Congrats, something actually worked."
else
echo "Patch not found, downloading… try not to break anything."
PATCH_URL="https://github.com/kaderbava/android_frameworks_base/commit/efddbe46a8848f52da2f80ce864d1ee51806024b.patch"
wget -O temp.patch "$PATCH_URL" || echo "Couldn't download patch; classic."
if git apply temp.patch; then
git add .
git commit -m "DT2W + mic permission patch"
echo "Patch applied. Miracles do happen."
else
echo "Patch refused to apply. Of course. Moving on."
fi
rm -f temp.patch
fi
cd ../..
echo "Patching done. Somehow."
echo "Starting build environment…"
source build/envsetup.sh
brunch RMX1971 user
send_telegram_message "*Build Finished*
Uploading… unless something dumb happens."
echo "Uploading zip… don't breathe too hard, it might break."
BUILD_END_TIME=$(date +%s)
DURATION=$((BUILD_END_TIME - BUILD_START_TIME))
DURATION_FORMATTED=$(printf '%dh:%dm:%ds' $(($DURATION/3600)) $(($DURATION%3600/60)) $(($DURATION%60)))
OUTPUT_DIR="out/target/product/RMX1971"
ZIP_FILE=$(find "$OUTPUT_DIR" -type f -iname "crDroidAndroid*.zip" -printf "%T@ %p\n" | sort -n | tail -n1 | cut -d' ' -f2-)
if [[ -f "$ZIP_FILE" ]]; then
echo "Uploading to pixeldrain… behave please."
RESPONSE=$(curl -s -u ":$PIXELDRAIN_API_KEY" -X POST -F "file=@$ZIP_FILE" https://pixeldrain.com/api/file)
FILE_ID=$(echo "$RESPONSE" | jq -r '.id')
if [[ "$FILE_ID" != "null" && -n "$FILE_ID" ]]; then
DOWNLOAD_URL="https://pixeldrain.com/u/$FILE_ID"
FILE_NAME=$(basename "$ZIP_FILE")
SIZE=$(stat -c%s "$ZIP_FILE")
SIZE_HUMAN=$(numfmt --to=iec --suffix=B "$SIZE")
NOW=$(date +"%Y-%m-%d %H:%M")
send_telegram_message "*Upload Done*
Build Time: \`$DURATION_FORMATTED\`
File: \`$FILE_NAME\`
Size: $SIZE_HUMAN
Download: $DOWNLOAD_URL"
else
send_telegram_message "*Upload Failed*
Pixeldrain said nope. Typical."
fi
else
send_telegram_message "*No ZIP found after build*
Amazing. Something broke. Again."
fi
echo "Done. If nothing caught fire, consider it a win."
trap - EXIT