-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolution.sh
More file actions
310 lines (271 loc) Β· 9.33 KB
/
Copy pathevolution.sh
File metadata and controls
310 lines (271 loc) Β· 9.33 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
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
#!/bin/bash
# Script by Dain using aistudio
set -e
# --- 1. System Configuration ---
echo "π Setting System Timezone to Cairo..."
sudo rm -f /etc/localtime
sudo ln -s /usr/share/zoneinfo/Africa/Cairo /etc/localtime
BUILD_LOG="build.log"
ERROR_LOG="error_log.txt"
# --- 2. Load Environment ---
if [ -f .env ]; then
set -o allexport
source .env
set +o allexport
else
echo "β .env is missing!"
exit 1
fi
# Validation
if [ -z "$TG_BOT_TOKEN" ] || [ -z "$TG_CHAT_ID" ] || [ -z "$PIXELDRAIN_API_KEY" ]; then
echo "β Missing variables in .env"
exit 1
fi
# Ensure jq is installed
if ! command -v jq &> /dev/null; then
mkdir -p ~/bin
curl -L -o ~/bin/jq https://github.com/jqlang/jq/releases/download/jq-1.7/jq-linux64
chmod +x ~/bin/jq
export PATH=$HOME/bin:$PATH
fi
# --- 3. Helper Functions ---
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" \
--data-urlencode "disable_web_page_preview=true" > /dev/null
}
send_telegram_return_json() {
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" \
--data-urlencode "disable_web_page_preview=true"
}
edit_telegram_message() {
local msg_id=$1
local text=$2
curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/editMessageText" \
--data-urlencode "chat_id=$TG_CHAT_ID" \
--data-urlencode "message_id=$msg_id" \
--data-urlencode "text=$text" \
--data-urlencode "parse_mode=Markdown" \
--data-urlencode "disable_web_page_preview=true" > /dev/null
}
send_telegram_file() {
local file_path="$1"
local caption="$2"
curl -s -F "chat_id=$TG_CHAT_ID" \
-F "document=@$file_path" \
-F "caption=$caption" \
"https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument" > /dev/null
}
upload_to_pixeldrain() {
local file_path=$1
local name=$2
if [ -f "$file_path" ]; then
RESPONSE=$(curl -s -u ":$PIXELDRAIN_API_KEY" -X POST -F "file=@$file_path" https://pixeldrain.com/api/file)
FILE_ID=$(echo "$RESPONSE" | jq -r '.id')
if [[ "$FILE_ID" != "null" && -n "$FILE_ID" ]]; then
echo "https://pixeldrain.com/u/$FILE_ID"
else
echo "error"
fi
else
echo "missing"
fi
}
handle_exit() {
code=$?
if [ ! -z "$MONITOR_PID" ]; then kill $MONITOR_PID 2>/dev/null; fi
if [ $code -ne 0 ]; then
if [ -f "$BUILD_LOG" ]; then
tail -n 200 "$BUILD_LOG" > "$ERROR_LOG"
send_telegram_message "π¨ *Build Failed!* β
Exit code: \`$code\`
See the attached log. π"
send_telegram_file "$ERROR_LOG" "Error Log Snippet"
else
send_telegram_message "π¨ *Build Failed!* (No Log)"
fi
fi
}
trap handle_exit EXIT
# --- 4. Build Environment Setup ---
export BUILD_USERNAME=dain
export BUILD_HOSTNAME=crave
export KBUILD_BUILD_USER=dain
export KBUILD_BUILD_HOST=crave
export USER=dain
export HOSTNAME=crave
# --- 5. Script Start ---
START_DISK=$(df -h . | awk 'NR==2 {print $4}')
send_telegram_message "π *Build Started for RMX1971*
User: \`$BUILD_USERNAME\`
Free Space: \`$START_DISK\`
Time: \`$(date '+%I:%M %p')\`"
BUILD_START_TIME=$(date +%s)
# Clean
echo "π§Ή Cleaning up..."
rm -rf out/target/product/RMX1971/system \
out/target/product/RMX1971/product .repo/local_manifests
rm -f "$BUILD_LOG" "$ERROR_LOG" ota.json
# Repo Init & Sync
echo "π Initializing Repo..."
repo init -u https://github.com/Evolution-X/manifest -b vic --git-lfs
git clone https://github.com/dain09/local_manifest -b evolution .repo/local_manifests
echo "β¬οΈ Syncing..."
SYNC_START=$(date +%s)
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
SYNC_END=$(date +%s)
SYNC_DIFF=$((SYNC_END - SYNC_START))
send_telegram_message "β
*Sync Completed* in $((SYNC_DIFF / 60)) mins.
Proceeding to patches..."
# Frameworks Patch
echo "π§ Checking Frameworks Patch..."
cd frameworks/base
rm -f temp.patch
if git log --oneline | grep -qi "dt2w\|double.*tap\|mute"; then
echo "β
Frameworks patch already applied."
else
echo "π₯ Downloading Frameworks patch..."
PATCH_URL="https://github.com/kaderbava/android_frameworks_base/commit/efddbe46a8848f52da2f80ce864d1ee51806024b.patch"
wget -q -O temp.patch "$PATCH_URL" || { echo "β Failed to download patch"; exit 1; }
if git apply temp.patch; then
git add .
git commit -m "DT2W + mic permission patch"
echo "β
Frameworks patch applied."
else
echo "β Failed to apply Frameworks patch!"
exit 1
fi
rm -f temp.patch
fi
cd ../..
# Soong Patch
echo "π§ Checking Soong Fixes..."
cd build/soong
rm -f temp.patch
if git log --oneline | grep -qi "Fix disallowed 'date'\|tar tool usage"; then
echo "β
Soong fix already applied."
else
echo "π₯ Downloading Soong patch..."
PATCH_URL="https://github.com/dain09/build_soong/commit/0184bf758d3b2a5ebe2d9aa92535212b719129ca.patch"
wget -q -O temp.patch "$PATCH_URL" || { echo "β Failed to download Soong patch"; exit 1; }
if git apply temp.patch; then
git add .
git commit -m "soong: Fix disallowed 'date' and 'tar' tool usage"
echo "β
Soong patch applied."
else
echo "β Failed to apply Soong patch!"
exit 1
fi
rm -f temp.patch
fi
cd ../..
# Build with Live Monitor
echo "ποΈ Starting Build..."
. build/envsetup.sh
lunch lineage_RMX1971-bp1a-user
MSG_JSON=$(send_telegram_return_json "ποΈ *Compiling RMX1971...*
Status: \`Initializing...\`")
MSG_ID=$(echo "$MSG_JSON" | jq -r '.result.message_id')
live_monitor() {
local msg_id=$1
while true; do
sleep 60
if [ -f "$BUILD_LOG" ]; then
PROGRESS=$(tail -n 5 "$BUILD_LOG" | grep -o '\[.*\]' | tail -n 1)
if [[ ! -z "$PROGRESS" ]]; then
edit_telegram_message "$msg_id" "ποΈ *Compiling RMX1971...*
Status: \`$PROGRESS\`
_Last Update: $(date +'%I:%M %p')_"
fi
fi
done
}
live_monitor "$MSG_ID" &
MONITOR_PID=$!
set -o pipefail
m evolution 2>&1 | tee "$BUILD_LOG"
kill $MONITOR_PID 2>/dev/null
MONITOR_PID=""
# --- 6. Post-Build & Upload ---
echo "π€ Build finished, processing artifacts..."
edit_telegram_message "$MSG_ID" "β
*Build Finished!*
Processing & Uploading..."
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)))
END_DISK=$(df -h . | awk 'NR==2 {print $4}')
OUTPUT_DIR="out/target/product/RMX1971"
ZIP_FILE=$(find "$OUTPUT_DIR" -type f -name "EvolutionX-15.0*.zip" -mmin -260 -printf "%T@ %p\n" | sort -n | tail -n1 | cut -d' ' -f2-)
BOOT_IMG=$(find "$OUTPUT_DIR" -type f -name "boot.img" -mmin -260 | head -n 1)
if [[ -f "$ZIP_FILE" ]]; then
MD5SUM=$(md5sum "$ZIP_FILE" | awk '{print $1}')
FILE_NAME=$(basename "$ZIP_FILE")
SIZE=$(stat -c%s "$ZIP_FILE")
SIZE_HUMAN=$(numfmt --to=iec --suffix=B "$SIZE")
# Build the initial part of the message
FINAL_MESSAGE="β
*Build Success!* π\n\n"
FINAL_MESSAGE+="β±οΈ *Time:* \`$DURATION_FORMATTED\`\n"
FINAL_MESSAGE+="πΎ *Size:* \`$SIZE_HUMAN\`\n"
FINAL_MESSAGE+="π¦ *File:* \`$FILE_NAME\`\n"
FINAL_MESSAGE+="π‘οΈ *MD5:* \`$MD5SUM\`\n"
FINAL_MESSAGE+="πΌ *Disk Left:* \`$END_DISK\`\n\n"
FINAL_MESSAGE+="π± *Downloads:*\n"
# Upload ZIP and check the result
ZIP_URL=$(upload_to_pixeldrain "$ZIP_FILE" "ROM")
if [[ "$ZIP_URL" == "error" || "$ZIP_URL" == "missing" ]]; then
FINAL_MESSAGE+="πΉ ROM ZIP: Upload Failed β\n"
else
FINAL_MESSAGE+="πΉ [ROM ZIP]($ZIP_URL)\n"
fi
# Upload Boot Image and check the result
BOOT_URL=$(upload_to_pixeldrain "$BOOT_IMG" "BOOT")
if [[ "$BOOT_URL" == "error" || "$BOOT_URL" == "missing" ]]; then
FINAL_MESSAGE+="πΉ Boot Image: Upload Failed or Not Found β\n"
else
FINAL_MESSAGE+="πΉ [Boot Image]($BOOT_URL)\n"
fi
# Generate OTA JSON only if ZIP upload was successful
if [[ "$ZIP_URL" != "error" && "$ZIP_URL" != "missing" ]]; then
TIMESTAMP=$(date +%s)
cat <<EOF > ota.json
{
"response": [
{
"datetime": $TIMESTAMP,
"filename": "$FILE_NAME",
"id": "$MD5SUM",
"romtype": "unofficial",
"size": $SIZE,
"url": "$ZIP_URL",
"version": "15.0"
}
]
}
EOF
JSON_URL=$(upload_to_pixeldrain "ota.json" "OTA Config")
if [[ "$JSON_URL" == "error" || "$JSON_URL" == "missing" ]]; then
FINAL_MESSAGE+="πΉ OTA JSON: Upload Failed β\n"
else
FINAL_MESSAGE+="πΉ [OTA JSON]($JSON_URL)\n"
fi
else
FINAL_MESSAGE+="πΉ OTA JSON: Not Generated (ROM upload failed)\n"
fi
# Add footer and send the complete message
FINAL_MESSAGE+="\ncc: @D_ai_n"
send_telegram_message "$FINAL_MESSAGE"
else
send_telegram_message "β *Build Failed (No ZIP)*
Build command finished, but no new ZIP file was found."
fi
trap - EXIT
echo "β
Done."