-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv.ps1
More file actions
52 lines (42 loc) · 1.94 KB
/
Copy pathenv.ps1
File metadata and controls
52 lines (42 loc) · 1.94 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
# Copyright 2022-2026 The MathWorks, Inc.
# This file is sourced by powershell at launch of the EC2 instance in user data.
# It defines all the environment variables required to startup properly.
# Obtain IMDSv2 session token
$IMDSToken = Invoke-RestMethod `
-Method PUT `
-Uri 'http://169.254.169.254/latest/api/token' `
-Headers @{ 'X-aws-ec2-metadata-token-ttl-seconds' = '21600' }
$IMDSHeaders = @{ 'X-aws-ec2-metadata-token' = $IMDSToken }
$Env:MATLABRoot = (Get-Item (Get-Command matlab).Path).Directory.Parent.FullName
$Env:PolyspaceRoot = $Env:MATLABRoot -replace 'MATLAB','Polyspace'
$Env:MATLABRelease = ([xml](Get-Content "$Env:MATLABRoot\VersionInfo.xml")).MathWorks_version_info.release
$Env:MJSBinDirectory = "$Env:MATLABRoot\toolbox\parallel\bin"
$Env:MJSDefFile = "$Env:MJSBinDirectory\mjs_def.bat"
$Env:EbsVolume = Invoke-RestMethod `
-Uri 'http://169.254.169.254/latest/meta-data/block-device-mapping/ebs1' `
-Headers $IMDSHeaders
If ($Env:EbsVolume) {
$Env:CheckpointRoot = 'D:\MJS\Checkpoint'
} Else {
$Env:CheckpointRoot = "$Env:ProgramData\MJS\Checkpoint"
}
$Env:SecurityRoot = "$Env:CheckpointRoot\security"
$Env:SecretFile = "$Env:SecurityRoot\secret"
$Env:CertFile = "$Env:SecurityRoot\cert"
$Env:MJSAdminPasswordFile = "$Env:SecurityRoot\initial_admin_password"
$Env:LocalHostname = Invoke-RestMethod `
-Uri 'http://169.254.169.254/latest/meta-data/local-hostname' `
-Headers $IMDSHeaders
$Env:DnsSearchSuffix = $Env:LocalHostname.Substring($Env:LocalHostname.IndexOf('.') + 1)
$Env:LocalIPv4 = Invoke-RestMethod `
-Uri 'http://169.254.169.254/latest/meta-data/local-ipv4' `
-Headers $IMDSHeaders
# public-hostname returns 404 when the instance has no public IP, treat it as empty
try {
$Env:PublicHostname = Invoke-RestMethod `
-Uri 'http://169.254.169.254/latest/meta-data/public-hostname' `
-Headers $IMDSHeaders `
-ErrorAction Stop
} catch {
$Env:PublicHostname = ''
}