Skip to content

Instantly share code, notes, and snippets.

@koloved
Created November 6, 2024 19:43
Show Gist options
  • Save koloved/43d72341bfa437f793e4ef697761e21c to your computer and use it in GitHub Desktop.
Save koloved/43d72341bfa437f793e4ef697761e21c to your computer and use it in GitHub Desktop.
Automatically reboot to Bazzite .bat script
@echo off
setlocal enabledelayedexpansion
rem Run bcdedit and save the output to a temporary file
echo Running bcdedit to enumerate firmware...
bcdedit /enum firmware > temp.txt
echo Output saved to temp.txt.
rem Initialize variables
set "target_description=bazzite"
set "identifier="
echo Target description set to: %target_description%
rem Initialize variables to store the last four lines
set "line1="
set "line2="
set "line3="
set "line4="
rem Read the temp file line by line
echo Reading temp.txt line by line...
for /f "tokens=*" %%a in (temp.txt) do (
set "line=%%a"
echo Processing line: !line!
rem Store the last four lines
set "line4=!line3!"
set "line3=!line2!"
set "line2=!line1!"
set "line1=!line!"
rem Check if the line contains the target description
echo !line! | findstr /c:"description %target_description%" >nul
if !errorlevel! equ 0 (
echo Found target description in line: !line!
rem Extract the identifier from the line four lines above
echo Extracting identifier from line: !line4!
for /f "tokens=2 delims={}" %%b in ("!line4!") do (
set "identifier={%%b}"
echo Extracted identifier: !identifier!
)
rem Set the boot sequence
if defined identifier (
echo Setting boot sequence to: !identifier!
bcdedit /set {fwbootmgr} bootsequence !identifier!
echo Boot sequence set to Bazzite !identifier!
set "found=1" rem Mark that we found the identifier
) else (
echo Identifier not found.
)
)
)
rem Clean up temporary file
echo Cleaning up temporary file...
del temp.txt
rem Reboot the system if the identifier was found
if defined found (
echo Rebooting system...
shutdown /r /t 0
) else (
echo Identifier not found. System will not reboot.
)
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment