@@ -366,6 +366,10 @@ function ConvertTo-UnitySetupComponent {
366
366
Manually specify the build hash, to select a private build.
367
367
. PARAMETER Components
368
368
What components would you like to search for? Defaults to All
369
+ . PARAMETER Cache
370
+ File path where installer and configuration for Linux will be downloaded to.
371
+ Preliminary installer and configuration download is necessary to retrieve actual paths of Unity components for Linux
372
+ and to allow subsequent components install. Defaults to ~/.unitysetup
369
373
. EXAMPLE
370
374
Find-UnitySetupInstaller -Version 2017.3.0f3
371
375
. EXAMPLE
@@ -381,9 +385,27 @@ function Find-UnitySetupInstaller {
381
385
[UnitySetupComponent ] $Components = [UnitySetupComponent ]::All,
382
386
383
387
[parameter (Mandatory = $false )]
384
- [string ] $Hash = " "
388
+ [string ] $Hash = " " ,
389
+
390
+ [parameter (Mandatory = $false )]
391
+ [string ]$Cache = [io.Path ]::Combine(" ~" , " .unitysetup" )
392
+
393
+ # ,
394
+ # [parameter(Mandatory = $false)]
395
+ # [switch]$Verbose = $false
385
396
)
386
397
398
+ # Note that this has to happen before calculating the full path since
399
+ # Resolve-Path throws an exception on missing paths.
400
+ if (! (Test-Path $Cache - PathType Container)) {
401
+ New-Item $Cache - ItemType Directory - ErrorAction Stop | Out-Null
402
+ }
403
+
404
+ # Expanding '~' to the absolute path on the system. `WebClient` on macOS asumes
405
+ # relative path. macOS also treats alt directory separators as part of the file
406
+ # name and this corrects the separators to current environment.
407
+ $fullCachePath = (Resolve-Path - Path $Cache ).Path
408
+
387
409
$Components = ConvertTo-UnitySetupComponent - Component $Components - Version $Version
388
410
389
411
$currentOS = Get-OperatingSystem
@@ -451,6 +473,9 @@ function Find-UnitySetupInstaller {
451
473
}
452
474
([OperatingSystem ]::Linux) {
453
475
$setupComponent = [UnitySetupComponent ]::Linux
476
+
477
+ # Note: This is the main installer small executable that is used to install all other components.
478
+ # It will be replaced later by Linux Editor component
454
479
$installerTemplates [$setupComponent ] = , " UnitySetup-$Version " ;
455
480
}
456
481
([OperatingSystem ]::Mac) {
@@ -541,16 +566,34 @@ function Find-UnitySetupInstaller {
541
566
542
567
$linkComponents = $prototypeLink -split " /$hashRegEx /" -ne " "
543
568
544
- $iniFileName = " unity-$Version -linux.ini"
545
- $baseUrl = $linkComponents [0 ] + " /" + $linkComponents [1 ]
546
- $iniLink = " $baseUrl /$iniFileName "
569
+ $unityPath = $linkComponents [0 ]
570
+ $unityHash = $linkComponents [1 ]
571
+ $unityVersion = $linkComponents [2 ] # simnilar to UnitySetup-2021.1.23f1
572
+
573
+ $baseUrl = " $unityPath /$unityHash "
574
+
575
+ Write-Verbose " Ready to download installer from $baseUrl "
576
+
577
+ # also download installer that will be used to install all other components
578
+ $installerName = $installerTemplates [[UnitySetupComponent ]::Linux ]
579
+ $installerUrl = " $baseUrl /$installerName "
580
+ $cachedInstallerBasePath = " $fullCachePath /Installers/Unity-$Version "
581
+ New-Item $cachedInstallerBasePath - ItemType Directory - Force | Out-Null
547
582
548
- $linuxIni = Invoke-WebRequest $iniLink - UseBasicParsing
583
+ $localCachedInstaller = " $cachedInstallerBasePath /$installerName "
584
+
585
+ Write-Verbose " Saving installer to $localCachedInstaller "
586
+
587
+ Invoke-WebRequest $installerUrl - UseBasicParsing | Set-Content - Path $localCachedInstaller
588
+
589
+ # Configuration file for installer
590
+ $iniFileName = " unity-$Version -linux.ini"
591
+ $iniUrl = " $baseUrl /$iniFileName "
549
592
550
593
# PsIni can read only from files and from stdin
551
- $localCachedIni = " /tmp /$iniFileName "
552
-
553
- Set-Content - Path $localCachedIni - Value $linuxIni
594
+ $localCachedIni = " $Cache /$iniFileName "
595
+
596
+ Invoke-WebRequest $iniUrl - UseBasicParsing | Set-Content - Path $localCachedIni
554
597
555
598
$iniContent = Get-IniContent $localCachedIni
556
599
@@ -947,6 +990,19 @@ function Request-UnitySetupInstaller {
947
990
}
948
991
}
949
992
993
+ function StartProcessWithArgs ($startProcessArgs )
994
+ {
995
+ $process = Start-Process @startProcessArgs
996
+ if ( $process ) {
997
+ if ( $process.ExitCode -ne 0 ) {
998
+ Write-Error " $ ( Get-Date ) : Failed with exit code: $ ( $process.ExitCode ) "
999
+ }
1000
+ else {
1001
+ Write-Verbose " $ ( Get-Date ) : Succeeded."
1002
+ }
1003
+ }
1004
+ }
1005
+
950
1006
function Install-UnitySetupPackage {
951
1007
[CmdletBinding ()]
952
1008
param (
@@ -968,7 +1024,70 @@ function Install-UnitySetupPackage {
968
1024
}
969
1025
}
970
1026
([OperatingSystem ]::Linux) {
971
- throw " Install-UnitySetupPackage has not been implemented on the Linux platform. Contributions welcomed!" ;
1027
+
1028
+ $VerbosePreference = " Continue"
1029
+
1030
+ # TODO: assert that tar and 7z are installed
1031
+
1032
+ Write-Verbose " Package path: $ ( $Package.Path ) "
1033
+ Write-Verbose " Destination: $Destination "
1034
+
1035
+ $isTarXz = $Package.Path -match " .*\.tar\.xz"
1036
+ $isPkg = $Package.Path -match " .*\.pkg"
1037
+
1038
+ if ($isTarXz ) {
1039
+ Write-Verbose " .tar.xz"
1040
+
1041
+ $unpackedDir = $ (Resolve-Path " $ ( $Package.Path ) " ) -replace ' \.tar\.xz$' , ' '
1042
+ New-Item - ItemType Directory - Force " $unpackedDir " | Out-Null
1043
+
1044
+ Write-Verbose " Unpack $ ( $Package.Path ) to $unpackedDir "
1045
+
1046
+ $startProcessArgs = @ {
1047
+ ' FilePath' = ' tar' ;
1048
+ ' ArgumentList' = @ (" xf" , $Package.Path , " -C" , " $unpackedDir " , " -v" );
1049
+ ' PassThru' = $true ;
1050
+ ' Wait' = $true ;
1051
+ }
1052
+
1053
+ StartProcessWithArgs($startProcessArgs )
1054
+ }
1055
+ elseif ($isPkg ) {
1056
+ Write-Verbose " .pkg"
1057
+
1058
+ $unpackedDir = $ (Resolve-Path " $ ( $Package.Path ) " ) -replace ' \.pkg$' , ' '
1059
+ New-Item - ItemType Directory - Force " $unpackedDir " | Out-Null
1060
+
1061
+ Write-Verbose " Unpack $ ( $Package.Path ) to $unpackedDir "
1062
+
1063
+ $startProcessArgs = @ {
1064
+ ' FilePath' = ' 7z' ;
1065
+ ' ArgumentList' = @ (" x" , $Package.Path , " -o$unpackedDir /" , " -t*" , " -y" );
1066
+ ' PassThru' = $true ;
1067
+ ' Wait' = $true ;
1068
+ }
1069
+
1070
+ StartProcessWithArgs($startProcessArgs )
1071
+ }
1072
+ else {
1073
+ throw " $ ( $Package.Path ) has unsupported archive format"
1074
+ }
1075
+
1076
+ $pkgInfo = [xml ](Get-Content ./ TargetSupport.pkg.tmp/ PackageInfo)
1077
+ $targetName = basename $ ($pkgInfo .' pkg-info' .' install-location' )
1078
+
1079
+ Write-Verbose " targetName: $targetName "
1080
+
1081
+ return
1082
+
1083
+ $payloadPath = " $unpackedDir /TargetSupport.pkg.tmp/Payload"
1084
+ # extract /TargetSupport.pkg.tmp/Payload to destination
1085
+ $startProcessArgs = @ {
1086
+ ' FilePath' = ' 7z' ;
1087
+ ' ArgumentList' = @ (" x" , $Package.Path , " -o$unpackedDir " , " -t*" );
1088
+ ' PassThru' = $true ;
1089
+ ' Wait' = $true ;
1090
+ }
972
1091
}
973
1092
([OperatingSystem ]::Mac) {
974
1093
# Note that $Destination has to be a disk path.
@@ -983,15 +1102,7 @@ function Install-UnitySetupPackage {
983
1102
}
984
1103
985
1104
Write-Verbose " $ ( Get-Date ) : Installing $ ( $Package.ComponentType ) to $Destination ."
986
- $process = Start-Process @startProcessArgs
987
- if ( $process ) {
988
- if ( $process.ExitCode -ne 0 ) {
989
- Write-Error " $ ( Get-Date ) : Failed with exit code: $ ( $process.ExitCode ) "
990
- }
991
- else {
992
- Write-Verbose " $ ( Get-Date ) : Succeeded."
993
- }
994
- }
1105
+ StartProcessWithArgs($startProcessArgs )
995
1106
}
996
1107
997
1108
<#
@@ -1033,7 +1144,7 @@ function Install-UnitySetupInstance {
1033
1144
)
1034
1145
begin {
1035
1146
$currentOS = Get-OperatingSystem
1036
-
1147
+
1037
1148
if ( -not $PSBoundParameters.ContainsKey (' BasePath' ) ) {
1038
1149
$defaultInstallPath = switch ($currentOS ) {
1039
1150
([OperatingSystem ]::Windows) {
0 commit comments