:
#
# system-release [-a | -n | -v | -h]
#

SHOWALL=1
SHOWHELP=0
SHOWARCH=0
SHOWNAME=0
SHOWVER=0

while [ -n "$1" ]; do
  FC=`echo $1|cut -c1`

  if [ "$1" == "-h" ]; then
    SHOWALL=0
    SHOWHELP=1
  elif [ "$1" == "-a" ]; then
    SHOWALL=0
    SHOWARCH=1
  elif [ "$1" == "-n" ]; then
    SHOWALL=0
    SHOWNAME=1
  elif [ "$1" == "-v" ]; then
    SHOWALL=0
    SHOWVER=1
  fi

  shift
done

if [ $SHOWHELP -eq 1 ]; then
  echo "Usage: system-release [-h | -n | -v | -a]"
  echo
  echo "    Display the OS name, version and architecture."
  echo
  echo "    -h  Show Nelp"
  echo "    -n  Show OS Name"
  echo "    -v  Show OS Version"
  echo "    -a  Show OS Architecture"
  echo
  exit 1
fi

if [ $SHOWALL -eq 1 ]; then
    SHOWNAME=1
    SHOWVER=1
    SHOWARCH=1
fi

#

ARCH=$( uname -m )

if [ -f /etc/os-release ]; then
  source /etc/os-release

elif [ -f /etc/system-release ]; then
  STR=$( head -n 1 /etc/system-release|sed -e "s/linux *//ig;s/release *//ig;s/(.*)//g;s/^ *//;s/ *$//;s/  */ /g;s/[A-Z]/\L&/g" )
  IFS=' ' read -r ID VERSION_ID <<< "$STR"


else
  echo not found

  exit 9
fi

SEPARATOR=0

if [ $SHOWNAME -eq 1 ]; then
  echo -n $ID
  SEPARATOR=1
fi

if [ $SHOWVER -eq 1 ]; then
  [ $SEPARATOR -eq 1 ] && echo -n '-'
  echo -n $VERSION_ID
  SEPARATOR=1
fi

if [ $SHOWARCH -eq 1 ]; then
  [ $SEPARATOR -eq 1 ] && echo -n '-'
  echo -n $ARCH
fi

echo
