
&"$PSScriptRoot\vars.ps1"
&"$PSScriptRoot\vars-config.ps1"

Write-Host "Saving Permissions"

# Directories

@(
$ROOT
) | ForEach-Object {
    $p = (Get-Item $_).FullName
    Write-Host $p
    $acl = Get-Acl $p
    ForEach ($usr in $CEDAR_INSTALL_USERS)
    {
        $a = New-Object System.Security.AccessControl.FileSystemAccessRule($usr, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
        $acl.AddAccessRule($a)
    }

    $acl.SetAccessRuleProtection($false,$true)

    Set-Acl $p $acl
}

# Core Directories

@(
'App\',
'Config\',
'Scripts\',
'src\',
'Template\',
'Web\'
) | ForEach-Object {
    Write-Host $_
    $path = "$ROOT/$_"
    $acl = Get-Acl $path
    ForEach ($usr in $CEDAR_INSTALL_USERS)
    {
        $a = New-Object System.Security.AccessControl.FileSystemAccessRule($usr, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
        $acl.AddAccessRule($a)
    }
    $acl.SetAccessRuleProtection($false,$true)
    Set-Acl $path $acl
}

# Directories

@(
'Var\Apps\',
'Var\DbCache\',
'Var\FileCache\',
'Var\FileStore\',
'Var\Photos\Cache\',
'Var\Photos\Student\',
'Var\Photos\Upload\',
'Var\Photos\',
'Var\temp\',
'Var\Upgrade\'
) | ForEach-Object {
    Write-Host $_
    $path = "$ROOT/$_"
    $acl = Get-Acl $path
    ForEach ($usr in $CEDAR_INSTALL_USERS)
    {
        $a = New-Object System.Security.AccessControl.FileSystemAccessRule($usr, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
        $acl.AddAccessRule($a)
    }
    $acl.SetAccessRuleProtection($false,$true)
    Set-Acl $path $acl
}

# Files

@(
'version.txt',
'cedar.ps1',
'Config\.env',
'Config\config.ini',
'Config\markbookHighlight.ini',
'Config\vocabulary.ini',
'composer.json',
'Var\LoginImages.json',
'Var\hash-fn.txt',
'Var\hash-git.txt',
'Var\hash-sp.txt',
'Var\version.txt',
'Web\web.config'
) | ForEach-Object {
    Write-Host $_
    $path = "$ROOT/$_"
    $acl = Get-Acl $path
    ForEach ($usr in $CEDAR_INSTALL_USERS)
    {
        $a = New-Object System.Security.AccessControl.FileSystemAccessRule($usr, "FullControl", "Allow")
        $acl.AddAccessRule($a)
    }
    $acl.SetAccessRuleProtection($false,$true)
    Set-Acl $path $acl
}
