files/bin/ZeroWrt-test
zhao 2f78989662 添加 bin/ZeroWrt-test
Signed-off-by: zhao <zj18139624826@gmail.com>
2024-12-24 00:41:42 +08:00

185 lines
6.1 KiB
Bash
Raw 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
# 彩色输出函数
color_output() {
echo -e "$1"
}
# 打印脚本头部,增加美观
print_header() {
clear
color_output "\e[35m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
color_output "\e[35m\ _____ __ __ _ / \e[0m"
color_output "\e[35m\ |__ /___ _ __ __\ \ / / __| |_ / \e[0m"
color_output "\e[35m\ / // _ \ '__/ _ \ \ /\ / / '__| __| / \e[0m"
color_output "\e[35m\ / /| __/ | | (_) \ V V /| | | |_ / \e[0m"
color_output "\e[35m\ /____\___|_| \___/ \_/\_/ |_| \__| / \e[0m"
color_output "\e[35m\ Z e r o W r t By Z e r o / \e[0m"
color_output "\e[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
color_output "==============================================="
color_output " 版本: 5.1 "
color_output " 作者: Zero "
color_output " 日期: $(date +'%Y-%m-%d') "
color_output "==============================================="
color_output " 本脚本帮助您设置 ZeroWrt-24.10。 "
color_output " 博客地址: https://www.kejizero.online "
color_output "==============================================="
}
# 显示菜单
show_menu() {
echo "=============================="
echo " ZeroWrt 菜单 "
echo "=============================="
echo "1. 更改 LAN 口 IP 地址"
echo "2. 更改管理员密码"
echo "3. 切换默认主题"
echo "4. 恢复出厂设置"
echo "5. 一键换源"
echo "6. 安装 ShellClash"
echo "7. 检测并更新脚本"
echo "0. 退出"
echo "=============================="
read -p "请输入您的选择 [0-7]: " choice
case "$choice" in
1) change_ip ;;
2) change_password ;;
3) change_theme ;;
4) reset_config ;;
5) change_source ;;
6) install_shellclash ;;
7) check_for_updates ;;
0) exit 0 ;;
*) echo "无效选项,请重新输入"; show_menu ;;
esac
}
# 1. 更换 LAN 口 IP 地址
change_ip() {
read -p "请输入新的 LAN 口 IP 地址(如 192.168.1.2: " new_ip
if [[ -n "$new_ip" ]]; then
uci set network.lan.ipaddr="$new_ip"
uci commit network
/etc/init.d/network restart
echo "LAN 口 IP 已成功更改为 $new_ip"
else
echo "无效的 IP 地址,操作取消。"
fi
read -p "按 Enter 键返回菜单..."
show_menu
}
# 2. 更改管理员密码
change_password() {
read -p "请输入新的管理员密码: " new_password
if [[ -n "$new_password" ]]; then
echo -e "$new_password\n$new_password" | passwd root
echo "管理员密码已成功更改。"
else
echo "无效的密码,操作取消。"
fi
read -p "按 Enter 键返回菜单..."
show_menu
}
# 3. 切换默认主题
change_theme() {
uci set luci.main.mediaurlbase='/luci-static/bootstrap'
uci commit luci
echo "主题已成功切换为设计主题。"
read -p "按 Enter 键返回菜单..."
show_menu
}
# 4. 一键重置配置
reset_config() {
echo "恢复出厂设置中..."
firstboot -y
echo "设备将在 5 秒钟后重启..."
sleep 5
reboot
}
# 5. 一键换源
change_source() {
echo "请选择要使用的源:"
echo "1. 阿里源"
echo "2. 清华源"
echo "3. 中科大源"
echo "4. 官方源"
echo "0. 返回"
read -p "请输入您的选择 [0-4]: " source_choice
case "$source_choice" in
1) base_url="https://mirrors.aliyun.com/openwrt/releases/24.10.0-rc3/packages/x86_64" ;;
2) base_url="https://mirrors.tuna.tsinghua.edu.cn/openwrt/releases/24.10.0-rc3/packages/x86_64" ;;
3) base_url="https://mirrors.ustc.edu.cn/openwrt/releases/24.10.0-rc3/packages/x86_64" ;;
4) base_url="https://downloads.openwrt.org/releases/24.10.0-rc3/packages/x86_64" ;;
0) show_menu ; return ;;
*) echo "无效选项,返回菜单。" ; show_menu ; return ;;
esac
cat <<EOF > /etc/opkg/distfeeds.conf
src/gz openwrt_base $base_url/base
src/gz openwrt_luci $base_url/luci
src/gz openwrt_packages $base_url/packages
src/gz openwrt_routing $base_url/routing
src/gz openwrt_telephony $base_url/telephony
EOF
echo "软件源已成功切换。"
read -p "按 Enter 键返回菜单..."
show_menu
}
# 6. 安装 ShellClash
install_shellclash() {
echo "请选择 ShellClash 的安装源:"
echo "1. GitHub 源"
echo "2. jsDelivr CDN 源"
echo "0. 返回"
read -p "请输入您的选择 [0-2]: " install_choice
case "$install_choice" in
1) export url='https://raw.githubusercontent.com/juewuy/ShellCrash/master' ;;
2) export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' ;;
0) show_menu ; return ;;
*) echo "无效选项,返回菜单。" ; show_menu ; return ;;
esac
sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null
echo "ShellClash 已成功安装。"
read -p "按 Enter 键返回菜单..."
show_menu
}
# 7. 检查并更新脚本
check_for_updates() {
# 本地脚本路径和远程脚本 URL
LOCAL_SCRIPT_PATH="/bin/ZeroWrt" # 请替换为实际的本地脚本路径
SCRIPT_URL="https://git.kejizero.online/zhao/files/raw/branch/main/bin/ZeroWrt" # 请替换为实际的远程脚本 URL
# 获取远程脚本的 SHA256 哈希值
remote_hash=$(curl -s $SCRIPT_URL | sha256sum | awk '{print $1}')
# 获取本地脚本的 SHA256 哈希值
local_hash=$(sha256sum $LOCAL_SCRIPT_PATH | awk '{print $1}')
# 比较哈希值,如果不同则更新脚本
if [ "$remote_hash" != "$local_hash" ]; then
echo "检测到新版本的脚本,正在更新..."
curl -s -o $LOCAL_SCRIPT_PATH $SCRIPT_URL # 从远程下载脚本并覆盖本地脚本
chmod +x $LOCAL_SCRIPT_PATH # 确保脚本有执行权限
echo "脚本已成功更新!"
else
echo "当前脚本已是最新版本。"
fi
read -p "按 Enter 键返回菜单..."
show_menu
}
# 启动菜单
print_header
show_menu