@@ -389,10 +389,6 @@ function Find-UnitySetupInstaller {
389389
390390 [parameter (Mandatory = $false )]
391391 [string ]$Cache = [io.Path ]::Combine(" ~" , " .unitysetup" )
392-
393- # ,
394- # [parameter(Mandatory = $false)]
395- # [switch]$Verbose = $false
396392 )
397393
398394 # Note that this has to happen before calculating the full path since
@@ -584,23 +580,28 @@ function Find-UnitySetupInstaller {
584580
585581 Write-Verbose " Saving installer to $localCachedInstaller "
586582
587- Invoke-WebRequest $installerUrl - UseBasicParsing | Set-Content - Path $localCachedInstaller
583+ Invoke-WebRequest $installerUrl - OutFile $localCachedInstaller
584+
585+ chmod + x $localCachedInstaller
588586
589587 # Configuration file for installer
590588 $iniFileName = " unity-$Version -linux.ini"
591589 $iniUrl = " $baseUrl /$iniFileName "
592590
593591 # PsIni can read only from files and from stdin
594- $localCachedIni = " $Cache /$iniFileName "
592+ $localCachedIni = " $cachedInstallerBasePath /$iniFileName "
593+
594+ Invoke-WebRequest $iniUrl - UseBasicParsing - OutFile $localCachedIni
595595
596- Invoke-WebRequest $iniUrl - UseBasicParsing | Set-Content - Path $localCachedIni
596+ Write-Verbose $localCachedIni
597597
598598 $iniContent = Get-IniContent $localCachedIni
599599
600600 # fill from scratch accessible targets using retrieved .ini
601601 $installerTemplates = @ {}
602602
603603 foreach ($section in $iniContent.GetEnumerator ()) {
604+ # replace "-" with "_" to match enum entries
604605 $sectionName = $section.Name.Replace (' -' , " _" )
605606 $url = $iniContent [$section.Name ].url
606607
@@ -1024,67 +1025,60 @@ function Install-UnitySetupPackage {
10241025 }
10251026 }
10261027 ([OperatingSystem ]::Linux) {
1027-
1028- $VerbosePreference = " Continue "
1028+ # Assume that UnitySetup in the same folder as package
1029+ $basePackagePath = [ System.IO.Path ]::GetDirectoryName( $Package .Path )
10291030
1030- # TODO: assert that tar and 7z are installed
1031+ $versionRegEx = " (\d+)\.(\d+)\.(\d+)([fpba])(\d+)"
1032+ if (-not ($Package.Path -match $versionRegEx )) {
1033+ throw " Can't determine Unity version from package"
1034+ }
10311035
1032- Write-Verbose " Package path: $ ( $Package.Path ) "
1033- Write-Verbose " Destination: $Destination "
1036+ $version = $Matches [0 ]
10341037
1035- $isTarXz = $Package.Path -match " .*\.tar\.xz"
1036- $isPkg = $Package.Path -match " .*\.pkg"
1038+ # installer is expected to be already donwloaded to the same location during Find-UnitySetupInstaller invocation
1039+ $installerName = " UnitySetup-$version "
1040+ $installerPath = " $basePackagePath /$installerName "
10371041
1038- if ($isTarXz ) {
1039- Write-Verbose " .tar.xz"
1042+ if (-not (Test-Path $installerPath )) {
1043+ throw " Can't find Unity installer, expected at $installerPath "
1044+ }
10401045
1041- $unpackedDir = $ ( Resolve-Path " $ ( $ Package.Path ) " ) -replace ' \.tar\.xz$ ' , ' '
1042- New-Item - ItemType Directory - Force " $unpackedDir " | Out-Null
1046+ Write-Verbose " Package path: $ ( $ Package.Path ) "
1047+ Write-Verbose " Destination: $Destination "
10431048
1044- Write-Verbose " Unpack $ ( $Package .Path ) to $unpackedDir "
1049+ Import-Module PsIni - MinimumVersion ' 3.1.3 ' - ErrorAction Stop
10451050
1046- $startProcessArgs = @ {
1047- ' FilePath' = ' tar' ;
1048- ' ArgumentList' = @ (" xf" , $Package.Path , " -C" , " $unpackedDir " , " -v" );
1049- ' PassThru' = $true ;
1050- ' Wait' = $true ;
1051- }
1051+ $iniFileName = " unity-$Version -linux.ini"
1052+ $iniPath = " $basePackagePath /$iniFileName "
10521053
1053- StartProcessWithArgs($startProcessArgs )
1054- }
1055- elseif ($isPkg ) {
1056- Write-Verbose " .pkg"
1054+ $iniContent = Get-IniContent $iniPath
10571055
1058- $unpackedDir = $ (Resolve-Path " $ ( $Package.Path ) " ) -replace ' \.pkg$' , ' '
1059- New-Item - ItemType Directory - Force " $unpackedDir " | Out-Null
1056+ $componentName = " "
1057+ foreach ($section in $iniContent.GetEnumerator ()) {
1058+ $sectionName = $section.Name
1059+ $url = $iniContent [$section.Name ].url # e.g. "LinuxEditorInstaller/Unity.tar.xz"
10601060
1061- Write-Verbose " Unpack $ ( $Package.Path ) to $unpackedDir "
1061+ # this should match package name
1062+ $urlFileName = [System.IO.Path ]::GetFileName($url ) # e.g. "Unity.tar.xz"
10621063
1063- $startProcessArgs = @ {
1064- ' FilePath' = ' 7z' ;
1065- ' ArgumentList' = @ (" x" , $Package.Path , " -o$unpackedDir /" , " -t*" , " -y" );
1066- ' PassThru' = $true ;
1067- ' Wait' = $true ;
1068- }
1064+ Write-Verbose " Retrieved $url for $sectionName "
10691065
1070- StartProcessWithArgs( $startProcessArgs )
1071- }
1072- else {
1073- throw " $ ( $Package .Path ) has unsupported archive format "
1066+ if ( $Package .Path -like " * $urlFileName " ) {
1067+ $componentName = $sectionName
1068+ break
1069+ }
10741070 }
10751071
1076- $pkgInfo = [xml ](Get-Content ./ TargetSupport.pkg.tmp/ PackageInfo)
1077- $targetName = basename $ ($pkgInfo .' pkg-info' .' install-location' )
1078-
1079- Write-Verbose " targetName: $targetName "
1072+ if (-not $componentName ) {
1073+ throw " Could not determine proper component name for $ ( $Package.Path ) "
1074+ }
10801075
1081- return
1076+ # Note: this way user will be asked for license confirmation.
1077+ # To bypass it, one should use "yes | <command>"
10821078
1083- $payloadPath = " $unpackedDir /TargetSupport.pkg.tmp/Payload"
1084- # extract /TargetSupport.pkg.tmp/Payload to destination
10851079 $startProcessArgs = @ {
1086- ' FilePath' = ' 7z ' ;
1087- ' ArgumentList' = @ (" x " , $Package .Path , " -o $unpackedDir " , " -t* " );
1080+ ' FilePath' = " $installerPath " ;
1081+ ' ArgumentList' = @ (' -u ' , ' -l ' , $Destination , ' -d ' , $basePackagePath , ' -c ' , $componentName );
10881082 ' PassThru' = $true ;
10891083 ' Wait' = $true ;
10901084 }
0 commit comments