-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdump.sh
executable file
·119 lines (95 loc) · 3.43 KB
/
dump.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
#!/bin/bash
# Script has been modified by Spike for additional functionality and clarity, originally by arter97 and luk1337.
# Print every command and exit immediately on failure
set -ex
# Set execute permissions for ota_extractor
chmod +x ./bin/ota_extractor
# Download OTA firmware with aria2c or gdown based on the link format, renaming it to ota.zip
download_with_gdown() {
echo "Downloading with gdown: $1"
gdown --fuzzy "$1" -O ota.zip
}
download_with_aria2c() {
echo "Downloading with aria2c: $1"
aria2c -x5 "$1" -o ota.zip
}
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
}
# Exit if no URL is provided
if [ -z "$1" ]; then
echo "No URL provided."
exit 1
fi
# Download the main OTA firmware
download_file "$1"
# Extract and process payload
unzip ota.zip payload.bin || { echo "Failed to unzip payload"; exit 1; }
mv payload.bin payload_working.bin
TAG=$(unzip -p ota.zip payload_properties.txt | grep ^POST_OTA_VERSION= | cut -b 18-)
BODY="[$TAG]($1) (full)"
rm ota.zip
# Create `ota` directory
mkdir -p ota
# Perform extraction on payload_working.bin
./bin/ota_extractor -output_dir ota -payload payload_working.bin || { echo "Failed to extract payload"; exit 1; }
rm payload_working.bin
# Apply incrementals when available
for i in "${@:2}"; do
download_file "$i"
unzip ota.zip payload.bin || { echo "Failed to unzip incremental payload"; exit 1; }
mv payload.bin payload_working.bin
TAG=$(unzip -p ota.zip payload_properties.txt | grep ^POST_OTA_VERSION= | cut -b 18-)
BODY="$BODY -> [$TAG]($i)"
rm ota.zip
mkdir ota_new
./bin/ota_extractor -input-dir ota -output_dir ota_new -payload payload_working.bin || { echo "Failed to extract incremental payload"; exit 1; }
rm -rf ota
mv ota_new ota
rm payload_working.bin
done
# Create required directories
mkdir -p out dyn syn
# Switch to `ota` directory
cd ota
# Generate hashes for all files in the `ota` directory and send them to `out` (tagged with `-hash`)
for h in md5 sha1 sha256 xxh128; do
if [ "$h" = "xxh128" ]; then
ls * | parallel xxh128sum | sort -k2 -V > ../out/${TAG}-hash.$h
else
ls * | parallel "openssl dgst -${h} -r" | sort -k2 -V > ../out/${TAG}-hash.$h
fi
done
# Move the `boot` category image files from `ota` to `syn` directory
for f in boot dtbo recovery vendor_boot vbmeta; do
mv ${f}.img ../syn
done
# Move the `logical` category image files from `ota` to `syn` directory
for f in system system_ext product vendor vendor_dlkm odm vbmeta_system vbmeta_vendor; do
mv ${f}.img ../dyn
done
# Switch to `syn` directory and create a 7z archive for `boot` categorty image files tagged with "-boot"
cd ../syn
7z a -mmt4 -mx6 ../out/${TAG}-image-boot.7z *
# Delete `syn` directory
rm -rf ../syn
# Switch to `ota` directory and create a 7z archive for `firmware` category image files tagged with "-firmware"
cd ../ota
7z a -mmt4 -mx6 ../out/${TAG}-image-firmware.7z *
# Delete `ota` directory
rm -rf ../ota
# Switch to `dyn` directory and create a split 7z archive for `logical` category image files tagged with "-logical"
cd ../dyn
7z a -mmt4 -mx6 -v1g ../out/${TAG}-image-logical.7z *
wait
# Delete `dyn` directory
rm -rf ../dyn
# Echo tag name, release body, and release history
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "body=$BODY" >> "$GITHUB_OUTPUT"