-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmake.ps1
More file actions
123 lines (114 loc) · 4.23 KB
/
Copy pathmake.ps1
File metadata and controls
123 lines (114 loc) · 4.23 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
#!/usr/bin/env pwsh
##############################################################################################################
Function Show-Usage {
Return "
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
Options:
build Build program
"
}
Function Request-File {
ForEach ($REPLY in $args) {
$OutFile = (Split-Path -Path $REPLY -Leaf).Split('?')[0]
$OutFilePath = Join-Path -Path (Get-Location) -ChildPath $OutFile
Try {
Write-Host "Downloading: $REPLY"
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $REPLY `
-OutFile $OutFilePath `
-TimeoutSec 600 `
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" `
-MaximumRedirection 5 | Out-Null
$fileSize = (Get-Item $OutFilePath).Length
Write-Host "Downloaded: $OutFile (Size: $([Math]::Round($fileSize/1MB, 2))MB)"
If ((Test-Path $OutFilePath) -and $fileSize -gt 100MB) {
Return $OutFile
} Else {
Throw "File is too small ($fileSize bytes) or doesn't exist"
}
} Catch {
Write-Error "Failed to download: $_"
If (Test-Path $OutFilePath) { Remove-Item $OutFilePath -Force }
Return $null
}
}
}
Function Install-Program {
While ($Input.MoveNext()) {
$FilePath = $Input.Current
If (Test-Path $FilePath) {
Write-Host "Installing: $FilePath"
$ext = (Split-Path -Path $FilePath -Leaf).Split('.')[-1]
Switch ($ext) {
'msi' {
& msiexec /passive /package $FilePath | Out-Host
}
'exe' {
& $FilePath /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Host
}
}
Remove-Item $FilePath -Force
Write-Host "Installation completed"
}
}
}
Function Build-Project {
$VAR = @{
Cmd = 'lazbuild'
Url = 'https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%204.8/lazarus-4.8-fpc-3.2.2-win64.exe/download'
Path = "C:\Lazarus"
}
Try {
Get-Command $VAR.Cmd | Out-Null
Write-Host "Lazarus is already installed"
} Catch {
Write-Host "Lazarus not found, installing..."
$OutFile = Request-File $VAR.Url
If ($OutFile) {
$OutFile | Install-Program
$env:PATH+=";$($VAR.Path)"
Get-Command $VAR.Cmd | Out-Null
Write-Host "Lazarus installed successfully"
} Else {
Throw "Failed to download Lazarus"
}
}
If ( Test-Path -Path 'use\components.txt' ) {
& git submodule update --recursive --init | Out-Host
& git submodule update --recursive --remote | Out-Host
Get-Content -Path 'use\components.txt' | ForEach-Object {
If ((-not (& lazbuild --verbose-pkgsearch $_ | Out-Null)) -and
(-not (& lazbuild --add-package $_ | Out-Null)) -and
(-not (Test-Path -Path 'use\components.txt'))) {
$OutFile = Request-File "https://packages.lazarus-ide.org/$($_).zip"
Expand-Archive -Path $OutFile -DestinationPath "use\$($_)" -Force
Remove-Item $OutFile
}
}
Get-ChildItem -Filter '*.lpk' -Recurse -File –Path 'use' | ForEach-Object {
& lazbuild --add-package-link $_ | Out-Host
}
}
Get-ChildItem -Filter '*.lpi' -Recurse -File –Path 'src' | ForEach-Object {
& lazbuild --no-write-project --recursive --build-mode=release $_ | Out-Host
}
}
Function Switch-Action {
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict -Trace 1
Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath
If ($args.count -gt 0) {
Switch ($args[0]) {
'build' {
Build-Project
}
Default {
Show-Usage
}
}
} Else {
Show-Usage
}
}
##############################################################################################################
Switch-Action @args | Out-Null