#!/bin/bash
dir=/opt/kylo/script/kylo-tail.d
opts="-Fn100"

# Check which OS is being used.
if [ -f /etc/redhat-release ]; then
        dir=$dir/redhat
elif  [  -f /etc/debian-release ]; then
        dir=$dir/debian
else
        echo "kylo-tail: cannot determine log file paths for this OS, exiting."; exit 1
fi

if [ "$1" == "-h" ]; then
  # need man pages.
  echo "kylo-tail: using no parameters, all logs are tailed. Using one or more parameters, it tails those logs. For example, kylo-tail nifi will only display nifi logs."; exit 1
fi
if [ "$1" == "-l" ]; then
  ls $dir | cut -d- -f2; exit 1
fi

if [ -z "$1" ]; then
  tail $opts $(eval echo $(cat $dir/*)) 2>/dev/null
else
  if [ "$#" -eq 1 ]; then
    tail $opts $(eval echo $(cat $dir/*$1)) 2>/dev/null
  else
    args=$(IFS=","; echo "$*")
    tail $opts $(cat $(eval echo $dir/*{$args})) 2>/dev/null
  fi
fi
