Skip to content

Self Update

Mikhail Deynekin edited this page Oct 12, 2026 · 2 revisions

Автообновление

Self-update

Self-update

sr update --check is there a newer release? sr update install it sr update --version 7.1.0 install a specific version sr update --channel prerelease sr update --source npm ask the npm registry instead of GitHub sr update --repo owner/name --path /usr/local/bin/sr

What sr detects

sr doctor prints the installation type. It decides how an update is applied:

standalone a single executable file (zipapp or installed script). sr can update itself: download → verify → smoke test → replace. pip / pipx the environment owns the files, so sr prints the exact upgrade command instead of touching site-packages. npm prints npm install -g sr-search-replace@latest. source a git checkout — updating is refused, use git pull && make.

The update sequence for a standalone install

  1. ask the GitHub releases API for the newest release on the channel (SR_GITHUB_TOKEN/GITHUB_TOKEN raises the rate limit)
  2. compare versions with semver rules; stop if not newer (unless --version)
  3. download the sr.pyz asset to a temporary directory
  4. verify its SHA-256 against the published sr.pyz.sha256 — a mismatch aborts the update and installs nothing
  5. smoke test: run python3 <downloaded> --version in a subprocess
  6. copy the current file to <file>.bak
  7. atomically replace the file (write sibling + rename) and keep its mode

Every step either succeeds or leaves the current installation untouched.

Background check

At most once per 24h, sr looks for a newer release on a daemon thread with a 2.5s budget and caches the answer under $XDG_CACHE_HOME/sr/update-check.json. It never blocks a run: if the network is slow or absent, nothing is printed and the cache is used next time. Turn it off with --no-update-check or SR_NO_UPDATE_CHECK=1 (a good idea in CI and on air-gapped machines).

Pinning

Install a specific version and disable the check to pin:

 sr update --version 7.0.0
 export SR_NO_UPDATE_CHECK=1

Offline / air-gapped

Download the two release assets on a connected machine, copy them over, then:

 sha256sum -c sr.pyz.sha256
 install -m 0755 sr.pyz /usr/local/bin/sr

Страница сгенерирована из встроенной справки sr 7.0.1 (sr help <topic>). Первоисточник — sr/help_system.py; он же питает man sr и sr help --all. Если страница и вывод sr help расходятся, верить нужно sr help: он всегда соответствует установленной версии.

Clone this wiki locally