From ea1078e5dbb6597f0fbba0a87109623341563f0d Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 20 Mar 2024 21:44:02 +0100 Subject: [PATCH] Add a script for running `bash` from `powershell` --- scripts/Windows/Scripts/BashScript.ps1 | 14 ++++++++++++++ scripts/Windows/Software/git/Manage.ps1 | 18 ++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 scripts/Windows/Scripts/BashScript.ps1 diff --git a/scripts/Windows/Scripts/BashScript.ps1 b/scripts/Windows/Scripts/BashScript.ps1 new file mode 100644 index 00000000..3b80bad3 --- /dev/null +++ b/scripts/Windows/Scripts/BashScript.ps1 @@ -0,0 +1,14 @@ +function Start-BashScript() { + param( + [Parameter(Mandatory=$true, Position=0)] + [string[]]$Content + ) + + Write-Information "Preparing setup script"; + $script = New-TemporaryFile; + $script = Rename-Item $script -NewName "$script.sh" -PassThru; + Set-Content $script ([string]::Join("`n", $Content)); + Write-Information "Running prepared script"; + Start-Process -Wait $script; + Remove-Item $script; +} diff --git a/scripts/Windows/Software/git/Manage.ps1 b/scripts/Windows/Software/git/Manage.ps1 index aad63ee8..a89c0c10 100644 --- a/scripts/Windows/Software/git/Manage.ps1 +++ b/scripts/Windows/Software/git/Manage.ps1 @@ -1,25 +1,15 @@ #!/bin/pwsh . "$PSScriptRoot/../../Scripts/Context.ps1"; +. "$PSScriptRoot/../../Scripts/BashScript.ps1"; $null = New-Module { function Backup-Git([Context] $context) {} function Restore-Git([Context] $context) { Write-Host "Restoring git"; - $script = New-TemporaryFile; - $script = Rename-Item $script "$($script.Name).sh" -PassThru; - Write-Information "Preparing setup script"; - - Set-Content $script ( - [string]::Join( - "`n", - @( - "bash `"$PSScriptRoot/../../../Common/Config/git/install.sh`"", - "rm ~/.bashrc"))); - - Write-Information "Running prepared script"; - Start-Process -Wait $script; - Remove-Item $script; + Start-BashScript @( + "bash `"$PSScriptRoot/../../../Common/Config/git/install.sh`"", + "rm ~/.bashrc"); } }