-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmx_install.ps1
69 lines (57 loc) · 2.24 KB
/
gmx_install.ps1
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
# Check if the script is running on Windows
if ($env:OS -eq "Windows_NT") {
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not ($currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
# If running on Windows, execute with elevated privileges
Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
Exit
} else {
Write-Host "User is elevated."
}
} else {
$currentUser = whoami
if (-not ($currentUser -eq "root")) {
# If running on macOS, execute with sudo
sudo pwsh -NoProfile -ExecutionPolicy Bypass -File "$PSCommandPath"
Exit
} else {
Write-Host "User is elevated."
}
}
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptpath
Push-Location $scriptDir # make sure the working directory is the script directory
$gmodPath = Read-Host -Prompt 'Input Garrys Mod path'
function SymLink {
param ([string]$sourcePath, [string]$targetPath)
Write-Host "Creating symlink $sourcePath -> $targetPath"
if ((Test-Path -Path $targetPath)) {
(Get-Item $targetPath).Delete()
}
try {
New-Item -ItemType SymbolicLink -Path $targetPath -Target $sourcePath
Write-Host "Symlink created" -ForegroundColor Green
} catch [System.Exception] {
Write-Host "Failed to create symlink $sourcePath -> $targetPath : $_" -ForegroundColor Red
}
}
# core
$symLinks = "gmx", "menu/menu.lua", "menu/_menu.lua"
Foreach ($link in $symLinks) {
$sourcePath = Join-Path -Path (Resolve-Path "./lua") -ChildPath "$link"
$targetPath = Join-Path -Path $gmodPath -ChildPath "lua/$link"
SymLink $sourcePath $targetPath
}
# binaries
Get-ChildItem "./lua/bin" -Filter *.dll | ForEach-Object {
$targetFileName = Split-Path "$_" -Leaf
$sourcePath = Join-Path -Path (Resolve-Path "./") -ChildPath "lua/bin/$targetFileName"
$targetPath = Join-Path -Path $gmodPath -ChildPath "lua/bin/$targetFileName"
SymLink $sourcePath $targetPath
}
# source theme
$sourceSchemePath = Resolve-Path "./resource/SourceScheme.res"
$targetSchemePath = Join-Path -Path $gmodPath -ChildPath "resource/SourceScheme.res"
SymLink $sourceSchemePath $targetSchemePath
Write-Host "All done! Exiting in 5s..."
Start-Sleep -Seconds 5