#!/bin/sh # curl -fsSL https://dl.omakasebiz.jp/cli/install.sh | sh # The call is deliberately last: a truncated download cannot start installation. set -eu omakase_install() { base=${OMAKASE_CLI_DOWNLOAD_BASE:-https://dl.omakasebiz.jp/cli} install_dir=${OMAKASE_INSTALL_DIR:-$HOME/.local/bin} version=${OMAKASE_CLI_VERSION:-} die() { echo "omakase install: $*" >&2; exit 1; } valid_version() { printf '%s' "$1" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]+$'; } case "$(uname -s):$(uname -m)" in Linux:x86_64) target=x86_64-unknown-linux-gnu ;; *) die 'no published binary for this OS/CPU; build from source' ;; esac command -v curl >/dev/null 2>&1 || die 'curl is required' if command -v sha256sum >/dev/null 2>&1; then sha=sha256sum elif command -v shasum >/dev/null 2>&1; then sha='shasum -a 256' else die 'a SHA-256 tool is required' fi if [ -z "$version" ]; then version=$(curl -fsSL "${base}/latest.txt" | tr -d '\r\n') fi valid_version "$version" || die 'invalid version name' case "$version" in v*) ;; *) version="v$version" ;; esac tmp=$(mktemp -d) || die 'cannot create a temporary directory' trap 'rm -rf "$tmp"' EXIT HUP INT TERM name="omakase-${target}" url="${base}/${version}/${name}" curl -fsSL "$url" -o "$tmp/$name" || die 'binary download failed' curl -fsSL "${url}.sha256" -o "$tmp/$name.sha256" || die 'checksum download failed' expected=$(cut -d ' ' -f 1 < "$tmp/$name.sha256") [ "${#expected}" -eq 64 ] || die 'invalid checksum' actual=$($sha "$tmp/$name" | cut -d ' ' -f 1) [ "$actual" = "$expected" ] || die 'checksum mismatch; nothing installed' chmod 755 "$tmp/$name" mkdir -p "$install_dir" staged=$(mktemp "$install_dir/.omakase-install.XXXXXX") || die 'cannot stage binary' trap 'rm -rf "$tmp"; rm -f "$staged"' EXIT HUP INT TERM cp "$tmp/$name" "$staged" || die 'cannot stage binary' chmod 755 "$staged" mv -f "$staged" "$install_dir/omakase" || die 'cannot install binary' echo "Installed $version to $install_dir/omakase" } omakase_install