#!/usr/bin/env bash

# linux-release
#
# Copyright (C) 2020 by RStudio, PBC.
# All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains the property of
# RStudio, PBC and its suppliers, if any. The intellectual and technical
# concepts contained herein are proprietary to RStudio, PBC and its suppliers
# and may be covered by U.S. and Foreign Patents, patents in process, and
# are protected by trade secret or copyright law. Dissemination of this
# information or reproduction of this material is strictly forbidden unless
# prior written permission is obtained.


function find_quoted {
	# find key="value" in file, return value
	key="$1"
	file="$2"
	grep "$key"  "$file" | cut -d '=' -f 2 | cut -d '"' -f 2
}

if [ -f /etc/system-release ]; then
	# Centos/RHEL
	cat /etc/system-release
elif [ -f /etc/lsb-release ]; then
	# Ubuntu
	DISTRO=$(find_quoted DISTRIB_DESCRIPTION /etc/lsb-release)
	CODENAME=$(find_quoted DISTRIB_CODENAME /etc/lsb-release)
	echo "${DISTRO} (${CODENAME})"
elif [ -f /etc/os-release ]; then
	# OpenSUSE
	find_quoted PRETTY_NAME /etc/os-release
else
	echo "unknown"
fi
