#!/usr/bin/env bash # Copyright (c) .NET Foundation and contributors. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. # # Stop script on NZEC set -e # Stop script if unbound variable found (use ${var:-} if intentional) set -u # By default cmd1 | cmd2 returns exit code of cmd2 regardless of cmd1 success # This is causing it to fail set -o pipefail # Use in the the functions: eval $invocation invocation='say_verbose "Calling: ${yellow:-}${FUNCNAME[0]} ${green:-}$*${normal:-}"' # standard output may be used as a return value in the functions # we need a way to write text on the screen in the functions so that # it won't interfere with the return value. # Exposing stream 3 as a pipe to standard output of the script itself exec 3>&1 say_err() { printf "%b\n" "get-os-distro: Error: $1" >&2 } # This platform list is finite - if the SDK/Runtime has supported Linux distribution-specific assets, # then and only then should the Linux distribution appear in this list. # Adding a Linux distribution to this list does not imply distribution-specific support. get_legacy_os_name_from_platform() { platform="$1" case "$platform" in "centos.7") echo "centos" return 0 ;; "debian.8") echo "debian" return 0 ;; "fedora.23") echo "fedora.23" return 0 ;; "fedora.27") echo "fedora.27" return 0 ;; "fedora.24") echo "fedora.24" return 0 ;; "opensuse.13.2") echo "opensuse.13.2" return 0 ;; "opensuse.42.1") echo "opensuse.42.1" return 0 ;; "opensuse.42.3") echo "opensuse.42.3" return 0 ;; "rhel.7"*) echo "rhel" return 0 ;; "ubuntu.14.04") echo "ubuntu" return 0 ;; "ubuntu.16.04") echo "ubuntu.16.04" return 0 ;; "ubuntu.16.10") echo "ubuntu.16.10" return 0 ;; "ubuntu.18.04") echo "ubuntu.18.04" return 0 ;; "alpine.3.4.3") echo "alpine" return 0 ;; esac return 1 } get_linux_platform_name() { if [ -e /etc/os-release ]; then . /etc/os-release echo "$ID.$VERSION_ID" return 0 elif [ -e /etc/redhat-release ]; then local redhatRelease=$( /dev/null; then CPUName=$(uname -m) case $CPUName in armv7l) echo "arm" return 0 ;; aarch64) echo "arm64" return 0 ;; esac fi # Always default to 'x64' echo "x64" return 0 } osName=$(get_current_os_name || echo "") legacyOsName=$(get_legacy_os_name || echo "") arch=$(get_machine_architecture || echo "") primaryName="$osName-$arch" legacyName="$legacyOsName" echo "Primary:$primaryName" echo "Legacy:$legacyName" if [ -z "$osName" ] && [ -z "$legacyOsName" ];then exit 1 fi