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