2021-01-01 05:57:39 +00:00
|
|
|
#!/bin/bash
|
2021-06-06 05:54:54 +00:00
|
|
|
# AutoBuild Module by Hyy2001 <https://github.com/Hyy2001X/AutoBuild-Actions>
|
2021-01-05 23:38:00 +00:00
|
|
|
# AutoBuild_Tools for Openwrt
|
2021-07-19 08:49:47 +00:00
|
|
|
# Depends on: bash wget curl block-mount e2fsprogs smartmontools
|
2021-01-03 03:12:31 +00:00
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
Version=V1.5
|
2021-06-19 15:58:51 +00:00
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO() {
|
|
|
|
local Color
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -z $1 ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
echo -ne "\n${Grey}[$(date "+%H:%M:%S")]${White} "
|
2021-06-19 15:58:51 +00:00
|
|
|
} || {
|
|
|
|
case $1 in
|
2021-07-19 08:49:47 +00:00
|
|
|
r) Color="${Red}";;
|
|
|
|
g) Color="${Green}";;
|
|
|
|
b) Color="${Blue}";;
|
|
|
|
y) Color="${Yellow}";;
|
|
|
|
x) Color="${Grey}";;
|
2021-06-19 15:58:51 +00:00
|
|
|
esac
|
|
|
|
[[ $# -lt 2 ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
echo -e "\n${Grey}[$(date "+%H:%M:%S")]${White} $1"
|
|
|
|
LOGGER $1
|
2021-06-19 15:58:51 +00:00
|
|
|
} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
echo -e "\n${Grey}[$(date "+%H:%M:%S")]${White} ${Color}$2${White}"
|
|
|
|
LOGGER $2
|
2021-06-19 15:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 03:12:31 +00:00
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
LOGGER() {
|
|
|
|
[[ ! -f ${Main_tmp}/AutoBuild_Tools.log ]] && touch ${Main_tmp}/AutoBuild_Tools.log
|
|
|
|
echo "[$(date "+%Y-%m-%d-%H:%M:%S")] $*" >> ${Main_tmp}/AutoBuild_Tools.log
|
|
|
|
}
|
|
|
|
|
2021-01-03 03:12:31 +00:00
|
|
|
AutoBuild_Tools() {
|
2021-04-22 08:06:01 +00:00
|
|
|
while :
|
|
|
|
do
|
|
|
|
clear
|
2021-06-19 15:58:51 +00:00
|
|
|
echo -e "${Skyb}$(cat /etc/banner)${White}"
|
2021-04-22 08:06:01 +00:00
|
|
|
echo -e "\n\nAutoBuild 固件工具箱 ${Version}\n"
|
|
|
|
echo "1. USB 空间扩展"
|
|
|
|
echo "2. Samba 一键共享"
|
|
|
|
echo "3. 软件包安装"
|
2021-06-19 15:58:51 +00:00
|
|
|
echo "4. 端口占用列表"
|
|
|
|
echo "5. 查看硬盘信息"
|
2021-04-22 08:06:01 +00:00
|
|
|
echo "u. 固件更新"
|
|
|
|
echo -e "\nx. 更新脚本"
|
|
|
|
echo -e "q. 退出\n"
|
|
|
|
read -p "请从上方选择一个操作:" Choose
|
|
|
|
case $Choose in
|
|
|
|
q)
|
2021-07-19 08:49:47 +00:00
|
|
|
rm -rf ${Main_tmp}
|
2021-01-03 03:12:31 +00:00
|
|
|
clear
|
2021-04-22 08:06:01 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
[ -f /bin/AutoUpdate.sh ] && {
|
|
|
|
AutoUpdate_UI
|
|
|
|
} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "未检测到 '/bin/AutoUpdate.sh',请确保当前固件支持一键更新!"
|
2021-04-22 08:06:01 +00:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
x)
|
2021-04-22 02:19:32 +00:00
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
wget -q ${Github_Raw}/Scripts/AutoBuild_Tools.sh -O ${Main_tmp}/AutoBuild_Tools.sh
|
2021-04-22 08:06:01 +00:00
|
|
|
if [[ $? == 0 ]];then
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "[AutoBuild_Tools] 脚本更新成功!"
|
2021-04-22 08:06:01 +00:00
|
|
|
rm -f /bin/AutoBuild_Tools.sh.sh
|
2021-07-19 08:49:47 +00:00
|
|
|
mv -f ${Main_tmp}/AutoBuild_Tools.sh /bin
|
2021-04-22 08:06:01 +00:00
|
|
|
chmod +x /bin/AutoBuild_Tools.sh
|
|
|
|
else
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "[AutoBuild_Tools] 脚本更新失败!"
|
2021-04-22 08:06:01 +00:00
|
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
which block > /dev/null 2>&1
|
|
|
|
[[ ! $? -eq 0 ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "缺少相应依赖包,请先安装 [block-mount] !"
|
2021-04-22 08:06:01 +00:00
|
|
|
sleep 3
|
|
|
|
} || {
|
|
|
|
uci set fstab.@global[0].auto_mount='0'
|
|
|
|
uci set fstab.@global[0].auto_swap='0'
|
|
|
|
uci commit fstab
|
|
|
|
AutoExpand_UI
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
AutoSamba_UI
|
|
|
|
;;
|
|
|
|
3)
|
|
|
|
AutoInstall_UI
|
|
|
|
;;
|
|
|
|
4)
|
2021-05-01 06:07:20 +00:00
|
|
|
clear
|
|
|
|
echo -e "端口 服务名称\n"
|
|
|
|
netstat -tanp | egrep ":::[0-9].+|0.0.0.0:[0-9]+|127.0.0.1:[0-9]+" | awk '{print $4"\t "$7}' | sed -r 's/:::/\1/' | sed -r 's/0.0.0.0:/\1/' | sed -r 's/127.0.0.1:/\1/'| sed -r 's/[0-9]+.\//\1/' | sort | uniq
|
|
|
|
Enter
|
|
|
|
;;
|
2021-06-19 15:58:51 +00:00
|
|
|
5)
|
2021-05-08 12:41:32 +00:00
|
|
|
which smartctl > /dev/null 2>&1
|
|
|
|
[[ ! $? -eq 0 ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "缺少相应依赖包,请先安装 [smartmontools] !"
|
2021-05-08 12:41:32 +00:00
|
|
|
sleep 3
|
|
|
|
} || Smart_Info
|
|
|
|
;;
|
2021-04-22 08:06:01 +00:00
|
|
|
esac
|
|
|
|
done
|
2021-01-03 03:12:31 +00:00
|
|
|
}
|
2021-01-01 05:57:39 +00:00
|
|
|
|
|
|
|
AutoExpand_UI() {
|
|
|
|
clear
|
2021-04-22 02:19:32 +00:00
|
|
|
echo -e "一键 USB 扩展内部空间/AutoExpand\n"
|
2021-01-03 03:12:31 +00:00
|
|
|
USB_Check_Core
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -n ${Check_Disk} ]] && {
|
2021-01-01 05:57:39 +00:00
|
|
|
for ((i=1;i<=${Disk_Number};i++));
|
|
|
|
do
|
|
|
|
Disk_info=$(sed -n ${i}p ${Disk_Processed_List})
|
|
|
|
List_Disk ${Disk_info}
|
|
|
|
done
|
2021-04-22 02:19:32 +00:00
|
|
|
echo -e "\nq. 返回"
|
|
|
|
echo "r. 重新载入列表"
|
2021-04-21 15:18:29 +00:00
|
|
|
} || {
|
2021-02-10 09:35:23 +00:00
|
|
|
echo "未检测到外接硬盘!" && sleep 2
|
2021-04-22 02:19:32 +00:00
|
|
|
return 1
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-01-01 05:57:39 +00:00
|
|
|
echo ""
|
|
|
|
read -p "请输入要操作的硬盘编号[1-${Disk_Number}]:" Choose
|
|
|
|
echo ""
|
|
|
|
case ${Choose} in
|
|
|
|
q)
|
2021-04-22 02:19:32 +00:00
|
|
|
return 0
|
2021-01-01 05:57:39 +00:00
|
|
|
;;
|
|
|
|
r)
|
2021-04-21 15:18:29 +00:00
|
|
|
block mount
|
2021-01-01 05:57:39 +00:00
|
|
|
AutoExpand_UI
|
|
|
|
;;
|
|
|
|
*)
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ ${Choose} -gt 0 ]] > /dev/null 2>&1 && [[ ${Choose} -le ${Disk_Number} ]] > /dev/null 2>&1 && {
|
2021-02-10 09:35:23 +00:00
|
|
|
which mkfs.ext4 > /dev/null 2>&1
|
2021-04-21 15:18:29 +00:00
|
|
|
[[ $? -eq 0 ]] && {
|
2021-02-10 09:35:23 +00:00
|
|
|
AutoExpand_Core
|
2021-04-21 15:18:29 +00:00
|
|
|
} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "缺少相应依赖包,请先安装 [e2fsprogs] !" && sleep 3
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
|
|
|
} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "选择错误,请输入正确的选项!"
|
2021-01-01 05:57:39 +00:00
|
|
|
sleep 2 && AutoExpand_UI
|
|
|
|
exit
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-01-01 05:57:39 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-01-03 03:12:31 +00:00
|
|
|
USB_Check_Core() {
|
|
|
|
block mount
|
2021-07-19 08:49:47 +00:00
|
|
|
rm -rf ${Main_tmp}/*
|
2021-01-03 03:12:31 +00:00
|
|
|
echo "$(block info)" > ${Block_Info}
|
2021-04-21 15:18:29 +00:00
|
|
|
Check_Disk="$(cat ${Block_Info} | awk -F ':' '/sd/{print $1}')"
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -n ${Check_Disk} ]] && {
|
2021-01-03 03:12:31 +00:00
|
|
|
echo "${Check_Disk}" > ${Disk_List}
|
|
|
|
Disk_Number=$(sed -n '$=' ${Disk_List})
|
|
|
|
for Disk_Name in $(cat ${Disk_List})
|
|
|
|
do
|
2021-04-21 15:18:29 +00:00
|
|
|
Mounted_Point=$(grep "${Disk_Name}" ${Block_Info} | egrep -o 'MOUNT="/[a-z].+' | awk -F '["]' '/MOUNT/{print $2}')
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -z ${Mounted_Point} ]] && Mounted_Point="$(df -h | grep "${Disk_Name}" | awk '{print $6}' | awk 'NR==1')"
|
2021-04-21 15:18:29 +00:00
|
|
|
Disk_Available="$(df -m | grep "${Disk_Name}" | awk '{print $4}' | awk 'NR==1')"
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -z ${Disk_Available} ]] && Disk_Available=0
|
2021-01-03 03:12:31 +00:00
|
|
|
Disk_Format="$(cat ${Block_Info} | grep "${Disk_Name}" | egrep -o 'TYPE="[a-z].+' | awk -F '["]' '/TYPE/{print $2}')"
|
|
|
|
touch ${Disk_Processed_List}
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -n ${Mounted_Point} ]] && {
|
2021-04-21 15:18:29 +00:00
|
|
|
echo "${Disk_Name} ${Mounted_Point} ${Disk_Format} ${Disk_Available}MB" >> ${Disk_Processed_List}
|
|
|
|
} || {
|
2021-01-03 03:12:31 +00:00
|
|
|
echo "${Disk_Name} ${Disk_Format}" >> ${Disk_Processed_List}
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-01-03 03:12:31 +00:00
|
|
|
done
|
2021-05-08 12:41:32 +00:00
|
|
|
grep -o "/dev/sd[a-z]" ${Disk_List} | sort | uniq > ${Phy_Disk_List}
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-01-03 03:12:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 05:57:39 +00:00
|
|
|
AutoExpand_Core() {
|
|
|
|
Choosed_Disk="$(sed -n ${Choose}p ${Disk_Processed_List} | awk '{print $1}')"
|
2021-01-03 03:12:31 +00:00
|
|
|
echo "警告: 本次操作将把硬盘: '${Choosed_Disk}' 格式化为 'ext4' 格式,请提前做好数据备份工作!"
|
2021-04-22 02:19:32 +00:00
|
|
|
echo "注意: 操作开始后请不要中断任务或进行其他操作,否则可能导致设备数据丢失!"
|
2021-01-01 05:57:39 +00:00
|
|
|
read -p "是否继续本次操作?[Y/n]:" Choose
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ ${Choose} == [Yy] ]] && sleep 3 && echo "" || {
|
2021-01-03 03:12:31 +00:00
|
|
|
sleep 3
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "用户已取消操作."
|
2021-01-03 03:12:31 +00:00
|
|
|
break
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ $(mount) =~ ${Choosed_Disk} ]] > /dev/null 2>&1 && {
|
2021-01-01 05:57:39 +00:00
|
|
|
Choosed_Disk_Mounted="$(mount | grep "${Choosed_Disk}" | awk '{print $3}')"
|
|
|
|
echo "取消挂载: '${Choosed_Disk}' on '${Choosed_Disk_Mounted}' ..."
|
2021-01-03 03:12:31 +00:00
|
|
|
umount -l ${Choosed_Disk_Mounted} > /dev/null 2>&1
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ $(mount) =~ ${Choosed_Disk_Mounted} ]] > /dev/null 2>&1 && {
|
2021-01-03 03:12:31 +00:00
|
|
|
echo "取消挂载: '${Choosed_Disk_Mounted}' 失败 !"
|
2021-04-22 02:19:32 +00:00
|
|
|
exit 1
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "正在格式化硬盘: '${Choosed_Disk}',请耐心等待 ..."
|
2021-01-01 05:57:39 +00:00
|
|
|
mkfs.ext4 -F ${Choosed_Disk} > /dev/null 2>&1
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "硬盘格式化完成! 挂载硬盘: '${Choosed_Disk}' 到 ' /tmp/extroot' ..."
|
2021-01-01 05:57:39 +00:00
|
|
|
mkdir -p /tmp/introot && mkdir -p /tmp/extroot
|
|
|
|
mount --bind / /tmp/introot
|
|
|
|
mount ${Choosed_Disk} /tmp/extroot
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "正在备份系统文件到硬盘: '${Choosed_Disk}',请耐心等待 ..."
|
2021-01-01 05:57:39 +00:00
|
|
|
tar -C /tmp/introot -cf - . | tar -C /tmp/extroot -xf -
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "取消挂载: '/tmp/introot' '/tmp/extroot' ..."
|
2021-01-01 05:57:39 +00:00
|
|
|
umount /tmp/introot && umount /tmp/extroot
|
|
|
|
[ ! -d /mnt/bak ] && mkdir -p /mnt/bak
|
|
|
|
mount ${Choosed_Disk} /mnt/bak
|
|
|
|
sync
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "写入 '分区表' 到 '/etc/config/fstab' ..."
|
2021-01-01 05:57:39 +00:00
|
|
|
block detect > /etc/config/fstab
|
|
|
|
sed -i "s?/mnt/bak?/?g" /etc/config/fstab
|
|
|
|
for ((i=0;i<=${Disk_Number};i++));
|
|
|
|
do
|
2021-04-22 02:19:32 +00:00
|
|
|
uci set fstab.@mount[${i}].enabled='1'
|
2021-01-01 05:57:39 +00:00
|
|
|
done
|
|
|
|
uci commit fstab
|
2021-01-03 03:12:31 +00:00
|
|
|
umount -l /mnt/bak
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "操作结束,外接硬盘: '${Choosed_Disk}' 已挂载到 '/'"
|
2021-02-10 09:35:23 +00:00
|
|
|
read -p "挂载完成后需要重启生效,是否立即重启路由器?[Y/n]:" Choose
|
2021-05-19 01:23:12 +00:00
|
|
|
[[ ${Choose} == [Yy] ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
sleep 3 && ECHO g "\n正在重启路由器,请耐心等待 ..."
|
2021-02-10 09:35:23 +00:00
|
|
|
sync
|
|
|
|
reboot
|
2021-04-21 15:18:29 +00:00
|
|
|
} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO "用户已取消重启操作."
|
2021-02-10 09:35:23 +00:00
|
|
|
sleep 3
|
|
|
|
break
|
2021-04-21 15:18:29 +00:00
|
|
|
}
|
2021-01-01 05:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
List_Disk() {
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -n $3 ]] && {
|
|
|
|
echo "${i}. '$1' 挂载点: '$2' 格式: '$3' 可用空间: $4"
|
|
|
|
} || echo "${i}. '$1' 格式: '$2' 未挂载"
|
2021-01-01 05:57:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 15:18:29 +00:00
|
|
|
AutoSamba_UI() {
|
2021-07-19 08:49:47 +00:00
|
|
|
USB_Check_Core
|
|
|
|
Samba_tmp="${Main_tmp}/AutoSamba"
|
|
|
|
Samba_UCI_List="${Main_tmp}/UCI_List"
|
|
|
|
[[ ! -d ${Main_tmp} ]] && mkdir -p "${Main_tmp}"
|
2021-01-03 03:12:31 +00:00
|
|
|
while :
|
|
|
|
do
|
|
|
|
clear
|
2021-04-22 02:19:32 +00:00
|
|
|
echo -e "Samba 工具箱/AutoSamba\n"
|
|
|
|
echo "1. 删除所有 Samba 挂载点"
|
|
|
|
echo "2. 自动生成 Samba 共享"
|
|
|
|
echo "3. 关闭/开启自动共享"
|
|
|
|
echo -e "\nq. 返回\n"
|
2021-01-03 03:12:31 +00:00
|
|
|
read -p "请从上方选择一个操作:" Choose
|
|
|
|
case $Choose in
|
|
|
|
1)
|
|
|
|
Remove_Samba_Settings
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
Mount_Samba_Devices
|
|
|
|
;;
|
2021-04-21 15:18:29 +00:00
|
|
|
3)
|
|
|
|
autosamba="$(uci get samba.@samba[0].autoshare)"
|
|
|
|
[[ ${autosamba} == 0 ]] && {
|
|
|
|
uci set samba.@samba[0].autoshare='1'
|
|
|
|
autosamba_mode="开启"
|
|
|
|
} || {
|
|
|
|
uci set samba.@samba[0].autoshare='0'
|
|
|
|
autosamba_mode="关闭"
|
|
|
|
}
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "已${autosamba_mode} Samba 自动共享!"
|
2021-04-21 15:18:29 +00:00
|
|
|
uci commit samba
|
2021-07-19 08:49:47 +00:00
|
|
|
sleep 2
|
2021-04-21 15:18:29 +00:00
|
|
|
;;
|
2021-01-03 03:12:31 +00:00
|
|
|
q)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
Remove_Samba_Settings() {
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
Samba_config="$(grep "sambashare" /etc/config/samba | wc -l)"
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ ${Samba_config} -eq 0 ]] && break
|
2021-01-03 03:12:31 +00:00
|
|
|
uci delete samba.@sambashare[0]
|
2021-07-19 08:49:47 +00:00
|
|
|
uci commit samba > /dev/null 2>&1
|
2021-01-03 03:12:31 +00:00
|
|
|
done
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "已删除所有 Samba 挂载点!"
|
2021-01-16 06:49:23 +00:00
|
|
|
sleep 2
|
2021-01-03 03:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Mount_Samba_Devices() {
|
2021-07-19 08:49:47 +00:00
|
|
|
Disk_Number=$(sed -n '$=' ${Disk_Processed_List})
|
2021-01-03 03:12:31 +00:00
|
|
|
for ((i=1;i<=${Disk_Number};i++));
|
|
|
|
do
|
2021-07-19 08:49:47 +00:00
|
|
|
Disk_Name=$(sed -n ${i}p ${Disk_Processed_List} | awk '{print $1}')
|
|
|
|
Disk_Mounted_Point=$(sed -n ${i}p ${Disk_Processed_List} | awk '{print $2}')
|
2021-04-21 15:18:29 +00:00
|
|
|
Samba_Name=${Disk_Mounted_Point#*/mnt/}
|
2021-07-19 08:49:47 +00:00
|
|
|
Samba_Name=$(echo ${Samba_Name} | cut -d "/" -f2-5)
|
2021-04-22 02:19:32 +00:00
|
|
|
uci show 2>&1 | grep "sambashare" > ${Samba_UCI_List}
|
2021-07-19 08:49:47 +00:00
|
|
|
if [[ ! $(cat ${Samba_UCI_List}) =~ ${Disk_Mounted_Point} ]] > /dev/null 2>&1 ;then
|
|
|
|
ECHO g "设置挂载点 '${Samba_Name}' ..."
|
|
|
|
cat >> /etc/config/samba <<EOF
|
|
|
|
|
|
|
|
config sambashare
|
|
|
|
option auto '1'
|
|
|
|
option name '${Samba_Name}'
|
|
|
|
option device '${Disk_Name}'
|
|
|
|
option path '${Disk_Mounted_Point}'
|
|
|
|
option read_only 'no'
|
|
|
|
option guest_ok 'yes'
|
|
|
|
option create_mask '0666'
|
|
|
|
option dir_mask '0777'
|
|
|
|
EOF
|
2021-01-16 06:49:23 +00:00
|
|
|
else
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "'${Disk_Mounted_Point}' 挂载点已存在 !"
|
2021-01-03 03:12:31 +00:00
|
|
|
fi
|
|
|
|
done
|
2021-07-19 08:49:47 +00:00
|
|
|
uci commit samba
|
2021-01-03 03:12:31 +00:00
|
|
|
/etc/init.d/samba restart
|
2021-04-21 15:18:29 +00:00
|
|
|
sleep 3
|
2021-01-16 06:49:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 15:18:29 +00:00
|
|
|
AutoInstall_UI() {
|
2021-02-10 09:35:23 +00:00
|
|
|
while :
|
2021-04-22 02:19:32 +00:00
|
|
|
do
|
2021-04-22 08:06:01 +00:00
|
|
|
clear
|
|
|
|
echo -e "安装软件包\n"
|
|
|
|
echo "1. 更新软件包列表"
|
|
|
|
AutoInstall_UI_mod 2 block-mount
|
|
|
|
AutoInstall_UI_mod 3 e2fsprogs
|
2021-05-08 12:41:32 +00:00
|
|
|
AutoInstall_UI_mod 4 smartmontools
|
2021-04-22 08:06:01 +00:00
|
|
|
echo "x. 自定义软件包名"
|
|
|
|
echo -e "\nq. 返回\n"
|
|
|
|
read -p "请从上方选择一个操作:" Choose
|
|
|
|
echo ""
|
|
|
|
case $Choose in
|
|
|
|
q)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
x)
|
|
|
|
echo -e "常用的附加参数:\n"
|
|
|
|
echo "--force-depends 在安装、删除软件包时无视失败的依赖"
|
|
|
|
echo "--force-downgrade 允许降级安装软件包"
|
|
|
|
echo -e "--force-reinstall 重新安装软件包\n"
|
|
|
|
read -p "请输入你想安装的软件包名和附加参数:" PKG_NAME
|
|
|
|
Install_opkg_mod $PKG_NAME
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
opkg update
|
|
|
|
sleep 1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
Install_opkg_mod block-mount
|
|
|
|
;;
|
|
|
|
3)
|
|
|
|
Install_opkg_mod e2fsprogs
|
|
|
|
;;
|
2021-05-08 12:41:32 +00:00
|
|
|
4)
|
|
|
|
Install_opkg_mod smartmontools
|
|
|
|
;;
|
2021-04-22 08:06:01 +00:00
|
|
|
esac
|
|
|
|
done
|
2021-02-10 09:35:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 02:19:32 +00:00
|
|
|
AutoUpdate_UI() {
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
AutoUpdate_Version=$(awk 'NR==6' /bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
|
|
|
|
clear
|
2021-07-19 08:49:47 +00:00
|
|
|
echo -e "AutoBuild 固件更新/AutoUpdate ${AutoUpdate_Version}\n"
|
2021-04-22 08:06:01 +00:00
|
|
|
echo "1. 更新固件 [保留配置]"
|
|
|
|
echo "2. 强制更新固件 (跳过版本号验证,自动安装缺失的软件包) [保留配置]"
|
|
|
|
echo "3. 不保留配置更新固件 [全新安装]"
|
2021-04-22 02:19:32 +00:00
|
|
|
echo "4. 列出固件信息"
|
|
|
|
echo "5. 清除固件下载缓存"
|
2021-05-08 12:41:32 +00:00
|
|
|
echo "6. 更改 Github API 地址"
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ ${DEFAULT_Device} == x86_64 ]] && echo "7. 指定 x86 设备下载 UEFI/Legacy 引导的固件"
|
2021-04-22 02:19:32 +00:00
|
|
|
echo -e "\nx. 更新 [AutoUpdate] 脚本"
|
|
|
|
echo -e "q. 返回\n"
|
|
|
|
read -p "请从上方选择一个操作:" Choose
|
|
|
|
case ${Choose} in
|
|
|
|
q)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
x)
|
2021-07-19 08:49:47 +00:00
|
|
|
wget -q ${Github_Raw}/Scripts/AutoUpdate.sh -O ${Main_tmp}/AutoUpdate.sh
|
2021-05-08 12:41:32 +00:00
|
|
|
[[ $? == 0 ]] && {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "脚本更新成功!"
|
2021-05-08 12:41:32 +00:00
|
|
|
rm -f /bin/AutoUpdate.sh
|
2021-07-19 08:49:47 +00:00
|
|
|
mv -f ${Main_tmp}/AutoUpdate.sh /bin
|
2021-05-08 12:41:32 +00:00
|
|
|
chmod +x /bin/AutoUpdate.sh
|
2021-07-19 08:49:47 +00:00
|
|
|
} || ECHO r "脚本更新失败!"
|
2021-04-22 02:19:32 +00:00
|
|
|
sleep 2
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
bash /bin/AutoUpdate.sh
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
bash /bin/AutoUpdate.sh -f
|
|
|
|
;;
|
|
|
|
3)
|
|
|
|
bash /bin/AutoUpdate.sh -n
|
|
|
|
;;
|
|
|
|
4)
|
2021-07-19 08:49:47 +00:00
|
|
|
bash /bin/AutoUpdate.sh --list
|
2021-04-22 08:06:01 +00:00
|
|
|
Enter
|
2021-04-22 02:19:32 +00:00
|
|
|
;;
|
|
|
|
5)
|
2021-06-19 15:58:51 +00:00
|
|
|
bash /bin/AutoUpdate.sh --clean
|
2021-05-08 12:41:32 +00:00
|
|
|
sleep 1
|
2021-04-22 02:19:32 +00:00
|
|
|
;;
|
|
|
|
6)
|
2021-04-22 08:06:01 +00:00
|
|
|
echo ""
|
2021-06-19 15:58:51 +00:00
|
|
|
read -p "请输入新的 Github 地址:" Github_URL
|
|
|
|
[[ -n ${Github_URL} ]] && bash /bin/AutoUpdate.sh -C ${Github_URL} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "Github 地址不能为空!"
|
2021-04-22 08:06:01 +00:00
|
|
|
}
|
|
|
|
sleep 2
|
2021-04-22 02:19:32 +00:00
|
|
|
;;
|
|
|
|
7)
|
2021-04-22 08:06:01 +00:00
|
|
|
echo ""
|
|
|
|
read -p "请输入你想要的启动方式[UEFI/Legacy]:" _BOOT
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -n ${_BOOT} ]] && bash /bin/AutoUpdate.sh -B ${_BOOT} || {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO r "启动方式不能为空!"
|
2021-04-22 08:06:01 +00:00
|
|
|
}
|
|
|
|
sleep 2
|
2021-04-22 02:19:32 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-05-08 12:41:32 +00:00
|
|
|
Smart_Info() {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO g "Loading disk information ,please wait..."
|
2021-05-08 12:41:32 +00:00
|
|
|
USB_Check_Core
|
|
|
|
clear
|
|
|
|
smartctl -v | awk 'NR==1'
|
|
|
|
cat ${Phy_Disk_List} | while read Phy_Disk
|
|
|
|
do
|
|
|
|
GET_Smart_Info ${Phy_Disk}
|
|
|
|
done
|
|
|
|
Enter
|
|
|
|
}
|
|
|
|
|
|
|
|
getinf() {
|
2021-06-19 15:58:51 +00:00
|
|
|
grep "$1" $2 | sed "s/^[$1]*//g" 2>/dev/null | sed 's/^[ \t]*//g' 2>/dev/null
|
2021-05-08 12:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GET_Smart_Info() {
|
|
|
|
smartctl -H -A -i $1 > ${Smart_Info1}
|
|
|
|
smartctl -H -A -i -d scsi $1 > ${Smart_Info2}
|
2021-06-19 15:58:51 +00:00
|
|
|
if [[ ! $(smartctl -H $1) =~ Unknown ]];then
|
|
|
|
[[ $(smartctl -H $1) =~ PASSED ]] && Phy_Health=PASSED || Phy_Health=Failure
|
2021-05-08 12:41:32 +00:00
|
|
|
else
|
|
|
|
Phy_Health=$(getinf "SMART Health Status:" ${Smart_Info2})
|
|
|
|
fi
|
|
|
|
Phy_Name=$(getinf "Device Model:" ${Smart_Info1})
|
|
|
|
Phy_ID=$(getinf "Serial number:" ${Smart_Info2})
|
|
|
|
Phy_Capacity=$(getinf "User Capacity:" ${Smart_Info2})
|
2021-06-19 15:58:51 +00:00
|
|
|
Phy_Part_Number=$(grep -c "${Phy_Disk}" ${Disk_Processed_List})
|
|
|
|
Phy_Factor=$(getinf "Form Factor:" ${Smart_Info2})
|
|
|
|
[[ -z ${Phy_Factor} ]] && Phy_Factor=不可用
|
2021-05-08 12:41:32 +00:00
|
|
|
Phy_Sata_Version=$(getinf "SATA Version is:" ${Smart_Info1})
|
|
|
|
[[ -z ${Phy_Sata_Version} ]] && Phy_Sata_Version=不可用
|
2021-06-19 15:58:51 +00:00
|
|
|
TRIM_Command=$(getinf "TRIM Command:" ${Smart_Info1})
|
|
|
|
[[ -z ${TRIM_Command} ]] && TRIM_Command=不可用
|
2021-05-08 12:41:32 +00:00
|
|
|
Power_On=$(grep "Power_On" ${Smart_Info1} | awk '{print $NF}')
|
2021-06-19 15:58:51 +00:00
|
|
|
Power_Cycle_Count=$(grep "Power_Cycle_Count" ${Smart_Info1} | awk '{print $NF}')
|
|
|
|
[[ -z ${Power_On} ]] && {
|
|
|
|
Power_Status=未知
|
|
|
|
} || {
|
|
|
|
Power_Status="${Power_On} 小时 / ${Power_Cycle_Count} 次"
|
|
|
|
}
|
|
|
|
if [[ $(getinf "Rotation Rate:" ${Smart_Info2}) =~ "Solid State" ]];then
|
|
|
|
Phy_Type=固态硬盘
|
|
|
|
Phy_RPM=不可用
|
2021-05-08 12:41:32 +00:00
|
|
|
else
|
2021-06-19 15:58:51 +00:00
|
|
|
Phy_Type=其他硬盘
|
|
|
|
if [[ $(getinf "Rotation Rate:" ${Smart_Info2}) =~ rpm ]];then
|
2021-05-08 12:41:32 +00:00
|
|
|
Phy_RPM="$(getinf "Rotation Rate:" ${Smart_Info2})"
|
2021-06-19 15:58:51 +00:00
|
|
|
Phy_Type=机械硬盘
|
2021-05-08 12:41:32 +00:00
|
|
|
else
|
2021-06-19 15:58:51 +00:00
|
|
|
Phy_RPM=不可用
|
2021-05-08 12:41:32 +00:00
|
|
|
fi
|
|
|
|
fi
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ -z ${Phy_Name} ]] && {
|
2021-05-08 12:41:32 +00:00
|
|
|
Phy_Name="$(getinf Vendor: ${Smart_Info2})$(getinf Product: ${Smart_Info2})"
|
|
|
|
}
|
|
|
|
Phy_LB=$(getinf "Logical block size:" ${Smart_Info2})
|
|
|
|
Phy_PB=$(getinf "Physical block size:" ${Smart_Info2})
|
2021-06-19 15:58:51 +00:00
|
|
|
if [[ -n ${Phy_PB} ]];then
|
2021-05-08 12:41:32 +00:00
|
|
|
Phy_BS="${Phy_LB} / ${Phy_PB}"
|
|
|
|
else
|
|
|
|
Phy_BS="${Phy_LB}"
|
|
|
|
fi
|
|
|
|
Phy_Localtime=$(getinf "Local Time is:" ${Smart_Info2})
|
2021-06-19 15:58:51 +00:00
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
硬盘型号: ${Phy_Name}
|
|
|
|
硬盘尺寸: ${Phy_Factor}
|
|
|
|
硬盘 ID : ${Phy_ID}
|
|
|
|
硬盘容量: ${Phy_Capacity}
|
|
|
|
健康状况: ${Phy_Health}
|
|
|
|
分区数量: ${Phy_Part_Number}
|
|
|
|
SATA 版本: ${Phy_Sata_Version}
|
|
|
|
TRIM 指令: ${TRIM_Command}
|
|
|
|
硬盘类型: ${Phy_Type}
|
|
|
|
硬盘转速: ${Phy_RPM}
|
|
|
|
扇区大小: ${Phy_BS}
|
|
|
|
通电情况: ${Power_Status}
|
|
|
|
|
|
|
|
========================================================
|
|
|
|
|
|
|
|
EOF
|
2021-05-08 12:41:32 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 02:19:32 +00:00
|
|
|
AutoInstall_UI_mod() {
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ $(opkg list | awk '{print $1}') =~ $2 ]] > /dev/null 2>&1 && {
|
|
|
|
echo "$1. 安装 [$2] [已安装]"
|
|
|
|
} || echo "$1. 未安装 [$2] [已安装]"
|
2021-02-10 09:35:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Install_opkg_mod() {
|
|
|
|
opkg install ${*}
|
2021-06-19 15:58:51 +00:00
|
|
|
[[ $(opkg list | awk '{print $1}') =~ $1 ]] > /dev/null 2>&1 && {
|
2021-07-19 08:49:47 +00:00
|
|
|
ECHO y "$1 安装成功!"
|
|
|
|
} || ECHO r "$1 安装失败!"
|
2021-02-10 09:35:23 +00:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2021-01-16 06:49:23 +00:00
|
|
|
Enter() {
|
|
|
|
echo "" && read -p "按下[回车]键以继续..." Key
|
2021-01-03 03:12:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
White="\e[0m"
|
|
|
|
Yellow="\e[33m"
|
|
|
|
Red="\e[31m"
|
|
|
|
Blue="\e[34m"
|
|
|
|
Skyb="\e[36m"
|
2021-04-22 02:19:32 +00:00
|
|
|
|
2021-07-19 08:49:47 +00:00
|
|
|
Main_tmp="/tmp/AutoBuild_Tools"
|
|
|
|
Disk_List="${Main_tmp}/Disk_List"
|
|
|
|
Block_Info="${Main_tmp}/Block_Info"
|
|
|
|
Disk_Processed_List="${Main_tmp}/Disk_Processed_List"
|
|
|
|
Phy_Disk_List="${Main_tmp}/Phy_Disk_List"
|
|
|
|
Smart_Info1="${Main_tmp}/Smart_Info1"
|
|
|
|
Smart_Info2="${Main_tmp}/Smart_Info2"
|
|
|
|
[[ ! -d ${Main_tmp} ]] && mkdir -p "${Main_tmp}"
|
2021-04-22 08:06:01 +00:00
|
|
|
Github_Raw="https://raw.githubusercontent.com/Hyy2001X/AutoBuild-Actions/master"
|
|
|
|
AutoBuild_Tools
|