chindabot / install.ps1
kobkrit's picture
The Windows one-line installer
2ac7875 verified
Raw History Blame Contribute Delete
3.79 kB
# ChindaBot on Windows, in one line (docs/shell/lite.md): in PowerShell,
# irm https://huggingface.co/iapp/chindabot/resolve/main/install.ps1 | iex
# It downloads the zip for this PC (Windows on Arm, or x64) from that page, holds it to the SHA-256 published
# beside it, unpacks it and runs its Install.cmd: the program is copied into this account's own folder, put on
# the desktop and in the Start menu, and opened. No administrator is needed. Run over a ChindaBot that is
# already installed it brings it up to the latest version: models and conversations are kept.
# A file PowerShell downloads carries no mark of the web, so Windows shows no "protected your PC" for it.
& {
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is many times slower while it draws its bar
$base = if ($env:CHINDABOT_BASE) { $env:CHINDABOT_BASE.TrimEnd('/') } else { 'https://huggingface.co/iapp/chindabot/resolve/main' }
# The machine's own processor, whatever this PowerShell was built for: an x64 PowerShell on Arm says AMD64 of itself.
$machine = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -ErrorAction SilentlyContinue).PROCESSOR_ARCHITECTURE
if (-not $machine) { $machine = $env:PROCESSOR_ARCHITECTURE }
$arch = if ($env:CHINDABOT_ARCH) { $env:CHINDABOT_ARCH } elseif ($machine -eq 'ARM64') { 'arm64' } elseif ($machine -eq 'AMD64') { 'x64' } else { throw "ChindaBot needs 64-bit Windows (this PC says $machine)." }
$file = "ChindaBot-windows-$arch.zip"
$work = Join-Path $env:TEMP ('chindabot-install-' + [Guid]::NewGuid().ToString('N').Substring(0, 8))
New-Item -ItemType Directory -Force $work | Out-Null
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Write-Host "Downloading ChindaBot for Windows ($arch)..."
Invoke-WebRequest -UseBasicParsing "$base/$file" -OutFile (Join-Path $work $file)
Invoke-WebRequest -UseBasicParsing "$base/SHA256SUMS" -OutFile (Join-Path $work 'SHA256SUMS')
# A line of SHA256SUMS is the sum, a space or two, and the file's name.
$line = Get-Content (Join-Path $work 'SHA256SUMS') | Where-Object { ($_ -split '\s+', 2)[1] -replace '^\*', '' -eq $file } | Select-Object -First 1
$want = if ($line) { ($line -split '\s+', 2)[0].ToLower() } else { '' }
$got = (Get-FileHash (Join-Path $work $file) -Algorithm SHA256).Hash.ToLower()
if ($want.Length -ne 64 -or $got -ne $want) { throw 'The download does not match the checksum published beside it. Nothing was installed: try again.' }
Write-Host 'Checked. Installing...'
Expand-Archive (Join-Path $work $file) $work -Force
$install = Join-Path $work "ChindaBot-windows-$arch\Install.cmd"
if (-not (Test-Path $install)) { throw 'The download holds no Install.cmd.' }
# cmd alone is waited for: -Wait would wait for the ChindaBot that Install.cmd opens as well. Nothing is given
# it to read, so that a copy that failed ends at its `pause` instead of waiting for a key in a hidden window.
$done = Start-Process cmd.exe -ArgumentList '/c', "`"`"$install`" < NUL`"" -PassThru -WindowStyle Hidden
$null = $done.Handle
if (-not $done.WaitForExit(120000)) { throw 'Install.cmd did not end in two minutes.' }
if ($done.ExitCode -ne 0) { throw "Install.cmd ended with $($done.ExitCode): ChindaBot could not be copied into $env:LOCALAPPDATA\Programs\ChindaBot." }
Write-Host 'ChindaBot is installed and open. Your models and conversations are as they were.'
} finally {
# What was downloaded is not needed once it is installed: the program runs from this account's own folder.
Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue
}
}