Libraries/Bootloader/Includes/Bootloader.Grub2.psm1
<#
.SYNOPSIS Search for a grub configuration .DESCRIPTION Search into local partition for a grub.cfg file. Default search for a "grub.cfg" file. If config name is overriden, use -Filename to search for custom filename. .EXAMPLE Find-OSBootloaderGrub2Cfg -Path "/boot" .EXAMPLE Find-OSBootloaderGrub2Cfg -Path "/boot" -Filename "mygrub.cfg" .NOTES General notes #> function Find-OSBootloaderGrub2Cfg { [CmdletBinding()] [OutputType([String])] Param ( # Path to start search [Parameter(Mandatory = $true, ValueFromPipeLine = $true)][string]$Path, # Custom filename to search for [Parameter(Mandatory = $false, ValueFromPipeLine = $false)][string]$Filename = "grub.cfg" ) Begin { Write-EnterFunction } Process { $grubcfg = Get-ChildItem -Path $Path $Filename -Recurse return ${grubcfg}?.fullname } End { Write-LeaveFunction } } function Get-OSBootloaderGrub2DefaultBoot { [CmdletBinding()] [OutputType([String])] Param ( [Alias('ConfigFile')] [Parameter(Mandatory = $false, ValueFromPipeLine = $false)][string]$Grub2Cfg = "/boot/Grub2/Grub2.cfg" ) Begin { Write-EnterFunction } Process { $rc = (Get-Content $Grub2Cfg | select-string "^LABEL") | ForEach-Object { $_ -match "^LABEL\s*(?<label>\w+)" } if ($rc) { return $Matches.label } else { return $null } } End { Write-LeaveFunction } } function Set-OSBootloaderGrub2DefaultBoot { [CmdletBinding()] [OutputType([System.Boolean])] Param ( [Alias('ConfigFile')] [Parameter(Mandatory = $false, ValueFromPipeLine = $false)][string]$Grub2Cfg = "/boot/Grub2/Grub2.cfg", [Parameter(Mandatory = $true, ValueFromPipeLine = $false)][string]$label ) Begin { Write-EnterFunction } Process { $Grub2 = (Get-Content $Grub2Cfg -Raw) -replace "^DEFAULT .*", "DEFAULT $label" $Grub2 | Out-File $Grub2Cfg return $? } End { Write-LeaveFunction } } |