mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-31 19:08:07 +08:00
core: 批处理脚本改用 rem 注释
This commit is contained in:
parent
76738362f1
commit
85b1b1bd58
@ -3,33 +3,36 @@ setlocal EnableDelayedExpansion
|
|||||||
set confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
|
set confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
|
||||||
set github_proxy=raw.fgit.cf
|
set github_proxy=raw.fgit.cf
|
||||||
|
|
||||||
:: Windows 7 SP1 winhttp 默认不支持 tls 1.2
|
rem 不要用 :: 注释
|
||||||
:: https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392
|
rem 否则可能会出现 系统找不到指定的驱动器
|
||||||
:: 有些系统根证书没更新
|
|
||||||
:: 所以不要用https
|
rem Windows 7 SP1 winhttp 默认不支持 tls 1.2
|
||||||
:: 进入脚本目录
|
rem https://support.microsoft.com/en-us/topic/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-winhttp-in-windows-c4bd73d2-31d7-761e-0178-11268bb10392
|
||||||
|
rem 有些系统根证书没更新
|
||||||
|
rem 所以不要用https
|
||||||
|
rem 进入脚本目录
|
||||||
cd /d %~dp0
|
cd /d %~dp0
|
||||||
|
|
||||||
:: 检查是否有管理员权限
|
rem 检查是否有管理员权限
|
||||||
openfiles 1>nul 2>&1
|
openfiles 1>nul 2>&1
|
||||||
if not !errorlevel! == 0 (
|
if not !errorlevel! == 0 (
|
||||||
echo Please run as administrator^^!
|
echo Please run as administrator^^!
|
||||||
exit /b
|
exit /b
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 有时 %tmp% 带会话 id,且文件夹不存在
|
rem 有时 %tmp% 带会话 id,且文件夹不存在
|
||||||
:: https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
|
rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
|
||||||
if not exist %tmp% (
|
if not exist %tmp% (
|
||||||
md %tmp%
|
md %tmp%
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 检查是否国内
|
rem 检查是否国内
|
||||||
if not exist %tmp%\geoip (
|
if not exist %tmp%\geoip (
|
||||||
call :download http://www.cloudflare.com/cdn-cgi/trace %tmp%\geoip
|
call :download http://www.cloudflare.com/cdn-cgi/trace %tmp%\geoip
|
||||||
)
|
)
|
||||||
findstr /c:"loc=CN" %tmp%\geoip >nul
|
findstr /c:"loc=CN" %tmp%\geoip >nul
|
||||||
if !errorlevel! == 0 (
|
if !errorlevel! == 0 (
|
||||||
:: mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
|
rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
|
||||||
set mirror=http://mirror.nju.edu.cn
|
set mirror=http://mirror.nju.edu.cn
|
||||||
|
|
||||||
if defined github_proxy (
|
if defined github_proxy (
|
||||||
@ -43,15 +46,13 @@ if !errorlevel! == 0 (
|
|||||||
set mirror=http://mirrors.kernel.org
|
set mirror=http://mirrors.kernel.org
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rem pkgs 改动了才重新运行 Cygwin 安装程序
|
||||||
:: pkgs 改动了才重新运行 Cygwin 安装程序
|
|
||||||
set pkgs="curl,cpio,p7zip,bind-utils,ipcalc"
|
set pkgs="curl,cpio,p7zip,bind-utils,ipcalc"
|
||||||
set tags=%tmp%\cygwin-installed-!pkgs!
|
set tags=%tmp%\cygwin-installed-!pkgs!
|
||||||
if not exist !tags! (
|
if not exist !tags! (
|
||||||
:: 检查32/64位
|
rem win10 arm 支持运行 x86 软件
|
||||||
:: win10 arm 支持运行 x86 软件
|
rem win11 arm 支持运行 x86 和 x86_64 软件
|
||||||
:: win11 arm 支持运行 x86 和 x86_64 软件
|
rem wmic os get osarchitecture
|
||||||
:: wmic os get osarchitecture
|
|
||||||
wmic ComputerSystem get SystemType | find "ARM" > nul
|
wmic ComputerSystem get SystemType | find "ARM" > nul
|
||||||
if not errorlevel 1 (
|
if not errorlevel 1 (
|
||||||
for /f "tokens=2 delims==" %%a in ('wmic os get BuildNumber /format:list ^| find "BuildNumber"') do set BuildNumber=%%a
|
for /f "tokens=2 delims==" %%a in ('wmic os get BuildNumber /format:list ^| find "BuildNumber"') do set BuildNumber=%%a
|
||||||
@ -75,10 +76,10 @@ if not exist !tags! (
|
|||||||
set dir=/sourceware/cygwin-archive/20221123
|
set dir=/sourceware/cygwin-archive/20221123
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 下载 Cygwin
|
rem 下载 Cygwin
|
||||||
call :download http://www.cygwin.com/setup-!CygwinArch!.exe %tmp%\setup-cygwin.exe
|
call :download http://www.cygwin.com/setup-!CygwinArch!.exe %tmp%\setup-cygwin.exe
|
||||||
|
|
||||||
:: 安装 Cygwin
|
rem 安装 Cygwin
|
||||||
set site=!mirror!!dir!
|
set site=!mirror!!dir!
|
||||||
%tmp%\setup-cygwin.exe --allow-unsupported-windows ^
|
%tmp%\setup-cygwin.exe --allow-unsupported-windows ^
|
||||||
--quiet-mode ^
|
--quiet-mode ^
|
||||||
@ -90,25 +91,25 @@ if not exist !tags! (
|
|||||||
&& type nul >!tags!
|
&& type nul >!tags!
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 下载 reinstall.sh
|
rem 下载 reinstall.sh
|
||||||
if not exist reinstall.sh (
|
if not exist reinstall.sh (
|
||||||
call :download %confhome%/reinstall.sh %~dp0reinstall.sh
|
call :download %confhome%/reinstall.sh %~dp0reinstall.sh
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 为每个参数添加引号,使参数正确传递到 bash
|
rem 为每个参数添加引号,使参数正确传递到 bash
|
||||||
for %%a in (%*) do (
|
for %%a in (%*) do (
|
||||||
set "param=!param! "%%~a""
|
set "param=!param! "%%~a""
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c,因此末尾要有 /
|
rem 在c盘根目录下执行 cygpath -ua . 会得到 /cygdrive/c,因此末尾要有 /
|
||||||
for /f %%a in ('%SystemDrive%\cygwin\bin\cygpath -ua ./') do set thisdir=%%a
|
for /f %%a in ('%SystemDrive%\cygwin\bin\cygpath -ua ./') do set thisdir=%%a
|
||||||
|
|
||||||
:: 方法1
|
rem 方法1
|
||||||
%SystemDrive%\cygwin\bin\bash -l -c '%thisdir%reinstall.sh !param!'
|
%SystemDrive%\cygwin\bin\bash -l -c '%thisdir%reinstall.sh !param!'
|
||||||
|
|
||||||
:: 方法2
|
rem 方法2
|
||||||
:: %SystemDrive%\cygwin\bin\bash reinstall.sh %*
|
rem %SystemDrive%\cygwin\bin\bash reinstall.sh %*
|
||||||
:: 再在 reinstall.sh 里运行 source /etc/profile
|
rem 再在 reinstall.sh 里运行 source /etc/profile
|
||||||
exit /b !errorlevel!
|
exit /b !errorlevel!
|
||||||
|
|
||||||
|
|
||||||
@ -116,9 +117,9 @@ exit /b !errorlevel!
|
|||||||
|
|
||||||
|
|
||||||
:download
|
:download
|
||||||
:: bits 要求有 Content-Length 才能下载
|
rem bits 要求有 Content-Length 才能下载
|
||||||
:: https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
|
rem https://learn.microsoft.com/en-us/windows/win32/bits/http-requirements-for-bits-downloads
|
||||||
:: certutil 会被 windows Defender 报毒
|
rem certutil 会被 windows Defender 报毒
|
||||||
echo Download: %~1 %~2
|
echo Download: %~1 %~2
|
||||||
certutil -urlcache -f -split %~1 %~2
|
certutil -urlcache -f -split %~1 %~2
|
||||||
exit /b !errorlevel!
|
exit /b !errorlevel!
|
||||||
|
@ -13,33 +13,33 @@ rem set ipv6_dns2=::2
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
|
|
||||||
:: 禁用 IPv6 地址标识符的随机化,防止 IPv6 和后台面板不一致
|
rem 禁用 IPv6 地址标识符的随机化,防止 IPv6 和后台面板不一致
|
||||||
netsh interface ipv6 set global randomizeidentifiers=disabled
|
netsh interface ipv6 set global randomizeidentifiers=disabled
|
||||||
|
|
||||||
:: 检查是否定义了 MAC 地址
|
rem 检查是否定义了 MAC 地址
|
||||||
if defined mac_addr (
|
if defined mac_addr (
|
||||||
for /f %%a in ('wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex ^| findstr [0-9]') do set id=%%a
|
for /f %%a in ('wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex ^| findstr [0-9]') do set id=%%a
|
||||||
if defined id (
|
if defined id (
|
||||||
:: 配置静态 IPv4 地址和网关
|
rem 配置静态 IPv4 地址和网关
|
||||||
if defined ipv4_addr if defined ipv4_gateway (
|
if defined ipv4_addr if defined ipv4_gateway (
|
||||||
:: gwmetric 默认值为 1,自动跃点需设为 0
|
rem gwmetric 默认值为 1,自动跃点需设为 0
|
||||||
netsh interface ipv4 set address !id! static !ipv4_addr! gateway=!ipv4_gateway! gwmetric=0
|
netsh interface ipv4 set address !id! static !ipv4_addr! gateway=!ipv4_gateway! gwmetric=0
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 配置静态 IPv4 DNS 服务器
|
rem 配置静态 IPv4 DNS 服务器
|
||||||
for %%i in (1, 2) do (
|
for %%i in (1, 2) do (
|
||||||
if defined ipv4_dns%%i (
|
if defined ipv4_dns%%i (
|
||||||
netsh interface ipv4 add dnsservers !id! !ipv4_dns%%i! %%i no
|
netsh interface ipv4 add dnsservers !id! !ipv4_dns%%i! %%i no
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 配置 IPv6 地址和网关
|
rem 配置 IPv6 地址和网关
|
||||||
if defined ipv6_addr if defined ipv6_gateway (
|
if defined ipv6_addr if defined ipv6_gateway (
|
||||||
netsh interface ipv6 set address !id! !ipv6_addr!
|
netsh interface ipv6 set address !id! !ipv6_addr!
|
||||||
netsh interface ipv6 add route prefix=::/0 !id! !ipv6_gateway!
|
netsh interface ipv6 add route prefix=::/0 !id! !ipv6_gateway!
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 配置 IPv6 DNS 服务器
|
rem 配置 IPv6 DNS 服务器
|
||||||
for %%i in (1, 2) do (
|
for %%i in (1, 2) do (
|
||||||
if defined ipv6_dns%%i (
|
if defined ipv6_dns%%i (
|
||||||
netsh interface ipv6 add dnsservers !id! !ipv6_dns%%i! %%i no
|
netsh interface ipv6 add dnsservers !id! !ipv6_dns%%i! %%i no
|
||||||
@ -48,5 +48,5 @@ if defined mac_addr (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 删除脚本文件
|
rem 删除脚本文件
|
||||||
del "%~f0"
|
del "%~f0"
|
||||||
|
@ -1,55 +1,55 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
:: 使用高性能模式
|
rem 使用高性能模式
|
||||||
:: https://learn.microsoft.com/windows-hardware/manufacture/desktop/capture-and-apply-windows-using-a-single-wim
|
rem https://learn.microsoft.com/windows-hardware/manufacture/desktop/capture-and-apply-windows-using-a-single-wim
|
||||||
:: win8 pe 没有 powercfg
|
rem win8 pe 没有 powercfg
|
||||||
call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2>nul
|
call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2>nul
|
||||||
|
|
||||||
:: 安装 SCSI 驱动
|
rem 安装 SCSI 驱动
|
||||||
for %%F in ("X:\drivers\*.inf") do (
|
for %%F in ("X:\drivers\*.inf") do (
|
||||||
:: 不要查找 Class=SCSIAdapter 因为有些驱动等号两边有空格
|
rem 不要查找 Class=SCSIAdapter 因为有些驱动等号两边有空格
|
||||||
find /i "SCSIAdapter" "%%~F" >nul
|
find /i "SCSIAdapter" "%%~F" >nul
|
||||||
if not errorlevel 1 (
|
if not errorlevel 1 (
|
||||||
drvload "%%~F"
|
drvload "%%~F"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 等待加载分区
|
rem 等待加载分区
|
||||||
:: 没有 timeout 命令
|
rem 没有 timeout 命令
|
||||||
:: 没有加载网卡驱动,无法用 ping 来等待
|
rem 没有加载网卡驱动,无法用 ping 来等待
|
||||||
echo wscript.sleep(5000) > X:\sleep.vbs
|
echo wscript.sleep(5000) > X:\sleep.vbs
|
||||||
cscript //nologo X:\sleep.vbs
|
cscript //nologo X:\sleep.vbs
|
||||||
del X:\sleep.vbs
|
del X:\sleep.vbs
|
||||||
|
|
||||||
:: 判断 efi 还是 bios
|
rem 判断 efi 还是 bios
|
||||||
:: 或者用 https://learn.microsoft.com/windows-hardware/manufacture/desktop/boot-to-uefi-mode-or-legacy-bios-mode
|
rem 或者用 https://learn.microsoft.com/windows-hardware/manufacture/desktop/boot-to-uefi-mode-or-legacy-bios-mode
|
||||||
:: pe 下没有 mountvol
|
rem pe 下没有 mountvol
|
||||||
echo list vol | diskpart | find "efi" && (
|
echo list vol | diskpart | find "efi" && (
|
||||||
set BootType=efi
|
set BootType=efi
|
||||||
) || (
|
) || (
|
||||||
set BootType=bios
|
set BootType=bios
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 获取 installer 卷 id
|
rem 获取 installer 卷 id
|
||||||
for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| find "installer"') do (
|
for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| find "installer"') do (
|
||||||
set "VolIndex=%%a"
|
set "VolIndex=%%a"
|
||||||
)
|
)
|
||||||
|
|
||||||
:: 将 installer 分区设为 Y 盘
|
rem 将 installer 分区设为 Y 盘
|
||||||
(echo select vol %VolIndex% & echo assign letter=Y) | diskpart
|
(echo select vol %VolIndex% & echo assign letter=Y) | diskpart
|
||||||
|
|
||||||
:: 设置虚拟内存,好像没必要,安装时会自动在 C 盘设置虚拟内存
|
rem 设置虚拟内存,好像没必要,安装时会自动在 C 盘设置虚拟内存
|
||||||
rem wpeutil CreatePageFile /path=Y:\pagefile.sys
|
rem wpeutil CreatePageFile /path=Y:\pagefile.sys
|
||||||
|
|
||||||
:: 获取主硬盘 id
|
rem 获取主硬盘 id
|
||||||
:: vista pe 没有 wmic,因此用 diskpart
|
rem vista pe 没有 wmic,因此用 diskpart
|
||||||
(echo select vol %VolIndex% & echo list disk) | diskpart | find "* " > X:\disk.txt
|
(echo select vol %VolIndex% & echo list disk) | diskpart | find "* " > X:\disk.txt
|
||||||
for /f "tokens=3" %%a in (X:\disk.txt) do (
|
for /f "tokens=3" %%a in (X:\disk.txt) do (
|
||||||
set "DiskIndex=%%a"
|
set "DiskIndex=%%a"
|
||||||
)
|
)
|
||||||
del X:\disk.txt
|
del X:\disk.txt
|
||||||
|
|
||||||
:: 重新分区/格式化
|
rem 重新分区/格式化
|
||||||
(if "%BootType%"=="efi" (
|
(if "%BootType%"=="efi" (
|
||||||
echo select disk %DiskIndex%
|
echo select disk %DiskIndex%
|
||||||
|
|
||||||
@ -74,15 +74,15 @@ del X:\disk.txt
|
|||||||
echo format fs=ntfs quick
|
echo format fs=ntfs quick
|
||||||
)) > X:\diskpart.txt
|
)) > X:\diskpart.txt
|
||||||
|
|
||||||
:: 使用 diskpart /s ,出错不会执行剩下的 diskpart 命令
|
rem 使用 diskpart /s ,出错不会执行剩下的 diskpart 命令
|
||||||
diskpart /s X:\diskpart.txt
|
diskpart /s X:\diskpart.txt
|
||||||
del X:\diskpart.txt
|
del X:\diskpart.txt
|
||||||
|
|
||||||
:: 盘符
|
rem 盘符
|
||||||
rem X boot.wim (ram)
|
rem X boot.wim (ram)
|
||||||
rem Y installer
|
rem Y installer
|
||||||
|
|
||||||
:: 设置 autounattend.xml 的主硬盘 id
|
rem 设置 autounattend.xml 的主硬盘 id
|
||||||
set "file=X:\autounattend.xml"
|
set "file=X:\autounattend.xml"
|
||||||
set "tempFile=X:\tmp.xml"
|
set "tempFile=X:\tmp.xml"
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ move /y %tempFile% %file%
|
|||||||
|
|
||||||
rename X:\setup.exe.disabled setup.exe
|
rename X:\setup.exe.disabled setup.exe
|
||||||
|
|
||||||
:: 运行 X:\setup.exe 的话
|
rem 运行 X:\setup.exe 的话
|
||||||
:: vista 会找不到安装源
|
rem vista 会找不到安装源
|
||||||
:: server 23h2 会无法运行
|
rem server 23h2 会无法运行
|
||||||
Y:\setup.exe /emsport:COM1 /emsbaudrate:115200
|
Y:\setup.exe /emsport:COM1 /emsbaudrate:115200
|
||||||
|
Loading…
x
Reference in New Issue
Block a user