| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- param(
- [Parameter(Mandatory = $true)]
- [string]$Path
- )
- $ErrorActionPreference = 'Stop'
- $launcher = " - [ bash, -lc, 'for d in /boot/firmware /boot; do [ -f ""`$d/waouw-activate.sh"" ] && exec bash ""`$d/waouw-activate.sh""; done; echo waouw-activate.sh introuvable >&2; exit 1' ]"
- $lines = Get-Content -LiteralPath $Path
- $out = New-Object System.Collections.Generic.List[string]
- $seenRuncmd = $false
- $added = $false
- $hasCloud = $false
- foreach ($line in $lines) {
- if ($line -match '^\#cloud-config') {
- $hasCloud = $true
- }
- if ($line -match '^\s*-\s+.*waouw-activate\.sh.*$') {
- continue
- }
- if ($line -match '^\s*runcmd:\s*$') {
- if (-not $seenRuncmd) {
- $out.Add('runcmd:')
- $out.Add($launcher)
- $seenRuncmd = $true
- $added = $true
- }
- continue
- }
- $out.Add($line)
- }
- if ((-not $seenRuncmd) -and $hasCloud) {
- if ($out.Count -gt 0 -and $out[$out.Count - 1] -ne '') {
- $out.Add('')
- }
- $out.Add('runcmd:')
- $out.Add($launcher)
- $added = $true
- }
- if (-not $added) {
- exit 8
- }
- [IO.File]::WriteAllLines($Path, $out, [Text.UTF8Encoding]::new($false))
|