|
| 1 | +# Crypt postinstall script |
| 2 | + |
| 3 | +$installPath = 'C:\Program Files\Crypt' |
| 4 | +$configDir = 'C:\ProgramData\ManagedEncryption' |
| 5 | +$configFile = Join-Path $configDir 'config.yaml' |
| 6 | + |
| 7 | +Write-Host "Crypt - Post-installation" -ForegroundColor Cyan |
| 8 | + |
| 9 | +# Add to system PATH |
| 10 | +$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine') |
| 11 | +if ($currentPath -notlike "*$installPath*") { |
| 12 | + $newPath = "$currentPath;$installPath" |
| 13 | + [Environment]::SetEnvironmentVariable('PATH', $newPath, 'Machine') |
| 14 | + Write-Host "Added $installPath to system PATH" -ForegroundColor Green |
| 15 | +} else { |
| 16 | + Write-Host "PATH already configured" -ForegroundColor Cyan |
| 17 | +} |
| 18 | + |
| 19 | +# Create config directory |
| 20 | +if (-not (Test-Path $configDir)) { |
| 21 | + New-Item -ItemType Directory -Path $configDir -Force | Out-Null |
| 22 | + Write-Host "Created config directory: $configDir" -ForegroundColor Green |
| 23 | +} |
| 24 | + |
| 25 | +# Create logs directory |
| 26 | +$logsDir = Join-Path $configDir 'logs' |
| 27 | +if (-not (Test-Path $logsDir)) { |
| 28 | + New-Item -ItemType Directory -Path $logsDir -Force | Out-Null |
| 29 | +} |
| 30 | + |
| 31 | +# Configure from environment variable if set |
| 32 | +$serverUrl = [Environment]::GetEnvironmentVariable('CRYPT_ESCROW_SERVER_URL', 'Machine') |
| 33 | +if ($serverUrl -and -not (Test-Path $configFile)) { |
| 34 | + Write-Host "Configuring Crypt server: $serverUrl" -ForegroundColor Cyan |
| 35 | + $config = @" |
| 36 | +server: |
| 37 | + url: $serverUrl |
| 38 | + skip_cert_check: false |
| 39 | +
|
| 40 | +escrow: |
| 41 | + auto_rotate: true |
| 42 | + cleanup_old_protectors: true |
| 43 | + key_escrow_interval_hours: 24 |
| 44 | + validate_key: true |
| 45 | +
|
| 46 | +logging: |
| 47 | + level: Info |
| 48 | + file_path: $configDir\logs\crypt.log |
| 49 | +"@ |
| 50 | + Set-Content -Path $configFile -Value $config -Encoding UTF8 |
| 51 | + Write-Host "Created config file: $configFile" -ForegroundColor Green |
| 52 | +} |
| 53 | + |
| 54 | +# Register scheduled task for automatic key rotation |
| 55 | +try { |
| 56 | + $cryptExe = Join-Path $installPath 'checkin.exe' |
| 57 | + if (Test-Path $cryptExe) { |
| 58 | + Write-Host "Registering hourly scheduled task..." -ForegroundColor Cyan |
| 59 | + & $cryptExe register-task --frequency hourly 2>&1 | Out-Null |
| 60 | + if ($LASTEXITCODE -eq 0) { |
| 61 | + Write-Host "Scheduled task registered successfully" -ForegroundColor Green |
| 62 | + } |
| 63 | + } |
| 64 | +} catch { |
| 65 | + Write-Host "Could not register scheduled task: $_" -ForegroundColor Yellow |
| 66 | +} |
| 67 | + |
| 68 | +Write-Host "`nCrypt installation complete!" -ForegroundColor Green |
| 69 | +Write-Host "Usage: checkin --help" -ForegroundColor Cyan |
| 70 | +if (-not (Test-Path $configFile)) { |
| 71 | + Write-Host "Configure: checkin config set server.url https://your-crypt-server" -ForegroundColor Yellow |
| 72 | +} |
0 commit comments