forked from askeing/B2G-flash-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shallow_flash.bat
148 lines (131 loc) · 5.14 KB
/
shallow_flash.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
@rem ==========================================================================
@rem This Source Code Form is subject to the terms of the Mozilla Public
@rem License, v. 2.0. If a copy of the MPL was not distributed with this
@rem file, You can obtain one at http://mozilla.org/MPL/2.0/.
@rem ==========================================================================
@rem Description:
@rem This script runs shallow flash.sh on Windows + Cygwin.
@rem Before use install Cygwin base package plus unzip
@rem
@rem Useage:
@rem
@rem Run in same folder as shallow_flash.sh and Gaia + Gecko archive files
@rem It will automatically flash gaia.zip and any b2g-*.android-arm.tar.gz
@rem ADB and fastboot can be run from the folder containing this script if
@rem you copy ADB*.* and fastboot.exe from the Android distribution.
@rem
@rem If Cygwin and unzip are not installed it will prompt with instructions.
@rem Cywin setup is then run with as little interaction user as as possible
@rem Just select a download site and click Next twice.
@rem
@rem Author: slee steve@opendirective.com
@rem History:
@rem 2014/10/11 slee: v1.0 First release.
@rem 2014/10/20 slee: v1.1 Added Cygwin installation.
@rem ==========================================================================
@setlocal
@echo ### Finding Cygwin
@set CYGWINBIN=
@call :findCygwin
@if not "%CYGWINBIN%"=="" goto check_Gecko
@rem Run Cygwin setup to install Base and unzip
@if exist setup-x86.exe (
@set SETUP=setup-x86.exe
) else if exist setup-x86_64.exe (
@set SETUP=setup-x86_64.exe
)
@if not exist %SETUP% goto error_no_CYGWIN_SETUP
@rem Note: Setup returns immediately - ie it runs async
@rem so we can't tell if it succeeded or not from errorlevel
@rem We wait until the task ends
@echo ### Installing Cygwin
@%SETUP% -q -C Base -P unzip -g
:loop
@tasklist | find /I "%SETUP%" > :null
@if errorlevel 1 (
@goto end_loop
) else (
@Rem Pause a few seconds. "Timeout" is Windows 7 onwards
@ping 127.0.0.1 -n 3 > :null
@goto loop
)
:end_loop
@rem Bail if still no Cywin or unzip
@call :findCygwin
@if "%CYGWINBIN%"=="" goto error_CYGWIN_FAILED
:check_gecko
@rem Find the Gaia and Gecko archive files
@echo ### Checking for Gaia and Gecko files to flash
@set "GAIA=gaia.zip"
@if not exist %GAIA% goto error_no_GAIA
@set GECKO=
@set "GECKOPATTERN=b2g-*.android-arm.tar.gz"
@for %%f in (%GECKOPATTERN%) do @(
@set "GECKO=%%f"
)
@if "%GECKO%"=="" goto error_no_GECKO
@rem Set path so Cygwin can find it's commands
@set "PATH=%CYGWINBIN%;%PATH%"
@rem Create a temp .bashrc that mounts /tmp and performs a few tests
@rem The # is to stop the Windows EOL \r breaking bash
@echo ### Preparing to flash
@set "BASHRC=%TEMP%\.bashrc"
@echo unset TMP # > %BASHRC%
@echo unset TEMP # >> %BASHRC%
@rem allow adb and fastboot to be run from the current dir.
@echo PATH="./:"$PATH # >> %BASHRC%
@echo mount "%TEMP%" /tmp ^&^> /dev/null # >> %BASHRC%
@echo $^(which adb ^&^> /dev/null^) ^|^| { printf "!!! Cannot find ADB\nEnsure it is installed or copied to the folder containing this script"; exit 1; } # >> %BASHRC%
@echo $^(which fastboot ^&^> /dev/null^) ^|^| { printf "!!! Cannot find Fastboot\nEnsure it is installed or copied to the folder containing this script"; exit 1; } # >> %BASHRC%
@for /F %%i in ('%CYGWINBIN%\cygpath "%BASHRC%"') do @(
@set "BASH_ENV=%%i"
)
@rem Run shallow_flash.sh
@%CYGWINBIN%\bash -- shallow_flash.sh -g%GAIA% -G%GECKO%
@goto end
@rem Subroutines -------------------------------------------------------------
@rem Find Cygwin bin
:findCygwin
@for /F "tokens=1,2*" %%i in ('reg query "HKLM\SOFTWARE\Cygwin\setup" /v "rootdir"') do @(
@if "%%i"=="rootdir" (
@if exist "%%k\bin\bash.exe" (
@if exist %%k\bin\unzip.exe (
@set "CYGWINBIN=%%k\bin"
)
)
)
)
@if "%CYGWINBIN%"=="" (
@for /F "tokens=1,2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Cygwin\setup" /v "rootdir"') do @(
@if "%%i"=="rootdir" (
@if exist "%%k\bin\bash.exe" (
@if exist %%k\bin\unzip.exe (
@set "CYGWINBIN=%%k\bin"
)
)
)
)
)
@exit /B 0
@rem -----------------------------------------------------------------------
:error_no_CYGWIN_SETUP
@echo !!! Cannot find Cygwin.
@echo Please download the Cygwin "setup*.exe" from https://cygwin.com/install.html
@echo and copy it to the folder containing this script.
@echo TRun this script again so it can install Cygwin.
@goto end
:error_CYGWIN_FAILED
@echo !!! Cygwin base and unzip have not been installed.
@echo Flashing cancelled.
@goto end
:error_no_GAIA
@echo !!! Cannot find the file "%GAIA%"
@echo Get one from Firefox OS nightlies and put it in same folder as this script
@goto end
:error_no_GECKO
@echo !!! Cannot find the file "%GECKOPATTERN%"
@echo Get one from Firefox OS nightlies and put it in same folder as this script
@goto end
:end
@rem pause if it looks like we were launched with a double clicked from explorer
@if %0 == "%~0" pause