Files
shell-scripts/基础脚本/检查系统版本.sh
2024-11-27 10:33:20 +08:00

66 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
### 为了文件美观直接继承了fontColor.sh文件 #####
#######第一种方法########
RED="31m" # Error message
GREEN="32m" # Success message
YELLOW="33m" # Warning message
BLUE="36m" # Info message
check_root(){
if [[ $EUID != 0 ]];then
colorEcho ${RED} "当前非root账号(或没有root权限)无法继续操作请更换root账号!"
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限执行后可能会提示输入root密码"
exit 1
fi
}
####### 获取系统版本及64位或32位信息
check_sys(){
sys_bit=$(uname -m)
case $sys_bit in
i[36]86)
os_bit="32"
release="386"
;;
x86_64)
os_bit="64"
release="amd64"
;;
*armv6*)
os_bit="arm"
release="arm6"
;;
*armv7*)
os_bit="arm"
release="arm7"
;;
*aarch64* | *armv8*)
os_bit="arm64"
release="arm64"
;;
*)
colorEcho ${RED} "
哈哈……这个 辣鸡脚本 不支持你的系统。 (-_-) \n
备注: 仅支持 Ubuntu 16+ / Debian 8+ / CentOS 7+ 系统
" && exit 1
;;
esac
return 0
}
######## 颜色函数方法很精妙 ############
colorEcho(){
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
}
main(){
check_root
check_sys
colorEcho $GREEN "\t你现在正在以root的身份查看系统信息"
colorEcho $YELLOW "\t操作系统是${os_bit}位的,发行版本是${release}"
}
main