refactor get distro to work more universally
parent
dd25a68355
commit
ef79f9623a
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue