147 lines
5.2 KiB
PowerShell
147 lines
5.2 KiB
PowerShell
# ========================================
|
|
# Gozareshgir Docker Bind Mounts Setup Script
|
|
# ========================================
|
|
# This script prepares the Windows host for Docker bind mounts
|
|
# Run this BEFORE starting the Docker container
|
|
|
|
param(
|
|
[string]$BasePath = "D:\AppData",
|
|
[switch]$GrantFullPermissions,
|
|
[string]$ServiceAccount = "Everyone"
|
|
)
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Gozareshgir Docker Setup Script" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Define directories
|
|
$directories = @(
|
|
"$BasePath\Faces",
|
|
"$BasePath\Storage",
|
|
"$BasePath\Logs"
|
|
)
|
|
|
|
# Step 1: Create directories
|
|
Write-Host "[1/3] Creating directories..." -ForegroundColor Yellow
|
|
foreach ($dir in $directories) {
|
|
if (Test-Path $dir) {
|
|
Write-Host " ✓ Already exists: $dir" -ForegroundColor Green
|
|
} else {
|
|
try {
|
|
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
|
Write-Host " ✓ Created: $dir" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " ✗ Failed to create: $dir" -ForegroundColor Red
|
|
Write-Host " Error: $_" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
Write-Host ""
|
|
|
|
# Step 2: Set permissions
|
|
Write-Host "[2/3] Setting permissions..." -ForegroundColor Yellow
|
|
if ($GrantFullPermissions) {
|
|
foreach ($dir in $directories) {
|
|
try {
|
|
# Grant full control
|
|
$acl = Get-Acl $dir
|
|
$permission = "$ServiceAccount", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow"
|
|
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
|
|
$acl.SetAccessRule($accessRule)
|
|
Set-Acl $dir $acl
|
|
|
|
Write-Host " ✓ Granted full control to '$ServiceAccount': $dir" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " ✗ Failed to set permissions: $dir" -ForegroundColor Red
|
|
Write-Host " Error: $_" -ForegroundColor Red
|
|
}
|
|
}
|
|
} else {
|
|
Write-Host " ⓘ Skipped (use -GrantFullPermissions to enable)" -ForegroundColor Gray
|
|
Write-Host " To grant permissions manually, run:" -ForegroundColor Gray
|
|
foreach ($dir in $directories) {
|
|
Write-Host " icacls `"$dir`" /grant Everyone:F /T" -ForegroundColor DarkGray
|
|
}
|
|
}
|
|
Write-Host ""
|
|
|
|
# Step 3: Verify setup
|
|
Write-Host "[3/3] Verifying setup..." -ForegroundColor Yellow
|
|
$allOk = $true
|
|
foreach ($dir in $directories) {
|
|
$exists = Test-Path $dir
|
|
$writable = $false
|
|
|
|
if ($exists) {
|
|
try {
|
|
$testFile = Join-Path $dir "test-write-$(Get-Random).txt"
|
|
"test" | Out-File -FilePath $testFile -ErrorAction Stop
|
|
Remove-Item $testFile -ErrorAction SilentlyContinue
|
|
$writable = $true
|
|
} catch {
|
|
$writable = $false
|
|
}
|
|
}
|
|
|
|
if ($exists -and $writable) {
|
|
Write-Host " ✓ OK: $dir" -ForegroundColor Green
|
|
} elseif ($exists -and -not $writable) {
|
|
Write-Host " ⚠ WARNING: $dir (exists but not writable)" -ForegroundColor Yellow
|
|
$allOk = $false
|
|
} else {
|
|
Write-Host " ✗ FAILED: $dir (does not exist)" -ForegroundColor Red
|
|
$allOk = $false
|
|
}
|
|
}
|
|
Write-Host ""
|
|
|
|
# Step 4: Check disk space
|
|
Write-Host "[Bonus] Checking disk space..." -ForegroundColor Yellow
|
|
try {
|
|
$drive = (Get-Item $BasePath).PSDrive
|
|
$driveInfo = Get-PSDrive $drive.Name
|
|
$freeGB = [math]::Round($driveInfo.Free / 1GB, 2)
|
|
$usedGB = [math]::Round($driveInfo.Used / 1GB, 2)
|
|
$totalGB = [math]::Round(($driveInfo.Used + $driveInfo.Free) / 1GB, 2)
|
|
|
|
Write-Host " Drive: $($drive.Name):" -ForegroundColor Cyan
|
|
Write-Host " Total: $totalGB GB" -ForegroundColor Gray
|
|
Write-Host " Used: $usedGB GB" -ForegroundColor Gray
|
|
Write-Host " Free: $freeGB GB" -ForegroundColor Gray
|
|
|
|
if ($freeGB -lt 10) {
|
|
Write-Host " ⚠ WARNING: Low disk space (less than 10 GB available)" -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host " ✓ Sufficient disk space available" -ForegroundColor Green
|
|
}
|
|
} catch {
|
|
Write-Host " ⓘ Could not check disk space" -ForegroundColor Gray
|
|
}
|
|
Write-Host ""
|
|
|
|
# Summary
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
if ($allOk) {
|
|
Write-Host "✓ Setup completed successfully!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Next steps:" -ForegroundColor Cyan
|
|
Write-Host " 1. Start the Docker container:" -ForegroundColor White
|
|
Write-Host " docker-compose up -d" -ForegroundColor Gray
|
|
Write-Host " 2. Verify the mounts:" -ForegroundColor White
|
|
Write-Host " docker exec gozareshgir-servicehost ls -la /app" -ForegroundColor Gray
|
|
} else {
|
|
Write-Host "⚠ Setup completed with warnings!" -ForegroundColor Yellow
|
|
Write-Host "Please review the issues above before starting Docker." -ForegroundColor Yellow
|
|
}
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Display docker-compose command
|
|
Write-Host "To start the container, run:" -ForegroundColor Cyan
|
|
Write-Host " cd $PSScriptRoot" -ForegroundColor Gray
|
|
Write-Host " docker-compose up -d" -ForegroundColor Green
|
|
Write-Host ""
|
|
|