Skip to content

Instantly share code, notes, and snippets.

@dialmak
Last active June 28, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dialmak/b9ff1987542bfa1d7e7d0e3f56eeb101 to your computer and use it in GitHub Desktop.
Save dialmak/b9ff1987542bfa1d7e7d0e3f56eeb101 to your computer and use it in GitHub Desktop.
// EXAMPLE.TBS
// by dialmak
const KEY_ENTER = 13
global grub2 = "bootx64_GRUB2.efi"
global bootx = "bootx64.efi"
global shimx = "shimx64.dat"
global fpath = "C:\EFI\BOOT"
sub main()
// save current directory at script startup
CWDOnStart=GetCWD()
// SetDrive(TBSAppPath)
// ChDir(TBSAppPath)
cls()
printl ("Install GRUB2 UEFI BootManager, please wait ...")
if CopyFile (BuildPath(fpath,grub2),BuildPath(fpath,bootx))=0 then
DelFile (BuildPath(fpath,shimx))
printl ("GRUB2 UEFI BootManager installed.")
end if
SetDrive(CWDOnStart)
ChDir(CWDOnStart)
// pause
printl("")
printl("Press <Enter> to continue ...")
while GetKey()<>KEY_ENTER
wend
end sub
sub CopyFile(file1,file2)
r=1
if len(findfirst(file1))=0 then
printl ("Error. File " # file1 # " not found.")
else
if ext("copy file " # file1 # " " # file2 # " -yq")=0 then
r=0
else
printl ("Error. Can not copy file " # file1 # ".")
end if
end if
return r
end sub
sub DelFile(file)
r=1
if len(findfirst(file))=0 then
printl ("Error. File " # file # " not found.")
else
if ext("del file " # file # " -yq")=0 then
r=0
else
printl ("Error. Can not delete file " # file # ".")
end if
end if
return r
end sub
//-------------------------------------------------------------------------
// Purpose: Combine a path and file
//
// Input: path - file path
// file - file name
//
// Output: combined path and file
//
// Notes: used to handle trailing separator
//
sub BuildPath(path, file)
// clean up separators
if tbsenv="LINUX" then
sepsch="\"
seprpl="/"
else
sepsch="/"
seprpl="\"
end if
pos=InStr(path, sepsch)
while pos>0
path=Left(path, pos-1) # seprpl # Mid(path, pos+1)
pos=InStr(path, sepsch)
wend
// add separator if needed
if len(path)>0 and Right(path, 1)<>seprpl then
path=path # seprpl
end if
// ensure file doesn't have separator
if Left(file, 1)=seprpl or Left(file, 1)=sepsch then
file=Mid(file, 2)
end if
pos=InStr(file, sepsch)
while pos>0
file=Left(file, pos-1) # seprpl # Mid(file, pos+1)
pos=InStr(file, sepsch)
wend
// finish combine
path=path # file
// return path
return path
end sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment