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