#!/bin/sh # Install ubimd — real-time collaborative Markdown editor # Usage: curl -sSf https://get.ubi.md | sh set -e BASE_URL="https://get.ubi.md" INSTALL_DIR="${UBIMD_INSTALL_DIR:-$HOME/.local/bin}" main() { os="$(uname -s)" arch="$(uname -m)" case "$os" in Linux) platform="linux" ;; Darwin) platform="macos" ;; *) err "Unsupported OS: $os" ;; esac case "$arch" in x86_64|amd64) arch="x86_64" ;; aarch64|arm64) arch="aarch64" ;; *) err "Unsupported architecture: $arch" ;; esac target="ubimd-${platform}-${arch}" url="${BASE_URL}/latest/${target}.tar.gz" echo "Installing ubimd (${platform}/${arch})..." # Download and extract tmpdir="$(mktemp -d)" trap 'rm -rf "$tmpdir"' EXIT if command -v curl >/dev/null 2>&1; then if ! curl -sSfL "$url" -o "$tmpdir/ubimd.tar.gz"; then err "Download failed. No release found at $url" fi elif command -v wget >/dev/null 2>&1; then if ! wget -qO "$tmpdir/ubimd.tar.gz" "$url"; then err "Download failed. No release found at $url" fi else err "Need curl or wget" fi tar xzf "$tmpdir/ubimd.tar.gz" -C "$tmpdir" # Install mkdir -p "$INSTALL_DIR" cp "$tmpdir/ubimd" "$INSTALL_DIR/ubimd" chmod +x "$INSTALL_DIR/ubimd" # Check if install dir is in PATH case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) shell_name="$(basename "$SHELL")" case "$shell_name" in zsh) profile="~/.zshrc" ;; bash) profile="~/.bashrc" ;; fish) profile="~/.config/fish/config.fish" ;; *) profile="your shell profile" ;; esac echo "" echo "Add ubimd to your PATH — paste this into your terminal:" echo "" echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> $profile && source $profile" echo "" ;; esac echo "Installed ubimd to $INSTALL_DIR/ubimd" echo "" echo "Get started:" echo " ubimd notes.md # edit a file" echo " ubimd notes.md --online # share for real-time collaboration" } err() { echo "Error: $1" >&2 exit 1 } main