#!/usr/bin/env bash
#
# install-bat.sh
#

set -e
set -o pipefail

distribution=$(grep ^ID= /etc/os-release | awk -F'=' '{ print $2 }')
version=$(grep ^VERSION_ID= /etc/os-release | awk -F'"' '{ print $2 }')
cmd1="unknown"

# Ubuntu
if [[ "${distribution?}" == "ubuntu" ]]; then

    if   [[ "${version?}" == "26.04" ]]; then
        msg1="installing bat"
        cmd1="sudo apt -y update"
        cmd2="sudo apt -y install bat"

    elif [[ "${version?}" == "24.04" ]]; then
        msg1="installing bat"
        cmd1="sudo apt -y update"
        cmd2="sudo apt -y install bat"

    elif [[ "${version?}" == "22.04" ]]; then
        msg1="installing bat"
        cmd1="sudo apt -y update"
        cmd2="sudo apt -y install bat"

    else
        msg="there is not bat/batcat for ubuntu ${version?}"
        cmd=""

    fi

# Debian / Raspberry Pi OS
elif [[ "${distribution?}" == "debian" ]]; then

    # v13 trixie
    if   [[ "${version?}" == "13" ]]; then
        msg1="installing bat"
        cmd1="sudo apt -y update"
        cmd2="sudo apt -y install bat"

    # v12 bookworm
    elif [[ "${version?}" == "12" ]]; then
        msg1="installing bat"
        cmd1="sudo apt -y update"
        cmd2="sudo apt -y install bat"

    fi

# Raspbian
elif [[ "${distribution?}" == "raspbian" ]]; then

    # v10 buster
    if   [[ "${version?}" == "10" ]]; then
        msg1="there is not bat/batcat for raspbian buster/v10"
        cmd1=""
        cmd2=""

    fi

fi

echo ""
echo "distribution: ${distribution?}"
echo "version:      ${version?}"
echo "message:      ${msg1?}"
echo "command 1:    ${cmd1?}"
echo "command 2:    ${cmd2?}"
echo ""

if [[ ! "${cmd1?}" == "unknown" ]]; then
    echo "executing command 1..."
    ${cmd1?}
    echo ""
    echo "executing command 2..."
    ${cmd2?}
    echo ""
    echo "done"
    echo ""
fi

