diff options
author | Peter Johanson <peter@peterjohanson.com> | 2021-09-11 05:16:40 +0000 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2021-09-13 22:04:55 -0400 |
commit | 2f0ad4cc8c7c4a4b0344206bce638a8241b85b95 (patch) | |
tree | 310bff1bb8e3fc380c1bb2ad3f3c6b8259d43fe1 | |
parent | c7e513634d2425dbdf21ccd693872301f80cad65 (diff) |
fix(setup): Fix setup.ps1 to check Get-Acl exists
* `Get-Acl` not found in Linux Powershell version, so only call it
if it exists.
-rw-r--r-- | docs/src/templates/setup.ps1.mustache | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index 0d2b4c5..12fd545 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -58,17 +58,30 @@ catch [System.Management.Automation.CommandNotFoundException] { Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" Test-Git-Config -Option "user.email" -ErrMsg "Git email not set!`nRun: git config --global user.email 'example@myemail.com'" -$permission = (Get-Acl $pwd).Access | -?{$_.IdentityReference -match $env:UserName ` - -and $_.FileSystemRights -match "FullControl" ` - -or $_.FileSystemRights -match "Write" } | - - Select IdentityReference,FileSystemRights - -If (-Not $permission){ - Write-Host "Sorry, you do not have write permissions in this directory." - Write-Host "Please try running this script again from a directory that you do have write permissions for." - exit 1 +function Test-CommandExists { + param ($command) + + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = ‘stop’ + + try { + if(Get-Command $command){ return $true } + } Catch { return $false } + Finally { $ErrorActionPreference=$oldPreference } +} + +if (Test-CommandExists Get-Acl) { + $permission = (Get-Acl $pwd).Access | + ?{$_.IdentityReference -match $env:UserName ` + -and $_.FileSystemRights -match "FullControl" ` + -or $_.FileSystemRights -match "Write" } | + Select IdentityReference,FileSystemRights + + If (-Not $permission){ + Write-Host "Sorry, you do not have write permissions in this directory." + Write-Host "Please try running this script again from a directory that you do have write permissions for." + exit 1 + } } $repo_path = "https://github.com/zmkfirmware/zmk-config-split-template.git" |