refactor get distro to work more universally

master
David Kebler 2023-02-23 11:16:55 -08:00
parent dd25a68355
commit ef79f9623a
1 changed files with 23 additions and 21 deletions

View File

@ -47,29 +47,31 @@ hostinfo () {
}
function get_distro() {
source /etc/os-release
declare valid=${@:-"arch alpine debian ubuntu"}
# echo $ID $ID_LIKE
[[ "${valid}" =~ $ID ]] && echo $ID && return 0
[[ "${valid}" =~ $ID_LIKE ]] && echo $ID_LIKE && return 0
return 1
}
# function get_distro() {
# source /etc/os-release
# declare distros=${@:-"arch alpine debian ubuntu"}
# # echo $ID $ID_LIKE
# for distro in $distros; do
# echo $distro $ID $ID_LIKE
# [[ $ID =~ $distro ]] && echo $distro && return 0
# [[ $ID_LIKE =~ $distro ]] && echo $distro && return 0
# done
# return 1
# }
# function get_release() {
# }
# get_distro() {
# local file=/etc/upstream-release/lsb-release
# local distro
# if [[ -f $file ]]; then
# echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
# return 0
# else
# file=/etc/os-release
# if [[ -f $file ]]; then
# echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
# fi
# fi
# }
get_distro() {
local file=/etc/upstream-release/lsb-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
return 0
else
file=/etc/os-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
fi
fi
}