-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.ps1
More file actions
144 lines (116 loc) · 4.93 KB
/
Copy pathsetup.ps1
File metadata and controls
144 lines (116 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Automated setup script for TUM Main Campus Unity Project
# Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
# Ensure script is running with administrator privileges
# if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Write-Error "This script must be run as Administrator! Restart the runner in a privileged shell."
# Exit 1
# }
# Set execution policy
# Set-ExecutionPolicy Unrestricted -Force
# Function to check if a command exists
function Test-CommandExists {
param ($command)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try { if (Get-Command $command) { return $true } }
catch { return $false }
finally { $ErrorActionPreference = $oldPreference }
}
# Install PowerShell modules if needed
if (Get-Module -ListAvailable -Name "powershell-yaml") {
Write-Host "PowerShell YAML module is already installed"
} else {
Write-Host "Installing PowerShell YAML module..."
Install-Module -Name powershell-yaml -Force
}
# Import required modules
Import-Module powershell-yaml
Write-Host "Searching for Python 3.11..."
# 1. Get all python executables available in the system PATH
$allPythons = where.exe python
$pythonCmd = $null
# 2. Loop through them to find version 3.11
foreach ($py in $allPythons) {
# Skip the Windows Store shortcut to avoid triggering the Microsoft Store popup
if ($py -match "WindowsApps") { continue }
# Check the version of this specific executable
$version = & $py --version 2>&1
if ($version -match "3\.11") {
$pythonCmd = $py
Write-Host "Success: Found Python 3.11 at $pythonCmd"
break
}
}
# 3. Exit if we never found a 3.11 version
if ($null -eq $pythonCmd) {
Write-Host "Python 3.11 is not installed or not in your PATH. Please install from https://www.python.org/downloads/"
Exit 1
}
# Install vcstool2
Write-Host "Installing vcstool2..."
& $pythonCmd -m pip install vcstool2
# Importing submodules using vcs
Write-Host "Importing submodules..."
# Try multiple potential locations for vcs
$vcsCommand = $null
# First try: installed via pip command
try {
$vcsPath = (& $pythonCmd -m pip show vcstool2 -f | Select-String "Location:" | ForEach-Object { $_.ToString().Split("Location:")[1].Trim() }) + "\Scripts\vcs.exe"
if (Test-Path $vcsPath) {
$vcsCommand = $vcsPath
}
} catch {
Write-Host "Could not find vcs.exe in pip location"
}
# Use the vcs command if found, otherwise fall back to direct git clone
if ($vcsCommand) {
Write-Host "Using vcs command at $vcsCommand"
Get-Content -Path "assets.repos" | & $vcsCommand import
} else {
Write-Host "Falling back to manual Git clone method using the assets.repos file..."
try {
# Read and parse the assets.repos file
$reposContent = Get-Content -Path "assets.repos" -Raw
$reposYaml = ConvertFrom-Yaml -Yaml $reposContent
if ($null -eq $reposYaml -or $null -eq $reposYaml.repositories) {
throw "Invalid YAML structure in assets.repos"
}
foreach ($repoPath in $reposYaml.repositories.Keys) {
$repo = $reposYaml.repositories[$repoPath]
$url = $repo.url
$branch = $repo.version
if (-not (Test-Path $repoPath)) {
Write-Host "Cloning repository to $repoPath..."
# Create the directory structure if it doesn't exist
New-Item -ItemType Directory -Path (Split-Path -Parent $repoPath) -Force | Out-Null
git clone -b $branch $url $repoPath
} else {
Write-Host "Directory $repoPath already exists, skipping..."
}
}
} catch {
Write-Host "Error parsing or using assets.repos file: $_"
}
}
# Create Assets/3d_model directory if it doesn't exist
if (-not (Test-Path "Assets/3d_model")) {
New-Item -ItemType Directory -Path "Assets/3d_model" -Force
}
# Setup Sumo Python environment
Write-Host "Setting up Sumo Python environment..."
# Check if Sumonity/SumoTraCI path exists after import
if (-not (Test-Path "Assets/Sumonity/SumoTraCI")) {
Write-Host "Assets/Sumonity/SumoTraCI directory does not exist yet. This is expected if the vcstool import hasn't completed."
Write-Host "You may need to run the setup script again after the repositories are cloned, or manually set up the Python environment."
Exit 0
}
cd Assets/Sumonity/SumoTraCI
# Install virtualenv
& $pythonCmd -m pip install virtualenv
# Create and activate virtual environment. Unity ignores folders starting with "." (https://docs.unity3d.com/Manual/SpecialFolders.html).
& $pythonCmd -m venv .venv
.\.venv\Scripts\Activate
# Install requirements
pip install -r requirements.txt
Write-Host "Setup completed successfully!"
Write-Host "You can now open the project in Unity and run the 'Main Campus' scene."