-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAviumUI.sh
More file actions
198 lines (156 loc) · 6.63 KB
/
AviumUI.sh
File metadata and controls
198 lines (156 loc) · 6.63 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
#!/bin/bash
# =================================================================
# AviumUI Build Script
# =================================================================
#
# Stop the script immediately if any command fails
set -e
# =======================
# SETUP & PRE-CHECKS
# =======================
# Load environment variables from .env file
if [ -f .env ]; then
set -o allexport
source .env
set +o allexport
else
echo "Error: .env file not found! Create one with your secrets."
exit 1
fi
# Check for required secrets
if [ -z "$GITHUB_TOKEN" ] || [ -z "$TG_BOT_TOKEN" ] || [ -z "$TG_CHAT_ID" ] || [ -z "$PIXELDRAIN_API_KEY" ]; then
echo "Error: One or more required variables are missing in your .env file."
echo "Required: GITHUB_TOKEN, TG_BOT_TOKEN, TG_CHAT_ID, PIXELDRAIN_API_KEY"
exit 1
fi
# Telegram notification function
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
}
# Trap to send a notification on script failure
handle_exit() {
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
send_telegram_message "❌ *Build Failed!*
The script exited with a non-zero status code: \`$EXIT_CODE\`.
Please check the logs for the exact error."
fi
}
trap handle_exit EXIT
# Send "Build Started" notification
send_telegram_message "🚀 *New Build Started for RMX1971!*
The build process has been initiated. I will notify you upon completion or failure."
# === Exports ===
BUILD_START_TIME=$(date +%s)
export BUILD_USERNAME=dain
export BUILD_HOSTNAME=crave
# =======================
# 1. CLEANUP SECTION
# =======================
echo "Cleaning up cloned repositories..."
rm -rf prebuilts/clang/host/linux-x86/clang-proton
rm -rf device/realme/RMX1971
rm -rf vendor/realme/RMX1971
rm -rf kernel/realme/sdm710
rm -rf packages/apps/ViPER4AndroidFX
rm -rf vendor/lineage-priv/keys
echo "Performing selective cleanup of 'out' directory..."
rm -rf out/target/product/RMX1971/system
rm -rf out/target/product/RMX1971/product
echo "Cleanup finished."
# =======================
# 2. REPO INITIALIZATION & SYNC
# =======================
#echo "Initializing Axion repository..."
#repo init -u https://github.com/AviumUI/android_manifests -b avium-16 --git-lfs
#echo "Syncing sources..."
#if [ -f "/opt/crave/resync.sh" ]; then
# /opt/crave/resync.sh
#else
# repo sync -c --force-sync --no-clone-bundle --no-tags -j$(nproc --all)
#fi
# =======================
# 3. APPLYING CHERRY-PICKS
# =======================
# Mic Fix
echo ">>> Applying frameworks/base patch..." && cd frameworks/base && (git log --oneline | grep -q "dt2w\|DT2W\|double.*tap" || (wget -O temp.patch "https://github.com/ij-project/frameworks_base_evox/commit/c49d293.patch" && (git apply temp.patch && git add . && git commit -m "Apply DT2W patch" || echo "Patch conflicts detected, continuing build...") && rm -f temp.patch)) && cd ../.. && echo ">>> Frameworks/base patch process completed!"
# =======================
# 4. CLONING ADDITIONAL REPOSITORIES
# =======================
echo "Cloning additional repositories..."
git clone https://github.com/kdrag0n/proton-clang --depth 1 prebuilts/clang/host/linux-x86/clang-proton
git clone https://github.com/dain09/device_realme_RMX1971 -b 16-Avium --depth 1 device/realme/RMX1971
git clone https://github.com/dain09/vendor_realme_RMX1971 --depth 1 -b 16 vendor/realme/RMX1971
git clone https://github.com/dain09/android_kernel_realme_sdm710-fork -b 16-r5p --depth 1 kernel/realme/sdm710
git clone https://github.com/TogoFire/packages_apps_ViPER4AndroidFX.git -b v4a packages/apps/ViPER4AndroidFX
rm -rf system/netd
git clone https://github.com/kaderbava/android_system_netd -b 16 --depth 1 system/netd
rm -rf system/bpf
git clone https://github.com/kaderbava/android_system_bpf -b 16 --depth 1 system/bpf
rm -rf packages/modules/Connectivity
git clone https://github.com/kaderbava/android_packages_modules_Connectivity -b 16 --depth 1 packages/modules/Connectivity
rm -rf hardware/lineage/compat
git clone https://github.com/hzosprj/android_hardware_lineage_compat -b 16 --depth 1 hardware/lineage/compat
# =======================
# 5. SETUP SIGNING KEYS
# =======================
echo "Setting up private signing keys..."
mkdir -p vendor/lineage-priv/keys
git clone https://${GITHUB_TOKEN}@github.com/dain09/Sign_keys vendor/lineage-priv/keys
# =======================
# 6. BUILD THE ROM
# =======================
echo "Starting the build process..."
. build/envsetup.sh
lunch lineage_RMX1971-bp2a-userdebug
echo "Running 'm installclean' for a safe build..."
m installclean
echo "Starting the main build..."
m bacon -j$(nproc --all)
send_telegram_message "✅ *Build Finished Successfully!*
Now preparing to upload the file..."
# =======================
# 7. UPLOAD THE BUILD
# =======================
echo "Starting the upload process..."
# === Stop Build Timer and Calculate Duration ===
BUILD_END_TIME=$(date +%s)
DURATION=$((BUILD_END_TIME - BUILD_START_TIME))
DURATION_FORMATTED=$(printf '%dh:%dm:%ds\n' $(($DURATION/3600)) $(($DURATION%3600/60)) $(($DURATION%60)))
OUTPUT_DIR="out/target/product/RMX1971"
ZIP_FILE=$(find "$OUTPUT_DIR" -type f -iname "AviumUI-16*.zip" -printf "%T@ %p\n" | sort -n | tail -n1 | cut -d' ' -f2-)
if [[ -f "$ZIP_FILE" ]]; then
echo "Uploading $ZIP_FILE to Pixeldrain..."
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")
FILE_SIZE_BYTES=$(stat -c%s "$ZIP_FILE")
FILE_SIZE_HUMAN=$(numfmt --to=iec --suffix=B "$FILE_SIZE_BYTES")
UPLOAD_DATE=$(date +"%Y-%m-%d %H:%M")
echo "Upload successful: $DOWNLOAD_URL"
UPLOAD_MESSAGE="🎉 *RMX1971 Upload Complete!*
*Build Time:* \`$DURATION_FORMATTED\`
📎 *Filename:* \`$FILE_NAME\`
📦 *Size:* $FILE_SIZE_HUMAN
🕓 *Uploaded:* $UPLOAD_DATE
🔗 [Download Link]($DOWNLOAD_URL)"
send_telegram_message "$UPLOAD_MESSAGE"
else
echo "Upload failed. Pixeldrain response: $RESPONSE"
send_telegram_message "❌ *Upload Failed!*
The build was successful, but the upload to Pixeldrain failed.
*Response:* \`$RESPONSE\`"
fi
else
echo "Error: No .zip file found in $OUTPUT_DIR"
send_telegram_message "❌ *Upload Failed!*
The build seemed to complete, but no .zip file was found in \`$OUTPUT_DIR\`."
fi
echo "Script finished."
# Unset the trap explicitly for a clean successful exit
trap - EXIT