Skip to content

Commit

Permalink
fix(setup): Fix setup.ps1 to check Get-Acl exists
Browse files Browse the repository at this point in the history
* `Get-Acl` not found in Linux Powershell version, so only call it
  if it exists.
  • Loading branch information
think4tomorrow committed Sep 14, 2021
1 parent d5460ae commit 54579a3
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions docs/src/templates/setup.ps1.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 54579a3

Please sign in to comment.