Windows 'Get Started' documentation has incorrect download URL

ajh0912
ajh0912
Community Member

The Windows tab on this page has an incorrect URL, in the section 'To install 1Password CLI with a single block of commands, run the following in Powershell as administrator:'

$env:ARCH="<choose between 386/amd64>"; `
Invoke-WebRequest "https://cache.agilebits.com/dist/1P/op2/pkg/v2.0.0/op_$($env:ARCH)_v2.0.0.zip" -OutFile op.zip; `
Expand-Archive op.zip -DestinationPath "C:\Program Files\1Password CLI"; `
[Environment]::SetEnvironmentVariable("PATH", "$([System.Environment]::GetEnvironmentVariable('PATH','machine'));C:\Program Files\1Password CLI", "Machine"); `
Remove-Item "op.zip"

The Invoke-WebRequest cmdlet has the URL:
"https://cache.agilebits.com/dist/1P/op2/pkg/v2.0.0/op_$($env:ARCH)_v2.0.0.zip"
but it should be:
"https://cache.agilebits.com/dist/1P/op2/pkg/v2.0.0/op_windows_$($env:ARCH)_v2.0.0.zip"
The command block will also add more than one 'C:\Program Files\1Password CLI' entry into PATH if ran multiple times.

I can understand having the simplicity of the user manually changing the first line to pick their OS architecture. If you want to make it better (but more complex), then I'd change it to:

$arch = (Get-CimInstance Win32_OperatingSystem).OSArchitecture
switch ($arch) {
    '64-bit' { $opArch = 'amd64'; break }
    '32-bit' { $opArch = '386'; break }
    Default { Write-Error "Sorry, your operating system architecture '$arch' is unsupported" -ErrorAction Stop }
}
$installDir = Join-Path -Path $env:ProgramFiles -ChildPath '1Password CLI'
Invoke-WebRequest -Uri "https://cache.agilebits.com/dist/1P/op2/pkg/v2.0.0/op_windows_$($opArch)_v2.0.0.zip" -OutFile op.zip
# Force switch is used to overwrite any previous op.exe file
Expand-Archive -Path op.zip -DestinationPath $installDir -Force
# Get current PATH environment variable, using GetEnvironmentVariable instead of $env:Path so we get the freshest value
$envMachinePath = [System.Environment]::GetEnvironmentVariable('PATH','machine')
# Check if current PATH already contains our 1Password CLI directory
if ($envMachinePath -split ';' -notcontains $installDir){
    # Current PATH didn't contain our 1Password CLI directory - backup current PATH before making changes
    $envMachinePath | Out-File $env:TEMP\$(Get-Date -Format FileDateTimeUniversal)-EnvMachinePath.txt
    # Add the new directory to PATH
    [Environment]::SetEnvironmentVariable('PATH', "$envMachinePath;$installDir", 'Machine')
}
Remove-Item -Path op.zip

(I didn't test it on a 32-bit or Arm OS)
Of course it'd be better with an installer that puts things in place, but a standalone executable can also have benefits - ideally both should be offered.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Windows 10

Comments

  • kevin.l_1P
    kevin.l_1P
    1Password Alumni

    Thanks for pointing out the incorrect install location, I've logged a ticket to get that fixed asap.

    Also, thanks for taking the time to improve the script as well! I've also logged a separate issue to tackle improving it :)

This discussion has been closed.