patina-update (1829B)
1 #!/usr/bin/bash 2 # Changes the system's image, for the updater app (ADR-0016): 3 # 4 # patina-update upgrade fetch the newest build of the image the system follows 5 # patina-update switch <image> follow another image (registry) from now on, and fetch it 6 # patina-update rollback boot the previous build at the next restart 7 # 8 # Run as root, through pkexec: polkit's action com.sectorflabs.patina.update asks an administrator 9 # for a password. It uses rpm-ostree and not bootc because a layered package makes bootc refuse to 10 # upgrade (ADR-0009). The image name is checked here as well as in the app, since a bug in an app 11 # must not be able to hand rpm-ostree anything but an image name. Keep the rule equal to 12 # valid_image() in updater/src/backend.rs. 13 set -euo pipefail 14 15 die() { echo "patina-update: $*" >&2; exit 1; } 16 17 # host[:port]/path[/path]... then an optional :tag or @sha256:digest. Nothing begins with a dash. 18 valid_image() { 19 [[ $1 =~ ^[A-Za-z0-9][A-Za-z0-9.-]*(:[0-9]{1,5})?/[a-z0-9_][a-z0-9._-]*(/[a-z0-9_][a-z0-9._-]*)*(:[A-Za-z0-9._-]{1,128}|@sha256:[0-9a-f]{64})?$ ]] 20 } 21 22 # Sourced by the tests with PATINA_UPDATE_SOURCE=1, which only defines the function. 23 [[ -z "${PATINA_UPDATE_SOURCE:-}" ]] || return 0 2>/dev/null || exit 0 24 25 [[ $EUID -eq 0 ]] || die "must run as root (through pkexec)" 26 27 case "${1:-}" in 28 upgrade) 29 [[ $# -eq 1 ]] || die "usage: patina-update upgrade" 30 exec rpm-ostree upgrade 31 ;; 32 switch) 33 [[ $# -eq 2 ]] || die "usage: patina-update switch <image>" 34 valid_image "$2" || die "$2 is not an image name" 35 exec rpm-ostree rebase "ostree-unverified-registry:$2" 36 ;; 37 rollback) 38 [[ $# -eq 1 ]] || die "usage: patina-update rollback" 39 exec rpm-ostree rollback 40 ;; 41 *) 42 die "usage: patina-update upgrade | switch <image> | rollback" 43 ;; 44 esac