Files
riptide/misc/riptideinstaller.sh
T

92 lines
1.9 KiB
Bash

#!/bin/sh
set -eu
repo="gigirassy/riptide"
base="https://codeberg.org/$repo"
api="https://codeberg.org/api/v1/repos/$repo/releases/latest"
green="$(printf '\033[1;32m')"
red="$(printf '\033[1;31m')"
blue="$(printf '\033[1;34m')"
reset="$(printf '\033[0m')"
info() {
printf '%s[+]%s %s\n' "$green" "$reset" "$*"
}
step() {
printf '%s[*]%s %s\n' "$blue" "$reset" "$*"
}
error() {
printf '%s[-]%s %s\n' "$red" "$reset" "$*" >&2
}
for cmd in curl jq sha256sum grep awk sed; do
command -v "$cmd" >/dev/null 2>&1 || {
error "missing dependency: $cmd !"
exit 1
}
done
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
if command -v run0 >/dev/null 2>&1; then
asroot="run0"
elif command -v doas >/dev/null 2>&1; then
asroot="doas"
elif command -v sudo >/dev/null 2>&1; then
asroot="sudo"
else
error "run0, doas, or sudo is required"
exit 1
fi
step "fetching latest release information..."
release_json="$(curl -fsSL "$api")"
version="$(printf '%s' "$release_json" | jq -r '.tag_name')"
[ -n "$version" ] && [ "$version" != "null" ] || {
error "failed to determine latest version!"
exit 1
}
checksum="$(
printf '%s' "$release_json" |
jq -r '.body' |
grep -oE '[a-f0-9]{64}' |
head -n1
)"
[ -n "$checksum" ] || {
error "failed to locate checksum!"
exit 1
}
url="$base/releases/download/$version/riptide"
info "latest version is $version!"
info "checksum is $checksum!"
step "downloading riptide..."
curl -fsSL "$url" -o "$tmpdir/riptide"
step "verifying checksum..."
printf '%s %s\n' "$checksum" "$tmpdir/riptide" | sha256sum -c - >/dev/null
info "checksum verified!"
chmod 755 "$tmpdir/riptide"
step "installing to /usr/local/bin/riptide"
step "authentication may be required ($asroot)"
"$asroot" install -m 755 "$tmpdir/riptide" /usr/local/bin/riptide
info "riptide $version installed successfully <3 have a nice day"