forked from Wishmasterflo/Firmware_flasher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepack.bat
182 lines (154 loc) · 5.54 KB
/
repack.bat
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
:: SPDX-FileCopyrightText: spike0en
:: SPDX-License-Identifier: MIT
@echo off
setlocal enabledelayedexpansion
title Pong Flashable Firmware Repacker Script
:: ###################
:: Script Information
:: ###################
echo.
echo ###############################################################
echo # Pong Flashable Firmware Repacker #
echo # Firmware Repo: https://github.com/spike0en/nothing_archive #
echo # Author: Spike (spike0en) #
echo ###############################################################
echo.
:: ##########################
:: Ask if 7-Zip is installed
:: ##########################
echo.
set /p install_7zip="Is 7-Zip installed on your system? (Y/N): "
if /i "%install_7zip%"=="Y" (
echo Proceeding with the script...
) else (
echo Please install 7-Zip and run the script again.
echo You can download it from: https://www.7-zip.org/
pause
exit /b
)
:: #################################
:: Get the current script directory
:: #################################
echo.
set script_dir=%~dp0
echo Script Directory: %script_dir%
echo.
:: #############################
:: Prepare Required Directories
:: #############################
echo.
:: Check if the firmware-update directory exists, delete it if it does,
:: and then create a new one.
if exist "%script_dir%firmware-update" (
echo Deleting existing firmware-update directory...
rd /s /q "%script_dir%firmware-update"
)
mkdir "%script_dir%firmware-update" || (
echo Failed to create firmware-update directory. Exiting...
pause
exit /b
)
:: Check if the tmp directory exists, delete it if it does, and create a new one.
if exist "%script_dir%tmp" (
echo Deleting existing tmp directory...
rd /s /q "%script_dir%tmp"
)
mkdir "%script_dir%tmp" || (
echo Failed to create tmp directory. Exiting...
pause
exit /b
)
:: ############################################
:: Ask for URL(s) (Boot & Firmware Categories)
:: ############################################
echo.
echo Please enter the URL for the boot category (-image-boot.7z).
echo Example: https://github.com/spike0en/nothing_archive/releases/download/3.0.0-pong.250113/Pong_V3.0-250113-1723-image-boot.7z
set /p boot_url="Enter the URL for the boot category: "
echo.
echo Please enter the URL for the firmware category (-image-firmware.7z).
echo Example: https://github.com/spike0en/nothing_archive/releases/download/3.0.0-pong.250113/Pong_V3.0-250113-1723-image-firmware.7z
set /p firmware_url="Enter the URL for the firmware category: "
echo.
:: ############################
:: Extract Filenames from URLs
:: ############################
for %%a in ("%boot_url%") do set boot_filename=%%~nxa
for %%a in ("%firmware_url%") do set firmware_filename=%%~nxa
echo Boot category file will be saved as: %boot_filename%
echo Firmware category file will be saved as: %firmware_filename%
echo.
:: ###############
:: Download Files
:: ###############
echo.
echo Downloading boot category file from: %boot_url%...
curl -L -o "%script_dir%tmp\%boot_filename%" %boot_url%
echo Downloading firmware category file from: %firmware_url%...
curl -L -o "%script_dir%tmp\%firmware_filename%" %firmware_url%
echo.
:: ############################
:: Extract downloaded 7z Files
:: ############################
echo.
echo Extracting boot category file...
"c:\Program Files\7-Zip\7z.exe" x "%script_dir%tmp\%boot_filename%" -o"%script_dir%tmp" -y >nul || (
echo Failed to extract boot category file. Exiting...
pause
exit /b
)
echo Extracting firmware category file...
"c:\Program Files\7-Zip\7z.exe" x "%script_dir%tmp\%firmware_filename%" -o"%script_dir%tmp" -y >nul || (
echo Failed to extract firmware category file. Exiting...
pause
exit /b
)
:: ########################################
:: Cleanup recovery and vbmeta image files
:: ########################################
echo.
echo Deleting unnecessary files (recovery.img and vbmeta.img)...
del "%script_dir%tmp\recovery.img" >nul 2>&1
del "%script_dir%tmp\vbmeta.img" >nul 2>&1
:: ############################
:: Remove Downloaded .7z Files
:: ############################
echo.
echo Cleaning up downloaded .7z files...
del "%script_dir%tmp\%boot_filename%"
del "%script_dir%tmp\%firmware_filename%"
:: ##############################################
:: Move image files to firmware-update directory
:: ##############################################
echo.
echo Moving .img files to firmware-update directory...
move /Y "%script_dir%tmp\*.img" "%script_dir%firmware-update\"
:: Cleanup temporary directory
rd /s /q "%script_dir%tmp"
:: ##############################
:: Set Build Number for Firmware
:: ##############################
echo.
set /p build_no="Enter the build number for the firmware (e.g., Pong-V3.0-250113-1723): "
echo You entered: %build_no%
echo.
:: #########################################################
:: Archiving firmware package into a recovery flashable zip
:: #########################################################
echo.
echo Compressing firmware-update and META-INF directories into a zip file...
:: Set the output zip file name based on the build number
set zip_name=FW_%build_no%.zip
:: Create the zip file containing the directories and their contents
"c:\Program Files\7-Zip\7z.exe" a -tzip -mx=6 "%script_dir%%zip_name%" "%script_dir%firmware-update" "%script_dir%META-INF"
if %errorlevel% neq 0 (
echo Failed to create zip file. Exiting...
pause
exit /b
)
:: #############
:: Finishing up
:: #############
echo.
echo Firmware update files have been compressed and saved as %zip_name%!
pause