forked from spike0en/oneplus_archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.sh
More file actions
executable file
·164 lines (136 loc) · 4.17 KB
/
dump.sh
File metadata and controls
executable file
·164 lines (136 loc) · 4.17 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
#!/bin/bash
#
# SPDX-FileCopyrightText: luk1337
# SPDX-License-Identifier: MIT
# Modified by: spike0en
#
set -ex
# Define path to devices.json
DEVICES_JSON="devices.json"
# Device codename, region, and workflow run URL from arguments
DEVICE_CODENAME="$1"
REGION="$2"
# Define partition categories
BOOT=$(jq -r --arg model "$DEVICE_CODENAME" '.devices[$model].boot_partitions | join(" ")' "$DEVICES_JSON")
FIRMWARE=$(jq -r --arg model "$DEVICE_CODENAME" '.devices[$model].firmware_partitions | join(" ")' "$DEVICES_JSON")
# Get the workflow run URL (last argument)
WORKFLOW_RUN_URL="${!#}"
# Collect OTA URLs into an array, excluding codename, region, and workflow URL
declare -a OTA_URLS
for ((i=3; i<=$#-1; i++)); do
OTA_URLS+=("${!i}")
done
echo "Device Codename: $DEVICE_CODENAME"
echo "Boot Partitions: $BOOT"
echo "Firmware Partitions: $FIRMWARE"
echo "Region: $REGION"
echo "Workflow Run URL: $WORKFLOW_RUN_URL"
# Download ota file using gdown (for Google Drive links)
download_with_gdown() {
echo "Downloading with gdown: $1"
gdown --fuzzy "$1" -O ota.zip
}
# Download ota file using aria2c (for other URLs)
download_with_aria2c() {
echo "Downloading with aria2c: $1"
aria2c -x 16 -s 16 --max-connection-per-server=16 "$1" -o ota.zip
}
# Determine the correct download method based on URL and call it
download_file() {
local url="$1"
echo "Processing URL: $url"
if [[ "$url" == *"drive.google.com"* ]]; then
download_with_gdown "$url"
else
download_with_aria2c "$url"
fi
}
# Check if at least one URL is provided
if [ ${#OTA_URLS[@]} -eq 0 ]; then
echo "Error: No OTA URL provided." >&2
exit 1
fi
# Extract full update
download_file "${OTA_URLS[0]}"
unzip ota.zip payload.bin
mv payload.bin payload_working.bin
TAG="`unzip -p ota.zip META-INF/com/android/metadata | grep ^version_name= | cut -b 14- | sed 's/ /_/g'`"
BODY="[$TAG](${OTA_URLS[0]}) (full)"
rm ota.zip
mkdir ota
(
./bin/ota_extractor -output_dir ota -payload payload_working.bin
rm payload_working.bin
) & # Allow subsequent downloads to be done in parallel
# Apply incrementals
for i in "${OTA_URLS[@]:1}"; do # Iterate from the second URL
download_file "$i"
unzip ota.zip payload.bin
wait
mv payload.bin payload_working.bin
TAG="`unzip -p ota.zip META-INF/com/android/metadata | grep ^version_name= | cut -b 14- | sed 's/ /_/g'`"
BODY="$BODY -> [$TAG]($i)"
rm ota.zip
(
mkdir ota_new
./bin/ota_extractor -input-dir ota -output_dir ota_new -payload payload_working.bin
rm -rf ota
mv ota_new ota
rm payload_working.bin
) & # Allow subsequent downloads to be done in parallel
done
wait
# Prepare output folders
mkdir -p out boot firmware
# Generate SHA-256 hashes for all extracted image files with parallel processing
echo "--- SHA256 Hashes ---"
cd ota
ls * | parallel -j $(nproc) "openssl dgst -sha256 -r" 2>/dev/null | sort -k2 -V | tee ../out/${TAG}_${REGION}-hash.sha256
# === Organize Images ===
echo "Organizing images..."
# Move boot-related images
for img in $BOOT; do
if [ -f "${img}.img" ]; then
mv "${img}.img" ../boot/
fi
done
# Move firmware-related images
for img in $FIRMWARE; do
if [ -f "${img}.img" ]; then
mv "${img}.img" ../firmware/
fi
done
# === Archive Images ===
echo "Archiving images using optimized compression settings..."
# Archive boot, firmware and logical images in parallel
(
cd ../boot
7z a -mx6 -mmt$(nproc) ../out/${TAG}_${REGION}-boot.7z *
) &
(
cd ../firmware
7z a -mx6 -mmt$(nproc) ../out/${TAG}_${REGION}-firmware.7z *
) &
(
cd ../ota
7z a -mx6 -mmt$(nproc) -v1900m ../out/${TAG}_${REGION}-logical.7z *
) &
wait
# Sanitize filenames for release assets
cd ../out
for f in *; do
safe_name=$(echo "$f" | sed 's/(/-/' | sed 's/)//g')
if [ "$f" != "$safe_name" ]; then
mv "$f" "$safe_name"
fi
done
cd ..
# Cleanup
rm -rf ota boot firmware
# Echo tag name and release body
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "body<<EOF" >> "$GITHUB_OUTPUT"
echo "$BODY" >> "$GITHUB_OUTPUT"
echo "" >> "$GITHUB_OUTPUT"
echo "**Workflow Run**: [Here]($WORKFLOW_RUN_URL)" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"