Compare commits

...

3 commits

6 changed files with 124 additions and 3 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
*.fish text eol=lf
*.sh text eol=lf

View file

@ -11,11 +11,18 @@ enum WindowsInstallerStage {
}
enum SetupStage {
Initialize
Configure
Install
CreateUser
}
enum BackupStage {
Initialize
Backup
BackupUsers
}
enum UserStage {
Create
Configure
@ -27,6 +34,7 @@ $null = New-Module {
[string] $configRoot = "HKLM:\Software\PortValhalla";
[string] $stageOption = "Stage";
[string] $setupStageOption = "SetupStage";
[string] $backupStageOption = "BackupStage";
[string] $userOption = "SetupUser";
[string] $userStageOption = "UserStage";
[string] $accountOption = "MSAccount";
@ -164,7 +172,7 @@ $null = New-Module {
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
if ($env:CONFIG_NAME) {
if ($env:CONFIG_NAME -or ($Script -eq "getProfiles")) {
$output = & {
if (-not $IsWindows) {
$escapedPath = (fish -c 'string escape $argv' "$scriptPath");
@ -408,6 +416,39 @@ $null = New-Module {
$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
Gets the current user to set up.

View file

@ -259,6 +259,10 @@ $null = New-Module {
}
};
if (-not $env:CONFIG_NAME) {
Show-ProfileNamePrompt;
}
$initialized = $true;
}
}

View file

@ -0,0 +1,4 @@
#!/bin/pwsh
. "$PSScriptRoot/Manage.ps1";
$env:INSTALLER_SCRIPT = "$PSCommandPath";
Start-WindowsBackup;

View file

@ -35,6 +35,16 @@ $null = New-Module {
};
}
<#
.SYNOPSIS
Creates a backup of the current Windows machine.
#>
function Start-WindowsBackup {
Start-Operation -NoImplicitCleanup {
Start-InstallationLoop ([WindowsInstallerAction]::Backup);
};
}
<#
.SYNOPSIS
Starts the installation loop.
@ -86,9 +96,12 @@ $null = New-Module {
switch (Get-SetupStage) {
($null) {
Set-SetupStage ([SetupStage]::Configure);
Set-SetupStage ([SetupStage]::Initialize);
break;
}
([SetupStage]::Initialize) {
Set-SetupStage ([SetupStage]::Configure);
}
([SetupStage]::Configure) {
if (Get-Config "valhalla.windows.dualboot.enable") {
if (-not (Test-Qemu)) {
@ -120,6 +133,8 @@ $null = New-Module {
Write-Host "Entering install phase";
Deploy-SoftwareAction;
Set-SetupStage ([SetupStage]::CreateUser);
Restart-Intermediate;
return;
}
([SetupStage]::CreateUser) {
Install-ValhallaUsers;
@ -128,6 +143,61 @@ $null = New-Module {
}
}
}
([WindowsInstallerAction]::Backup) {
$finished = $false;
$adminGroup = @{
SID = [SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null);
};
while (-not $finished) {
switch (Get-BackupStage) {
$null {
Set-BackupStage ([BackupStage]::Initialize);
}
([BackupStage]::Initialize) {
$user = Get-SetupUser;
Add-LocalUser $user;
Add-LocalGroupMember -Member "$user" @adminGroup;
Set-AutologinUser $user;
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;
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;
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);

View file

@ -53,7 +53,7 @@ $null = New-Module {
function Get-StartupCommand {
($env:PWSH_PATH ? "`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" : "") +
($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:CONFIG_NAME = $(ConvertTo-Injection $env:CONFIG_NAME);" +
"& `$env:INSTALLER_SCRIPT;";