#!/usr/bin/env bash
##makedesc: Install software from brew

set -eo pipefail

if [ "$(uname -s)" != "Darwin" ]; then
    echo "ERROR: This script is for MacOS only." >&2
    exit 1
fi

installed() { command -v "$1" >/dev/null 2>&1; }

install() {
    echo
    echo "==============================================="
    echo "Installing software from brew"
    echo "==============================================="
    echo

    if ! installed brew; then
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    fi

    brew install \
        bash \
        stow \
        gnupg \
        pinentry-mac

    mkdir -p ~/.gnupg
    echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
    gpgconf --kill gpg-agent

    echo
    echo "Finish!"
    echo
}

case "$1" in
    *) install ;;
esac
