#!/usr/bin/env bash

# omarchy:summary=Install cinch, the os command
# omarchy:requires-sudo=true

# Based: cinch has no package on either OS, so its checkout builds into
# /usr/local, or into the Homebrew prefix on a Mac.

set -eo pipefail

echo "Installing cinch..."
omarchy-pkg-add git make linux=only

prefix=/usr/local
as_root=sudo
if [[ $(omarchy-os) == darwin ]]; then
  prefix=$(brew --prefix)
  as_root=
fi

if [[ ! -x $prefix/bin/os ]]; then
  tmp=$(mktemp -d)
  trap 'rm -rf "$tmp"' EXIT
  git clone https://gitlab.com/based-linux/cinch.git "$tmp/cinch"
  (cd "$tmp/cinch" && $as_root make install PREFIX="$prefix")
fi
