更新选项菜单

Signed-off-by: zhao <zhao@noreply.localhost>
This commit is contained in:
zhao 2024-12-25 14:15:30 +08:00
parent 8e47010b9f
commit e20353b61c

View File

@ -8,38 +8,48 @@ color_output() {
# 打印脚本头部,增加美观 # 打印脚本头部,增加美观
print_header() { print_header() {
clear clear
color_output "\e[35m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m" # 获取系统信息
color_output "\e[35m\ _____ __ __ _ / \e[0m" local model=$(cat /tmp/sysinfo/model 2>/dev/null || echo "未知设备")
color_output "\e[35m\ |__ /___ _ __ __\ \ / / __| |_ / \e[0m" # 使用更可靠的方式获取 CPU 使用率
color_output "\e[35m\ / // _ \ '__/ _ \ \ /\ / / '__| __| / \e[0m" local cpu_usage=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf "%.1f%%", usage}')
color_output "\e[35m\ / /| __/ | | (_) \ V V /| | | |_ / \e[0m" local mem_total=$(free | grep Mem | awk '{print $2}')
color_output "\e[35m\ /____\___|_| \___/ \_/\_/ |_| \__| / \e[0m" local mem_used=$(free | grep Mem | awk '{print $3}')
color_output "\e[35m\ Z e r o W r t By Z e r o / \e[0m" local mem_usage=$((mem_used * 100 / mem_total))
color_output "\e[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
color_output "===============================================" color_output "\e[36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\e[0m"
color_output " 版本: 5.1 " color_output "\e[36m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\e[0m"
color_output " 作者: Zero " color_output "\e[36m┃ ┃\e[0m"
color_output " 日期: $(date +'%Y-%m-%d') " color_output "\e[36m┃ \e[33m欢迎使用 OpenWrt 配置工具\e[36m ┃\e[0m"
color_output "===============================================" color_output "\e[36m┃ ┃\e[0m"
color_output " 本脚本帮助您设置 ZeroWrt-24.10。 " color_output "\e[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m"
color_output " 博客地址: https://www.kejizero.online " color_output "\e[36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\e[0m"
color_output "===============================================" color_output ""
color_output "\e[34m系统信息\e[0m"
color_output "----------------------------------------"
color_output " 设备型号: $model"
color_output " CPU 占用: $cpu_usage"
color_output " 内存占用: ${mem_usage}%"
color_output "----------------------------------------"
color_output "\e[32m说明本工具用于配置 OpenWrt-24.10\e[0m"
color_output "\e[32m博客https://www.kejizero.online\e[0m"
color_output "----------------------------------------"
echo ""
} }
# 显示菜单 # 显示菜单
show_menu() { show_menu() {
echo "==============================" color_output "\e[36m┏━━━━━━━━━━━━━━━ 功能菜单 ━━━━━━━━━━━━━━━┓\e[0m"
echo " ZeroWrt 菜单 " color_output "\e[36m┃ ┃\e[0m"
echo "==============================" color_output "\e[36m┃\e[0m 1. 更改 LAN 口 IP 地址 \e[36m┃\e[0m"
echo "1. 更改 LAN 口 IP 地址" color_output "\e[36m┃\e[0m 2. 更改管理员密码 \e[36m┃\e[0m"
echo "2. 更改管理员密码" color_output "\e[36m┃\e[0m 3. 切换默认主题 \e[36m┃\e[0m"
echo "3. 切换默认主题" color_output "\e[36m┃\e[0m 4. 恢复出厂设置 \e[36m┃\e[0m"
echo "4. 恢复出厂设置" color_output "\e[36m┃\e[0m 5. 一键换源 \e[36m┃\e[0m"
echo "5. 一键换源" color_output "\e[36m┃\e[0m 6. 安装 ShellClash \e[36m┃\e[0m"
echo "6. 安装 ShellClash" color_output "\e[36m┃\e[0m 0. 退出 \e[36m┃\e[0m"
echo "0. 退出" color_output "\e[36m┃ ┃\e[0m"
echo "==============================" color_output "\e[36m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\e[0m"
read -p "请输入您的选择 [0-6]: " choice read -p "$(color_output "\e[33m请输入您的选择 [0-6]: \e[0m")" choice
case "$choice" in case "$choice" in
1) change_ip ;; 1) change_ip ;;
2) change_password ;; 2) change_password ;;
@ -54,14 +64,15 @@ show_menu() {
# 1. 更换 LAN 口 IP 地址 # 1. 更换 LAN 口 IP 地址
change_ip() { change_ip() {
color_output "\e[34m[更改 LAN 口 IP 地址]\e[0m"
read -p "请输入新的 LAN 口 IP 地址(如 192.168.1.2: " new_ip read -p "请输入新的 LAN 口 IP 地址(如 192.168.1.2: " new_ip
if [[ -n "$new_ip" ]]; then if [[ -n "$new_ip" ]]; then
uci set network.lan.ipaddr="$new_ip" uci set network.lan.ipaddr="$new_ip"
uci commit network uci commit network
/etc/init.d/network restart /etc/init.d/network restart
echo "LAN 口 IP 已成功更改为 $new_ip" color_output "\e[32mLAN 口 IP 已成功更改为 $new_ip\e[0m"
else else
echo "无效的 IP 地址,操作取消。" color_output "\e[31m无效的 IP 地址,操作取消。\e[0m"
fi fi
read -p "按 Enter 键返回菜单..." read -p "按 Enter 键返回菜单..."
show_menu show_menu
@ -69,12 +80,13 @@ change_ip() {
# 2. 更改管理员密码 # 2. 更改管理员密码
change_password() { change_password() {
color_output "\e[34m[更改管理员密码]\e[0m"
read -p "请输入新的管理员密码: " new_password read -p "请输入新的管理员密码: " new_password
if [[ -n "$new_password" ]]; then if [[ -n "$new_password" ]]; then
echo -e "$new_password\n$new_password" | passwd root echo -e "$new_password\n$new_password" | passwd root
echo "管理员密码已成功更改。" color_output "\e[32m管理员密码已成功更改。\e[0m"
else else
echo "无效的密码,操作取消。" color_output "\e[31m无效的密码,操作取消。\e[0m"
fi fi
read -p "按 Enter 键返回菜单..." read -p "按 Enter 键返回菜单..."
show_menu show_menu
@ -82,39 +94,50 @@ change_password() {
# 3. 切换默认主题 # 3. 切换默认主题
change_theme() { change_theme() {
color_output "\e[34m[切换默认主题]\e[0m"
uci set luci.main.mediaurlbase='/luci-static/bootstrap' uci set luci.main.mediaurlbase='/luci-static/bootstrap'
uci commit luci uci commit luci
echo "主题已成功切换为设计主题。" color_output "\e[32m主题已成功切换为默认主题。\e[0m"
read -p "按 Enter 键返回菜单..." read -p "按 Enter 键返回菜单..."
show_menu show_menu
} }
# 4. 一键重置配置 # 4. 一键重置配置
reset_config() { reset_config() {
echo "恢复出厂设置中..." color_output "\e[31m[恢复出厂设置]\e[0m"
firstboot -y color_output "\e[31m警告此操作将清除所有设置\e[0m"
echo "设备将在 5 秒钟后重启..." read -p "确定要继续吗?(y/n): " confirm
sleep 5 if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
reboot echo "恢复出厂设置中..."
firstboot -y
color_output "\e[33m设备将在 5 秒钟后重启...\e[0m"
sleep 5
reboot
else
color_output "\e[32m操作已取消\e[0m"
read -p "按 Enter 键返回菜单..."
show_menu
fi
} }
# 5. 一键换源 # 5. 一键换源
change_source() { change_source() {
echo "请选择要使用的源:" color_output "\e[34m[更换软件源]\e[0m"
echo "1. 阿里源" color_output "\e[36m请选择要使用的源\e[0m"
echo "2. 清华源" color_output "1. 阿里源"
echo "3. 中科大源" color_output "2. 清华源"
echo "4. 官方源" color_output "3. 中科大源"
echo "0. 返回" color_output "4. 官方源"
color_output "0. 返回"
read -p "请输入您的选择 [0-4]: " source_choice read -p "请输入您的选择 [0-4]: " source_choice
case "$source_choice" in case "$source_choice" in
1) base_url="https://mirrors.aliyun.com/openwrt/releases/24.10.0-rc3/packages/x86_64" ;; 1) base_url="https://mirrors.aliyun.com/openwrt/releases/24.10.0-rc4/packages/x86_64" ;;
2) base_url="https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/24.10.0-rc3/packages/x86_64" ;; 2) base_url="https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/24.10.0-rc4/packages/x86_64" ;;
3) base_url="https://mirrors.ustc.edu.cn/openwrt/releases/24.10.0-rc3/packages/x86_64" ;; 3) base_url="https://mirrors.ustc.edu.cn/openwrt/releases/24.10.0-rc4/packages/x86_64" ;;
4) base_url="https://downloads.openwrt.org/releases/24.10.0-rc3/packages/x86_64" ;; 4) base_url="https://downloads.openwrt.org/releases/24.10.0-rc4/packages/x86_64" ;;
0) show_menu ; return ;; 0) show_menu ; return ;;
*) echo "无效选项,返回菜单。" ; show_menu ; return ;; *) color_output "\e[31m无效选项,返回菜单。\e[0m" ; show_menu ; return ;;
esac esac
cat <<EOF > /etc/opkg/distfeeds.conf cat <<EOF > /etc/opkg/distfeeds.conf
@ -125,28 +148,29 @@ src/gz openwrt_routing $base_url/routing
src/gz openwrt_telephony $base_url/telephony src/gz openwrt_telephony $base_url/telephony
EOF EOF
echo "软件源已成功切换。" color_output "\e[32m软件源已成功切换。\e[0m"
read -p "按 Enter 键返回菜单..." read -p "按 Enter 键返回菜单..."
show_menu show_menu
} }
# 6. 安装 ShellClash # 6. 安装 ShellClash
install_shellclash() { install_shellclash() {
echo "请选择 ShellClash 的安装源:" color_output "\e[34m[安装 ShellClash]\e[0m"
echo "1. GitHub 源" color_output "\e[36m请选择 ShellClash 的安装源:\e[0m"
echo "2. jsDelivr CDN 源" color_output "1. GitHub 源"
echo "0. 返回" color_output "2. jsDelivr CDN 源"
color_output "0. 返回"
read -p "请输入您的选择 [0-2]: " install_choice read -p "请输入您的选择 [0-2]: " install_choice
case "$install_choice" in case "$install_choice" in
1) export url='https://raw.githubusercontent.com/juewuy/ShellCrash/master' ;; 1) export url='https://raw.githubusercontent.com/juewuy/ShellCrash/master' ;;
2) export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' ;; 2) export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' ;;
0) show_menu ; return ;; 0) show_menu ; return ;;
*) echo "无效选项,返回菜单。" ; show_menu ; return ;; *) color_output "\e[31m无效选项,返回菜单。\e[0m" ; show_menu ; return ;;
esac esac
sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null
echo "ShellClash 已成功安装。" color_output "\e[32mShellClash 已成功安装。\e[0m"
read -p "按 Enter 键返回菜单..." read -p "按 Enter 键返回菜单..."
show_menu show_menu
} }