# Riflo public fresh installation, using a fixed HTTPS archive and exact SHA-256 identities. # Native components remain unsigned; these integrity pins are not Authenticode or a publisher signature. # Standard installation: usage reporting and visual sponsors, as described on riflo.app. # Local-only installation remains available at /install.ps1. No automatic music or model calls. [CmdletBinding()]param([switch]$Inspect,[switch]$EnableStatisticsAndSponsors=$true) $ErrorActionPreference='Stop' Set-StrictMode -Version Latest if($env:OS-cne'Windows_NT'-or-not[Environment]::Is64BitProcess){throw 'Use an ordinary 64-bit Windows PowerShell session.'} # Data verification only until the caller explicitly invokes the checked entry. foreach($musicModule in @('Microsoft.PowerShell.Management','Microsoft.PowerShell.Utility','Microsoft.PowerShell.Security')){Import-Module (Join-Path $PSHOME ('Modules\'+$musicModule+'\'+$musicModule+'.psd1')) -ErrorAction Stop} function Assert-MusicDownloadPath([string]$Path){ if($Path-cnotmatch'^[A-Za-z]:[\\/]' -or $Path-match'[\x00-\x1f<>|*?"%]' -or $Path.Substring(2).Contains(':')){throw 'Use a literal local download directory.'} $full=[IO.Path]::GetFullPath($Path).TrimEnd('\','/');if($full.Length-le3){throw 'A drive root is not a download directory.'} for($at=$full;$at;$at=[IO.Path]::GetDirectoryName($at)){if((Test-Path -LiteralPath $at)-and((Get-Item -LiteralPath $at -Force).Attributes-band[IO.FileAttributes]::ReparsePoint)){throw 'Download paths cannot contain filesystem links.'}} return $full } function Protect-MusicDownloadDirectory([string]$Directory){ $sid=[Security.Principal.WindowsIdentity]::GetCurrent().User;$acl=[Security.AccessControl.DirectorySecurity]::new();$acl.SetOwner($sid);$acl.SetAccessRuleProtection($true,$false) $acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new($sid,'FullControl','ContainerInherit,ObjectInherit','None','Allow'));Set-Acl -LiteralPath $Directory -AclObject $acl } function New-MusicDownloadDirectory([string]$Cache){ $cache=Assert-MusicDownloadPath $Cache if(-not(Test-Path -LiteralPath $cache)){[void][IO.Directory]::CreateDirectory($cache);Protect-MusicDownloadDirectory $cache} $acl=Get-Acl -LiteralPath $cache;$sid=[Security.Principal.WindowsIdentity]::GetCurrent().User.Value if($acl.GetOwner([Security.Principal.SecurityIdentifier]).Value-cne$sid-or-not$acl.AreAccessRulesProtected){throw 'The Music download cache requires protected account ownership.'} foreach($rule in $acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier])){if($rule.AccessControlType-eq'Allow'-and$rule.IdentityReference.Value-cne$sid){throw 'The Music download cache permits another identity.'}} $run=Join-Path $cache ([guid]::NewGuid().ToString('N'));[void][IO.Directory]::CreateDirectory($run);return $run } function Get-MusicHttpsFile([string]$Url,[string]$Destination,[long]$Maximum,[int]$Seconds){ $uri=[uri]$Url if($uri.Scheme-cne'https'-or$uri.Authority-cne'admin.130.61.58.111.nip.io'-or$uri.UserInfo-or$uri.Query-or$uri.Fragment-or$uri.AbsolutePath-cnotmatch'^/music/(?:[a-zA-Z0-9._-]+/)*[a-zA-Z0-9._-]+$'){throw 'Unapproved Music download destination.'} if($Maximum-lt1-or$Maximum-gt268435456-or$Seconds-lt1-or$Seconds-gt900){throw 'Invalid Music download budget.'} [void](Assert-MusicDownloadPath $Destination) $clock=[Diagnostics.Stopwatch]::StartNew();$output=$null;$pieceLimit=8388608L try{ $output=[IO.File]::Open($Destination,'CreateNew','Write','None') while($output.Length-lt$Maximum){ $start=$output.Length;$end=[Math]::Min($Maximum-1,$start+$pieceLimit-1);$length=[int]($end-$start+1) $piece=New-Object byte[] $length;$complete=$false for($attempt=1;$attempt-le3;$attempt++){ $remaining=[int][Math]::Floor($Seconds-$clock.Elapsed.TotalSeconds) if($remaining-lt1){throw [TimeoutException]::new('Music download exceeded its total deadline.')} $request=[Net.HttpWebRequest]::Create($uri);$request.AllowAutoRedirect=$false;$request.Timeout=[Math]::Min($remaining*1000,60000);$request.ReadWriteTimeout=[Math]::Min($remaining*1000,15000);$request.UserAgent='Riflo-Verified-Setup/2';$request.AutomaticDecompression=[Net.DecompressionMethods]::None;$request.AddRange([long]$start,[long]$end) $response=$null;$inputStream=$null try{ $response=$request.GetResponse() $expectedRange='bytes '+$start+'-'+$end+'/'+$Maximum if([int]$response.StatusCode-ne206-or$response.ContentLength-ne$length-or$response.Headers['Content-Range']-cne$expectedRange-or$response.Headers['Content-Encoding']){throw [IO.InvalidDataException]::new('Music download range or size differed from the pinned package.')} $inputStream=$response.GetResponseStream();$received=0 while($received-lt$length){ if($clock.Elapsed.TotalSeconds-gt$Seconds){throw [TimeoutException]::new('Music download exceeded its total deadline.')} $count=$inputStream.Read($piece,$received,$length-$received) if($count-eq0){throw [IO.EndOfStreamException]::new('Music download segment was interrupted.')} $received+=$count } $complete=$true }catch{ $retryable=$false;$invalid=$false;$httpStatus=0 for($cause=$_.Exception;$null-ne$cause;$cause=$cause.InnerException){ if($cause-is[IO.InvalidDataException]-or$cause-is[TimeoutException]){$invalid=$true} if($cause-is[IO.IOException]){$retryable=$true} if($cause-is[Net.WebException]){ if($cause.Response){$httpStatus=[int]$cause.Response.StatusCode;$cause.Response.Dispose();$retryable=($httpStatus-in@(408,429,500,502,503,504))} else{$retryable=$true} } } if($invalid-or-not$retryable-or$attempt-eq3){throw} Write-Host ('Riflo: retrying interrupted download segment ('+$attempt+'/3).') Start-Sleep -Seconds $attempt }finally{if($inputStream){$inputStream.Dispose()};if($response){$response.Dispose()};$request.Abort()} if($complete){break} } if(-not$complete){throw 'Music download segment was not verified.'} $output.Write($piece,0,$length) } $output.Flush($true) }finally{if($output){$output.Dispose()}} } function Expand-MusicVerifiedPackage([string]$Archive,[string]$Run,$Release){ $run=Assert-MusicDownloadPath $Run;$archive=Assert-MusicDownloadPath $Archive if(-not$archive.StartsWith($run+'\',[StringComparison]::OrdinalIgnoreCase)){throw 'The Music package is outside its private workspace.'} if((Get-Item -LiteralPath $archive).Length-ne$Release.artifact.bytes-or(Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant()-cne$Release.artifact.sha256){throw 'Music package bytes differ from the pinned release.'} Add-Type -AssemblyName System.IO.Compression;Add-Type -AssemblyName System.IO.Compression.FileSystem $inputStream=[IO.File]::Open($archive,'Open','Read','Read');$zip=$null;$destination=Join-Path $run 'setup';$held=New-Object 'Collections.Generic.List[IDisposable]' try{ $zip=[IO.Compression.ZipArchive]::new($inputStream,[IO.Compression.ZipArchiveMode]::Read,$true) if($zip.Entries.Count-lt8-or$zip.Entries.Count-gt385){throw 'Unexpected Music archive file count.'} $seen=@{};$total=0L foreach($entry in $zip.Entries){ $name=$entry.FullName if($name-cnotmatch'^(?:[A-Za-z0-9_][A-Za-z0-9._-]*/)*[A-Za-z0-9_][A-Za-z0-9._-]*$'-or$seen.ContainsKey($name)-or$entry.Length-lt1-or$entry.Length-gt268435456-or(($entry.ExternalAttributes-shr16)-band0xF000)-eq0xA000-or($entry.ExternalAttributes-band0x410)){throw 'Unsafe Music archive entry.'} foreach($segment in $name.Split('/')){if($segment.EndsWith('.')-or$segment-cmatch'^(?i:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)'){throw 'Reserved Music archive entry.'}} $seen[$name]=$true;$total+=$entry.Length;if($total-gt536870912){throw 'Music archive exceeds its unpacked limit.'} } [void][IO.Directory]::CreateDirectory($destination) foreach($entry in $zip.Entries){ $target=[IO.Path]::GetFullPath((Join-Path $destination $entry.FullName));if(-not$target.StartsWith($destination+'\',[StringComparison]::OrdinalIgnoreCase)){throw 'Music extraction escaped its directory.'} [void][IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($target));$source=$entry.Open();$output=[IO.File]::Open($target,'CreateNew','Write','None') try{$buffer=New-Object byte[] 65536;$written=0L;while(($count=$source.Read($buffer,0,$buffer.Length))-gt0){$written+=$count;if($written-gt$entry.Length){throw 'Music extraction exceeded its declared length.'};$output.Write($buffer,0,$count)};$output.Flush($true);if($output.Length-ne$entry.Length){throw 'Music extraction length differed.'}}finally{$output.Dispose();$source.Dispose()} } $lockPath=Join-Path $destination 'delivery-lock.json';if((Get-FileHash -LiteralPath $lockPath -Algorithm SHA256).Hash.ToLowerInvariant()-cne$Release.delivery.lockSha256){throw 'Music delivery lock differs from the pinned release.'} if((Get-Item -LiteralPath $lockPath).Length-gt131072){throw 'Music delivery inventory exceeds its limit.'};$lock=Get-Content -LiteralPath $lockPath -Raw -Encoding UTF8|ConvertFrom-Json if($lock.schema-ne1-or$lock.kind-cne'music-command-setup-private-preview'-or$lock.manifestSha256-cne$Release.delivery.manifestSha256-or$lock.version-cne$Release.version-or$lock.ownerCredentialsIncluded-isnot[bool]-or$lock.ownerCredentialsIncluded-or$lock.publicReleaseReady-isnot[bool]-or$lock.publicReleaseReady-or$lock.files.Count-ne($zip.Entries.Count-1)){throw 'Music delivery inventory differs.'} $declared=@{};foreach($file in $lock.files){ if($file.path-ceq'delivery-lock.json'-or-not$seen.ContainsKey($file.path)-or$declared.ContainsKey($file.path)-or$file.sha256-cnotmatch'^[a-f0-9]{64}$'){throw 'Music file declaration is invalid.'} $target=Join-Path $destination $file.path;$stream=[IO.File]::Open($target,'Open','Read','Read');$held.Add($stream) if($stream.Length-ne$file.bytes-or(Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash.ToLowerInvariant()-cne$file.sha256){throw 'A Music component differs from the reviewed release.'};$declared[$file.path]=$true } foreach($required in @('bin/music-setup.mjs','windows/backend.ps1','delivery/runtime/dependencies/node/node.exe','delivery/runtime/bundle.json')){if(-not$declared.ContainsKey($required)){throw 'A required Music component is absent.'}} return [pscustomobject]@{schema=1;status='downloaded-and-verified';directory=$destination;entry=(Join-Path $destination 'bin\music-setup.mjs');node=(Join-Path $destination 'delivery\runtime\dependencies\node\node.exe');files=$lock.files.Count;manifestSha256=$lock.manifestSha256} }finally{foreach($stream in $held){$stream.Dispose()};if($zip){$zip.Dispose()};$inputStream.Dispose()} } $musicLocal=[Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData) $musicRun=New-MusicDownloadDirectory (Join-Path $musicLocal 'YouTubeTuiMusicDownloads') try{ Write-Host 'Riflo: downloading and verifying the complete Windows package...' $musicArchive=Join-Path $musicRun 'music.package' Get-MusicHttpsFile 'https://admin.130.61.58.111.nip.io/music/public/releases/20261204-online11/windows-x64.package' $musicArchive 167378118 900 $musicRelease=[pscustomobject]@{version='0.1.0-preview.24';artifact=[pscustomobject]@{bytes=167378118;sha256='4ef6deb48181e814658d70254c92dbc1162a0a992c4f3be7ae3d7593e4234bb5'};delivery=[pscustomobject]@{lockSha256='6ab5c139c7822296801bc5675109e59ef3b7c8bc964bf8450fadab989daf8d31';manifestSha256='b4cf77a2d54b5777b87134eeac6cb6ff71850502eaef0024b6b67e0c6ae8537d'}} $musicPrepared=Expand-MusicVerifiedPackage $musicArchive $musicRun $musicRelease Write-Host ('Verified setup and recovery folder: '+$musicRun) if($Inspect){ & $musicPrepared.node $musicPrepared.entry inspect --json if($LASTEXITCODE-ne0){throw 'Verified inspection needs attention.'} return } $musicCheckText=& $musicPrepared.node $musicPrepared.entry runtime-check --json|Out-String $musicCheckCode=$LASTEXITCODE $musicCheck=$musicCheckText|ConvertFrom-Json if($musicCheckCode-ne0-or$musicCheck.status-cne'runtime-ready'-or$musicCheck.changes-ne$false-or$musicCheck.serviceStarted-ne$false-or$musicCheck.audioStarted-ne$false){throw 'The original runtime readiness preflight did not pass. No installation was requested.'} Write-Host 'Installing Riflo in this Windows account and configuring supported detected integrations and startup. No music starts automatically.' $musicResultText=& $musicPrepared.node $musicPrepared.entry setup --all-detected --apply --yes --json|Out-String $musicResultCode=$LASTEXITCODE $musicResult=$musicResultText|ConvertFrom-Json if($musicResultCode-notin@(0,2)-or$musicResult.status-cnotin@('configured','completed-with-attention','configured-receipt-unavailable')-or$musicResult.audioStarted-ne$false-or$musicResult.modelRequests-ne0-or$musicResult.statisticsEnrolled-ne$false-or$musicResult.advertisingEnrolled-ne$false){throw 'Setup did not confirm its outcome. Preserve its receipts before recovery; do not retry an unresolved operation automatically.'} Write-Host ('Riflo setup status: '+$musicResult.status) if($musicResultCode-eq2){Write-Warning 'Riflo reports a setup step needing attention. Keep the printed recovery folder and individual receipts.';exit 2} if($EnableStatisticsAndSponsors){ $activationFile=Join-Path $musicRun 'public-activation.json' $request=[Net.HttpWebRequest]::Create('https://admin.130.61.58.111.nip.io/v1/install/windows');$request.AllowAutoRedirect=$false;$request.Timeout=15000;$request.ReadWriteTimeout=15000 $response=$null;$stream=$null try{ $response=$request.GetResponse();if([int]$response.StatusCode-ne200-or$response.ContentType.Split(';')[0]-cne'application/json'-or$response.ContentLength-gt4096){throw 'Public activation response differs.'} $stream=$response.GetResponseStream();$memory=[IO.MemoryStream]::new();try{$buffer=New-Object byte[] 1024;while(($count=$stream.Read($buffer,0,1024))-gt0){if($memory.Length+$count-gt4096){throw 'Public activation exceeds its bound.'};$memory.Write($buffer,0,$count)};$bytes=$memory.ToArray()}finally{$memory.Dispose()} $activation=[Text.UTF8Encoding]::new($false,$true).GetString($bytes)|ConvertFrom-Json if(($activation.PSObject.Properties.Name|Sort-Object)-join','-cne'expiresAt,invitation,release,schema'-or$activation.schema-ne1-or$activation.release-cne'riflo-public-windows-v1'-or$activation.invitation-cnotmatch'^[A-Za-z0-9_-]{43}$'){throw 'Public activation identity differs.'} [IO.File]::WriteAllBytes($activationFile,$bytes) }finally{if($stream){$stream.Dispose()};if($response){$response.Dispose()};$request.Abort()} $onlineText=& $musicPrepared.node $musicPrepared.entry online --mode on --apply --allow-statistics --activation-file $activationFile --json|Out-String $onlineCode=$LASTEXITCODE;$onlineResult=$onlineText|ConvertFrom-Json if($onlineCode-ne0-or$onlineResult.status-cne'online-enabled'-or$onlineResult.statisticsEnabled-ne$true-or$onlineResult.sponsorsEnabled-ne$true-or$onlineResult.collectorAvailable-ne$true){throw 'Riflo core is installed; online activation needs attention. Preserve this recovery folder.'} } Write-Host 'Riflo setup completed. Open a new PowerShell terminal for supported CLI integrations. Browser extension activation remains manual.' }catch{Write-Host ('Preserve this verified download for diagnosis: '+$musicRun);Write-Error ('Riflo setup stopped: '+$_.Exception.Message);exit 1}