V1.8.1 优化USB设备检测

This commit is contained in:
Hyy2001X 2021-12-18 14:27:39 +08:00
parent 7e906f7141
commit 2cb6f82162
1 changed files with 25 additions and 30 deletions

View File

@ -3,7 +3,7 @@
# AutoBuild_Tools for Openwrt
# Dependences: bash wget curl block-mount e2fsprogs smartmontools
Version=V1.8
Version=V1.8.1
ECHO() {
case $1 in
@ -179,18 +179,17 @@ done
AutoExpand_UI() {
USB_Info
[[ -s ${Block_Info} ]] && {
[[ $? == 0 ]] && {
clear
ECHO x "USB 扩展内部空间\n"
printf "${Yellow} %-14s %-40s %-12s %-15s %-18s %-10s\n${White}" 设备 UUID 格式 挂载点 可用空间 状态
local X i=1;while read X;do
[[ $(echo ${X} | awk '{print $4}') =~ (/boot|/rom|/opt) || $(echo ${X} | awk '{print $5}') == '-' ]] && {
printf "${Yellow}%-7s %-14s %-40s %-14s %-15s %-18s %-10s\n${White}" 编号 设备 UUID 分区格式 挂载点 可用空间 状态
local X;while read X;do
[[ $(echo ${X} | awk '{print $5}') =~ (/boot|/rom|/opt) || $(echo ${X} | awk '{print $6}') == '-' ]] && {
Status="不推荐"
} || {
[[ $(echo ${X} | awk '{print $4}') == '/' ]] && Status="已挂载" || Status="可用"
[[ $(echo ${X} | awk '{print $5}') == '/' ]] && Status="已挂载" || Status="可用"
}
printf "${i}. %-12s %-40s %-10s %-12s %-14s %-10s\n" ${X} ${Status}
i=$(($i + 1))
printf " %-4s %-12s %-40s %-10s %-12s %-14s %-10s\n" ${X} ${Status}
done < ${Disk_Processed_List}
echo -e "\nq. 返回"
echo "r. 重新载入列表"
@ -199,7 +198,7 @@ AutoExpand_UI() {
sleep 2
return 1
}
Logic_Disk_Count=$(sed -n '$=' ${Logic_Disk_List})
Logic_Disk_Count=$(tail -n1 ${Disk_Processed_List} | awk '{print $1}')
echo
read -p "请输入要操作的设备编号[1-${Logic_Disk_Count}]:" Choose
case ${Choose} in
@ -212,15 +211,14 @@ AutoExpand_UI() {
*)
[[ ${Choose} =~ [0-9] && ${Choose} -le ${Logic_Disk_Count} && ${Choose} -gt 0 ]] > /dev/null 2>&1 && {
if [[ $(CHECK_PKG mkfs.ext4) == true ]];then
Choose_Disk=$(sed -n ${Choose}p ${Disk_Processed_List} | awk '{print $1}')
Choose_Mount=$(grep "${Choose_Disk}" ${Disk_Processed_List} | awk '{print $4}')
Choose_Disk=$(sed -n ${Choose}p ${Disk_Processed_List} | awk '{print $2}')
Choose_Mount=$(grep "${Choose_Disk}" ${Disk_Processed_List} | awk '{print $5}')
AutoExpand_Core ${Choose_Disk} ${Choose_Mount}
else
ECHO r "\n系统缺少相应依赖包,请先安装 [e2fsprogs] !" && sleep 2
return
fi
} || {
ECHO r "\n输入错误,请输入正确的选项!"
AutoExpand_UI
}
;;
@ -231,17 +229,15 @@ USB_Info() {
Logic_Disk_List="${Tools_Cache}/Logic_Disk_List"
Phy_Disk_List="${Tools_Cache}/Phy_Disk_List"
Block_Info="${Tools_Cache}/Block_Info"
dev_Info="${Tools_Cache}/dev_Info"
Disk_Processed_List="${Tools_Cache}/Disk_Processed_List"
echo -ne "\n${Yellow}Loading USB Configuration ...${White}"
rm -f ${Block_Info} ${Logic_Disk_List} ${Disk_Processed_List} ${Phy_Disk_List}
touch ${Disk_Processed_List}
block mount
block info | grep -v "mtdblock" | egrep "sd[a-z][0-9]|mmcblk[0-9]+[a-z][0-9]+" > ${Block_Info}
ls -1 /dev | egrep "sd[a-z]|mmcblk|nvme" > ${dev_Info}
[[ -s ${Block_Info} ]] && {
cat ${Block_Info} | awk -F '[:]' '{print $1}' > ${Logic_Disk_List}
for Disk_Name in $(cat ${Logic_Disk_List})
lsblk -l | grep part | awk '{print "/dev/"$1}' > ${Logic_Disk_List}
local i=1;for Disk_Name in $(cat ${Logic_Disk_List})
do
UUID=$(grep "${Disk_Name}" ${Block_Info} | egrep -o 'UUID=".+"' | awk -F '["]' '/UUID/{print $2}')
Logic_Mount=$(grep "${Disk_Name}" ${Block_Info} | egrep -o 'MOUNT="/[0-9a-zA-Z].+"|MOUNT="/"' | awk -F '["]' '/MOUNT/{print $2}')
@ -252,12 +248,13 @@ USB_Info() {
[[ -z ${Logic_Format} ]] && Logic_Format='-'
[[ -z ${Logic_Mount} ]] && Logic_Mount='-'
[[ -z ${Logic_Available} ]] && Logic_Available='-'
echo "${Disk_Name} ${UUID} ${Logic_Format} ${Logic_Mount} ${Logic_Available}" >> ${Disk_Processed_List}
printf "%-3s %-14s %-40s %-14s %-15s %-18s %-10s\n" ${i} ${Disk_Name} ${UUID} ${Logic_Format} ${Logic_Mount} ${Logic_Available} >> ${Disk_Processed_List}
i=$(expr $i + 1 2> /dev/null)
done
lsblk | grep disk | awk '{print "/dev/"$1}' | sort | uniq > ${Phy_Disk_List}
}
echo -ne "\r \r"
return
[[ -n $(cat ${Phy_Disk_List}) ]] && return 0 || return 1
}
AutoExpand_Core() {
@ -268,7 +265,7 @@ AutoExpand_Core() {
[[ ${Choose} == [Yesyes] ]] && {
ECHO y "\n开始运行一键挂载脚本 ..."
sleep 2
} || return 0
} || return
echo "禁用自动挂载 ..."
uci set fstab.@global[0].auto_mount='0'
uci commit fstab
@ -518,36 +515,34 @@ done
SmartInfo_UI() {
USB_Info
[[ -s ${Phy_Disk_List} ]] && {
if [[ $? == 0 ]]
then
clear
ECHO x "硬盘信息列表"
cat ${Phy_Disk_List} | while read Phy_Disk;do
SmartInfo_Core ${Phy_Disk}
sleep 1
done
ENTER
} || {
else
ECHO r "未检测到任何外接设备,请检查 USB 接口可用性或插入更多 USB 设备!"
sleep 2
return 1
}
fi
}
SmartInfo_Core() {
Smart_Info1="${Tools_Cache}/Smart_Info1"
Smart_Info2="${Tools_Cache}/Smart_Info2"
Smart_Info3="${Tools_Cache}/Smart_Info3"
rm -f ${Smart_Info1} ${Smart_Info2} ${Smart_Info3}
smartctl -H -A -i $1 > ${Smart_Info1}
smartctl -H -A -i -d scsi $1 > ${Smart_Info2}
smartctl -H -A -i -d sat $1 > ${Smart_Info3}
Phy_Health=$(GET_INFO "SMART Health Status:")
if [[ -z ${Phy_Health} ]]
then
Phy_Health=$(GET_INFO "SMART overall-health self-assessment test result:")
fi
[[ -z ${Phy_Health} ]] && Phy_Health=$(GET_INFO "SMART overall-health self-assessment test result:")
Phy_Name=$(GET_INFO "Device Model:")
Phy_Temp=$(grep "Temperature_Celsius" ${Smart_Info3} | awk '{print $10}')
[[ -z ${Phy_Temp} ]] && Phy_Temp="未知"
[[ -n ${Phy_Temp} ]] && Phy_Temp="${Phy_Temp}°C" || Phy_Temp="未知"
Phy_ID=$(GET_INFO "Serial number:")
Phy_Capacity=$(GET_INFO "User Capacity:")
Phy_Part_Number=$(grep -c "${Phy_Disk}" ${Disk_Processed_List})
@ -574,7 +569,7 @@ SmartInfo_Core() {
Phy_RPM=$(GET_INFO "Rotation Rate:")
Phy_Type="机械硬盘"
else
Phy_RPM="未知"
Phy_RPM="不可用"
fi
fi
[[ -z ${Phy_Name} ]] && {
@ -592,11 +587,11 @@ SmartInfo_Core() {
硬盘型号: ${Phy_Name}
硬盘温度: ${Phy_Temp}
硬盘路径: $1
分区数量: ${Phy_Part_Number}
硬盘尺寸: ${Phy_Factor}
硬盘 ID : ${Phy_ID}
硬盘容量: ${Phy_Capacity}
健康状况: ${Phy_Health}
分区数量: ${Phy_Part_Number}
SATA版本: ${Phy_Sata_Version}
TRIM指令: ${TRIM_Command}
硬盘类型: ${Phy_Type}