1
0

win32loader.bat 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. @ECHO OFF&@PUSHD %~DP0 &TITLE Win32Loader
  2. setlocal enabledelayedexpansion
  3. ::Author MoeClub.org
  4. color 87
  5. cd.>%windir%\GetAdmin
  6. if exist %windir%\GetAdmin (del /f /q "%windir%\GetAdmin") else (
  7. echo CreateObject^("Shell.Application"^).ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\Admin.vbs"
  8. "%temp%\Admin.vbs"
  9. del /s /q "%temp%\Admin.vbs"
  10. exit /b 2)
  11. cls
  12. echo * Init Win32Loader.
  13. set download=0
  14. set try_download=1
  15. set URL=https://api.moeclub.org/redirect/loader
  16. :InitCheck
  17. mkdir "%SystemDrive%\win32-loader" >NUL 2>NUL
  18. if exist "%SystemDrive%\Windows\System32\WindowsPowerShell" (
  19. set use_ps=1
  20. ) else (
  21. set use_ps=0
  22. echo Not found PowerShell.
  23. )
  24. :Init
  25. if %use_ps% equ 1 (
  26. goto InitIt
  27. ) else (
  28. goto InitFail
  29. )
  30. :InitIt
  31. set try_download=0
  32. call:DownloadFile "!URL!/g2ldr/g2ldr","%SystemDrive%\g2ldr"
  33. call:DownloadFile "!URL!/g2ldr/g2ldr.mbr","%SystemDrive%\g2ldr.mbr"
  34. call:DownloadFile "!URL!/g2ldr/grub.cfg","%SystemDrive%\win32-loader\grub.cfg"
  35. goto InitDone
  36. :InitFail
  37. echo.
  38. echo Please download them by yourself.
  39. echo '%SystemDrive%\g2ldr'
  40. echo -- !URL!/g2ldr/g2ldr
  41. echo '%SystemDrive%\g2ldr.mbr'
  42. echo -- !URL!/g2ldr/g2ldr.mbr
  43. echo '%SystemDrive%\win32-loader\grub.cfg'
  44. echo -- !URL!/g2ldr/grub.cfg
  45. echo Press [ENTER] when you finished.
  46. pause >NUL 2>NUL
  47. goto InitDone
  48. :InitDone
  49. if !try_download! equ 0 (
  50. set InitOption=InitFail
  51. ) else (
  52. set InitOption=Init
  53. )
  54. if not exist "%SystemDrive%\g2ldr" goto !InitOption!
  55. if not exist "%SystemDrive%\g2ldr.mbr" goto !InitOption!
  56. if not exist "%SystemDrive%\win32-loader\grub.cfg" goto !InitOption!
  57. :Image
  58. echo.
  59. echo * Please select initrd mode.
  60. echo [1] Online download
  61. echo [2] Local file
  62. choice /n /c 12 /m Select:
  63. if errorlevel 2 goto LocalMode
  64. if errorlevel 1 goto OnlineMode
  65. goto Image
  66. :OnlineMode
  67. echo.
  68. echo * Please select source.
  69. echo [1] by MoeClub [Linux](Debian, DHCP or VNC Support)
  70. echo [2] by MoeClub [Windows](Win8.1EMB, DHCP or VNC Support)
  71. echo [3] by Yourself
  72. choice /n /c 1234 /m Select:
  73. if errorlevel 3 goto Yourself
  74. if errorlevel 2 goto MoeClub_Win8.1EMB
  75. if errorlevel 1 goto MoeClub_Linux
  76. goto OnlineMode
  77. :Yourself
  78. echo.
  79. echo if 'initrd.img' URL is 'https://api.moeclub.org/redirect/loader/Debian/initrd.img',
  80. echo Please input 'https://api.moeclub.org/redirect/loader/Debian'.
  81. set /p IMG_URL_TMP=URL :
  82. if defined IMG_URL_TMP (
  83. set IMG_URL=%IMG_URL_TMP%
  84. goto Download
  85. ) else (
  86. goto MoeClub
  87. )
  88. :MoeClub_Win8.1EMB
  89. set IMG_URL=https://api.moeclub.org/redirect/loader/Win8.1EMB
  90. set INITRD_SHA1=0032B38A6E0C3EC9CC2E3FDCC68C7CC394ED68EA
  91. set VMLINUZ_SHA1=C84BF89869868B0325F56F1C0E62604A83B9443F
  92. goto Download
  93. :MoeClub_Linux
  94. set IMG_URL=https://api.moeclub.org/redirect/loader/Debian
  95. set INITRD_SHA1=899F9F00A4932827A92D58583734647E4A6BC0D4
  96. set VMLINUZ_SHA1=85DA55C0C03BA698BF7F4184961F4E2E6DCA36F3
  97. goto Download
  98. :Download
  99. if %use_ps% equ 1 (
  100. echo.
  101. echo Downloading 'initrd.img'...
  102. call:DownloadFile "!IMG_URL!/initrd.img","%SystemDrive%\win32-loader\initrd.img"
  103. call:CheckFile "%SystemDrive%\win32-loader\initrd.img"
  104. call:CheckSUM "%SystemDrive%\win32-loader\initrd.img","%INITRD_SHA1%"
  105. echo Downloading 'vmlinuz'...
  106. call:DownloadFile "!IMG_URL!/vmlinuz","%SystemDrive%\win32-loader\vmlinuz"
  107. call:CheckFile "%SystemDrive%\win32-loader\vmlinuz"
  108. call:CheckSUM "%SystemDrive%\win32-loader\vmlinuz","%VMLINUZ_SHA1%"
  109. set download=1
  110. ) else (
  111. echo Not support online download, auto change Local initrd.
  112. goto LocalMode
  113. )
  114. :LocalMode
  115. if !download! equ 0 (
  116. echo.
  117. echo Please put 'initrd.img' and 'vmlinuz' to '%SystemDrive%\win32-loader' .
  118. echo Press [ENTER] when you finished.
  119. pause >NUL 2>NUL
  120. )
  121. :Done0
  122. set download=0
  123. if exist "%SystemDrive%\win32-loader\initrd.img" (
  124. goto Done1
  125. ) else (
  126. echo Not found '%SystemDrive%\win32-loader\initrd.img' .
  127. goto LocalMode
  128. )
  129. :Done1
  130. set download=0
  131. if exist "%SystemDrive%\win32-loader\vmlinuz" (
  132. goto Done
  133. ) else (
  134. echo Not found '%SystemDrive%\win32-loader\vmlinuz' .
  135. goto LocalMode
  136. )
  137. :Done
  138. echo.
  139. echo Press [ENTER] to continue...
  140. echo IT WILL REBOOT IMMEDIATELY
  141. pause >NUL 2>NUL
  142. echo.
  143. call:CheckFile "%SystemDrive%\g2ldr"
  144. call:CheckFile "%SystemDrive%\g2ldr.mbr"
  145. call:CheckFile "%SystemDrive%\win32-loader\grub.cfg"
  146. call:CheckFile "%SystemDrive%\win32-loader\initrd.img"
  147. call:CheckFile "%SystemDrive%\win32-loader\vmlinuz"
  148. call:CheckSUM "%SystemDrive%\g2ldr","2FCB1009A64C127AD3CC39FF0B5E068B38CBA772"
  149. call:CheckSUM "%SystemDrive%\g2ldr.mbr","29401C8BC951F0AEFD30DC370A3797D1055D64B4"
  150. call:CheckSUM "%SystemDrive%\win32-loader\grub.cfg","58C499EFEE7E60790B3FE2166B536C04B6717B14"
  151. set id={01234567-89ab-cdef-fedc-ba9876543210}
  152. bcdedit /create %id% /d "Debian GUN/Linux" /application bootsector >NUL 2>NUL
  153. bcdedit /set %id% device partition=%SystemDrive% >NUL 2>NUL
  154. bcdedit /set %id% path \g2ldr.mbr >NUL 2>NUL
  155. bcdedit /displayorder %id% /addlast >NUL 2>NUL
  156. bcdedit /bootsequence %id% /addfirst >NUL 2>NUL
  157. shutdown -r -t 0
  158. :CheckSUM
  159. for /f "delims=: tokens=2" %%i in ('powershell.exe "& {Get-FileHash -Algorithm SHA1 -Path %1|Format-List -Property HASH}"') do (set tmp_var=%%i)
  160. set var=%tmp_var:~1%
  161. if "%var%" == %2 (
  162. echo Check %1 SHA1 OK.
  163. ) else (
  164. if "%var%" == "CommandNotFoundException" (
  165. echo Check %1 SHA1 SKIP.
  166. ) else (
  167. echo Check %1 SHA1 FAIL.
  168. call:ErrorExit
  169. )
  170. )
  171. GOTO:EOF
  172. :CheckFile
  173. if not exist %1 (
  174. echo Not found %1 .
  175. call:ErrorExit
  176. )
  177. GOTO:EOF
  178. :DownloadFile
  179. powershell.exe -command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $client = new-object System.Net.WebClient; $client.DownloadFile('%1','%2')}" >NUL 2>NUL
  180. GOTO:EOF
  181. :ErrorExit
  182. echo.
  183. echo Error, Clear CACHE...
  184. del /S /F /Q "%SystemDrive%\g2ldr" >NUL 2>NUL
  185. del /S /F /Q "%SystemDrive%\g2ldr.mbr" >NUL 2>NUL
  186. rd /S /Q "%SystemDrive%\win32-loader" >NUL 2>NUL
  187. echo Press [ENTER] to exit.
  188. pause >NUL 2>NUL
  189. exit 1
  190. GOTO:EOF