Skip to content

Commit

Permalink
add support for FQDN
Browse files Browse the repository at this point in the history
  • Loading branch information
ztrhgf committed Oct 31, 2023
1 parent ae8d371 commit 06a9f6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
20 changes: 14 additions & 6 deletions repo_content_set_up/custom/Repo_sync/repo_sync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ Function _copyFolder {
function _flattenArray {
# flattens input in case, that string and arrays are entered at the same time
param (
[array] $inputArray
[array] $inputArray,

[switch] $fqdnToHostname
)

foreach ($item in $inputArray) {
Expand All @@ -591,7 +593,12 @@ function _flattenArray {
_flattenArray $item
} else {
# output non-arrays
$item
if ($fqdnToHostname -and $item -like "*.*") {
# return just hostname part
($item -split "\.")[0]
} else {
$item
}
}
}
}
Expand Down Expand Up @@ -732,7 +739,8 @@ try {
# resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master
"$(Get-Date -Format HH:mm:ss) - Discarding local changes"
$defaultBranch = ((git symbolic-ref refs/remotes/origin/HEAD) -split "/")[-1]
$null = _startProcess git -argumentList "reset --hard origin/$defaultBranch"
$result = _startProcess git -argumentList "reset --hard origin/$defaultBranch" -outputErr2Std
if ($result -match "fatal: ") { throw $result }
# delete untracked files and folders (generated modules etc)
_startProcess git -argumentList "clean -fd"

Expand Down Expand Up @@ -990,7 +998,7 @@ try {
# limit NTFS rights accordingly
$readUserC = $configData.computerName
# computer AD accounts end with $
$readUserC = (_flattenArray $readUserC) | % { $_ + "$" }
$readUserC = (_flattenArray $readUserC -fqdnToHostname) | % { $_ + "$" }
" - limiting NTFS permissions on $folderName`n - access just for: $($readUserC -join ', ')"
_setPermissions $folder -readUser $readUserC -writeUser $writeUser
} else {
Expand Down Expand Up @@ -1065,7 +1073,7 @@ try {
$destProfile = (Join-Path $repository "profile.ps1")
if ($_computerWithProfile) {
# computer AD accounts end with $
$readUserP = (_flattenArray $_computerWithProfile) | % { $_ + "$" }
$readUserP = (_flattenArray $_computerWithProfile -fqdnToHostname) | % { $_ + "$" }

" - limiting NTFS permissions on $destProfile`n - access just for: $($readUserP -join ', ')"
_setPermissions $destProfile -readUser $readUserP -writeUser $writeUser
Expand Down Expand Up @@ -1194,7 +1202,7 @@ try {
} else {
$readUserC = $configData.computerName
# computer AD ucty maji $ za svym jmenem, pridam
$readUserC = (_flattenArray $readUserC) | % { $_ + "$" }
$readUserC = (_flattenArray $readUserC -fqdnToHostname) | % { $_ + "$" }
}

" - limiting NTFS permissions on $folderName`n - access just for: $($readUserC -join ', ')"
Expand Down
21 changes: 14 additions & 7 deletions repo_content_set_up/scripts2root/PS_env_set_up.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ function _isFilelocked {
function _flattenArray {
# flattens input in case, that string and arrays are entered at the same time
param (
[array] $inputArray
[array] $inputArray,

[switch] $fqdnToHostname
)

foreach ($item in $inputArray) {
Expand All @@ -127,7 +129,12 @@ function _flattenArray {
_flattenArray $item
} else {
# output non-arrays
$item
if ($fqdnToHostname -and $item -like "*.*") {
# return just hostname part
($item -split "\.")[0]
} else {
$item
}
}
}
}
Expand Down Expand Up @@ -405,7 +412,7 @@ if ($synchronize -contains "module") {
$modulesConfig | ForEach-Object {
$customModules += $_.folderName

if ($hostname -in (_flattenArray $_.computerName)) {
if ($hostname -in (_flattenArray $_.computerName -fqdnToHostname)) {
$thisPCModules += $_.folderName
}
}
Expand Down Expand Up @@ -479,7 +486,7 @@ if ($synchronize -contains "module") {
$commitHistorySrc = Join-Path $repository "commitHistory"
# copy file with commit history locally
# so prompt function in profile.ps1 where this file is used to check how much is that console obsolete, will be as fast as possible
if ((Test-Path $commitHistorySrc -ea SilentlyContinue) -and ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile))) {
if ((Test-Path $commitHistorySrc -ea SilentlyContinue) -and ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile -fqdnToHostname))) {
[Void][System.IO.Directory]::CreateDirectory($customDstFolder)
Copy-Item $commitHistorySrc $customDstFolder -Force -Confirm:$false
}
Expand All @@ -500,7 +507,7 @@ if ($synchronize -contains "profile") {

if (Test-Path $profileSrc -ea SilentlyContinue) {
# DFS share contains profile.ps1
if ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile)) {
if ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile -fqdnToHostname)) {
# profile.ps1 should be copied to this computer
if (Test-Path $profileDst -ea SilentlyContinue) {
# profile.ps1 already exist on this computer, check whether it differs
Expand Down Expand Up @@ -531,7 +538,7 @@ if ($synchronize -contains "profile") {
}
} else {
# in DFS share there is not profile.ps1
if ((Test-Path $profileDst -ea SilentlyContinue) -and ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile)) -and $isOurProfile) {
if ((Test-Path $profileDst -ea SilentlyContinue) -and ($env:COMPUTERNAME -in (_flattenArray $_computerWithProfile -fqdnToHostname)) -and $isOurProfile) {
# profile.ps1 is on this computer and was copied by this script == delete it
" - deleting $profileDst"
Remove-Item $profileDst -Force -Confirm:$false
Expand Down Expand Up @@ -571,7 +578,7 @@ if ($synchronize -contains "custom") {
$thisPCCustSchedTask = @()

foreach ($custom in $customConfig) {
if ($hostname -in (_flattenArray $custom.computerName)) {
if ($hostname -in (_flattenArray $custom.computerName -fqdnToHostname)) {
if ($customToSync -and $customToSync -notcontains $custom.folderName) {
" - skipping custom folder {0} (not in customToSync argument)" -f $custom.folderName
continue
Expand Down

0 comments on commit 06a9f6a

Please sign in to comment.