Files
CatTools/cattools.sh
2023-12-27 18:02:25 +08:00

228 lines
5.9 KiB
Bash

#!/bin/bash
###
# @Author: miaoermua
# @Date: 2023-12-12 16:59:27
# @LastEditors: miaoermua
# @LastEditTime: 2023-12-27 15:42:39
# @FilePath: \undefinedd:\Git\cattools\cattools.sh
###
DEFAULT_IP="192.168.1.4"
RELEASE="/etc/catwrt_release"
AMD64_REPO="https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo/amd64/distfeeds.conf"
MT798X_REPO="https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo/mt798x/distfeeds.conf"
AMD64_EFI_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v23.8/CatWrt.v23.8.x86_64-squashfs-combined-efi.img.gz"
AMD64_BIOS_SYSUP="https://github.com/miaoermua/CatWrt/releases/download/v23.8/CatWrt.v23.8.x86_64-squashfs-combined.img.gz"
# Check OpenWrt
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root user"
exit 1
fi
release=$(cat /etc/openwrt_release)
if [[ $release =~ "OpenWrt" ]]; then
echo "$(date) - Starting CatWrt Network Diagnostics"
else
echo "Abnormal system environment..."
echo " "
exit 1
fi
update(){
if ! curl -fsSL https://service.miaoer.xyz/cattools/cattools.sh -o; then
echo "无法连接更新站点"
if ! curl -fsSL https://fastly.jsdelivr.net/gh/miaoermua/cattools@main/repo/mt798x/cattools.sh -o; then
echo "无法连接更新仓库"
if ! curl -fsSL https://raw.githubusercontent.com/miaoermua/service/main/cattools/cattools.sh -o; then
echo "无法连接更新仓库"
echo "无法连接互联网,请联系作者!"
return
fi
fi
fi
exec $(readlink -f "$0")
}
setip(){
read -p "请输入 IP(默认为 $DEFAULT_IP): " input_ip
if [ -z $input_ip ]; then
input_ip=$DEFAULT_IP
fi
uci set network.lan.ipaddr=$input_ip
uci commit network
/etc/init.d/network restart
echo "默认 IP 已设置为 $input_ip"
}
catwrt_update(){
/usr/bin/catwrt-update
}
catwrt_network_diagnostics(){
/usr/bin/catnd
}
use_repo(){
echo "Warning:"
echo "软件源纯属免费分享,赞助我们复制链接在浏览器打开,这对我们继续保持在线服务有很大影响。"
echo "本人不对所有软件进行保证,我们没有第三方商业服务,风险需要自行承担。"
echo "支持我们: https://www.miaoer.xyz/sponsor"
echo "你需要同意 CatWrt 软件源用户协议,请确认是否继续 (y/n)"
read -t 10 -p "您有 10 秒选择,输入 y 继续,其他退出:" confirm
[ "$confirm" != y ] && return
arch=$(uname -m)
# Check ARCH release
model=$(grep "Model:" $release | cut -d ' ' -f2)
if [[ $model =~ "mt798x" ]]; then
# mt798x
curl -o /etc/opkg/distfeeds.conf $MT798X_REPO
elif [ "$arch" = "x86_64" ]; then
# amd64
curl -o /etc/opkg/distfeeds.conf $AMD64_REPO
else
echo "不支持的机型: $model"
return
fi
}
catwrt_sysupgrade(){
# uname
if [[ $(uname -m) =~ "x86_64" ]]; then
echo "CatWrt ARCH: x86_64(AMD64)"
# Check Disk space remaining
size=$(fdisk -l /dev | grep "Disk /dev" | awk '{print $5}')
size=${size%\*}
if [[ $size > 820 ]]; then
echo "磁盘空间出现了更改!脚本退出!"
exit
fi
# Check EFI remaining
if [[ -b /dev/sda128 || -b /dev/vda128 ]]; then
efi_part=true
else
efi_part=false
fi
# confirmation
echo "即将升级系统,存在风险请你三思确认 (y/n) 30 秒后默认退出脚本!"
read -t 30 confirm
confirm=${confirm:-n}
# upgrade
if [[ $confirm =~ [Yy] ]]; then
if [[ $efi_part == true ]]; then
sysupgrade -v $AMD64_EFI_SYSUP
else
sysupgrade -v $AMD64_BIOS_SYSUP
fi
else
echo "用户已取消升级!"
fi
else
echo "仅有 x86_64 可以使用脚本进行系统升级。"
fi
}
debug(){
if [ -f /www/logs.txt ]; then
rm /www/logs.txt
fi
cat /etc/banner >> /www/logs.txt
echo "## RELEASE" >> /www/logs.txt
cat /etc/catwrt_release >> /www/logs.txt
echo "## SYSLOG" >> /www/logs.txt
logread >> /www/logs.txt
echo "## DMESG" >> /www/logs.txt
dmesg >> /www/logs.txt
lan_ip=$(uci get network.lan.ipaddr)
echo "日志已收集到 /www/logs.txt"
echo "使用浏览器访问下载 http://$lan_ip/logs.txt"
exit
}
bypass_gateway(){
echo "没做完"
exit
}
update
while :; do
clear
echo " "
echo " CatTools"
echo "----------------------------------------"
echo "1. Set IPv4 Addr 设置 IP"
echo "2. check update 检查系统更新"
echo "3. network diagnostics 网络诊断"
echo "4. use repo 使用软件源"
echo "5. sysupgrade 升级系统"
echo "6. debug 日志收集"
echo "7. setup bypass gateway 旁路网关"
echo "0. Exit 退出脚本"
echo "----------------------------------------"
echo "请选择数字按下回车: "
choice=""
while [ -z $choice ]; do
read choice
done
case $choice in
1)
setip
;;
2)
catwrt_update
;;
3)
catwrt_network_diagnostics
;;
4)
use_repo
;;
5)
catwrt_sysupgrade
;;
6)
debug
;;
7)
bypass_gateway
;;
0)
echo "Exit CatTools 退出脚本..."
break
;;
*)
echo "无效的选择, 请重新输入"
;;
esac
sleep 1
done
echo "结束!"