-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathworker.sh
More file actions
executable file
·152 lines (126 loc) · 5.31 KB
/
worker.sh
File metadata and controls
executable file
·152 lines (126 loc) · 5.31 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
#!/bin/bash
set -x
# Load helper scripts
source "$WDIR/images.conf"
source "$WDIR/tools/gofile.sh"
export PATH="$PATH:$WDIR/lptools"
# Override config with environment variables if set
[ -n "$WORKFLOW_MODE" ] && WORKFLOW_MODE="$WORKFLOW_MODE"
[ -n "$STORAGE_FRIENDLY" ] && STORAGE_FRIENDLY="$STORAGE_FRIENDLY"
extract() {
cd "$WDIR/Downloads"
echo -e "\n${MINT_GREEN}[+] Selectively extracting required firmware files...${RESET}\n"
# Define required files to extract
required_files=("${REQUIRED_IMAGES[@]}")
if [ ${#REQUIRED_LOGICAL_IMAGES[@]} -gt 0 ]; then
required_files+=("super.img")
fi
# Extract only .tar.md5 files from zip
unzip firmware.zip "*.tar.md5" && rm firmware.zip
# Extract required files from each tar
for file in *.tar.md5; do
tar_files=$(tar -tf "$file")
to_extract=()
for req in "${required_files[@]}"; do
if echo "$tar_files" | grep -q "^$req$"; then
to_extract+=("$req")
fi
if echo "$tar_files" | grep -q "^$req.lz4$"; then
to_extract+=("$req.lz4")
fi
done
if [ ${#to_extract[@]} -gt 0 ]; then
tar -xvf "$file" "${to_extract[@]}"
fi
done
rm -rf *.tar.md5
# Decompress only required .lz4 files
for req in "${required_files[@]}"; do
if [ -e "$req.lz4" ]; then
echo -e "${LIGHT_YELLOW}[i] Decompressing $req.lz4${RESET}"
lz4 -d "$req.lz4" "$req" && rm "$req.lz4"
fi
done
# Convert super.img if it's sparse and logical partitions are defined
if [ -e "super.img" ] && [ ${#REQUIRED_LOGICAL_IMAGES[@]} -gt 0 ]; then
if file super.img | grep -q "Android sparse image"; then
echo -e "${MINT_GREEN}[+] Converting sparse super.img to raw...${RESET}\n"
simg2img super.img super_raw.img && mv super_raw.img super.img
fi
fi
# Storage-friendly cleanup: remove any remaining unnecessary files
if [ "${STORAGE_FRIENDLY:-0}" = "1" ]; then
echo -e "${LIGHT_YELLOW}[i] Storage-friendly mode: Cleaning up unnecessary files...${RESET}"
for file in *; do
if [[ "$file" == super.img ]] && [ ${#REQUIRED_LOGICAL_IMAGES[@]} -gt 0 ]; then
continue
fi
if [[ " ${required_files[@]} " =~ " ${file} " ]]; then
continue
fi
if [ -f "$file" ]; then
rm -f "$file"
fi
done
fi
echo -e "\n${LIGHT_YELLOW}[i] Selective extraction completed..!${RESET}"
}
collect_and_package_files() {
echo -e "${MINT_GREEN}[+] Copying the Required stock files for Magisk...${RESET}\n"
# Create output directory if it doesn't exist
mkdir -p "$WDIR/output"
# Extract logical partitions from super.img if it exists
cd "$WDIR/Downloads"
if [ -e "super.img" ] && [ ${#REQUIRED_LOGICAL_IMAGES[@]} -gt 0 ]; then
echo -e "${MINT_GREEN}[+] Extracting logical partitions...${RESET}\n"
for partition in "${REQUIRED_LOGICAL_IMAGES[@]}"; do
if [ -n "$partition" ]; then
partition_name="${partition%.img}"
echo -e "${LIGHT_YELLOW}[i] Extracting ${partition_name}.img${RESET}"
lpunpack "-p=${partition_name}" super.img
if [ -e "${partition_name}.img" ]; then
echo -e "${LIGHT_YELLOW}[i] Copying ${partition_name}.img${RESET}"
cp "${partition_name}.img" "$WDIR/output/"
else
echo -e "${LIGHT_RED}[!] ${partition_name}.img not found after extraction${RESET}"
fi
fi
done
echo -e "\n${LIGHT_YELLOW}[i] Logical partition extraction completed.${RESET}\n"
# Storage-friendly cleanup: remove super.img after logical extraction
if [ "${STORAGE_FRIENDLY:-0}" = "1" ]; then
echo -e "${LIGHT_YELLOW}[i] Storage-friendly mode: Removing super.img after logical extraction...${RESET}"
rm -f "$WDIR/Downloads/super.img"
fi
fi
# Copy all existing required images to output directory
for img in "${REQUIRED_IMAGES[@]}"; do
if [ -e "$img" ]; then
echo -e "${LIGHT_YELLOW}[i] Copying $img${RESET}"
cp "$img" "$WDIR/output/"
fi
done
# Storage-friendly cleanup: remove Downloads after copying required files
if [ "${STORAGE_FRIENDLY:-0}" = "1" ]; then
echo -e "${LIGHT_YELLOW}[i] Storage-friendly mode: Removing Downloads directory after copying files...${RESET}"
rm -rf "$WDIR/Downloads"
fi
# If not in workflow mode, skip packaging and uploading
if [ "${WORKFLOW_MODE:-0}" != "1" ]; then
echo -e "\n${LIGHT_YELLOW}[i] Images extracted to output directory (extract only mode)${RESET}\n"
return
fi
# Create the tar file with all image files
cd "$WDIR/output"
TAR_NAME="${MODEL}-Magisk-files.tar"
tar -cvf "$TAR_NAME" *.img && rm *.img
# Create maximum compressed zip from the tar file
mkdir -p "$WDIR/Dist"
zip -9 "$WDIR/Dist/${TAR_NAME}.zip" "$TAR_NAME"
rm "$TAR_NAME"
echo -e "\n${LIGHT_YELLOW}[i] Zip file created: ${TAR_NAME}.zip${RESET}\n"
upload_to_gofile "$WDIR/Dist/${TAR_NAME}.zip"
}
# Main execution
extract
collect_and_package_files