Add install-AdHoc-Backup.ps1
This commit is contained in:
parent
01f3214449
commit
0a1d4275ee
61
install-AdHoc-Backup.ps1
Normal file
61
install-AdHoc-Backup.ps1
Normal file
@ -0,0 +1,61 @@
|
||||
# install-AdHoc-Backup.ps1
|
||||
# Uso tipico:
|
||||
# iwr -useb https://<il-tuo-raw-url>/install-AdHoc-Backup.ps1 | iex
|
||||
# Opzioni:
|
||||
# ... } -ForceConfig # sovrascrive backup.conf se già esiste
|
||||
# ... } -NoRun # installa senza eseguire il backup
|
||||
# ... } -AdHocArgs '-WhatIf' # argomenti aggiuntivi da passare allo script di backup
|
||||
|
||||
param(
|
||||
[string]$InstallDir = 'C:\polo\scripts',
|
||||
[string]$ScriptUrl = 'https://gitea.poloinformatico.it/Mattia/Backup-AdHoc/raw/branch/main/AdHoc_Backup.ps1',
|
||||
[string]$ConfigUrl = 'https://gitea.poloinformatico.it/Mattia/Backup-AdHoc/raw/branch/main/backup.conf',
|
||||
[switch]$ForceConfig,
|
||||
[switch]$NoRun,
|
||||
[string[]]$AdHocArgs
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13 } catch {}
|
||||
|
||||
# 1) Crea cartella di destinazione
|
||||
if (-not (Test-Path -LiteralPath $InstallDir)) {
|
||||
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
||||
}
|
||||
|
||||
# 2) Scarica i due file
|
||||
$ScriptPath = Join-Path $InstallDir 'AdHoc-Backup.ps1' # <- nome finale con trattino
|
||||
$ConfigPath = Join-Path $InstallDir 'backup.conf'
|
||||
|
||||
Write-Host "Scarico script: $ScriptUrl -> $ScriptPath"
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $ScriptUrl -OutFile $ScriptPath
|
||||
|
||||
if ((-not (Test-Path -LiteralPath $ConfigPath)) -or $ForceConfig.IsPresent) {
|
||||
Write-Host "Scarico config: $ConfigUrl -> $ConfigPath"
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $ConfigUrl -OutFile $ConfigPath
|
||||
} else {
|
||||
Write-Host "Config già presente, non sovrascrivo (usa -ForceConfig per forzare)."
|
||||
}
|
||||
|
||||
# 3) Sblocca eventuali zone mark
|
||||
foreach ($p in @($ScriptPath, $ConfigPath)) {
|
||||
if (Test-Path -LiteralPath $p) {
|
||||
Unblock-File -LiteralPath $p -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# 4) Esegui lo script (se non esplicitamente evitato)
|
||||
if (-not $NoRun.IsPresent) {
|
||||
Write-Host "Avvio: $ScriptPath"
|
||||
# Se il tuo AdHoc-Backup richiede la config, la passiamo in modo esplicito:
|
||||
$argsToPass = @()
|
||||
if (Test-Path -LiteralPath $ConfigPath) {
|
||||
$argsToPass += @('-Config', $ConfigPath)
|
||||
}
|
||||
if ($AdHocArgs) {
|
||||
$argsToPass += $AdHocArgs
|
||||
}
|
||||
|
||||
# Esegui in un processo figlio con ExecutionPolicy limitata al processo
|
||||
& powershell -NoProfile -ExecutionPolicy Bypass -File $ScriptPath @argsToPass
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user