#!/bin/bash
sh_v="1.0.0"
huang='\033[33m'
bai='\033[0m'
kjlan='\033[96m'
lv='\033[0;32m'
cp ./vps.sh /usr/local/bin/k > /dev/null 2>&1
ip_address() {
ipv4_address=$(curl -s ipv4.ip.sb)
ipv6_address=$(curl -s --max-time 1 ipv6.ip.sb)
}
output_status() {
output=$(awk 'BEGIN { rx_total = 0; tx_total = 0 }
NR > 2 { rx_total += $2; tx_total += $10 }
END {
rx_units = "Bytes";
tx_units = "Bytes";
if (rx_total > 1024) { rx_total /= 1024; rx_units = "KB"; }
if (rx_total > 1024) { rx_total /= 1024; rx_units = "MB"; }
if (rx_total > 1024) { rx_total /= 1024; rx_units = "GB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "KB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "MB"; }
if (tx_total > 1024) { tx_total /= 1024; tx_units = "GB"; }
printf("总接收: %.2f %s\n总发送: %.2f %s\n", rx_total, rx_units, tx_total, tx_units);
}' /proc/net/dev)
}
linux_update() {
if [ -f "/etc/debian_version" ]; then
apt update -y && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y
fi
if [ -f "/etc/redhat-release" ]; then
yum -y update
fi
if [ -f "/etc/alpine-release" ]; then
apk update && apk upgrade
fi
}
break_end() {
echo -e "${lv}操作完成${bai}"
echo "按任意键继续..."
read -n 1 -s -r -p ""
echo ""
clear
}
while true; do
clear
echo -e "${kjlan}_ _ ____ _ _ _ _ ____ _ _ "
echo "|_/ |___ | | | | | | |\ | "
echo "| \_ |___ _| | |___ | |__| | \| "
echo " "
echo -e "${kjlan}科技lion一键脚本工具 v$sh_v (支持Ubuntu/Debian/CentOS/Alpine系统)${bai}"
echo -e "${kjlan}-输入${huang}k${kjlan}可快速启动此脚本-${bai}"
echo "------------------------"
echo "1. 系统信息查询"
echo "2. 系统更新"
echo "3. 系统清理"
echo "------------------------"
echo "00. 脚本更新"
echo "------------------------"
echo "0. 退出脚本"
echo "------------------------"
read -p "请输入你的选择: " choice
case $choice in
1)
clear
ip_address
hostname=$(hostname)
isp_info=$(curl -s ipinfo.io/org)
os_info=$(lsb_release -ds 2>/dev/null)
if [ -z "$os_info" ]; then
if [ -f "/etc/os-release" ]; then
os_info=$(source /etc/os-release && echo "$PRETTY_NAME")
elif [ -f "/etc/debian_version" ]; then
os_info="Debian $(cat /etc/debian_version)"
elif [ -f "/etc/redhat-release" ]; then
os_info=$(cat /etc/redhat-release)
else
os_info="Unknown"
fi
fi
kernel_version=$(uname -r)
cpu_arch=$(uname -m)
if [ "$(uname -m)" == "x86_64" ]; then
cpu_info=$(cat /proc/cpuinfo | grep 'model name' | uniq | sed -e 's/model name[[:space:]]*: //')
else
cpu_info=$(lscpu | grep 'BIOS Model name' | awk -F': ' '{print $2}' | sed 's/^[ \t]*//')
fi
cpu_cores=$(nproc)
if [ -f /etc/alpine-release ]; then
cpu_usage_percent=$(top -bn1 | grep '^CPU' | awk '{print " "$4}' | cut -c 1-2)
else
cpu_usage_percent=$(top -bn1 | grep "Cpu(s)" | awk '{print " "$2}')
fi
mem_info=$(free -b | awk 'NR==2{printf "%.2f/%.2f MB (%.2f%%)", $3/1024/1024, $2/1024/1024, $3*100/$2}')
swap_used=$(free -m | awk 'NR==3{print $3}')
swap_total=$(free -m | awk 'NR==3{print $2}')
if [ "$swap_total" -eq 0 ]; then
swap_percentage=0
else
swap_percentage=$((swap_used * 100 / swap_total))
fi
swap_info="${swap_used}MB/${swap_total}MB (${swap_percentage}%)"
disk_info=$(df -h | awk '$NF=="/"{printf "%s/%s (%s)", $3, $2, $5}')
congestion_algorithm=$(sysctl -n net.ipv4.tcp_congestion_control)
queue_algorithm=$(sysctl -n net.core.default_qdisc)
country=$(curl -s ipinfo.io/country)
city=$(curl -s ipinfo.io/city)
current_time=$(date "+%Y-%m-%d %I:%M %p")
output_status
echo ""
echo "系统信息查询"
echo "------------------------"
echo "主机名:$hostname"
echo "运营商:$isp_info"
echo "------------------------"
echo "系统版本: $os_info"
echo "Linux版本: $kernel_version"
echo "------------------------"
echo "CPU架构: $cpu_arch"
echo "CPU型号: $cpu_info"
echo "CPU核心数: $cpu_cores"
echo "------------------------"
echo "CPU占用: $cpu_usage_percent%"
echo "物理内存: $mem_info"
echo "虚拟内存: $swap_info"
echo "硬盘占用: $disk_info"
echo "------------------------"
echo "$output"
echo "------------------------"
echo "网络拥堵算法: $congestion_algorithm $queue_algorithm"
echo "------------------------"
echo "公网IPv4地址: $ipv4_address"
echo "公网IPv6地址: $ipv6_address"
echo "------------------------"
echo "地理位置: $country $city"
echo "系统时间: $current_time"
echo "------------------------"
;;
0)
clear
exit
;;
*)
echo "无效的输入!"
;;
esac
break_end
done