66 lines
2.0 KiB
Bash
66 lines
2.0 KiB
Bash
# ------------------------------------------------------------------------------
|
|
# Version determination function
|
|
# This file is part of the init.sh project
|
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
|
# ------------------------------------------------------------------------------
|
|
# This file is distributed under 3-clause BSD license.
|
|
# The complete license agreement can be obtained at:
|
|
# https://opensource.org/licenses/BSD-3-Clause
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Return on stdout $distro $version $codename
|
|
read_os_release()
|
|
{
|
|
if [[ ! -f /etc/os-release ]]; then
|
|
prnt E "Your distribution doesn't have the needed os-release file."
|
|
die 8 --force
|
|
fi
|
|
|
|
# Create a sub-shell to avoid polluting the environnement
|
|
(
|
|
# Iniitalise version codename in case the var don't exists
|
|
VERSION_CODENAME="NULL"
|
|
|
|
# Import the file in the environment
|
|
source /etc/os-release
|
|
|
|
if [[ -z $ID ]]; then
|
|
prnt E "Your /etc/os-release file mises some vital information."
|
|
die --force 8
|
|
fi
|
|
|
|
if [[ -z $VERSION_ID ]]; then
|
|
local maj=$(uname -r | cut -d'.' -f1)
|
|
local min=$(uname -r | cut -d'.' -f2)
|
|
VERSION_ID="$maj.$min"
|
|
unset maj min
|
|
fi
|
|
|
|
# Return values on standard stdout
|
|
echo ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}
|
|
)
|
|
}
|
|
export read_os_release
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Create system related variables
|
|
# ------------------------------------------------------------------------------
|
|
get_os_version()
|
|
{
|
|
if [[ $# -ne 3 ]]; then
|
|
prnt E "get_os_version(): incorect number of parameters ($@)."
|
|
die 7 --force
|
|
fi
|
|
|
|
export SYS_DIST=$1
|
|
export SYS_VER=$2
|
|
if [[ $3 != "null" ]]; then
|
|
export SYS_CODE=$3
|
|
fi
|
|
}
|
|
export -f get_os_version
|
|
|
|
# EOF
|