#!/bin/bash

# exit this script if any error occurs
set -e

# get the directory where this script is in
SCRIPTDIR="$(realpath -s "$(dirname "$0")")"

# check if repositry contains inxi
if [ ! -d "${SCRIPTDIR}/inxi" ]; then
  echo "ERROR: There is no subdirectory inxi!"
  exit 1
fi

EXEC_INXI="${SCRIPTDIR}/inxi/inxi"
EXEC_NEOFETCH="${SCRIPTDIR}/neofetch"

# check if inxi is there
if [ ! -x "${EXEC_INXI}" ] || ! $("${EXEC_INXI}" --version | grep -q "^inxi"); then
  echo "ERROR: No inxi found!"
  exit 1
fi

# check if neofetch is there
if [ ! -x "${EXEC_NEOFETCH}" ] || ! $("${EXEC_NEOFETCH}" --version | grep -q "^Neofetch"); then
  echo "ERROR: No neofetch found!"
  exit 1
fi

echo "Congratulations! Task solved correctly!"

# exit the script with zero exit code
exit 0
