# -*- Mode: shell-script; -*-
################################################################################
#
# Driver for Xilinx network controllers and boards
# Copyright 2021 Xilinx Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation, incorporated herein by reference.
#
################################################################################

err  () { echo >&2 "$*";    }
log  () { err "$p: $*";    }
fail () { log "$*"; exit 1; }
try  () { "$@" || fail "'$*' failed"; }

# Please DO NOT reduce the set of recognised distros, even if we are
# dropping support elsewhere in the codebase.

# ssh to rpmbuild and run this to show some examples
#   grep -Hnr . /mnt/{rhel,sle}*/etc/*-release

xilinx-efct_disttag() {
  if [ -f /etc/redhat-release ]; then
    awk '
	/Red Hat Linux release/ { gsub(/\./,""); printf "RH%s\n", $5; exit }
	/Red Hat Enterprise Linux release/ { printf "RHEL%s\n", substr($6, 1, 1); exit }
	/Red Hat Enterprise Linux (WS|Server|Client|Workstation)/ { printf "RHEL%s\n", substr($7, 1, 1); exit }
        /CentOS Linux release 7/ { printf "RHEL7\n"; exit }
	' /etc/redhat-release
  elif [ -f /etc/debian_version ]; then
      echo "Debian"`sed 's/\//-/g' /etc/debian_version`
  elif [ -x "$(command -v hostnamectl)" ]; then
    hostnamectl | awk '
	/SUSE Linux Enterprise Server/ { printf "SLES%s\n", $7; exit }
	'
  else
    echo "unsupportedOS"
    return 1
  fi
  return 0
}
