Загрузка данных
# =====================================================
# СКРИПТ АВТОМАТИЧЕСКОЙ УСТАНОВКИ ПОДПИСИ ПРЕДСЕДАТЕЛЯ
# Клиника - замена зама по КЭР
# Сервер: 10.0.2.21\Disk_M
# =====================================================
# === НАСТРОЙКИ ===
$ServerShare = "\\10.0.2.21\Disk_M\ОБМЕН\fss_ecp"
$NetContainerPath = "$ServerShare\fsspred.000"
$NetCertPath = "$ServerShare\cert_pred.cer"
$ContainerName = "fsspred.000"
# === ЛОКАЛЬНЫЕ ПУТИ ===
$LocalAppData = [Environment]::GetFolderPath("LocalApplicationData")
$LocalContainerPath = Join-Path $LocalAppData "CryptoPro\$ContainerName"
$MarkerFile = Join-Path $LocalAppData "Clinic_Chairman_Deployed_v1.txt"
$LogFile = Join-Path $LocalAppData "Clinic_Chairman_Deploy.log"
# === ФУНКЦИЯ ЛОГИРОВАНИЯ ===
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp | $env:COMPUTERNAME | $env:USERNAME | $Message"
try {
Add-Content -Path $LogFile -Value $logEntry -ErrorAction Stop
} catch {
# Если не удалось записать лог - ничего страшного
}
}
# === ПРОВЕРКА: УЖЕ УСТАНОВЛЕНО? ===
if (Test-Path $MarkerFile) {
Write-Log "Маркер найден - установка уже выполнена ранее. Выход."
Exit
}
Write-Log "=== НАЧАЛО УСТАНОВКИ ==="
# === ШАГ 1: ПРОВЕРКА ДОСТУПНОСТИ СЕТЕВЫХ РЕСУРСОВ ===
if (-not (Test-Path $NetContainerPath)) {
Write-Log "ОШИБКА: Сетевой контейнер НЕ найден: $NetContainerPath"
Exit
}
if (-not (Test-Path $NetCertPath)) {
Write-Log "ОШИБКА: Сетевой сертификат НЕ найден: $NetCertPath"
Exit
}
Write-Log "Сетевые ресурсы доступны"
# === ШАГ 2: КОПИРУЕМ КОНТЕЙНЕР НА ЛОКАЛЬНЫЙ ДИСК ===
try {
if (-not (Test-Path $LocalContainerPath)) {
New-Item -Path $LocalContainerPath -ItemType Directory -Force | Out-Null
}
Copy-Item -Path "$NetContainerPath\*" -Destination $LocalContainerPath -Force -Recurse
# Проверяем, что файлы скопировались
$filesCount = (Get-ChildItem -Path $LocalContainerPath -File).Count
if ($filesCount -eq 0) {
Write-Log "ОШИБКА: Контейнер скопирован, но файлы отсутствуют"
Exit
}
Write-Log "Контейнер скопирован в $LocalContainerPath (файлов: $filesCount)"
} catch {
Write-Log "ОШИБКА копирования контейнера: $_"
Exit
}
# === ШАГ 3: ПРОВЕРКА certutil.exe ===
$certutilPath = (Get-Command certutil.exe -ErrorAction SilentlyContinue).Source
if (-not $certutilPath) {
Write-Log "ОШИБКА: certutil.exe не найден в системе"
Exit
}
Write-Log "certutil.exe найден: $certutilPath"
# === ШАГ 4: ИМПОРТ СЕРТИФИКАТА В ХРАНИЛИЩЕ ПОЛЬЗОВАТЕЛЯ ===
try {
$output = & certutil.exe -user -addstore "My" $NetCertPath 2>&1
$outputStr = $output | Out-String
Write-Log "Результат импорта сертификата: $outputStr"
} catch {
Write-Log "ОШИБКА импорта сертификата: $_"
Exit
}
# === ШАГ 5: ПРОВЕРКА УСТАНОВКИ СЕРТИФИКАТА ===
try {
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" |
Where-Object { $_.Subject -like "*председатель*" -or $_.Subject -like "*зам*" }
if ($cert) {
Write-Log "Сертификат найден в хранилище: $($cert.Subject)"
} else {
Write-Log "ВНИМАНИЕ: Сертификат не найден в хранилище после импорта (возможно, имя субъекта не совпадает с фильтром)"
}
} catch {
Write-Log "ОШИБКА проверки установки: $_"
}
# === ШАГ 6: СТАВИМ МАРКЕР ===
try {
New-Item -Path $MarkerFile -ItemType File -Force | Out-Null
Write-Log "Маркер установлен: $MarkerFile"
Write-Log "=== УСТАНОВКА ЗАВЕРШЕНА УСПЕШНО ==="
} catch {
Write-Log "ОШИБКА создания маркера: $_"
}