Fixed BOM

This commit is contained in:
PTah
2026-05-22 10:28:40 +10:00
parent 83f5c7de63
commit eccffe927a
2 changed files with 78 additions and 42 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
При выпуске новой сборки обновляйте на шаре **`Login_Monitor.ps1`** и при необходимости **`version.txt`** (логика описана в разделе «Версии»). При выпуске новой сборки обновляйте на шаре **`Login_Monitor.ps1`** и при необходимости **`version.txt`** (логика описана в разделе «Версии»).
На сервере публикации можно использовать скрипт **`update-rdp-monitor.ps1`** из репозитория (копия на диск, например `C:\soft\update-rdp-monitor.ps1`): `git pull` с **git.kalinamall.ru** и копирование трёх файлов в `\\b26\NETLOGON\RDP-login-monitor\`. На сервере публикации (например DC3): клон в `C:\Soft\Git\RDP-login-monitor`, скрипт **`update-rdp-monitor.ps1`** — при отсутствии remote сам добавит `origin` на `https://git.kalinamall.ru/PapaTramp/RDP-login-monitor.git`, выполнит `git pull` и скопирует три файла в `\\b26\NETLOGON\RDP-login-monitor\`. Лог: `C:\soft\Logs\update-rdp-monitor.log`.
## Как это работает ## Как это работает
+77 -41
View File
@@ -1,19 +1,20 @@
<# <#
.SYNOPSIS .SYNOPSIS
Обновляет локальный клон RDP-login-monitor с git.kalinamall.ru и копирует дистрибутив на NETLOGON. Obnovlyaet klon RDP-login-monitor s git.kalinamall.ru i kopiruet dist na NETLOGON.
.DESCRIPTION .DESCRIPTION
Запуск на сервере с доступом к \\b26\NETLOGON (SYSVOL), например с правами администратора домена. Dlya servera publikatsii (napr. DC3). Ne trebuet imenovaniya remote: pri otsutstvii
Копируются: Login_Monitor.ps1, version.txt, Deploy-LoginMonitor.ps1. dobavlyaetsya origin ili vypolnyaetsya git pull po URL.
Kopiruyutsya: Login_Monitor.ps1, version.txt, Deploy-LoginMonitor.ps1.
.EXAMPLE .EXAMPLE
C:\soft\update-rdp-monitor.ps1 powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\soft\update-rdp-monitor.ps1
.EXAMPLE .EXAMPLE
C:\soft\update-rdp-monitor.ps1 -RepoPath 'C:\soft\Git\RDP-login-monitor' -WhatIf powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\soft\update-rdp-monitor.ps1 -WhatIf
#> #>
[CmdletBinding(SupportsShouldProcess = $true)] [CmdletBinding(SupportsShouldProcess = $true)]
param( param(
[string]$RepoPath = 'C:\soft\Git\RDP-login-monitor', [string]$RepoPath = 'C:\Soft\Git\RDP-login-monitor',
[string]$NetlogonDest = '\\b26\NETLOGON\RDP-login-monitor', [string]$NetlogonDest = '\\b26\NETLOGON\RDP-login-monitor',
[string]$GitRemote = 'kalinamall', [string]$GitUrl = 'https://git.kalinamall.ru/PapaTramp/RDP-login-monitor.git',
[string]$GitBranch = 'main', [string]$GitBranch = 'main',
[string]$LogFile = 'C:\soft\Logs\update-rdp-monitor.log' [string]$LogFile = 'C:\soft\Logs\update-rdp-monitor.log'
) )
@@ -29,75 +30,110 @@ function Write-UpdateLog {
if (-not (Test-Path -LiteralPath $dir)) { if (-not (Test-Path -LiteralPath $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null New-Item -ItemType Directory -Path $dir -Force | Out-Null
} }
Add-Content -LiteralPath $LogFile -Value $line -Encoding UTF8 $utf8Bom = New-Object System.Text.UTF8Encoding $true
[System.IO.File]::AppendAllText($LogFile, $line + [Environment]::NewLine, $utf8Bom)
}
function Invoke-GitCommand {
param(
[Parameter(Mandatory = $true)][string[]]$Arguments,
[string]$WorkingDirectory = $RepoPath
)
$prevEap = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
Push-Location -LiteralPath $WorkingDirectory
$out = & git @Arguments 2>&1
$code = $LASTEXITCODE
} finally {
Pop-Location
$ErrorActionPreference = $prevEap
}
foreach ($line in @($out)) {
if ($null -ne $line -and "$line".Length -gt 0) {
Write-UpdateLog "git: $line"
}
}
if ($code -ne 0) {
throw ("git {0} failed (exit {1})" -f ($Arguments -join ' '), $code)
}
return @($out)
} }
function Ensure-GitAvailable { function Ensure-GitAvailable {
$git = Get-Command git -ErrorAction SilentlyContinue if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
if (-not $git) { throw 'git.exe not found in PATH. Install Git for Windows.'
throw 'Git не найден в PATH. Установите Git for Windows или добавьте git.exe в PATH.'
} }
} }
function Ensure-GitRepository {
$gitDir = Join-Path $RepoPath '.git'
if (-not (Test-Path -LiteralPath $gitDir)) {
throw "Not a git repo (no .git): $RepoPath. Clone first: git clone $GitUrl `"$RepoPath`""
}
}
function Get-ConfiguredGitRemoteName {
$names = @(Invoke-GitCommand -Arguments @('remote') | ForEach-Object { "$_".Trim() } | Where-Object { $_ })
if ($names.Count -gt 0) {
if ('origin' -in $names) { return 'origin' }
return $names[0]
}
return $null
}
function Ensure-GitOriginRemote {
$name = Get-ConfiguredGitRemoteName
if ($null -ne $name) {
Write-UpdateLog "Using remote: $name"
return $name
}
Write-UpdateLog "No remotes; adding origin -> $GitUrl"
Invoke-GitCommand -Arguments @('remote', 'add', 'origin', $GitUrl)
return 'origin'
}
function Update-Repository { function Update-Repository {
if (-not (Test-Path -LiteralPath (Join-Path $RepoPath '.git'))) { Ensure-GitRepository
throw "Не найден git-репозиторий: $RepoPath (нет папки .git). Сначала выполните: git clone https://git.kalinamall.ru/PapaTramp/RDP-login-monitor.git `"$RepoPath`"" $remote = Ensure-GitOriginRemote
} Invoke-GitCommand -Arguments @('fetch', $remote, $GitBranch)
Push-Location -LiteralPath $RepoPath Invoke-GitCommand -Arguments @('pull', $remote, $GitBranch)
try { $null = Invoke-GitCommand -Arguments @('rev-parse', '--short', 'HEAD')
$remotes = @(git remote 2>&1)
if ($GitRemote -notin $remotes) {
if ('origin' -in $remotes) {
Write-UpdateLog "Remote '$GitRemote' не найден, используется origin."
$script:GitRemote = 'origin'
} else {
throw "Нет remote '$GitRemote'. Доступные: $($remotes -join ', '). Добавьте: git remote add kalinamall https://git.kalinamall.ru/PapaTramp/RDP-login-monitor.git"
}
}
Write-UpdateLog "git fetch $GitRemote"
git fetch $GitRemote 2>&1 | ForEach-Object { Write-UpdateLog $_ }
Write-UpdateLog "git pull $GitRemote $GitBranch"
git pull $GitRemote $GitBranch 2>&1 | ForEach-Object { Write-UpdateLog $_ }
$head = (git rev-parse --short HEAD 2>&1)
Write-UpdateLog "HEAD после pull: $head"
} finally {
Pop-Location
}
} }
function Publish-DistributionFiles { function Publish-DistributionFiles {
if (-not (Test-Path -LiteralPath $NetlogonDest)) { if (-not (Test-Path -LiteralPath $NetlogonDest)) {
if ($PSCmdlet.ShouldProcess($NetlogonDest, 'Create directory')) { if ($PSCmdlet.ShouldProcess($NetlogonDest, 'Create directory')) {
New-Item -ItemType Directory -Path $NetlogonDest -Force | Out-Null New-Item -ItemType Directory -Path $NetlogonDest -Force | Out-Null
Write-UpdateLog "Создан каталог: $NetlogonDest" Write-UpdateLog "Created: $NetlogonDest"
} }
} }
foreach ($name in $DistFiles) { foreach ($name in $DistFiles) {
$src = Join-Path $RepoPath $name $src = Join-Path $RepoPath $name
if (-not (Test-Path -LiteralPath $src)) { if (-not (Test-Path -LiteralPath $src)) {
throw "В репозитории нет файла: $src" throw "Missing in repo: $src"
} }
$dst = Join-Path $NetlogonDest $name $dst = Join-Path $NetlogonDest $name
if ($PSCmdlet.ShouldProcess($dst, "Copy from $src")) { if ($PSCmdlet.ShouldProcess($dst, "Copy from $src")) {
Copy-Item -LiteralPath $src -Destination $dst -Force Copy-Item -LiteralPath $src -Destination $dst -Force
Write-UpdateLog "Скопировано: $name -> $NetlogonDest" Write-UpdateLog "Copied: $name -> $NetlogonDest"
} }
} }
$verFile = Join-Path $NetlogonDest 'version.txt' $verFile = Join-Path $NetlogonDest 'version.txt'
if (Test-Path -LiteralPath $verFile) { if (Test-Path -LiteralPath $verFile) {
$ver = (Get-Content -LiteralPath $verFile -Raw).Trim() $ver = (Get-Content -LiteralPath $verFile -Raw).Trim()
Write-UpdateLog "Версия на NETLOGON: $ver" Write-UpdateLog "NETLOGON version: $ver"
} }
} }
try { try {
Write-UpdateLog '=== Старт обновления RDP-login-monitor -> NETLOGON ===' Write-UpdateLog '=== RDP-login-monitor: git pull -> NETLOGON ==='
Ensure-GitAvailable Ensure-GitAvailable
Update-Repository Update-Repository
Publish-DistributionFiles Publish-DistributionFiles
Write-UpdateLog '=== Готово ===' Write-UpdateLog '=== Done ==='
exit 0 exit 0
} catch { } catch {
Write-UpdateLog "ОШИБКА: $($_.Exception.Message)" Write-UpdateLog "ERROR: $($_.Exception.Message)"
exit 1 exit 1
} }