#!/bin/sh # Installs Rota from the latest GitHub release: # curl -fsSL https://raw.githubusercontent.com/psardana/rota/main/install.sh | sh # # It puts `rota` in ~/.local/bin (or $ROTA_PREFIX/bin), starts the background # service, and on macOS adds the menu bar app to ~/Applications. # Set ROTA_VERSION=0.2.0 for a given release, or ROTA_NO_SERVICE=1 to skip the service. set -eu REPO=psardana/rota PREFIX="${ROTA_PREFIX:-$HOME/.local}" say() { printf '%s\n' "$*"; } fail() { say "rota install: $*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "needs $1"; } need curl need tar need uname case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "Rota runs on macOS and Linux only" ;; esac case "$(uname -m)" in arm64 | aarch64) arch=arm64 ;; x86_64 | amd64) arch=amd64 ;; *) fail "no build for $(uname -m); build from source instead: https://github.com/$REPO#install" ;; esac if [ -n "${ROTA_VERSION:-}" ]; then version="${ROTA_VERSION#v}" else version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | sed -n 's/.*"tag_name": *"v\{0,1\}\([^"]*\)".*/\1/p' | head -n 1) [ -n "$version" ] || fail "could not find the latest release" fi tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM base="${ROTA_DOWNLOAD_URL:-https://github.com/$REPO/releases/download/v$version}" name="rota_${version}_${os}_${arch}" say "Downloading Rota $version for $os/$arch..." curl -fsSL "$base/$name.tar.gz" -o "$tmp/$name.tar.gz" curl -fsSL "$base/checksums.txt" -o "$tmp/checksums.txt" sum() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 else shasum -a 256 "$1" | cut -d' ' -f1; fi } check() { want=$(grep " $1\$" "$tmp/checksums.txt" | cut -d' ' -f1) [ -n "$want" ] && [ "$want" = "$(sum "$tmp/$1")" ] || fail "checksum mismatch for $1" } check "$name.tar.gz" tar -xzf "$tmp/$name.tar.gz" -C "$tmp" mkdir -p "$PREFIX/bin" # A new file, not an overwrite: macOS kills a signed binary changed in place. cp "$tmp/$name/rota" "$PREFIX/bin/rota.new" chmod 755 "$PREFIX/bin/rota.new" mv -f "$PREFIX/bin/rota.new" "$PREFIX/bin/rota" say "Installed $PREFIX/bin/rota" if [ -z "${ROTA_NO_SERVICE:-}" ]; then "$PREFIX/bin/rota" service install fi if [ "$os" = darwin ] && [ -z "${ROTA_NO_APP:-}" ]; then app="Rota_${version}_macos.zip" if curl -fsSL "$base/$app" -o "$tmp/$app"; then check "$app" mkdir -p "$HOME/Applications" rm -rf "$HOME/Applications/Rota.app" ditto -x -k "$tmp/$app" "$HOME/Applications" say "Installed the menu bar app in ~/Applications/Rota.app" open "$HOME/Applications/Rota.app" 2>/dev/null || true fi fi if [ "$os" = linux ] && [ -d "$tmp/$name/linux" ]; then apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" auto="${XDG_CONFIG_HOME:-$HOME/.config}/autostart" mkdir -p "$apps" "$auto" sed "s|^Exec=rota|Exec=$PREFIX/bin/rota|" "$tmp/$name/linux/rota.desktop" >"$apps/rota.desktop" sed "s|^Exec=rota|Exec=$PREFIX/bin/rota|" "$tmp/$name/linux/rota-tray.desktop" >"$auto/rota-tray.desktop" say "Added a Rota launcher, and the tray icon at login (start it now with: rota tray &)" fi case ":$PATH:" in *":$PREFIX/bin:"*) ;; *) say "Add $PREFIX/bin to your PATH to use rota from any shell." ;; esac say "Done. Open the dashboard with: rota open"