重构 AutoBuild 代码

This commit is contained in:
Hyy2001X
2021-01-06 07:38:00 +08:00
parent ed8263e4ce
commit 33ea15d330
9 changed files with 160 additions and 155 deletions
+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild DiyScript
Diy_Core() {
Author=Hyy2001
Default_Device=d-team_newifi-d2
}
Diy-Part1() {
# [ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default
[ ! -d package/lean ] && mkdir -p package/lean
Replace_File Scripts/AutoUpdate.sh package/base-files/files/bin
Replace_File Scripts/AutoBuild_Tools.sh package/base-files/files/bin
Replace_File Customize/mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File Customize/system package/base-files/files/etc/config
Replace_File Customize/banner package/base-files/files/etc
# ExtraPackages svn network/services dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services dropbear https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services ppp https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn network/services hostapd https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
ExtraPackages git lean helloworld https://github.com/fw876 master
ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main
ExtraPackages git lean luci-theme-argon https://github.com/jerrykuku 18.06
ExtraPackages git other luci-app-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages svn other smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages git other OpenClash https://github.com/vernesong master
ExtraPackages git other luci-app-serverchan https://github.com/tty228 master
ExtraPackages svn other luci-app-socat https://github.com/project-openwrt/openwrt/trunk/package/lienol
}
Diy-Part2() {
GET_TARGET_INFO
Replace_File Customize/mwan3.config package/feeds/packages/mwan3/files/etc/config mwan3
sed -i 's/143/143,25,5222/' package/lean/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
# ExtraPackages svn feeds/packages mwan3 https://github.com/openwrt/packages/trunk/net
echo "Author: ${Author}"
echo "Openwrt Version: ${Openwrt_Version}"
echo "AutoUpdate Version: ${AutoUpdate_Version}"
echo "Router: ${TARGET_PROFILE}"
[ -f $Default_File ] && sed -i "s?${Lede_Version}?${Lede_Version} Compiled by ${Author} [${Display_Date}]?g" $Default_File
echo "${Openwrt_Version}" > package/base-files/files/etc/openwrt_info
sed -i "s?Openwrt?Openwrt ${Openwrt_Version} / AutoUpdate ${AutoUpdate_Version}?g" package/base-files/files/etc/banner
}
Diy-Part3() {
GET_TARGET_INFO
Default_Firmware="openwrt-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}-squashfs-sysupgrade.bin"
AutoBuild_Firmware="AutoBuild-${TARGET_PROFILE}-Lede-${Openwrt_Version}.bin"
AutoBuild_Detail="AutoBuild-${TARGET_PROFILE}-Lede-${Openwrt_Version}.detail"
mkdir -p bin/Firmware
echo "Firmware: ${AutoBuild_Firmware}"
mv -f bin/targets/"${TARGET_BOARD}/${TARGET_SUBTARGET}/${Default_Firmware}" bin/Firmware/"${AutoBuild_Firmware}"
_MD5=$(md5sum bin/Firmware/${AutoBuild_Firmware} | cut -d ' ' -f1)
_SHA256=$(sha256sum bin/Firmware/${AutoBuild_Firmware} | cut -d ' ' -f1)
echo -e "\nMD5:${_MD5}\nSHA256:${_SHA256}" > bin/Firmware/"${AutoBuild_Detail}"
}
+75
View File
@@ -0,0 +1,75 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild Functions
GET_TARGET_INFO() {
Diy_Core
[ -f ${GITHUB_WORKSPACE}/Openwrt.info ] && . ${GITHUB_WORKSPACE}/Openwrt.info
AutoUpdate_Version=$(awk 'NR==6' package/base-files/files/bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
[ -z ${AutoUpdate_Version} ] && AutoUpdate_Version="未知"
Default_File="package/lean/default-settings/files/zzz-default-settings"
[ -f ${Default_File} ] && Lede_Version=$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" $Default_File)
[ -z ${Lede_Version} ] && Lede_Version="AutoBuild"
Openwrt_Version="${Lede_Version}-${Compile_Date}"
TARGET_PROFILE=$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
[ -z "${TARGET_PROFILE}" ] && TARGET_PROFILE="${Default_Device}"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)
}
ExtraPackages() {
PKG_PROTO=${1}
PKG_DIR=${2}
PKG_NAME=${3}
REPO_URL=${4}
REPO_BRANCH=${5}
[ -d package/${PKG_DIR} ] && mkdir -p package/${PKG_DIR}
[ -d package/${PKG_DIR}/${PKG_NAME} ] && rm -rf package/${PKG_DIR}/${PKG_NAME}
[ -d ${PKG_NAME} ] && rm -rf ${PKG_NAME}
Retry_Times=3
while [ ! -f ${PKG_NAME}/Makefile ]
do
echo "[$(date "+%H:%M:%S")] Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..."
case ${PKG_PROTO} in
git)
git clone -b ${REPO_BRANCH} ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
;;
svn)
svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
esac
if [ -f ${PKG_NAME}/Makefile ] || [ -f ${PKG_NAME}/README* ];then
echo "[$(date "+%H:%M:%S")] Package [${PKG_NAME}] is detected!"
mv ${PKG_NAME} package/${PKG_DIR}
break
else
[ ${Retry_Times} -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [${PKG_NAME}] ..." && break
echo "[$(date "+%H:%M:%S")] [Error] [${Retry_Times}] Checkout failed,retry in 3s ..."
Retry_Times=$(($Retry_Times - 1))
rm -rf ${PKG_NAME} > /dev/null 2>&1
sleep 3
fi
done
}
Replace_File() {
FILE_NAME=${1}
PATCH_DIR=${GITHUB_WORKSPACE}/openwrt/${2}
FILE_RENAME=${3}
[ ! -d "${PATCH_DIR}" ] && mkdir -p ${PATCH_DIR}
[ -f "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="f" && _TYPE2="File"
[ -d "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="d" && _TYPE2="Folder"
if [ -e "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then
[ ! -z "${FILE_RENAME}" ] && _RENAME="${FILE_RENAME}" || _RENAME=""
if [ -${_TYPE1} "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then
echo "[$(date "+%H:%M:%S")] Move ${FILE_NAME} to ${PATCH_DIR}/${FILE_RENAME} ..."
mv -f ${GITHUB_WORKSPACE}/${FILE_NAME} ${PATCH_DIR}/${_RENAME}
else
echo "[$(date "+%H:%M:%S")] Customize ${_TYPE2} [${FILE_NAME}] is not detected,skip move ..."
fi
fi
unset _RENAME
}
+227
View File
@@ -0,0 +1,227 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild_Tools for Openwrt
Version=V1.1-BETA
AutoBuild_Tools() {
while :
do
clear
echo -e "USB \ Samba 工具箱 ${Version}\n"
echo "1.内部空间扩展"
echo "2.Samba"
echo -e "\nq.退出\n"
read -p "请从上方选择一个操作:" Choose
case $Choose in
q)
rm -rf /tmp/AutoExpand /tmp/AutoSamba
clear
exit
;;
1)
AutoExpand_UI
;;
2)
Samba_UI
;;
esac
done
}
AutoExpand_UI() {
uci set fstab.@global[0].auto_mount='0'
uci set fstab.@global[0].auto_swap='0'
uci commit fstab
clear
echo -e "Newifi-D2 一键扩展内部空间\n"
USB_Check_Core
if [ ! -z "${Check_Disk}" ];then
for ((i=1;i<=${Disk_Number};i++));
do
Disk_info=$(sed -n ${i}p ${Disk_Processed_List})
List_Disk ${Disk_info}
done
echo -e "\nq.返回"
echo "r.重新载入列表"
else
echo "未检测到外接硬盘!"
exit
fi
echo ""
read -p "请输入要操作的硬盘编号[1-${Disk_Number}]:" Choose
echo ""
case ${Choose} in
q)
break
;;
r)
AutoExpand_UI
;;
*)
if [ ${Choose} -gt 0 ] > /dev/null 2>&1 && [ ${Choose} -le ${Disk_Number} ] > /dev/null 2>&1;then
AutoExpand_Core
else
echo "选择错误,请输入正确的选项!"
sleep 2 && AutoExpand_UI
exit
fi
;;
esac
}
USB_Check_Core() {
block mount
rm -rf ${AutoExpend_Tmp}/*
echo "$(block info)" > ${Block_Info}
Check_Disk="$(cat ${Block_Info} | awk -F ':' '/sd/{print $1}')"
if [ ! -z "${Check_Disk}" ];then
echo "${Check_Disk}" > ${Disk_List}
Disk_Number=$(sed -n '$=' ${Disk_List})
for Disk_Name in $(cat ${Disk_List})
do
Mounted_on="$(df -h | grep "${Disk_Name}" | awk '{print $6}')"
Disk_Available="$(df -m | grep "${Disk_Name}" | awk '{print $4}')"
Disk_Format="$(cat ${Block_Info} | grep "${Disk_Name}" | egrep -o 'TYPE="[a-z].+' | awk -F '["]' '/TYPE/{print $2}')"
touch ${Disk_Processed_List}
if [ ! -z "$Mounted_on" ];then
echo "${Disk_Name} ${Mounted_on} ${Disk_Format} ${Disk_Available}MB" >> ${Disk_Processed_List}
else
echo "${Disk_Name} ${Disk_Format}" >> ${Disk_Processed_List}
fi
done
fi
}
AutoExpand_Core() {
Choosed_Disk="$(sed -n ${Choose}p ${Disk_Processed_List} | awk '{print $1}')"
echo "警告: 本次操作将把硬盘: '${Choosed_Disk}' 格式化为 'ext4' 格式,请提前做好数据备份工作!"
read -p "是否继续本次操作?[Y/n]:" Choose
if [ ${Choose} == Y ] || [ ${Choose} == y ];then
sleep 3 && echo ""
else
sleep 3
echo "用户已取消操作."
break
fi
if [[ "$(mount)" =~ "${Choosed_Disk}" ]] > /dev/null 2>&1 ;then
Choosed_Disk_Mounted="$(mount | grep "${Choosed_Disk}" | awk '{print $3}')"
echo "取消挂载: '${Choosed_Disk}' on '${Choosed_Disk_Mounted}' ..."
umount -l ${Choosed_Disk_Mounted} > /dev/null 2>&1
if [ "$(mount)" =~ "${Choosed_Disk_Mounted}" ];then
echo "取消挂载: '${Choosed_Disk_Mounted}' 失败 !"
exit
fi
fi
if [[ ! "$(opkg list | awk '{print $1}')" =~ "e2fsprogs" ]];then
echo "正在安装: 'e2fsprogs',请耐心等待 ..."
opkg update > /dev/null 2>&1
opkg install e2fsprogs > /dev/null 2>&1
fi
echo "正在格式化硬盘: '${Choosed_Disk}' 为 'ext4' ..."
mkfs.ext4 -F ${Choosed_Disk} > /dev/null 2>&1
echo "格式化完成! 挂载硬盘: '${Choosed_Disk}' 到 ' /tmp/extroot' ..."
mkdir -p /tmp/introot && mkdir -p /tmp/extroot
mount --bind / /tmp/introot
mount ${Choosed_Disk} /tmp/extroot
echo "正在备份系统文件到 硬盘: '${Choosed_Disk}',请耐心等待 ..."
tar -C /tmp/introot -cf - . | tar -C /tmp/extroot -xf -
echo "取消挂载: '/tmp/introot' '/tmp/extroot' ..."
umount /tmp/introot && umount /tmp/extroot
[ ! -d /mnt/bak ] && mkdir -p /mnt/bak
mount ${Choosed_Disk} /mnt/bak
echo "同步系统文件改动 ..."
sync
echo "写入 '分区表' 到 '/etc/config/fstab' ..."
block detect > /etc/config/fstab
sed -i "s?/mnt/bak?/?g" /etc/config/fstab
for ((i=0;i<=${Disk_Number};i++));
do
uci set fstab.@mount[${i}].enabled='1' > /dev/null 2>&1
done
uci commit fstab
umount -l /mnt/bak
echo "操作结束,外接硬盘: '${Choosed_Disk}' 已挂载到 '/'."
sleep 3
break
}
List_Disk() {
if [ ! -z ${3} ];then
echo "${i}.外接硬盘: '${1}' 挂载点: '${2}' 格式: '${3}' 可用空间: ${4}"
else
echo "${i}.外接硬盘: '${1}' 格式: '${2}' 未挂载"
fi
}
Samba_UI() {
while :
do
clear
echo -e "Samba 工具箱\n"
echo "1.删除所有 Samba 挂载点"
echo "2.自动共享所有已连接的硬盘"
echo -e "\nq.返回\n"
read -p "请从上方选择一个操作:" Choose
case $Choose in
1)
Remove_Samba_Settings
;;
2)
Mount_Samba_Devices
;;
q)
break
;;
esac
done
}
Remove_Samba_Settings() {
while :
do
Samba_config="$(grep "sambashare" /etc/config/samba | wc -l)"
[ "${Samba_config}" -eq 0 ] && break
uci delete samba.@sambashare[0]
uci commit
done
}
Mount_Samba_Devices() {
echo "$(cat /proc/mounts | awk -F ':' '/sd/{print $1}')" > ${Disk_List}
Disk_Number=$(sed -n '$=' ${Disk_List})
for ((i=1;i<=${Disk_Number};i++));
do
Disk_Name=$(sed -n ${i}p ${Disk_List} | awk '{print $1}')
Disk_Mounted_on=$(sed -n ${i}p ${Disk_List} | awk '{print $2}')
Samba_Name=${Disk_Mounted_on#*/mnt/}
uci show 2>&1 | grep "sambashare" > ${UCI_Show_List}
if [[ ! "$(cat ${UCI_Show_List})" =~ "${Disk_Name}" ]] > /dev/null 2>&1 ;then
echo -e "\nconfig sambashare" >> ${Samba_Config_File}
echo -e "\toption auto '1'" >> ${Samba_Config_File}
echo -e "\toption name '${Samba_Name}'" >> ${Samba_Config_File}
echo -e "\toption device '${Disk_Name}'" >> ${Samba_Config_File}
echo -e "\toption path '${Disk_Mounted_on}'" >> ${Samba_Config_File}
echo -e "\toption read_only 'no'" >> ${Samba_Config_File}
echo -e "\toption guest_ok 'yes'" >> ${Samba_Config_File}
echo -e "\toption create_mask '0666'" >> ${Samba_Config_File}
echo -e "\toption dir_mask '0777'" >> ${Samba_Config_File}
fi
done
/etc/init.d/samba restart
}
AutoExpend_Tmp="/tmp/AutoExpand"
Disk_List="${AutoExpend_Tmp}/Disk_List"
Block_Info="${AutoExpend_Tmp}/Block_Info"
Disk_Processed_List="${AutoExpend_Tmp}/Disk_Processed_List"
[ ! -d ${AutoExpend_Tmp} ] && mkdir -p ${AutoExpend_Tmp}
Samba_Config_File="/etc/config/samba"
Samba_Tmp="/tmp/AutoSamba"
Disk_List="${Samba_Tmp}/Disk_List"
UCI_Show_List="${Samba_Tmp}/UCI_List"
[ ! -d ${Samba_Tmp} ] && mkdir -p ${Samba_Tmp}
AutoBuild_Tools
+186
View File
@@ -0,0 +1,186 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoUpdate for Openwrt
Version=V4.6
DEFAULT_DEVICE=d-team_newifi-d2
Github=https://github.com/Hyy2001X/AutoBuild-Actions
TIME() {
echo -ne "\n[$(date "+%H:%M:%S")] "
}
Github_Download=${Github}/releases/download/AutoUpdate
Author=${Github##*com/}
Github_Tags=https://api.github.com/repos/${Author}/releases/latest
cd /etc
CURRENT_VERSION=$(awk 'NR==1' openwrt_info)
CURRENT_DEVICE=$(jsonfilter -e '@.model.id' < "/etc/board.json" | tr ',' '_')
clear && echo "Openwrt-AutoUpdate Script ${Version}"
Input_Option="$1"
if [[ -z "${Input_Option}" ]];then
Upgrade_Options="-q" && TIME && echo "执行: 保留配置更新固件[静默模式]"
else
case ${Input_Option} in
-n)
TIME && echo "执行: 不保留配置更新固件"
;;
-q)
TIME && echo "执行: 保留配置更新固件[静默模式]"
;;
-v)
TIME && echo "执行: 保留配置更新固件[详细模式]"
;;
-f)
Force_Update="1"
Upgrade_Options="-q"
TIME && echo "执行: 强制更新固件并保留配置"
;;
-u)
AutoUpdate_Mode="1"
Upgrade_Options="-q"
;;
*)
echo -e "\nUsage: bash /bin/AutoUpdate.sh [<Option>]"
echo -e "\n可使用的选项:"
echo " -f 强制更新固件并保留配置"
echo " -q 更新固件并保留配置[静默模式]"
echo " -v 更新固件并保留配置[详细模式]"
echo " -n 更新固件但不保留配置"
echo " -u 适用于定时更新的参数"
echo -e "\n项目地址: ${Github}"
echo -e "默认设备: ${DEFAULT_DEVICE}\n"
exit
;;
esac
if [[ ! "${Force_Update}" == "1" ]] && [[ ! "${AutoUpdate_Mode}" == "1" ]];then
Upgrade_Options="${Input_Option}"
fi
fi
opkg list | awk '{print $1}' > /tmp/Package_list
if [[ ! "${Force_Update}" == "1" ]] && [[ ! "${AutoUpdate_Mode}" == "1" ]];then
grep "curl" /tmp/Package_list > /dev/null 2>&1
if [[ ! $? -ne 0 ]];then
Google_Check=$(curl -I -s --connect-timeout 5 www.google.com -w %{http_code} | tail -n1)
[ ! "$Google_Check" == 200 ] && TIME && echo "Google 连接失败,可能导致固件下载速度缓慢!"
fi
fi
grep "wget" /tmp/Package_list > /dev/null 2>&1
if [[ $? -ne 0 ]];then
if [[ "${Force_Update}" == "1" ]] || [[ "${AutoUpdate_Mode}" == "1" ]];then
Choose="Y"
else
TIME && read -p "未安装[wget],是否执行安装?[Y/n]:" Choose
fi
if [[ "${Choose}" == Y ]] || [[ "${Choose}" == y ]];then
TIME && echo -e "开始安装[wget],请耐心等待...\n"
opkg update > /dev/null 2>&1
opkg install wget
else
TIME && echo "用户已取消安装,即将退出更新脚本..."
sleep 2
exit
fi
fi
if [[ -z "${CURRENT_VERSION}" ]];then
TIME && echo "警告: 当前固件版本获取失败!"
CURRENT_VERSION="未知"
fi
if [[ -z "${CURRENT_DEVICE}" ]];then
[[ "${Force_Update}" == "1" ]] && exit
TIME && echo "警告: 当前设备名称获取失败,使用预设名称[$DEFAULT_DEVICE]"
CURRENT_DEVICE="${DEFAULT_DEVICE}"
fi
TIME && echo "正在检查版本更新..."
[ ! -f /tmp/Github_Tags ] && touch /tmp/Github_Tags
wget -q ${Github_Tags} -O - > /tmp/Github_Tags
GET_FullVersion=$(cat /tmp/Github_Tags | egrep -o "AutoBuild-${CURRENT_DEVICE}-Lede-R[0-9]+.[0-9]+.[0-9]+.[0-9]+" | awk 'END {print}')
GET_Version="${GET_FullVersion#*Lede-}"
if [[ -z "${GET_FullVersion}" ]] || [[ -z "${GET_Version}" ]];then
TIME && echo "检查更新失败,请稍后重试!"
exit
fi
echo -e "\n固件作者: ${Author%/*}"
echo "设备名称: ${DEFAULT_DEVICE}"
echo -e "\n当前固件版本: ${CURRENT_VERSION}"
echo "云端固件版本: ${GET_Version}"
if [[ ! ${Force_Update} == 1 ]];then
if [[ "${CURRENT_VERSION}" == "${GET_Version}" ]];then
[[ "${AutoUpdate_Mode}" == "1" ]] && exit
TIME && read -p "已是最新版本,是否强制更新固件?[Y/n]:" Choose
if [[ "${Choose}" == Y ]] || [[ "${Choose}" == y ]];then
TIME && echo "开始强制更新固件..."
else
TIME && echo "已取消强制更新,即将退出更新程序..."
sleep 2
exit
fi
fi
fi
Firmware_Info="${GET_FullVersion}"
Firmware="${Firmware_Info}.bin"
Firmware_Detail="${Firmware_Info}.detail"
echo -e "\n云端固件名称: ${Firmware}"
Disk_List="/tmp/disk_list"
[ -f $Disk_List ] && rm -f $Disk_List
Check_Disk="$(mount | egrep -o "mnt/+sd[a-zA-Z][0-9]+")"
if [ ! -z "${Check_Disk}" ];then
echo "${Check_Disk}" > ${Disk_List}
Disk_Number=$(sed -n '$=' ${Disk_List})
if [ ${Disk_Number} -gt 1 ];then
for Disk_Name in $(cat ${Disk_List})
do
Disk_Available="$(df -m | grep "${Disk_Name}" | awk '{print $4}')"
if [ "${Disk_Available}" -gt 20 ];then
Download_Path="/${Disk_Name}"
break
else
Download_Path="/tmp"
fi
done
else
Disk_Name="${Check_Disk}"
Disk_Available="$(df -m | grep "${Disk_Name}" | awk '{print $4}')"
if [ "${Disk_Available}" -gt 20 ];then
Download_Path="/${Disk_Name}"
else
Download_Path="/tmp"
fi
fi
else
Download_Path="/tmp"
fi
[ ! -d "${Download_Path}/Downloads" ] && mkdir -p ${Download_Path}/Downloads
cd ${Download_Path}/Downloads
echo "固件保存位置: ${Download_Path}/Downloads"
TIME && echo "正在下载固件,请耐心等待..."
wget -q ${Github_Download}/${Firmware} -O ${Firmware}
if [[ ! $? == 0 ]];then
TIME && echo "固件下载失败,请检查网络后重试!"
exit
fi
TIME && echo "下载成功!固件大小:$(du -h ${Download_Path}/Downloads/${Firmware} | awk '{print $1}')B"
TIME && echo "正在获取云端固件MD5,请耐心等待..."
wget -q ${Github_Download}/${Firmware_Detail} -O ${Firmware_Detail}
if [[ ! $? == 0 ]];then
TIME && echo "MD5 获取失败,请检查网络后重试!"
exit
fi
GET_MD5=$(awk -F '[ :]' '/MD5/ {print $2;exit}' ${Firmware_Detail})
CURRENT_MD5=$(md5sum ${Firmware} | cut -d ' ' -f1)
echo -e "\n本地固件MD5:${CURRENT_MD5}"
echo "云端固件MD5:${GET_MD5}"
if [[ -z "${GET_MD5}" ]] || [[ -z "${CURRENT_MD5}" ]];then
echo -e "\nMD5 获取失败!"
exit
fi
if [[ ! "${GET_MD5}" == "${CURRENT_MD5}" ]];then
echo -e "\nMD5 对比失败,请检查网络后重试!"
exit
else
TIME && echo -e "MD5 对比通过!"
fi
TIME && echo -e "开始更新固件,请耐心等待路由器重启...\n"
sleep 3
sysupgrade ${Upgrade_Options} ${Firmware}
-146
View File
@@ -1,146 +0,0 @@
#!/bin/bash
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
# AutoBuild Actions
Diy_Core() {
Author=Hyy2001
Default_Device=d-team_newifi-d2
}
Diy-Part1() {
[ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default
[ ! -d package/lean ] && mkdir -p package/lean
Replace_File mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File system package/base-files/files/etc/config
Replace_File AutoUpdate.sh package/base-files/files/bin
Replace_File AutoExpand.sh package/base-files/files/bin
Replace_File banner package/base-files/files/etc
ExtraPackages svn network/services dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services dropbear https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services ppp https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services hostapd https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main
ExtraPackages git lean luci-theme-argon https://github.com/jerrykuku 18.06
ExtraPackages git other luci-app-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages svn other smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages git other OpenClash https://github.com/vernesong master
ExtraPackages git other luci-app-serverchan https://github.com/tty228 master
ExtraPackages svn other luci-app-socat https://github.com/project-openwrt/openwrt/trunk/package/lienol
# [UPX 压缩] ExtraPackages git other openwrt-upx https://github.com/Hyy2001X master
# [应用过滤] ExtraPackages git OAF openwrt-OpenAppFilter https://github.com/Lienol master
# [AdGuardHome 核心] ExtraPackages svn other AdGuardHome https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
}
Diy-Part2() {
GET_TARGET_INFO
Replace_File mwan3 package/feeds/packages/mwan3/files/etc/config
sed -i 's/143/143,25,5222/' package/feeds/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
# ExtraPackages svn feeds/packages mwan3 https://github.com/openwrt/packages/trunk/net
echo "Author: $Author"
echo "Openwrt Version: $Openwrt_Version"
echo "AutoUpdate Version: $AutoUpdate_Version"
echo "Router: $TARGET_PROFILE"
sed -i "s?$Lede_Version?$Lede_Version Compiled by $Author [$Display_Date]?g" $Default_File
echo "$Openwrt_Version" > package/base-files/files/etc/openwrt_info
sed -i "s?Openwrt?Openwrt $Openwrt_Version / AutoUpdate $AutoUpdate_Version?g" package/base-files/files/etc/banner
}
Diy-Part3() {
GET_TARGET_INFO
Default_Firmware=openwrt-$TARGET_BOARD-$TARGET_SUBTARGET-$TARGET_PROFILE-squashfs-sysupgrade.bin
AutoBuild_Firmware=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.bin
AutoBuild_Detail=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.detail
mkdir -p bin/Firmware
echo "Firmware: $AutoBuild_Firmware"
mv bin/targets/$TARGET_BOARD/$TARGET_SUBTARGET/$Default_Firmware bin/Firmware/$AutoBuild_Firmware
echo "[$(date "+%H:%M:%S")] Calculating MD5 and SHA256 ..."
Firmware_MD5=$(md5sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
Firmware_SHA256=$(sha256sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
echo -e "MD5: $Firmware_MD5\nSHA256: $Firmware_SHA256"
touch bin/Firmware/$AutoBuild_Detail
echo -e "\nMD5:$Firmware_MD5\nSHA256:$Firmware_SHA256" >> bin/Firmware/$AutoBuild_Detail
}
GET_TARGET_INFO() {
Diy_Core
[ -e $GITHUB_WORKSPACE/Openwrt.info ] && . $GITHUB_WORKSPACE/Openwrt.info
AutoUpdate_Version=$(awk 'NR==6' package/base-files/files/bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
Default_File="package/lean/default-settings/files/zzz-default-settings"
Lede_Version=$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" $Default_File)
Openwrt_Version="$Lede_Version-$Compile_Date"
TARGET_PROFILE=$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
[ -z "$TARGET_PROFILE" ] && TARGET_PROFILE="$Default_Device"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)
}
ExtraPackages() {
PKG_PROTO=$1
PKG_DIR=$2
PKG_NAME=$3
REPO_URL=$4
REPO_BRANCH=$5
[ -d package/$PKG_DIR ] && mkdir -p package/$PKG_DIR
[ -d package/$PKG_DIR/$PKG_NAME ] && rm -rf package/$PKG_DIR/$PKG_NAME
[ -d $PKG_NAME ] && rm -rf $PKG_NAME
Retry_Times=3
while [ ! -e $PKG_NAME/Makefile ]
do
echo "[$(date "+%H:%M:%S")] Checking out package [$PKG_NAME] ..."
case $PKG_PROTO in
git)
git clone -b $REPO_BRANCH $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
;;
svn)
svn checkout $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
esac
if [ -e $PKG_NAME/Makefile ] || [ -e $PKG_NAME/README* ];then
echo "[$(date "+%H:%M:%S")] Package [$PKG_NAME] is detected!"
mv $PKG_NAME package/$PKG_DIR
break
else
[ $Retry_Times -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [$PKG_NAME] ..." && break
echo "[$(date "+%H:%M:%S")] [Error] [$Retry_Times] Checkout failed,retry in 3s ..."
Retry_Times=$(($Retry_Times - 1))
rm -rf $PKG_NAME > /dev/null 2>&1
sleep 3
fi
done
}
Replace_File() {
FILE_NAME=$1
PATCH_DIR=$GITHUB_WORKSPACE/openwrt/$2
FILE_RENAME=$3
[ ! -d $PATCH_DIR ] && mkdir -p $PATCH_DIR
if [ -f $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
if [ -e $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is detected!"
if [ -z $FILE_RENAME ];then
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$FILE_NAME
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$1
else
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$3
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$3
fi
else
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is not detected,skip move ..."
fi
else
if [ -d $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is detected !"
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR
else
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is not detected,skip move ..."
fi
fi
}