-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxlings-install.ps1.txt
157 lines (130 loc) · 4.15 KB
/
xlings-install.ps1.txt
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
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env pwsh
#Requires -version 5
function Show-Progress {
param (
[string]$Activity,
[int]$PercentComplete
)
if ($PercentComplete -ge 100) {
Write-Progress -Activity $Activity -Completed
} else {
Write-Progress -Activity $Activity -PercentComplete $PercentComplete
}
}
$xlingsBinDir = "C:\Users\Public\xlings\bin"
$softwareName = "xlings"
$tempDir = [System.IO.Path]::GetTempPath()
$installDir = Join-Path $tempDir $softwareName
$zipFile = Join-Path $tempDir "$softwareName.zip"
$downloadUrl = "https://github.com/d2learn/xlings/archive/refs/heads/main.zip"
# ---------------------------------------------------------------
$xlings = @"
__ __ _ _
\ \ / / | | (_) pre-v0.0.1
\ V / | | _ _ __ __ _ ___
> < | | | || '_ \ / _ |/ __|
/ . \ | |____| || | | || (_| |\__ \
/_/ \_\ |______|_||_| |_| \__, ||___/
__/ |
|___/
repo: https://github.com/d2learn/xlings
forum: https://forum.d2learn.org
---
"@
Write-Host $xlings -ForegroundColor Green
$SOFTWARE_URL1 = "https://github.com/d2learn/xlings/archive/refs/heads/main.zip"
$SOFTWARE_URL2 = "https://gitee.com/sunrisepeak/xlings-pkg/raw/master/xlings-main.zip"
function Measure-Latency {
param (
[string]$Url
)
$domain = ([System.Uri]$Url).Host
try {
$ping = Test-Connection -ComputerName $domain -Count 3 -ErrorAction Stop
$latency = $ping | Measure-Object -Property ResponseTime -Average | Select-Object -ExpandProperty Average
return [math]::Round($latency, 2)
}
catch {
Write-Warning "Unable to ping $domain"
return 999999
}
}
Write-Host "Testing network..."
$latency1 = Measure-Latency -Url $SOFTWARE_URL1
$latency2 = Measure-Latency -Url $SOFTWARE_URL2
Write-Host "Latency for github.com : $latency1 ms"
Write-Host "Latency for gitee.com : $latency2 ms"
if ($latency1 -lt $latency2) {
$downloadUrl = $SOFTWARE_URL1
}
else {
$downloadUrl = $SOFTWARE_URL2
}
#Write-Host "Final URL: $downloadUrl"
#exit 0
# ---------------------------------------------------------------
# Clear old-cache
if (Test-Path $installDir) {
Remove-Item $installDir -Recurse -Force
}
if (Test-Path $zipFile) {
Remove-Item $zipFile -Force
}
# Create Dir
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
# Downloading
Show-Progress -Activity "Downloading $softwareName" -PercentComplete 10
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipFile -UseBasicParsing
}
catch {
Write-Error "Failed to download the software: $_"
Read-Host "Press Enter to exit"
exit 1
}
# Extracting
Show-Progress -Activity "Extracting $softwareName" -PercentComplete 30
try {
Expand-Archive -Path $zipFile -DestinationPath $installDir -Force
}
catch {
Write-Error "Failed to extract the software: $_"
Read-Host "Press Enter to exit"
exit 1
}
# Install
Show-Progress -Activity "Installing $softwareName" -PercentComplete 50
$installScript = Get-ChildItem -Path $installDir -Recurse -Include "install.win.bat" | Select-Object -First 1
if ($installScript) {
try {
Push-Location $installScript.Directory
cd $installDir\xlings-main
if ($installScript.Name -eq "install.win.bat") {
& cmd.exe /c $installScript.FullName disable_reopen
}
else {
#& $installScript.FullName
}
Pop-Location
}
catch {
Write-Error "Failed to run the installation script: $_"
Read-Host "Press Enter to exit"
exit 1
}
}
else {
Write-Error "Installation script not found: $installScript"
Read-Host "Press Enter to exit"
exit 1
}
# Clear
Show-Progress -Activity "Cleaning up..." -PercentComplete 70
Write-Host "removing directory: $installDir (tmpfiles)"
Remove-Item $installDir -Recurse -Force
Remove-Item $zipFile -Force
Show-Progress -Activity "Installation complete" -PercentComplete 100
Write-Host "$softwareName has been successfully installed."
# Update env
$env:Path += ";$xlingsBinDir"
# powershell.exe -ExecutionPolicy Bypass -File tools/other/quick_install.ps1