Add a script for creating backups
This commit is contained in:
parent
ab4ce633db
commit
438c0b1cdf
4 changed files with 119 additions and 2 deletions
|
@ -11,11 +11,18 @@ enum WindowsInstallerStage {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SetupStage {
|
enum SetupStage {
|
||||||
|
Initialize
|
||||||
Configure
|
Configure
|
||||||
Install
|
Install
|
||||||
CreateUser
|
CreateUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum BackupStage {
|
||||||
|
Initialize
|
||||||
|
Backup
|
||||||
|
BackupUsers
|
||||||
|
}
|
||||||
|
|
||||||
enum UserStage {
|
enum UserStage {
|
||||||
Create
|
Create
|
||||||
Configure
|
Configure
|
||||||
|
@ -27,6 +34,7 @@ $null = New-Module {
|
||||||
[string] $configRoot = "HKLM:\Software\PortValhalla";
|
[string] $configRoot = "HKLM:\Software\PortValhalla";
|
||||||
[string] $stageOption = "Stage";
|
[string] $stageOption = "Stage";
|
||||||
[string] $setupStageOption = "SetupStage";
|
[string] $setupStageOption = "SetupStage";
|
||||||
|
[string] $backupStageOption = "BackupStage";
|
||||||
[string] $userOption = "SetupUser";
|
[string] $userOption = "SetupUser";
|
||||||
[string] $userStageOption = "UserStage";
|
[string] $userStageOption = "UserStage";
|
||||||
[string] $accountOption = "MSAccount";
|
[string] $accountOption = "MSAccount";
|
||||||
|
@ -408,6 +416,39 @@ $null = New-Module {
|
||||||
$null = Set-SetupOption $setupStageOption $Name;
|
$null = Set-SetupOption $setupStageOption $Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Gets the name of the current stage of the backup.
|
||||||
|
#>
|
||||||
|
function Get-BackupStage {
|
||||||
|
$stage = Get-SetupOption $backupStageOption;
|
||||||
|
|
||||||
|
if ($null -ne $stage) {
|
||||||
|
$stage = [BackupStage]$stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Sets the current stage of the backup.
|
||||||
|
|
||||||
|
.PARAMETER Name
|
||||||
|
The name to set the current stage to.
|
||||||
|
#>
|
||||||
|
function Set-BackupStage {
|
||||||
|
param(
|
||||||
|
$Name
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not (($null -eq $Name) -or ($Name -is [string]))) {
|
||||||
|
$Name = ([BackupStage]$Name).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
$null = Set-SetupOption $backupStageOption $Name;
|
||||||
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Gets the current user to set up.
|
Gets the current user to set up.
|
||||||
|
|
4
scripts/Windows/OS/Backup.ps1
Normal file
4
scripts/Windows/OS/Backup.ps1
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/pwsh
|
||||||
|
. "$PSScriptRoot/Manage.ps1";
|
||||||
|
$env:INSTALLER_SCRIPT = "$PSCommandPath";
|
||||||
|
Start-WindowsBackup;
|
|
@ -36,6 +36,16 @@ $null = New-Module {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Creates a backup of the current Windows machine.
|
||||||
|
#>
|
||||||
|
function Start-WindowsBackup {
|
||||||
|
Start-Operation -NoImplicitCleanup {
|
||||||
|
Start-InstallationLoop ([WindowsInstallerAction]::Backup);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Starts the installation loop.
|
Starts the installation loop.
|
||||||
|
@ -87,9 +97,12 @@ $null = New-Module {
|
||||||
|
|
||||||
switch (Get-SetupStage) {
|
switch (Get-SetupStage) {
|
||||||
($null) {
|
($null) {
|
||||||
Set-SetupStage ([SetupStage]::Configure);
|
Set-SetupStage ([SetupStage]::Initialize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
([SetupStage]::Initialize) {
|
||||||
|
Set-SetupStage ([SetupStage]::Configure);
|
||||||
|
}
|
||||||
([SetupStage]::Configure) {
|
([SetupStage]::Configure) {
|
||||||
if (Get-Config "valhalla.windows.dualboot.enable") {
|
if (Get-Config "valhalla.windows.dualboot.enable") {
|
||||||
if (-not (Test-Qemu)) {
|
if (-not (Test-Qemu)) {
|
||||||
|
@ -129,6 +142,65 @@ $null = New-Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
([WindowsInstallerAction]::Backup) {
|
||||||
|
$finished = $false;
|
||||||
|
$setupUser = Get-SetupUser;
|
||||||
|
|
||||||
|
$adminGroup = @{
|
||||||
|
SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null);
|
||||||
|
};
|
||||||
|
|
||||||
|
while (-not $finished) {
|
||||||
|
switch (Get-BackupStage) {
|
||||||
|
$null {
|
||||||
|
Set-BackupStage ([BackupStage]::Initialize);
|
||||||
|
}
|
||||||
|
([BackupStage]::Initialize) {
|
||||||
|
$null = New-LocalUser $setupUser -NoPassword;
|
||||||
|
Set-LocalUser $setupUser -PasswordNeverExpires $true;
|
||||||
|
Set-LocalUser $setupUser -PasswordNeverExpires $false;
|
||||||
|
Add-LocalGroupMember -Member $setupUser @adminGroup;
|
||||||
|
Set-AutologinUser $setupUser;
|
||||||
|
Disable-UAC;
|
||||||
|
Set-BackupStage ([BackupStage]::Backup);
|
||||||
|
Restart-Intermediate;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
([BackupStage]::Backup) {
|
||||||
|
Deploy-SoftwareAction ([InstallerAction]::Backup);
|
||||||
|
Set-BackupStage ([BackupStage]::BackupUsers);
|
||||||
|
}
|
||||||
|
([BackupStage]::BackupUsers) {
|
||||||
|
$users = @(Get-Users);
|
||||||
|
$i = Get-CurrentUser;
|
||||||
|
Disable-LocalUser $setupUser;
|
||||||
|
|
||||||
|
for (; $i -lt $users.Count; $i++) {
|
||||||
|
Set-CurrentUser $i;
|
||||||
|
$user = $users[$i];
|
||||||
|
|
||||||
|
if ($env:UserName -ne $user) {
|
||||||
|
Set-BootMessage "Please Log In" "Please log in with the user ``$user``";
|
||||||
|
Add-LocalGroupMember -Member "$user" @adminGroup -ErrorAction SilentlyContinue;
|
||||||
|
Disable-Autologin;
|
||||||
|
Restart-Intermediate;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Deploy-SoftwareAction -Action ([InstallerAction]::BackupUser);
|
||||||
|
Remove-LocalGroupMember -Member "$user" @adminGroup;
|
||||||
|
|
||||||
|
foreach ($group in Get-UserConfig -UserName "$user" "groups") {
|
||||||
|
Add-LocalGroupMember -Member "$user" $group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Disable-BootMessage;
|
||||||
|
$finished = $true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Stage ([WindowsInstallerStage]::Cleanup);
|
Set-Stage ([WindowsInstallerStage]::Cleanup);
|
||||||
|
|
|
@ -53,7 +53,7 @@ $null = New-Module {
|
||||||
function Get-StartupCommand {
|
function Get-StartupCommand {
|
||||||
($env:PWSH_PATH ? "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" : "") +
|
($env:PWSH_PATH ? "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" : "") +
|
||||||
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
($env:DEBUG ? "`$env:DEBUG = $([int]$env:DEBUG);" : "") +
|
||||||
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection (Resolve-Path $env:BACKUP_ARCHIVE));" : "") +
|
($env:BACKUP_ARCHIVE ? "`$env:BACKUP_ARCHIVE = $(ConvertTo-Injection ([System.IO.Path]::GetFullPath($env:BACKUP_ARCHIVE)));" : "") +
|
||||||
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
|
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
|
||||||
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
|
"`$env:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
|
||||||
"& `$env:INSTALLER_SCRIPT;";
|
"& `$env:INSTALLER_SCRIPT;";
|
||||||
|
|
Loading…
Reference in a new issue