# Update the Mango wallet browser extension on this Windows machine, in one command. # # WHAT THIS IS FOR. An extension loaded with "Load unpacked" never updates itself. This # script is the manual path made one click: it asks https://namid.net/mango/latest.json # what the newest build is, and if it is newer than the folder you already have it # downloads the zip, checks the sha256, and swaps the folder. The browser then needs one # click on Reload at chrome://extensions - Chromium re-reads an unpacked folder only when # asked. If you want updates with NO clicks at all, use scripts/install-mango-autoupdate.ps1 # instead; that installs the signed .crx against an update server and Chromium's own # updater keeps it current. # # NOTHING IS DELETED. The folder being replaced is moved aside to # mango-wallet-extension.old- next to it, so a bad update is one rename away from # undone. Delete those yourself when you are happy. # # THE EXTENSION ID DOES NOT CHANGE. It is pinned by "key" in manifest.json, so your # password, your approved sites and your sign-ins all survive an update. # # Run it: powershell -ExecutionPolicy Bypass -File .\scripts\update-mango-extension.ps1 # # Not executed before shipping: this repository lives on a Linux laptop with no # PowerShell on it. Read it before you run it. [CmdletBinding()] param( # Where the extension folder lives. The default is where this script puts it the first time. [string] $InstallRoot = (Join-Path $env:LOCALAPPDATA 'MangoWallet'), [string] $LatestUrl = 'https://namid.net/mango/latest.json', # Re-download and re-install even if the version on disk already matches. [switch] $Force ) $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest $ExpectedId = 'pfeojhejabjihflngblcidnjpicekigb' $target = Join-Path $InstallRoot 'mango-wallet-extension' Write-Host "Mango wallet extension updater" -ForegroundColor Cyan Write-Host " install root : $InstallRoot" Write-Host " manifest : $LatestUrl" # --- what is on disk now ------------------------------------------------------------- $localVersion = $null $localManifest = Join-Path $target 'manifest.json' if (Test-Path -LiteralPath $localManifest) { $localVersion = (Get-Content -LiteralPath $localManifest -Raw | ConvertFrom-Json).version Write-Host " installed : $localVersion" } else { Write-Host " installed : nothing yet (first install)" } # --- what is published --------------------------------------------------------------- $latest = Invoke-RestMethod -Uri $LatestUrl -UseBasicParsing if (-not $latest.version -or -not $latest.zip -or -not $latest.zip_sha256) { throw "The publish manifest at $LatestUrl is missing version/zip/zip_sha256." } if ($latest.extension_id -ne $ExpectedId) { throw "Refusing to install: the published extension id is '$($latest.extension_id)', not $ExpectedId. A different id would appear as a second extension and lose your approvals." } Write-Host " published : $($latest.version)" if ($localVersion -eq $latest.version -and -not $Force) { Write-Host "`nAlready on $($latest.version). Nothing to do." -ForegroundColor Green exit 0 } # --- download and check -------------------------------------------------------------- $work = Join-Path ([System.IO.Path]::GetTempPath()) ("mango-" + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $work -Force | Out-Null $zip = Join-Path $work 'mango.zip' Write-Host "`nDownloading $($latest.zip)" Invoke-WebRequest -Uri $latest.zip -OutFile $zip -UseBasicParsing $got = (Get-FileHash -Algorithm SHA256 -LiteralPath $zip).Hash.ToLower() if ($got -ne $latest.zip_sha256.ToLower()) { throw "SHA256 mismatch. Expected $($latest.zip_sha256), got $got. The download is not the published build; nothing was changed." } Write-Host "SHA256 matches $got" -ForegroundColor Green Expand-Archive -LiteralPath $zip -DestinationPath $work -Force $unpacked = Join-Path $work 'mango-wallet-extension' if (-not (Test-Path -LiteralPath (Join-Path $unpacked 'manifest.json'))) { throw "The zip did not contain a mango-wallet-extension\manifest.json. Nothing was changed." } $newManifest = Get-Content -LiteralPath (Join-Path $unpacked 'manifest.json') -Raw | ConvertFrom-Json if ($newManifest.version -ne $latest.version) { throw "The zip holds version $($newManifest.version) but the manifest advertised $($latest.version). Nothing was changed." } # --- swap it in ---------------------------------------------------------------------- New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null if (Test-Path -LiteralPath $target) { $backup = "$target.old-" + (Get-Date -Format 'yyyyMMddTHHmmss') Move-Item -LiteralPath $target -Destination $backup Write-Host "Previous folder kept at $backup" } Move-Item -LiteralPath $unpacked -Destination $target Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue Write-Host "`nInstalled $($newManifest.name) $($newManifest.version)" -ForegroundColor Green Write-Host "Folder: $target" Write-Host "" if ($null -eq $localVersion) { Write-Host "Now load it once:" -ForegroundColor Yellow Write-Host " 1. Open chrome://extensions (or brave://extensions)" Write-Host " 2. Turn on Developer mode, top right" Write-Host " 3. Click 'Load unpacked' and pick: $target" Write-Host " 4. Check the card reads 'Mango wallet $($newManifest.version)' and the id $ExpectedId" } else { Write-Host "One click left:" -ForegroundColor Yellow Write-Host " 1. Open chrome://extensions (or brave://extensions)" Write-Host " 2. Click the circular Reload arrow on the Mango wallet card" Write-Host " 3. The card should read 'Mango wallet $($newManifest.version)'" }