From 9918465b275bbac21833b323c8253c6a23affdf7 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Thu, 21 Mar 2024 00:06:34 +0100
Subject: [PATCH] Allow installing PowerShell scripts for the default user

---
 scripts/Common/Config/powershell/lib.ps1 | 41 +++++++++++++++---------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/scripts/Common/Config/powershell/lib.ps1 b/scripts/Common/Config/powershell/lib.ps1
index cbdc532f..68f4e0ea 100644
--- a/scripts/Common/Config/powershell/lib.ps1
+++ b/scripts/Common/Config/powershell/lib.ps1
@@ -4,9 +4,12 @@ $null = New-Module {
         param (
             [Parameter(ParameterSetName="Global", Mandatory)]
             [switch]$System,
+            [Parameter(ParameterSetName="DefaultUser", Mandatory)]
+            [switch]$DefaultUser,
             [Parameter(ParameterSetName="Home")]
             [string]$HomeDir = "~",
             [Parameter(ParameterSetName="Global", Mandatory)]
+            [Parameter(ParameterSetName="DefaultUser")]
             [Parameter(ParameterSetName="Home")]
             [string]$Category = $null,
             [Parameter(Position=0, Mandatory=$true)]
@@ -29,6 +32,14 @@ $null = New-Module {
         } else {
             [System.Collections.Generic.List[string]] $shells = @();
 
+            if ($DefaultUser) {
+                if ($IsWindows) {
+                    $HomeDir = "C:/Users/Default";
+                } else {
+                    $HomeDir = "/etc/skel"
+                }
+            }
+
             if (Get-Command pwsh -ErrorAction SilentlyContinue) {
                 $shells.Add("pwsh");
             }
@@ -44,6 +55,21 @@ $null = New-Module {
 
             Push-Location ~;
             $profiles = $profiles | ForEach-Object { [System.IO.Path]::GetRelativePath($(Get-Location), $_); };
+
+            $profiles | ForEach-Object {
+                $fileName = "$HomeDir/$_";
+                $dirName = Split-Path -Parent $fileName;
+
+                if (-not (Test-Path -PathType Container $dirName)) {
+                    $null = New-Item -ItemType Directory -Force $dirName;
+                }
+
+                if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {
+                    Add-Content -Force "$fileName" "`n$Statement";
+                } else {
+                    Set-Content -Force "$fileName" "$Statement";
+                }
+            };
         }
 
         if ($Category) {
@@ -54,21 +80,6 @@ $null = New-Module {
             $profiles = $profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "conf.d" "$Category.ps1"; };
         }
 
-        $profiles | ForEach-Object {
-            $fileName = "$HomeDir/$_";
-            $dirName = Split-Path -Parent $fileName;
-
-            if (-not (Test-Path -PathType Container $dirName)) {
-                $null = New-Item -ItemType Directory -Force $dirName;
-            }
-
-            if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {
-                Add-Content -Force "$fileName" "`n$Statement";
-            } else {
-                Set-Content -Force "$fileName" "$Statement";
-            }
-        };
-
         Pop-Location;
     }