From 1c312baa6ed636d5c430f62b2fb97d841f5fb2a4 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 16 Jun 2023 20:24:22 +0200 Subject: [PATCH] Add a script for installing windows --- scripts/Windows/OS/Install.ps1 | 4 ++++ scripts/Windows/OS/Manage.ps1 | 18 ++++++++++++++++++ scripts/Windows/OS/Setup.ps1 | 2 +- scripts/Windows/Scripts/Context.ps1 | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 scripts/Windows/OS/Install.ps1 diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 new file mode 100644 index 00000000..7d2794a6 --- /dev/null +++ b/scripts/Windows/OS/Install.ps1 @@ -0,0 +1,4 @@ +. "$PSScriptRoot/Manage.ps1"; + +Invoke-WindowsRestore; + diff --git a/scripts/Windows/OS/Manage.ps1 b/scripts/Windows/OS/Manage.ps1 index aec38c50..dc6e28b2 100644 --- a/scripts/Windows/OS/Manage.ps1 +++ b/scripts/Windows/OS/Manage.ps1 @@ -28,3 +28,21 @@ function Invoke-WindowsBackup([Context] $context) { Invoke-BackupVisualStudio $context; $context.Backup($backupRoot, "$backupRoot.7z", @("-sdel")); } + +function Invoke-WindowsRestore() { + function Read-Path() + { + $backupPath = Read-Host -Prompt "Please enter the path to the archive load the backup from."; + + if (-not (Test-Path -PathType Leaf $backupPath)) + { + Write-Host "No file could be found at the specified path."; + return Read-Path; + } + } + + $backupPath = Read-Path; + $context = [Context]::new(); + $context.BackupName = "PortValhalla"; + $context.Restore($backupPath, $context.BackupRoot()); +} diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 index 26c5dff6..cb153bb4 100644 --- a/scripts/Windows/OS/Setup.ps1 +++ b/scripts/Windows/OS/Setup.ps1 @@ -9,7 +9,7 @@ foreach ($module in @("PSWindowsUpdate")) Import-Module PSWindowsUpdate; Import-Module ScheduledTasks; -$installerPath = "$PSScriptRoot/Manage.ps1"; +$installerPath = "$PSScriptRoot/Install.ps1"; $setupPath = "$($MyInvocation.MyCommand.Path)"; Install-WindowsUpdate -AcceptAll -IgnoreReboot; diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index e945d69c..6f7252cc 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -33,4 +33,16 @@ class Context { -Wait ` -NoNewWindow; } + + [void] Restore([string]$archivePath, [string]$destinationPath) { + if (-not (Test-Path -PathType Container $destinationPath)) { + New-Item -ItemType Directory "$destinationPath"; + } + + Start-Process -WorkingDirectory "$destinationPath" ` + -FilePath "7z" + -ArgumentList "x" ` + -Wait ` + -NoNewWindow; + } }