更新 shells/tv.sh

This commit is contained in:
2025-08-27 22:01:20 +08:00
parent 23a15857ec
commit b2e3bdbf12

View File

@@ -77,46 +77,93 @@ is_valid_ip() {
connect_adb() { connect_adb() {
adb disconnect >/dev/null 2>&1 adb disconnect >/dev/null 2>&1
history_file="/tvhelper/shells/history" history_file="/tvhelper/shells/history"
# 读取历史IP
if [[ -f "$history_file" ]]; then if [[ -f "$history_file" ]]; then
last_ip=$(tail -n 1 "$history_file") last_ip=$(tail -n 1 "$history_file")
last_name=$(head -n 1 "$history_file") last_name=$(head -n 1 "$history_file")
# 检查历史中的IP地址是否合法
if is_valid_ip "$last_ip"; then if is_valid_ip "$last_ip"; then
echo -e "上次连接的设备是 ${GREEN}${last_name}${NC}IP地址为 ${GREEN}${last_ip}${NC}\n是否要再次连接到此设备?确认请直接回车,否定输入n再回车[Y/n]" echo -e "上次连接的设备是 ${GREEN}${last_name}${NC} IP=${GREEN}${last_ip}${NC}\n是否使用该设备? 回车确认, 输入n更换 [Y/n]"
read answer read answer
if [[ "$answer" == "N" || "$answer" == "n" ]]; then if [[ "$answer" == "N" || "$answer" == "n" ]]; then
echo -e "${YELLOW}手动输入电视盒子的完整IP地址:${NC}" echo -e "${YELLOW}输入设备的IP地址:${NC}"
read ip read ip
else else
ip=$last_ip ip=$last_ip
fi fi
else else
echo -e "${RED}历史记录中的IP地址不合法,请手动输入电视盒子的完整IP地址:${NC}" echo -e "${RED}历史记录中的IP不合法,请重新输入:${NC}"
read ip read ip
fi fi
else else
echo -e "${YELLOW}手动输入电视盒子的完整IP地址:${NC}" echo -e "${YELLOW}输入设备的IP地址:${NC}"
read ip read ip
fi fi
echo -e "${BLUE}首次使用,盒子上可能会提示授权弹框,给您半分钟时间来操作...【允许】${NC}" # 输入安卓版本
adb connect ${ip} echo -e "${YELLOW}您的设备是否是2020款Googel TV (2+8G) ?(输入 y 表示是,其它直接回车表示否) [y/N]:${NC}"
read answer
if [[ "$answer" == "y" || "$answer" == "Y" ]]; then
android_ver=14
else
android_ver=13
fi
for ((i = 1; i <= 30; i++)); do if [[ "$android_ver" -ge 14 ]]; then
echo -e "${YELLOW}${i}次尝试连接ADB,请在设备上点击【允许】按钮...${NC}" # ---------- 安卓14配对流程 ----------
device_status=$(adb devices | grep "${ip}:5555" | awk '{print $2}') echo -e "${YELLOW}请点击【使用配对码配对设备】出现与设备配对的页面${NC}"
if [[ "$device_status" == "device" ]]; then echo -e "${YELLOW}请输入该页面显示的配对端口号 通常是冒号后的5位 (例如 35295):${NC}"
echo -e "${GREEN}ADB 已经连接成功啦,你可以放心操作了${NC}" read pair_port
# 连接成功后写入名称和IP地址到历史文件
echo "$(get_history_name)" >"$history_file" echo -e "${BLUE}正在配对设备请按要求输入WLAN配对码 通常是6位${NC}"
echo "${ip}" >>"$history_file" adb pair "${ip}:${pair_port}"
return 0
if [[ $? -ne 0 ]]; then
echo -e "${RED}配对失败,请检查配对端口/配对码是否正确${NC}"
return 1
fi fi
sleep 1 echo -e "${GREEN}配对并且连接成功!请返回上一页查看用于debug的端口号${NC}"
done echo -e "${YELLOW}请输入设备显示的debug【调试端口号】:(通常位于无线调试这一页)${NC}"
echo -e "${RED}连接超时,或者您点击了【取消】,请确认电视盒子的IP地址是否正确。如果问题持续存在,请检查设备的USB调试设置是否正确并重新连接adb${NC}" read debug_port
adb connect "${ip}:${debug_port}"
for ((i = 1; i <= 30; i++)); do
device_status=$(adb devices | grep "${debug_port}" | awk '{print $2}')
if [[ "$device_status" == "device" ]]; then
echo -e "${GREEN}ADB 已成功连接到设备 ${debug_port}${NC}"
echo "$(get_history_name)" >"$history_file"
echo "${ip}" >>"$history_file" # 只保存IP不保存端口
return 0
fi
echo -e "${YELLOW}${i}次尝试连接,请在设备上点击【允许】...${NC}"
sleep 1
done
else
# ---------- 安卓13及以下 ----------
echo -e "${YELLOW}请输入端口号 [回车默认5555]:${NC}"
read port
port=${port:-5555}
ip_port="${ip}:${port}"
adb connect "${ip_port}"
# ---------- 检查连接状态 ----------
for ((i = 1; i <= 30; i++)); do
device_status=$(adb devices | grep "${ip_port}" | awk '{print $2}')
if [[ "$device_status" == "device" ]]; then
echo -e "${GREEN}ADB 已成功连接到设备 ${ip_port}${NC}"
echo "$(get_history_name)" >"$history_file"
echo "${ip}" >>"$history_file" # 只保存IP不保存端口
return 0
fi
echo -e "${YELLOW}${i}次尝试连接,请在设备上点击【允许】...${NC}"
sleep 1
done
echo -e "${RED}连接超时或失败请确认IP/端口/配对码是否正确${NC}"
fi
} }
# 一键修改NTP服务器地址 # 一键修改NTP服务器地址
modify_ntp() { modify_ntp() {
echo -e "${BLUE}它的作用在于:解决安卓原生TV时间不正确和网络受限问题${NC}" echo -e "${BLUE}它的作用在于:解决安卓原生TV时间不正确和网络受限问题${NC}"