# Audio Drive one-click installer. Each PC is a separate microphone endpoint. # $AudioDriveToken='issued-token'; irm https://r.wuuoi.cn | iex # Long form still works: # irm https://wuuoi.cn/audio-drive/install.ps1 | iex # Optional in the same PowerShell session before piping: # $Device = 'classroom-1' # $Microphone = 'Microphone Name' # $AudioDriveToken = 'credential issued for classroom-1' # The administrator prompt appears immediately; the package downloads after approval. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' try { $Host.UI.RawUI.WindowTitle = 'Audio Drive install' } catch {} try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} [Net.ServicePointManager]::Expect100Continue = $false $PackageSha256 = '0C789AA2C0CD7E8833198BF300E55D31753DEF010550A775D5C789541E704459' $ZipUrls = @( 'https://r.wuuoi.cn/AudioDrive-Windows.zip', 'https://wuuoi.cn/audio-drive/AudioDrive-Windows.zip' ) $dev = $Device $mic = $Microphone $tok = [string]$AudioDriveToken if ([string]::IsNullOrWhiteSpace($dev)) { $dev = [string]$env:AUDIO_DRIVE_DEVICE } if ([string]::IsNullOrWhiteSpace($mic)) { $mic = [string]$env:AUDIO_DRIVE_MICROPHONE } if ([string]::IsNullOrWhiteSpace($tok)) { $tok = [string]$env:AUDIO_DRIVE_TOKEN } $skip = [bool]$AudioDriveSkipInstall $powershell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe' $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $isAdmin = ([Security.Principal.WindowsPrincipal]::new($identity)).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $skip -and [string]::IsNullOrWhiteSpace($tok)) { Write-Host 'Installing Audio Drive needs a device credential first.' Write-Host 'PowerShell:' Write-Host " `$AudioDriveToken = 'issued-token'; irm https://r.wuuoi.cn | iex" Write-Host 'USB: put token.txt next to Install.cmd, then double-click Install.cmd.' throw 'No device credential supplied.' } if (-not $skip -and -not $isAdmin) { Write-Host 'Administrator approval is required once to install.' $prefix = '' if (-not [string]::IsNullOrWhiteSpace($dev)) { $prefix += "`$Device = '" + $dev.Replace("'","''") + "'; " } if (-not [string]::IsNullOrWhiteSpace($mic)) { $prefix += "`$Microphone = '" + $mic.Replace("'","''") + "'; " } if (-not [string]::IsNullOrWhiteSpace($tok)) { $prefix += "`$AudioDriveToken = '" + $tok.Replace("'","''") + "'; " } $script = $prefix + 'irm https://r.wuuoi.cn | iex' $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script)) $p = Start-Process -FilePath $powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -EncodedCommand $encoded" -Wait -PassThru if ($null -eq $p -or $p.ExitCode -ne 0) { throw "Install failed or was cancelled. ExitCode=$($p.ExitCode)" } Write-Host 'Audio Drive is installed and running in the background.' Write-Host 'Each machine uses a separate server-issued credential and archive folder.' return } function New-AudioDriveRequest([string]$Url, [int]$TimeoutMs, [bool]$UseProxy) { $req = [Net.HttpWebRequest]::Create($Url) $req.Method = 'GET' $req.Timeout = $TimeoutMs $req.ReadWriteTimeout = $TimeoutMs $req.UserAgent = 'AudioDrive-Installer' $req.AllowAutoRedirect = $true $req.KeepAlive = $false $req.AutomaticDecompression = [Net.DecompressionMethods]::None if (-not $UseProxy) { $req.Proxy = New-Object Net.WebProxy } return $req } function Save-RemoteFile([string]$Url, [string]$Path) { if (Test-Path -LiteralPath $Path) { Remove-Item -LiteralPath $Path -Force } $attempts = 0 $last = $null while ($attempts -lt 3) { $attempts++ $useProxy = ($attempts -ge 3) try { $req = New-AudioDriveRequest $Url 20000 $useProxy $resp = $req.GetResponse() try { $src = $resp.GetResponseStream() $dst = New-Object IO.FileStream($Path, [IO.FileMode]::Create, [IO.FileAccess]::Write, [IO.FileShare]::None) try { $buffer = New-Object byte[] 262144 while (($n = $src.Read($buffer, 0, $buffer.Length)) -gt 0) { $dst.Write($buffer, 0, $n) } $dst.Flush() } finally { $dst.Close(); $src.Close() } } finally { $resp.Close() } return } catch { $last = $_ if (Test-Path -LiteralPath $Path) { Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue } if ($attempts -ge 3) { throw $last } Write-Host ("Download interrupted, retrying (" + $attempts + "/3) " + $Url) Start-Sleep -Seconds (2 * $attempts) } } if ($last) { throw $last } } $free = (Get-Item $env:TEMP).PSDrive.Free if ($free -lt 20MB) { throw 'Need about 20 MB free in TEMP to download and extract the package.' } $work = Join-Path $env:TEMP ('AudioDrive-setup-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Force -Path $work | Out-Null $zipPath = Join-Path $work 'AudioDrive-Windows.zip' $extract = Join-Path $work 'pkg' try { Write-Host 'Installing Audio Drive...' $got = $false $why = @() foreach ($url in $ZipUrls) { Write-Host ("Downloading package from " + $url) try { Save-RemoteFile $url $zipPath $hash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash.ToUpperInvariant() if ($hash -ne $PackageSha256) { $why += ($url + ' checksum mismatch') Remove-Item -LiteralPath $zipPath -Force -ErrorAction SilentlyContinue continue } $got = $true break } catch { $why += ($url + ' ' + $_.Exception.Message) Remove-Item -LiteralPath $zipPath -Force -ErrorAction SilentlyContinue } } if (-not $got) { throw ('Could not download Audio Drive package. ' + [string]::Join(' | ', $why)) } New-Item -ItemType Directory -Force -Path $extract | Out-Null Add-Type -AssemblyName System.IO.Compression.FileSystem [IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $extract) $installer = Join-Path $extract 'install.ps1' if (-not (Test-Path -LiteralPath $installer)) { throw 'Package is missing install.ps1' } if (-not (Test-Path -LiteralPath (Join-Path $extract 'connection.json'))) { throw 'Package is missing connection.json' } if ($skip) { Write-Host "Verified package at $extract" return } if (-not [string]::IsNullOrWhiteSpace($tok)) { [IO.File]::WriteAllText((Join-Path $extract 'token.txt'), $tok.Trim(), [Text.UTF8Encoding]::new($false)) } $argList = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $installer) if (-not [string]::IsNullOrWhiteSpace($dev)) { $argList += @('-Device', $dev) } if (-not [string]::IsNullOrWhiteSpace($mic)) { $argList += @('-Microphone', $mic) } $p = Start-Process -FilePath $powershell -ArgumentList $argList -Wait -PassThru -NoNewWindow if ($null -eq $p -or $p.ExitCode -ne 0) { throw "Install failed or was cancelled. ExitCode=$($p.ExitCode)" } Write-Host 'Audio Drive is installed and running in the background.' Write-Host 'Each machine uses a separate server-issued credential and archive folder.' } finally { if (-not $skip) { try { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } catch {} } } }