-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.psm1
More file actions
103 lines (94 loc) · 3.09 KB
/
functions.psm1
File metadata and controls
103 lines (94 loc) · 3.09 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
function InstallChocolatey {
try {
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
return $true
} catch {
Write-Error "Failed to install Chocolatey: $($_.Exception.Message)"
return $false
}
}
function CheckChocolateyInstallation {
$ChocolateyInstalled = Test-Path "C:\ProgramData\chocolatey\bin\choco.exe"
if (-not $ChocolateyInstalled) {
Write-Host "Chocolatey is not installed. Installing..." -ForegroundColor Yellow
return (InstallChocolatey)
}
return $true
}
function InstallGsudo {
Write-Information "Installing Gsudo..." -ForegroundColor Yellow
try {
winget install gerardog.gsudo --accept-source-agreements --accept-package-agreements -h --disable-interactivity
return $true
} catch {
Write-Error "Failed to install Gsudo: $($_.Exception.Message)"
return $false
}
}
function CheckGsudoInstallation {
$GsudoInstalled = Test-Path -Path "C:\Program Files\gsudo\Current\gsudo.exe"
if (-not $GsudoInstalled) {
Write-Host "Winget is not installed. Installing..." -ForegroundColor Yellow
return (InstallGsudo)
}
return $true
}
function InstallWinget {
if (CheckChocolateyInstallation) {
Write-Host "Installing winget via Chocolatey..." -ForegroundColor Yellow
try {
sudo choco install winget -y
return $true
} catch {
Write-Error "Failed to install winget via Chocolatey: $($_.Exception.Message)"
return $false
}
}
return $false
}
function InstallPwshViaWinget {
Write-Host "Installing PowerShell 7 via Winget..." -ForegroundColor Yellow
try {
winget install Microsoft.PowerShell --accept-source-agreements --accept-package-agreements -h --disable-interactivity
return $true
} catch {
Write-Error "Failed to install PowerShell 7 (pwsh) via winget: $($_.Exception.Message)"
return $false
}
}
function InstallPwshViaChocolatey {
Write-Host "Installing PowerShell 7 via Chocolatey..." -ForegroundColor Yellow
try {
choco.exe install powershell-core -y
return $true
} catch {
Write-Error "Failed to install PowerShell 7 (pwsh) via chocolatey: $($_.Exception.Message)"
return $false
}
}
function CheckWingetInstallation {
$wingetInstalled = Test-Path -Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*\winget.exe"
if (-not $wingetInstalled) {
Write-Host "Winget is not installed. Installing..." -ForegroundColor Yellow
return (InstallWinget)
}
return $true
# Start-Process -FilePath "winget" -ArgumentList "upgrade" -NoNewWindow -Wait
}
function CheckPwshInstallation {
$pwshInstalled = Test-Path "C:\Program Files\PowerShell\7\pwsh.exe"
if (-not $pwshInstalled) {
Write-Host "PowerShell 7 (pwsh) is not installed. Attempting to install..." -ForegroundColor Yellow
return (InstallPwsh)
}
return $true
# Start-Process -FilePath "pwsh" -ArgumentList "-NoExit" -NoNewWindow -Wait
}
function InstallPwsh {
if (CheckWingetInstallation) {
return InstallPwshViaWinget
}
return InstallPwshViaChocolatey
}