vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Add a one-command install script for the stable channel
16a8be36308947758ae81c97500f9f891be18e52 · Keenan Nemetz · 13d ago · parent 1b1571bb
Add a one-command install script for the stable channel The signed package repositories still left a four- or five-command trust bootstrap on first install, because apt cannot fetch a key from a URL and pacman requires an explicit keyring signature. Ship packaging/install.sh as a release artifact served at channels/stable/install.sh: it detects the distribution, writes the key and repository, and hands the install to apt, dnf, or pacman. The script pins the release key's SHA-256 and fingerprint, and the release now publishes the committed key verbatim so the pin is exact. scripts/check-install.sh covers the three families without root or network, and the release attaches the script before SHA256SUMS so the checksum list covers it. closes: 01M7XG0ANWCC442YMFJSMW7HCC
packaging/install.sh +374
| @@ -0,0 +1,374 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # Install Vole from the signed package repository. | ||
| 3 | # | ||
| 4 | # The release publishes this file as install.sh and serves it at | ||
| 5 | # /<repository>/channels/<channel>/install.sh. It detects the distribution, | ||
| 6 | # installs the release key and a package source, and then hands the install to | ||
| 7 | # apt, dnf, or pacman. It does not install packages itself, so package and | ||
| 8 | # repository signature checks stay with the package manager. | ||
| 9 | # | ||
| 10 | # The key is pinned twice: its SHA-256 and its fingerprint. Both belong to | ||
| 11 | # packaging/keys/vole-release.asc, which sign-release.py publishes verbatim, so | ||
| 12 | # a host that serves a different key is refused before any file is written. | ||
| 13 | # Rotating the release key means updating the two constants below in the same | ||
| 14 | # change; scripts/check-install.sh fails when they disagree with the committed | ||
| 15 | # key. | ||
| 16 | # | ||
| 17 | # Run with --help for the options. This file is POSIX sh and is tested by | ||
| 18 | # scripts/check-install.sh in every push. | ||
| 19 | set -eu | ||
| 20 | |||
| 21 | VOLE_KEY_SHA256=f484ed987d8be0c3ef4aa3f16e5e0f14e12310cc65a3f8899aa70d72f86004ca | ||
| 22 | VOLE_KEY_FPR=01A6F610DBD731DD3C2321C52D74BC712CE88523 | ||
| 23 | |||
| 24 | BASE=https://rodent.software/vole | ||
| 25 | CHANNEL=stable | ||
| 26 | PIN= | ||
| 27 | REPO_ONLY=0 | ||
| 28 | DRY_RUN=0 | ||
| 29 | ROOT=/ | ||
| 30 | KEY_FILE= | ||
| 31 | |||
| 32 | PROG=vole-install | ||
| 33 | |||
| 34 | usage() { | ||
| 35 | cat <<'EOF' | ||
| 36 | Install Vole from its signed package repository. | ||
| 37 | |||
| 38 | Usage: install.sh [options] | ||
| 39 | |||
| 40 | Options: | ||
| 41 | --channel <name> follow this release channel (default: stable) | ||
| 42 | --version <tag> install a pinned release, for example v0.2.0 | ||
| 43 | --repo-only write the key and repository, do not install | ||
| 44 | --dry-run print the plan, change nothing | ||
| 45 | --yes accepted for non-interactive callers | ||
| 46 | --root <dir> write configuration under <dir>; does not install | ||
| 47 | --key <file> use a local release key instead of downloading it | ||
| 48 | -h, --help show this help | ||
| 49 | |||
| 50 | The script supports Debian and Ubuntu, Fedora, RHEL, Rocky, and AlmaLinux, and | ||
| 51 | Arch Linux. On anything else it stops and points at the manual steps. | ||
| 52 | EOF | ||
| 53 | } | ||
| 54 | |||
| 55 | log() { | ||
| 56 | printf '%s: %s\n' "$PROG" "$*" | ||
| 57 | } | ||
| 58 | |||
| 59 | die() { | ||
| 60 | printf '%s: %s\n' "$PROG" "$*" >&2 | ||
| 61 | exit 1 | ||
| 62 | } | ||
| 63 | |||
| 64 | fetch() { | ||
| 65 | if command -v curl >/dev/null 2>&1; then | ||
| 66 | curl -fsSL --retry 3 --retry-delay 2 -o "$2" "$1" | ||
| 67 | elif command -v wget >/dev/null 2>&1; then | ||
| 68 | wget -q -O "$2" "$1" | ||
| 69 | else | ||
| 70 | die "curl or wget is required to download $1" | ||
| 71 | fi | ||
| 72 | } | ||
| 73 | |||
| 74 | sha256() { | ||
| 75 | if command -v sha256sum >/dev/null 2>&1; then | ||
| 76 | sha256sum "$1" | awk '{print $1}' | ||
| 77 | elif command -v shasum >/dev/null 2>&1; then | ||
| 78 | shasum -a 256 "$1" | awk '{print $1}' | ||
| 79 | elif command -v openssl >/dev/null 2>&1; then | ||
| 80 | openssl dgst -sha256 -r "$1" | awk '{print $1}' | ||
| 81 | else | ||
| 82 | die "sha256sum, shasum, or openssl is required to verify the release key" | ||
| 83 | fi | ||
| 84 | } | ||
| 85 | |||
| 86 | while [ "$#" -gt 0 ]; do | ||
| 87 | case "$1" in | ||
| 88 | --channel) | ||
| 89 | [ "$#" -ge 2 ] || die "--channel needs a value" | ||
| 90 | [ -n "$2" ] || die "--channel needs a value" | ||
| 91 | CHANNEL=$2 | ||
| 92 | shift 2 | ||
| 93 | ;; | ||
| 94 | --channel=*) | ||
| 95 | CHANNEL=${1#*=} | ||
| 96 | [ -n "$CHANNEL" ] || die "--channel needs a value" | ||
| 97 | shift | ||
| 98 | ;; | ||
| 99 | --version) | ||
| 100 | [ "$#" -ge 2 ] || die "--version needs a value" | ||
| 101 | [ -n "$2" ] || die "--version needs a value" | ||
| 102 | PIN=$2 | ||
| 103 | shift 2 | ||
| 104 | ;; | ||
| 105 | --version=*) | ||
| 106 | PIN=${1#*=} | ||
| 107 | [ -n "$PIN" ] || die "--version needs a value" | ||
| 108 | shift | ||
| 109 | ;; | ||
| 110 | --repo-only) | ||
| 111 | REPO_ONLY=1 | ||
| 112 | shift | ||
| 113 | ;; | ||
| 114 | --dry-run) | ||
| 115 | DRY_RUN=1 | ||
| 116 | shift | ||
| 117 | ;; | ||
| 118 | --yes | -y) | ||
| 119 | shift | ||
| 120 | ;; | ||
| 121 | --root) | ||
| 122 | [ "$#" -ge 2 ] || die "--root needs a value" | ||
| 123 | [ -n "$2" ] || die "--root needs a value" | ||
| 124 | ROOT=$2 | ||
| 125 | shift 2 | ||
| 126 | ;; | ||
| 127 | --root=*) | ||
| 128 | ROOT=${1#*=} | ||
| 129 | [ -n "$ROOT" ] || die "--root needs a value" | ||
| 130 | shift | ||
| 131 | ;; | ||
| 132 | --key) | ||
| 133 | [ "$#" -ge 2 ] || die "--key needs a value" | ||
| 134 | [ -n "$2" ] || die "--key needs a value" | ||
| 135 | KEY_FILE=$2 | ||
| 136 | shift 2 | ||
| 137 | ;; | ||
| 138 | --key=*) | ||
| 139 | KEY_FILE=${1#*=} | ||
| 140 | [ -n "$KEY_FILE" ] || die "--key needs a value" | ||
| 141 | shift | ||
| 142 | ;; | ||
| 143 | -h | --help) | ||
| 144 | usage | ||
| 145 | exit 0 | ||
| 146 | ;; | ||
| 147 | *) | ||
| 148 | die "unknown option: $1 (try --help)" | ||
| 149 | ;; | ||
| 150 | esac | ||
| 151 | done | ||
| 152 | |||
| 153 | case "$CHANNEL" in | ||
| 154 | '' | *[!A-Za-z0-9._-]*) | ||
| 155 | die "invalid channel name: $CHANNEL" | ||
| 156 | ;; | ||
| 157 | esac | ||
| 158 | |||
| 159 | if [ -n "$PIN" ]; then | ||
| 160 | case "$PIN" in | ||
| 161 | v*) ;; | ||
| 162 | *) PIN="v$PIN" ;; | ||
| 163 | esac | ||
| 164 | case "$PIN" in | ||
| 165 | *[!A-Za-z0-9._-]*) | ||
| 166 | die "invalid release version: $PIN" | ||
| 167 | ;; | ||
| 168 | esac | ||
| 169 | BASE_URL="$BASE/releases/$PIN/artifacts" | ||
| 170 | else | ||
| 171 | BASE_URL="$BASE/channels/$CHANNEL" | ||
| 172 | fi | ||
| 173 | |||
| 174 | case "$ROOT" in | ||
| 175 | /) ;; | ||
| 176 | /*) ROOT=${ROOT%/} ;; | ||
| 177 | *) die "--root must be an absolute path" ;; | ||
| 178 | esac | ||
| 179 | [ -n "$ROOT" ] || ROOT=/ | ||
| 180 | if [ "$ROOT" = / ]; then | ||
| 181 | ETC=/etc | ||
| 182 | else | ||
| 183 | ETC="$ROOT/etc" | ||
| 184 | fi | ||
| 185 | OS_RELEASE="$ETC/os-release" | ||
| 186 | |||
| 187 | if [ -n "$KEY_FILE" ]; then | ||
| 188 | KEY_SOURCE=$KEY_FILE | ||
| 189 | else | ||
| 190 | KEY_SOURCE="$BASE_URL/vole-release-key.asc" | ||
| 191 | fi | ||
| 192 | |||
| 193 | detect() { | ||
| 194 | if [ ! -r "$OS_RELEASE" ]; then | ||
| 195 | die "cannot read $OS_RELEASE; this script needs a Linux distribution that provides it" | ||
| 196 | fi | ||
| 197 | # shellcheck disable=SC1090,SC1091 | ||
| 198 | . "$OS_RELEASE" | ||
| 199 | DISTRO=${ID:-unknown} | ||
| 200 | ids=" ${ID:-} ${ID_LIKE:-} " | ||
| 201 | case "$ids" in | ||
| 202 | *" debian "* | *" ubuntu "*) | ||
| 203 | FAMILY=apt | ||
| 204 | ;; | ||
| 205 | *" fedora "* | *" rhel "* | *" centos "* | *" rocky "* | *" almalinux "*) | ||
| 206 | FAMILY=dnf | ||
| 207 | ;; | ||
| 208 | *" arch "*) | ||
| 209 | FAMILY=pacman | ||
| 210 | ;; | ||
| 211 | *) | ||
| 212 | die "unsupported distribution '$DISTRO' (ID_LIKE='${ID_LIKE:-}'); add the repository by hand: https://vole.rodent.software/install/#add-the-repository-by-hand" | ||
| 213 | ;; | ||
| 214 | esac | ||
| 215 | ARCH=$(uname -m) | ||
| 216 | case "$ARCH" in | ||
| 217 | x86_64 | amd64 | aarch64 | arm64) ;; | ||
| 218 | *) die "unsupported architecture: $ARCH" ;; | ||
| 219 | esac | ||
| 220 | } | ||
| 221 | |||
| 222 | hint() { | ||
| 223 | case "$FAMILY" in | ||
| 224 | apt) echo "apt-get update && apt-get install vole" ;; | ||
| 225 | dnf) echo "dnf install vole" ;; | ||
| 226 | pacman) echo "pacman -Syu vole" ;; | ||
| 227 | esac | ||
| 228 | } | ||
| 229 | |||
| 230 | plan() { | ||
| 231 | if [ -n "$PIN" ]; then | ||
| 232 | log "would install release $PIN from $BASE_URL" | ||
| 233 | else | ||
| 234 | log "would follow channel $CHANNEL at $BASE_URL" | ||
| 235 | fi | ||
| 236 | log "detected $DISTRO ($FAMILY) on $ARCH" | ||
| 237 | log "release key: $KEY_SOURCE (sha256 $VOLE_KEY_SHA256, fingerprint $VOLE_KEY_FPR)" | ||
| 238 | case "$FAMILY" in | ||
| 239 | apt) | ||
| 240 | log "would write $ETC/apt/keyrings/vole.asc and $ETC/apt/sources.list.d/vole.list" | ||
| 241 | ;; | ||
| 242 | dnf) | ||
| 243 | log "would write $ETC/pki/rpm-gpg/RPM-GPG-KEY-vole and $ETC/yum.repos.d/vole.repo" | ||
| 244 | ;; | ||
| 245 | pacman) | ||
| 246 | log "would add [vole] to $ETC/pacman.conf and import the key into the pacman keyring" | ||
| 247 | ;; | ||
| 248 | esac | ||
| 249 | if [ "$REPO_ONLY" = 1 ] || [ "$ROOT" != / ]; then | ||
| 250 | log "would stop after the repository; install with: $(hint)" | ||
| 251 | else | ||
| 252 | log "would run: $(hint)" | ||
| 253 | fi | ||
| 254 | } | ||
| 255 | |||
| 256 | verify_key() { | ||
| 257 | actual=$(sha256 "$1") | ||
| 258 | if [ "$actual" != "$VOLE_KEY_SHA256" ]; then | ||
| 259 | die "release key checksum mismatch: expected $VOLE_KEY_SHA256, got $actual" | ||
| 260 | fi | ||
| 261 | if command -v gpg >/dev/null 2>&1; then | ||
| 262 | fingerprint=$(gpg --batch --with-colons --import-options show-only --import "$1" 2>/dev/null | | ||
| 263 | awk -F: '$1 == "fpr" {print $10; exit}') | ||
| 264 | if [ "$fingerprint" != "$VOLE_KEY_FPR" ]; then | ||
| 265 | die "release key fingerprint mismatch: expected $VOLE_KEY_FPR, got ${fingerprint:-none}" | ||
| 266 | fi | ||
| 267 | fi | ||
| 268 | } | ||
| 269 | |||
| 270 | configure_apt() { | ||
| 271 | install -d -m 0755 "$ETC/apt/keyrings" "$ETC/apt/sources.list.d" | ||
| 272 | install -m 0644 "$tmp/key.asc" "$ETC/apt/keyrings/vole.asc" | ||
| 273 | printf 'deb [signed-by=/etc/apt/keyrings/vole.asc] %s/apt ./\n' "$BASE_URL" >"$tmp/vole.list" | ||
| 274 | install -m 0644 "$tmp/vole.list" "$ETC/apt/sources.list.d/vole.list" | ||
| 275 | } | ||
| 276 | |||
| 277 | configure_dnf() { | ||
| 278 | install -d -m 0755 "$ETC/pki/rpm-gpg" "$ETC/yum.repos.d" | ||
| 279 | install -m 0644 "$tmp/key.asc" "$ETC/pki/rpm-gpg/RPM-GPG-KEY-vole" | ||
| 280 | { | ||
| 281 | printf '[vole]\n' | ||
| 282 | printf 'name=Vole\n' | ||
| 283 | printf 'baseurl=%s/yum/\n' "$BASE_URL" | ||
| 284 | printf 'enabled=1\n' | ||
| 285 | printf 'gpgcheck=1\n' | ||
| 286 | printf 'repo_gpgcheck=1\n' | ||
| 287 | printf 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-vole\n' | ||
| 288 | } >"$tmp/vole.repo" | ||
| 289 | install -m 0644 "$tmp/vole.repo" "$ETC/yum.repos.d/vole.repo" | ||
| 290 | if [ "$ROOT" = / ]; then | ||
| 291 | rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-vole | ||
| 292 | fi | ||
| 293 | } | ||
| 294 | |||
| 295 | configure_pacman() { | ||
| 296 | install -d -m 0755 "$ETC" | ||
| 297 | if [ ! -e "$ETC/pacman.conf" ]; then | ||
| 298 | : >"$ETC/pacman.conf" | ||
| 299 | fi | ||
| 300 | if ! grep -q '^\[vole\]$' "$ETC/pacman.conf"; then | ||
| 301 | { | ||
| 302 | printf '\n[vole]\n' | ||
| 303 | printf 'Server = %s/pacman/$arch\n' "$BASE_URL" | ||
| 304 | printf 'SigLevel = Required DatabaseRequired\n' | ||
| 305 | } >>"$ETC/pacman.conf" | ||
| 306 | fi | ||
| 307 | if [ "$ROOT" = / ]; then | ||
| 308 | [ -d /etc/pacman.d/gnupg ] || pacman-key --init | ||
| 309 | pacman-key --add "$tmp/key.asc" | ||
| 310 | pacman-key --lsign-key "$VOLE_KEY_FPR" | ||
| 311 | fi | ||
| 312 | } | ||
| 313 | |||
| 314 | install_package() { | ||
| 315 | case "$FAMILY" in | ||
| 316 | apt) | ||
| 317 | apt-get update | ||
| 318 | DEBIAN_FRONTEND=noninteractive apt-get install -y vole | ||
| 319 | ;; | ||
| 320 | dnf) | ||
| 321 | dnf install -y vole | ||
| 322 | ;; | ||
| 323 | pacman) | ||
| 324 | pacman -Syu --needed --noconfirm vole | ||
| 325 | ;; | ||
| 326 | esac | ||
| 327 | } | ||
| 328 | |||
| 329 | detect | ||
| 330 | |||
| 331 | if [ "$DRY_RUN" = 1 ]; then | ||
| 332 | plan | ||
| 333 | exit 0 | ||
| 334 | fi | ||
| 335 | |||
| 336 | if [ "$ROOT" = / ] && [ "$(id -u)" -ne 0 ]; then | ||
| 337 | die "run as root, for example: curl -fsSL $BASE_URL/install.sh | sudo sh" | ||
| 338 | fi | ||
| 339 | if [ -n "$KEY_FILE" ] && [ ! -r "$KEY_FILE" ]; then | ||
| 340 | die "cannot read key file: $KEY_FILE" | ||
| 341 | fi | ||
| 342 | |||
| 343 | tmp=$(mktemp -d) | ||
| 344 | trap 'rm -rf "$tmp"' 0 | ||
| 345 | |||
| 346 | if [ -n "$KEY_FILE" ]; then | ||
| 347 | cp "$KEY_FILE" "$tmp/key.asc" | ||
| 348 | else | ||
| 349 | fetch "$KEY_SOURCE" "$tmp/key.asc" | ||
| 350 | fi | ||
| 351 | verify_key "$tmp/key.asc" | ||
| 352 | |||
| 353 | case "$FAMILY" in | ||
| 354 | apt) configure_apt ;; | ||
| 355 | dnf) configure_dnf ;; | ||
| 356 | pacman) configure_pacman ;; | ||
| 357 | esac | ||
| 358 | |||
| 359 | if [ "$REPO_ONLY" = 1 ] || [ "$ROOT" != / ]; then | ||
| 360 | log "repository configured from $BASE_URL" | ||
| 361 | if [ "$ROOT" != / ]; then | ||
| 362 | log "wrote files under $ROOT; --root does not install packages" | ||
| 363 | else | ||
| 364 | log "install with: $(hint)" | ||
| 365 | fi | ||
| 366 | exit 0 | ||
| 367 | fi | ||
| 368 | |||
| 369 | install_package | ||
| 370 | if command -v vole >/dev/null 2>&1; then | ||
| 371 | log "installed vole $(vole version 2>/dev/null || true)" | ||
| 372 | else | ||
| 373 | log "installed vole" | ||
| 374 | fi | ||