#!/bin/sh # Installs keybars, the free command-line music equaliser for your keyboard. # # curl -fsSL https://keybars.app/install.sh | sh # curl -fsSL https://keybars.app/install.sh | sh -s -- --dir ~/bin # curl -fsSL https://keybars.app/install.sh | sh -s -- --pro # # It downloads the latest release for this computer from GitHub, checks it # against the release's checksums, and puts the keybars binary in # /usr/local/bin if it can write there, else ~/.local/bin. It never asks for # sudo. Options: --version v0.4.0, --dir DIR, --pro (keybars Pro, the app). # KEYBARS_VERSION and KEYBARS_INSTALL_DIR do the same as --version and --dir. # # Read it first: https://keybars.app/install.sh set -eu repo=jwarykowski/keybars site=https://keybars.app say() { printf '%s\n' "$*"; } fail() { printf 'keybars install: %s\n' "$*" >&2 exit 1 } # fetch URL FILE downloads with curl or wget. fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 2 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" else fail "needs curl or wget" fi } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1 else fail "needs sha256sum or shasum to check the download" fi } platform() { case $(uname -s) in Linux) os=linux ;; Darwin) os=darwin ;; *) fail "keybars runs on Linux and macOS; on $(uname -s), see $site/docs/" ;; esac case $(uname -m) in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) fail "there's no keybars build for $(uname -m) yet; go install github.com/$repo@latest builds one" ;; esac } # latest is the newest release's tag, from where GitHub's latest link leads. latest() { tmp_tag=$1/latest.json fetch "https://api.github.com/repos/$repo/releases/latest" "$tmp_tag" || fail "couldn't reach GitHub to find the latest release" tag=$(sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$tmp_tag" | head -n 1) [ -n "$tag" ] || fail "couldn't read the latest release from GitHub" printf '%s' "$tag" } # pick_dir chooses where the binary goes: --dir, else /usr/local/bin if # writable, else ~/.local/bin. pick_dir() { if [ -n "$dir" ]; then mkdir -p "$dir" || fail "can't make $dir" [ -w "$dir" ] || fail "can't write to $dir" return fi if [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then dir=/usr/local/bin else dir=$HOME/.local/bin mkdir -p "$dir" || fail "can't make $dir" fi } on_path() { case ":$PATH:" in *":$1:"*) return 0 ;; esac return 1 } install_free() { platform work=$(mktemp -d) trap 'rm -rf "$work"' EXIT INT TERM if [ -z "$version" ]; then version=$(latest "$work") fi case $version in v*) ;; *) version=v$version ;; esac name=keybars_${version#v}_${os}_${arch}.tar.gz base=https://github.com/$repo/releases/download/$version say "Downloading keybars $version for $os/$arch" fetch "$base/$name" "$work/$name" || fail "no $name in release $version" fetch "$base/checksums.txt" "$work/checksums.txt" || fail "release $version has no checksums.txt" want=$(grep " $name\$" "$work/checksums.txt" | cut -d' ' -f1) [ -n "$want" ] || fail "$name isn't in the release's checksums" [ "$(sha256 "$work/$name")" = "$want" ] || fail "$name doesn't match its checksum; nothing was installed" tar -xzf "$work/$name" -C "$work" keybars || fail "couldn't unpack $name" pick_dir # replace in one step, so a running keybars isn't left half-written cp "$work/keybars" "$dir/.keybars.new" chmod 755 "$dir/.keybars.new" mv -f "$dir/.keybars.new" "$dir/keybars" say "Installed keybars $version to $dir/keybars" if ! on_path "$dir"; then say "" say "$dir isn't on your PATH yet. Add it in your shell's startup file:" say " export PATH=\"$dir:\$PATH\"" fi if ! command -v cava >/dev/null 2>&1; then say "" say "keybars listens through cava, which isn't installed. Install it with:" if [ "$os" = darwin ]; then say " brew install cava" say "macOS also needs a loopback device such as BlackHole: $site/docs/#macos-audio" elif command -v dnf >/dev/null 2>&1; then say " sudo dnf install cava" elif command -v apt-get >/dev/null 2>&1; then say " sudo apt install cava" elif command -v pacman >/dev/null 2>&1; then say " sudo pacman -S cava" else say " your package manager, or from https://github.com/karlstav/cava" fi fi say "" say "Then run: keybars ($site/docs/ for the rest)" } install_pro() { say "keybars Pro, the desktop app, isn't released yet." say "Join the waitlist for a launch email and the founder discount: $site/pro/#join" exit 1 } usage() { cat <