Browse Source

add library

master
lework 5 years ago
parent
commit
61b41e8d25
  1. 98
      shell/library.sh

98
shell/library.sh

@ -577,6 +577,104 @@ func_ipv4_addr(){ @@ -577,6 +577,104 @@ func_ipv4_addr(){
echo $ips
}
# Get OS information
get_os_name () {
centos_flavor="centos"
# Use lsb_release if possible
if command -V lsb_release > /dev/null 2>&1; then
os=`lsb_release -is | tr '[:upper:]' '[:lower:]'`
codename=`lsb_release -cs | tr '[:upper:]' '[:lower:]'`
release=`lsb_release -rs | sed 's/\..*$//'`
if [ "$os" = "redhatenterpriseserver" -o "$os" = "oracleserver" ]; then
os="centos"
centos_flavor="red hat linux"
fi
# Otherwise it's getting a little bit more tricky
else
if ! ls /etc/*-release > /dev/null 2>&1; then
os=`uname -s | \
tr '[:upper:]' '[:lower:]'`
else
os=`cat /etc/*-release | grep '^ID=' | \
sed 's/^ID=["]*\([a-zA-Z]*\).*$/\1/' | \
tr '[:upper:]' '[:lower:]'`
if [ -z "$os" ]; then
if grep -i "oracle linux" /etc/*-release > /dev/null 2>&1 || \
grep -i "red hat" /etc/*-release > /dev/null 2>&1; then
os="rhel"
else
if grep -i "centos" /etc/*-release > /dev/null 2>&1; then
os="centos"
else
os="linux"
fi
fi
fi
fi
case "$os" in
ubuntu)
codename=`cat /etc/*-release | grep '^DISTRIB_CODENAME' | \
sed 's/^[^=]*=\([^=]*\)/\1/' | \
tr '[:upper:]' '[:lower:]'`
;;
debian)
codename=`cat /etc/*-release | grep '^VERSION=' | \
sed 's/.*(\(.*\)).*/\1/' | \
tr '[:upper:]' '[:lower:]'`
;;
centos)
codename=`cat /etc/*-release | grep -i 'centos.*(' | \
sed 's/.*(\(.*\)).*/\1/' | head -1 | \
tr '[:upper:]' '[:lower:]'`
# For CentOS grab release
release=`cat /etc/*-release | grep -i 'centos.*[0-9]' | \
sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' | head -1`
;;
rhel|ol)
codename=`cat /etc/*-release | grep -i 'red hat.*(' | \
sed 's/.*(\(.*\)).*/\1/' | head -1 | \
tr '[:upper:]' '[:lower:]'`
# For Red Hat also grab release
release=`cat /etc/*-release | grep -i 'red hat.*[0-9]' | \
sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' | head -1`
if [ -z "$release" ]; then
release=`cat /etc/*-release | grep -i '^VERSION_ID=' | \
sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/' | head -1`
fi
os="centos"
centos_flavor="red hat linux"
;;
amzn)
codename="amazon-linux-ami"
release_amzn=`cat /etc/*-release | grep -i 'amazon.*[0-9]' | \
sed 's/^[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' | \
head -1`
amzn=`rpm --eval "%{amzn}"`
if [ ${amzn} == 1 ]; then
release="latest"
else
release=${amzn}
fi
os="amzn"
centos_flavor="amazon linux"
;;
*)
codename=""
release=""
;;
esac
fi
}
###############################################################################
# #

Loading…
Cancel
Save