Self-update
A device runs warpzone from a git clone with a venv next to it, and an updater script keeps the
clone on a release that works (the contract is in Autonomous updates (contract)). There
is one way to install a device, from the clone itself: git clone the repository, then
sh <clone>/warpzone/data/updater.sh install <device>. A pipx or wheel install is not a
supported device install.
selfupdate.py holds what warpzone knows about the script, as pure functions apart from
run_tick: where the live copy, the settings, the state and the bad/ folder are
(live_path, conf_path, state_path, bad_dir), render_conf and parse_kv for the settings file, updater_abi and
install_decision for renewing the live copy, parse_bad, frontend_names, and the wrapper
run_tick. The tests use real git repositories for the script and fakes for the rest.
- Install (
updater.sh install DEVICE [--config FILE] [--venv DIR] [--channel stable|rc] [-- ARGS...]). Run from the clone, with a Python 3.11 or newer. Everything that can be refused is refused before anything changes: the clone must be on a release tag or on a clean branch insideorigin/main(a tree with changes or commits of its own is refused, with noreset,stashorclean), a Python must exist, and a release must pass the rules of a tick (channel, ancestor oforigin/main, its__version__, not retired, signed when signatures are required) and carrywarpzone/data/updater.sh. The tags are fetched first when the remote answers. It then checks out the best such release of the channel (stableunless--channel rc), makes the venv (see below) unless it already works, checks that the release imports with it, and runspython -m warpzone provision device DEVICE [--config FILE] [ARGS...]from the clone, which installs the live copy, writes the settings and starts the timer. It takes the same lock as a tick. The venv isvenvnext to the clone unless--venvsays another folder; a relative--configis taken from the folder the person ran it in. Exit0when it all worked,2for a usage error,1otherwise (andprovision’s own code when it fails). - Python repair. The settings name the venv’s interpreter (
python). At each tick, when that is<folder>/venv/bin/pythonand it does not run, or the venv no longer finds the clone, and another Python 3.11 or newer exists, the script makes the venv again withpython -m venv --without-pip --clear <folder>, addswarpzone-clone.pth(the clone’s path) to itssite-packagesand writesbin/warpzone, a shim that runspython -m warpzone "$@". That needs no network and no setuptools (unlikepip install -e, which wantssetuptools>=77), and the path of the venv’s Python, which units and ES-DE scripts hold, stays the same. Everything runs with-m warpzone.--clearis run only on a folder that is calledvenv, does not exist or holds the markwarpzone-venv(which the script writes when it makes one, so a venv of the user’s, or the one of an older install, is never cleared:installrefuses it and a tick logs it and leaves it; the mark is also noted invenv-ownedin the state folder before the--clear, so a power cut between the clear and the mark still leaves a venv that may be repaired, andinstallmarks a working venv that haswarpzone-clone.pthand no mark), is not a symlink and does not hold the clone; never on the folder around it, which holdsplay-state. A venv that works is left alone (it is judged by findingwarpzonewithout importing it). A tick repairs only a checkout on a release (a tag or a clean branch insideorigin/main), never adevordirtyone. - The live copy.
provision_updater.ensure_updaterputs the script that ships with the running version at~/.local/share/warpzone/updater/updater.sh, outside the clone. The new text is written beside it, checked withsh -nand withsh <copy> selftest(which must printselftest: ok abi=Nfor the script’s ownUPDATER_ABI), then the old file is saved asupdater.sh.prevand the copy replaces it with a rename, so a tick that is running keeps the file it started with.selfupdate.install_decisionis the rule: no live copy, or another script of an ABI that is not lower, installs; the same text is current; a copy of a lower ABI than the live one is never installed (a rollback to an older release does not downgrade the script); a script with noUPDATER_ABIis refused. A failed check leaves the live copy as it was and warns. The new text goes to a temporary file with a name of its own in the same folder, and what is live is read again, and judged by the same rule, just before the rename, so twoprovisionruns at once cannot install a script that the other has not checked. A copy that is kept during a trial. Theprovision --unattendedof a release under trial installs that release’s updater, and a script with a faultselftestdoes not see would then stop the device from updating, with the previous version’sprovisionunable to put the old one back (a lower ABI is never installed over a higher one, and a rollback may not runprovision). So before the first switch of a trial the tick copies the live script toupdater/updater.sh.goodin the state folder (not again while it is there, since a resumed trial finds the candidate’s script live) and, whenever it goes back to the previous version (a bad release, an environment failure, a trial given up, a failed probation), it puts that copy back with a rename, whatever the ABI of the script it replaces. The copy is dropped at the next tick when no trial or probation is on, and when probation passes. It is written to a temporary file, flushed withsyncand renamed, and a live script is only kept, and a kept one only put back, when it is not empty, has itsUPDATER_ABI=line and passessh -n(a power cut can leave a file of no bytes); otherwise the live one is left as it is and the log says so. Only the live copy itself is ever kept or replaced: the running script, with every symlink resolved (cd -P,pwd -P), must be~/.local/share/warpzone/updater/updater.sh(WZ_LIVEmoves it for tests), so the clone’s own script, run by hand or through a symlink, is never touched. - The settings.
provision_updater.ensure_self_updatewrites~/.local/state/warpzone/updater/conffrom the device’s table inconfig.toml:device,config(the absolute path of the config file),clone(the git checkout warpzone runs from),python(the interpreter that ranprovision),channel,pin(empty for none),enabled(fromself_update) andfrontend(the process names of the frontend:[es_systems].processof the profile, else ES-DE’s).selfupdate.render_confwrites onekey=valueper line and raises on a value with a line break, so nothing in it can be executed. The file is rewritten only when its content differs. A device withself_update = falsegets no updater, and one that already has settings getsenabled=falsethere, so its timer’s ticks stop. Nothing is installed, with a warning, when the clone is not a git checkout or the interpreter cannot import warpzone from outside the current folder. warpzone self-update. A wrapper: it runssh <live copy> tick, as the timer does, and exits with its code. It needs no config and has no--dry-run. Without a live copy it says so and exits1.
provision device calls ensure_self_update for every device, whatever its profile and
folders; its last step is ensure_update_timer. updatetimer.py renders the two units (pure):
warpzone-self-update.service (Type=oneshot, TimeoutStartSec=30min,
ExecStart=/bin/sh <live copy> tick, the path quoted for systemd) and
warpzone-self-update.timer (OnBootSec=45s, OnUnitActiveSec=15min, no random delay,
WantedBy=timers.target) in ~/.config/systemd/user/. The timer is a piece of its own, apart
from the script: another launcher can start the same tick. The units are rewritten only when
their content differs (mode 0644, atomically); daemon-reload, enable --now and, when the
timer was already running with other units, restart follow only when something changed or the
timer is not enabled and active. It installs nothing, with a warning, when the live copy is not
there or systemctl --user show-environment fails (no user manager); --dry-run runs only the
read-only systemctl queries and prints what it would do. self_update = false under
[devices.<name>] skips it; an installed timer is never removed by provision.
doctor checks the updater in group Updates, on a Linux machine that is a configured device
subscribed to library without self_update = false (found through the local wz-library
folder, as for the frontend):
Self-update timer(judge_update_timer):[ok]when both units exist, the service runs/bin/sh <live copy> tick, and the timer is enabled and active;[! ]when the units are missing, the service runs something else (an old unit that ranpython -m warpzone self-update), the timer is not enabled or not active, or systemd cannot be asked.Updater script(judge_updater_script):[! ]when the live copy is missing or differs from the one that ships with this version;[ok]when it is the same, or has a higher ABI (after a rollback).Updater settings(judge_updater_conf):[! ]when the file is missing, whendevice,config,channel,pin,enabledorfrontenddiffer from what the config says, or whenpythonis not executable orcloneis not a git checkout.Updater state(judge_updater_state): readsstateandbad/. One line per problem,[! ]unless noted: the updater has not run yet; a rollback in the last 14 days (abad/<tag>file that recent, orlast_result=rolled-back);stuck([!!]); adirtyordevcheckout, which the updater does not move;no-python;pin_retired; signatures not required (signingis not1); no successful run (last_ok) in more than 14 days, or none at all. When none applies, one[ok]line.