Update Nlbench.sh

This commit is contained in:
Jensfrank 2024-07-12 23:46:41 +08:00 committed by GitHub
parent 8016aea694
commit e7f8a9f984
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,14 +19,16 @@ if [ "$(id -u)" != "0" ]; then
echo "已获取 sudo 权限。" echo "已获取 sudo 权限。"
fi fi
# 检查并安装依赖 # 更新系统并安装依赖
install_dependencies() { install_dependencies() {
echo -e "${YELLOW}正在检查并安装必要的依赖项...${NC}" echo -e "${YELLOW}正在检查并安装必要的依赖项...${NC}"
# 更新包列表 # 更新系统
if ! sudo apt-get update; then echo -e "${YELLOW}正在更新系统...${NC}"
echo -e "${RED}无法更新包列表。请检查您的网络连接和系统设置。${NC}" if update_system; then
exit 1 echo -e "${GREEN}系统更新完成。${NC}"
else
echo -e "${RED}系统更新失败。继续安装依赖项。${NC}"
fi fi
# 安装依赖 # 安装依赖
@ -39,7 +41,7 @@ install_dependencies() {
for dep in "${dependencies[@]}"; do for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &> /dev/null; then if ! command -v "$dep" &> /dev/null; then
echo -e "${YELLOW}正在安装 $dep...${NC}" echo -e "${YELLOW}正在安装 $dep...${NC}"
if ! sudo apt-get install -y "$dep"; then if ! install_package "$dep"; then
echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}"
fi fi
else else
@ -51,6 +53,41 @@ install_dependencies() {
clear clear
} }
# 更新系统
update_system() {
if command -v apt &>/dev/null; then
sudo apt-get update && sudo apt-get upgrade -y
elif command -v dnf &>/dev/null; then
sudo dnf check-update && sudo dnf upgrade -y
elif command -v yum &>/dev/null; then
sudo yum check-update && sudo yum upgrade -y
elif command -v apk &>/dev/null; then
sudo apk update && sudo apk upgrade
else
echo -e "${RED}不支持的Linux发行版${NC}"
return 1
fi
return 0
}
# 安装包
install_package() {
local package=$1
if command -v apt &>/dev/null; then
sudo apt-get install -y "$package"
elif command -v dnf &>/dev/null; then
sudo dnf install -y "$package"
elif command -v yum &>/dev/null; then
sudo yum install -y "$package"
elif command -v apk &>/dev/null; then
sudo apk add "$package"
else
echo -e "${RED}不支持的Linux发行版${NC}"
return 1
fi
return 0
}
# 获取IP地址和ISP信息 # 获取IP地址和ISP信息
ip_address_and_isp() { ip_address_and_isp() {
ipv4_address=$(curl -s --max-time 5 ipv4.ip.sb) ipv4_address=$(curl -s --max-time 5 ipv4.ip.sb)