77 lines
3.2 KiB
PowerShell
77 lines
3.2 KiB
PowerShell
# CleanINF03Session.ps1
|
|
# Wymaga uruchomienia z uprawnieniami Administratora
|
|
#Requires -RunAsAdministrator
|
|
|
|
$inf03Path = "C:\Users\inf03"
|
|
$xamppHtdocs = "C:\xampp\htdocs"
|
|
$mysqlData = "C:\xampp\mysql\data"
|
|
$mysqlBackup = "C:\xampp\mysql\backup"
|
|
|
|
Write-Host "Rozpoczynam sprzątanie stanowiska (profil: inf03)..." -ForegroundColor Cyan
|
|
Write-Host "----------------------------------------------------"
|
|
|
|
# 1. Zatrzymanie usług XAMPP
|
|
Write-Host "[1/6] Zatrzymywanie usług Apache i MySQL..." -NoNewline
|
|
try {
|
|
# Domyślne nazwy usług w XAMPP to 'Apache2.4' oraz 'mysql'
|
|
Stop-Service -Name "Apache2.4", "mysql" -Force -ErrorAction SilentlyContinue
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " POMINIĘTO (usługi mogą być wyłączone)" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Czekamy 2 sekundy, aby upewnić się, że usługi puściły blokady na plikach bazy danych
|
|
Start-Sleep -Seconds 2
|
|
|
|
# 2. Czyszczenie htdocs
|
|
Write-Host "[2/6] Czyszczenie folderu htdocs..." -NoNewline
|
|
if (Test-Path $xamppHtdocs) {
|
|
Remove-Item -Path "$xamppHtdocs\*" -Recurse -Force -ErrorAction SilentlyContinue
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " BRAK FOLDERU" -ForegroundColor Yellow
|
|
}
|
|
|
|
# 3. Czyszczenie Obrazów i Dokumentów
|
|
Write-Host "[3/6] Usuwanie danych z folderów Obrazy i Dokumenty..." -NoNewline
|
|
$docsPath = "$inf03Path\Documents"
|
|
$picsPath = "$inf03Path\Pictures"
|
|
|
|
if (Test-Path $docsPath) { Remove-Item -Path "$docsPath\*" -Recurse -Force -ErrorAction SilentlyContinue }
|
|
if (Test-Path $picsPath) { Remove-Item -Path "$picsPath\*" -Recurse -Force -ErrorAction SilentlyContinue }
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
|
|
# 4. Resetowanie bazy danych MySQL do stanu czystego
|
|
Write-Host "[4/6] Przywracanie czystej bazy danych MySQL..." -NoNewline
|
|
if ((Test-Path $mysqlData) -and (Test-Path $mysqlBackup)) {
|
|
# Usuwamy zmienioną bazę
|
|
Remove-Item -Path "$mysqlData\*" -Recurse -Force -ErrorAction SilentlyContinue
|
|
# Kopiujemy świeże pliki z backupu
|
|
Copy-Item -Path "$mysqlBackup\*" -Destination $mysqlData -Recurse -Force
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " BŁĄD (Brak folderu data lub backup w C:\xampp\mysql\)" -ForegroundColor Red
|
|
}
|
|
|
|
# 5. Uruchomienie usług
|
|
Write-Host "[5/6] Uruchamianie usług Apache i MySQL..." -NoNewline
|
|
try {
|
|
Start-Service -Name "Apache2.4", "mysql" -ErrorAction Stop
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " BŁĄD (Sprawdź w panelu XAMPP)" -ForegroundColor Red
|
|
}
|
|
|
|
# 6. Usuwanie KATALOGÓW z pulpitu
|
|
Write-Host "[6/6] Usuwanie projektów (katalogów) z Pulpitu..." -NoNewline
|
|
$desktopPath = "$inf03Path\Desktop"
|
|
if (Test-Path $desktopPath) {
|
|
# Get-ChildItem -Directory gwarantuje, że skasujemy tylko foldery, oszczędzając skróty (.lnk)
|
|
Get-ChildItem -Path $desktopPath -Directory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
|
Write-Host " GOTOWE" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " BRAK PULPITU" -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host "----------------------------------------------------"
|
|
Write-Host "Stanowisko przygotowane do kolejnego egzaminu!" -ForegroundColor Cyan |