From c7efcdec733176bde1a0542f6c45723f5dc88ae7 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Fri, 26 Jul 2024 14:29:45 +0200
Subject: [PATCH] Pass the project path in to the installation script

---
 winiso/deploy.fish               | 27 ++++++++++++++++++++-------
 winiso/winfs/Scripts/Startup.ps1 |  8 +++-----
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/winiso/deploy.fish b/winiso/deploy.fish
index 17960ea0..4f7b1a9f 100644
--- a/winiso/deploy.fish
+++ b/winiso/deploy.fish
@@ -9,7 +9,13 @@ begin
         exit 1
     end
 
+    function mkWinPath
+        sed "s/\//\\\\/g"
+    end
+
     set -l setupLabel "winiso-valhalla"
+    set -l projectPath "PortValhalla"
+    set -l localProjectPath "sources/\$OEM\$/\$1/$projectPath"
     set -l buildDir "$(status dirname)/build"
     set -l cacheDir ~/.cache/winiso-valhalla
     set -l isoFile "$buildDir/winiso-valhalla.iso"
@@ -66,7 +72,7 @@ begin
         set -l url "$entry[2]"
         set -l type "$entry[3]"
         set -l dir "$entry[4]"
-        set -l winPath "X:\\$(echo "$name" | sed "s/\//\\\\/g")"
+        set -l winPath "X:\\$(echo "$name" | mkWinPath)"
         set -l file "$cacheDir/$name.$type"
         set -l target "$winpeOverlay/$name"
 
@@ -119,13 +125,15 @@ begin
             end
 
             printf %s\n \
-                "@echo off" \
-                "echo Loading Drivers..." (
+                "@echo off" (
                     string join ";" \
                         "set PATH=%PATH%" \
                         $path \
                         "$git[4]\\bin"
                 ) \
+                "set LOCAL_PROJECT_PATH=$(echo "$localProjectPath" | mkWinPath)" \
+                "set REMOTE_PROJECT_PATH=$(echo "$projectPath" | mkWinPath)" \
+                "echo Loading Drivers..." \
                 'pwsh -file "X:\Scripts\Drivers.ps1"' \
                 "echo Configuring Network..." \
                 "wpeinit" \
@@ -159,13 +167,18 @@ begin
     end
 
     begin
-        set -l sourceDir "$winOverlay/sources"
-        set -l projectPath "$sourceDir/\$OEM\$/\$1/PortValhalla"
-        chmod u+w "$sourceDir"
+        set -l projectPath "$winOverlay/$localProjectPath"
+        set -l rootDir "$projectPath"
+
+        while [ ! -d "$rootDir" ]
+            set rootDir (dirname "$rootDir")
+        end
+
+        chmod u+w "$rootDir"
         mkdir -p "$projectPath"
         source "$dir/../scripts/copy-repo.fish" "$projectPath"
         rm -rf "$projectPath/archiso"
-        chmod -R u-w "$sourceDir"
+        chmod -R u-w "$rootDir"
     end
 
     sudo mount --mkdir -t overlay overlay -o lowerdir="$winOverlay":"$winpePath":"$winPath",upperdir="$upperDir",workdir="$workDir" "$valhallaPath"
diff --git a/winiso/winfs/Scripts/Startup.ps1 b/winiso/winfs/Scripts/Startup.ps1
index 3a2cd806..f6311d7c 100644
--- a/winiso/winfs/Scripts/Startup.ps1
+++ b/winiso/winfs/Scripts/Startup.ps1
@@ -1,5 +1,3 @@
-$null = $env:WIN_COMPUTER_NAME;
-$null = $env:SETUP_SCRIPT_NAME;
-
-git clone https://git.nuth.ch/manuth/PortValhalla.git;
-Set-Location PortValhalla;
+$drives = & wmic volume get "DriveLetter,Label";
+$drive = $($($drives | Select-String -Pattern "winiso-valhalla") -split "\s+")[0];
+Set-Location (Join-Path $drive $env:LOCAL_PROJECT_PATH)