forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-IronPython.ps1
More file actions
executable file
·143 lines (120 loc) · 5.74 KB
/
Install-IronPython.ps1
File metadata and controls
executable file
·143 lines (120 loc) · 5.74 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
#!/usr/bin/env pwsh
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.
<#
.SYNOPSIS
Install IronPython 3 from an official zip file distributable.
.DESCRIPTION
This script facilitates installation of IronPython binaries from a zip file. The zip file is assumed to have content as published on the IronPython's download page. The zip file is produced by IronPython's "package" build target.
.EXAMPLE
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0/IronPython.3.4.0.zip -OutFile IronPython.3.4.0.zip
PS>Expand-Archive -Path IronPython.3.4.0.zip -DestinationPath IronPython-unzipped
PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.0
The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.0.
.EXAMPLE
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0/IronPython.3.4.0.zip -OutFile IronPython.3.4.0.zip
PS>Install-IronPython -Path ~/ipyenv/v3.4.0 -ZipFile IronPython.3.4.0.zip -Framework net462 -Force
The official binaries are downloaded from GitHub to the current directory and then the installation proceeds using the downloaded zip file. IronPython is installed into ~/ipyenv/v3.4.0, overwriting any previous installation in that location. IronPython binaries running on .NET Framework 4.6.2 are used during the installation.
This example assumes that the installation script is in a directory on the search path ($env:PATH).
.EXAMPLE
PS>./make
PS>./make package
PS>./Src/Scripts/Install-IronPython.ps1 env
These commands should be issued on a Powershell prompt with the current directory set to the project root.
The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env".
#>
[CmdletBinding()]
Param(
# Target directory to which IronPython is to be installed.
[Parameter(Position=0, Mandatory)]
[string] $Path,
# The path to the downloaded zip file with IronPython binaries. If empty, the script will try to grab the package directly produced by the local build.
[string] $ZipFile,
# The moniker of the .NET platform to install for.
[string] $Framework = "net6.0",
# If the target path exists, it will be wiped clean beforehand.
[switch] $Force
)
$ErrorActionPreference = "Stop"
if (-not $ZipFile) {
# If zipfile path not given, try to locate it
$splitPSScriptRoot = $PSScriptRoot -split "\$([IO.Path]::DirectorySeparatorChar)"
if ($splitPSScriptRoot[-1] -eq "scripts" -and (Test-Path (Join-Path (Split-Path $PSScriptRoot) "lib"))) {
# Script run from within already expanded zip file
$unzipDir = $PSScriptRoot | Split-Path
} elseif ($splitPSScriptRoot[-2] -eq "Src" -and $splitPSScriptRoot[-1] -eq "Scripts") {
# Script run from within a checked out code base
# Locate the zip archive in the standard location of the package target
$projectRoot = $PSScriptRoot | Split-Path | Split-Path
$zipFiles = @(Resolve-Path (Join-Path $projectRoot "Package/Release/Packages/IronPython-*/IronPython.3.*.zip"))
if ($zipFiles.Count -gt 1) {
Write-Error (@("Ambiguous implicit project zip files:") + $zipFiles -join "`n")
} elseif ($zipFiles.Count -lt 1) {
Write-Error "Missing zip file. Have you run './make package'?"
}
$ZipFile = $zipFiles
} else {
Write-Error "Cannot locate implicit zip file. Provide path to the zip file using '-ZipFile <path>'."
}
} elseif (-not (Test-Path $ZipFile)) {
Write-Error "ZipFile not found: $ZipFile"
}
# Prepare destination path
if (Test-Path $Path) {
if ($Force) {
if ((Resolve-Path $Path).Count -gt 1) {
Write-Error "Overwriting of multiple destinations not allowed: $Path"
}
Remove-Item -Path $Path -Force -Recurse
} else {
Write-Error "Path already exists: $Path"
}
}
New-Item $Path -ItemType Directory | Out-Null
# Unzip archive
if (-not $unzipDir) {
$unzipDir = Join-Path $Path "unzipped"
Expand-Archive -Path $ZipFile -DestinationPath $unzipDir
$unzipped = $true
}
# Copy files into place
Copy-Item -Path (Join-Path $unzipDir (Join-Path $Framework "*")) -Destination $Path -Recurse
Copy-Item -Path (Join-Path $unzipDir "lib") -Destination $Path -Recurse
# Prepare startup scripts
if ($Framework -notlike "net4*") {
$ipyPath = Join-Path $Path "ipy.ps1"
Set-Content -Path $ipyPath -Value @'
#!/usr/bin/env pwsh
dotnet (Join-Path $PSScriptRoot ipy.dll) @args
'@
if ($PSVersionTable.PSEdition -eq "Desktop" -or $IsWindows) {
$ipyPath = Join-Path $Path "ipy.bat"
Set-Content -Path $ipyPath -Value @'
@dotnet "%~dp0ipy.dll" %*
'@
}
if ($IsMacOS -or $IsLinux) {
chmod +x $ipyPath
chmod +x (Join-Path $Path "ipy.sh")
Move-Item -Path (Join-Path $Path "ipy.sh") -Destination (Join-Path $Path "ipy")
}
} elseif ($IsMacOS -or $IsLinux) { # Mono
$ipyPath = Join-Path $Path "ipy"
Set-Content -Path $ipyPath -Value @'
#!/bin/sh
BASEDIR=$(dirname "$0")
ABS_PATH=$(cd "$BASEDIR"; pwd)
mono "$ABS_PATH/ipy.exe" "$@"
'@
chmod +x $ipyPath
}
# Install additional scripts
Copy-Item -Path (Join-Path $unzipDir "scripts/Enter-IronPythonEnvironment.ps1") -Destination $Path
if ($IsMacOS -or $IsLinux) {
chmod -x (Join-Path $Path "Enter-IronPythonEnvironment.ps1")
}
# Clean up unzipped files
if ($unzipped) {
Remove-Item -Path $unzipDir -Recurse
}