Skip to content

Instantly share code, notes, and snippets.

@benzBrake
Created November 26, 2016 12:43
Show Gist options
  • Save benzBrake/79596e42df2dccb2eab35144d60feaf5 to your computer and use it in GitHub Desktop.
Save benzBrake/79596e42df2dccb2eab35144d60feaf5 to your computer and use it in GitHub Desktop.
linux_check.sh
#/bin/bash
linux_check() {
if $(grep -qi "CentOS" /etc/issue) || $(grep -q "CentOS" /etc/*-release); then
OS="CentOS"
elif $(grep -qi "Ubuntu" /etc/issue) || $(grep -q "Ubuntu" /etc/*-release); then
OS="Ubuntu"
elif $(grep -qi "Debian" /etc/issue) || $(grep -q "Debian" /etc/*-release); then
OS="Debian"
else
cat >&2 <<-'EOF'
本脚本仅支持 CentOS 6+, Debian 7+ 或者 Ubuntu 12+, 其他系统请向脚本作者反馈以寻求支持!
EOF
exit 1
fi
OS_VSRSION=$(grep -oEh "[0-9]+" /etc/*-release | head -n 1) || {
cat >&2 <<-'EOF'
无法获取操作系统版本, 请联系脚本作者反馈错误!
EOF
exit 1
}
if [ "$OS" = "CentOS" -a $OS_VSRSION -lt 6 ]; then
cat >&2 <<-'EOF'
暂不支持 CentOS 6 以下版本, 请升级系统或向脚本作者反馈以寻求支持!
EOF
exit 1
fi
if [ "$OS" = "Ubuntu" -a $OS_VSRSION -lt 12 ]; then
cat >&2 <<-'EOF'
暂不支持 Ubuntu 12 以下版本, 请升级系统或向脚本作者反馈以寻求支持!
EOF
exit 1
fi
if [ "$OS" = "Debian" -a $OS_VSRSION -lt 7 ]; then
cat >&2 <<-'EOF'
暂不支持 Debian 7 以下版本, 请升级系统或向脚本作者反馈以寻求支持!
EOF
exit 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment