From e8a6205c9f9e156b2c1bc6a4f7c56d3c0968482a Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Mon, 11 Jan 2021 21:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=87=BD=E6=95=B0=E3=80=81?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/AutoBuild_DiyScript.sh | 39 ++++------------ Scripts/AutoBuild_Function.sh | 85 ++++++++++++++++++++++++++++++---- 2 files changed, 86 insertions(+), 38 deletions(-) diff --git a/Scripts/AutoBuild_DiyScript.sh b/Scripts/AutoBuild_DiyScript.sh index 70b8566..bd4c1d2 100644 --- a/Scripts/AutoBuild_DiyScript.sh +++ b/Scripts/AutoBuild_DiyScript.sh @@ -6,18 +6,15 @@ Diy_Core() { Author=Hyy2001 Default_Device=d-team_newifi-d2 + + INCLUDE_AutoUpdate=true + INCLUDE_SSR_Plus=true + INCLUDE_Latest_Ray=true } 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 + Diy_Part1_Base - Update_Makefile xray package/lean/xray - Update_Makefile v2ray package/lean/v2ray - Update_Makefile v2ray-plugin package/lean/v2ray-plugin - - 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 @@ -27,9 +24,8 @@ Diy-Part1() { # 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 @@ -41,28 +37,11 @@ Diy-Part1() { } Diy-Part2() { - GET_TARGET_INFO + Diy_Part2_Base 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}-${Openwrt_Version}.bin" - AutoBuild_Detail="AutoBuild-${TARGET_PROFILE}-${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}" -} \ No newline at end of file + Diy_Part3_Base +} diff --git a/Scripts/AutoBuild_Function.sh b/Scripts/AutoBuild_Function.sh index 470a215..eb56cf2 100644 --- a/Scripts/AutoBuild_Function.sh +++ b/Scripts/AutoBuild_Function.sh @@ -16,6 +16,65 @@ GET_TARGET_INFO() { [ -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) + Github_Repo="$(grep "https://github.com/[a-zA-Z0-9]" ${GITHUB_WORKSPACE}/.git/config | cut -c8-100)" +} + +Diy_Part1_Base() { + Mkdir package/lean + if [ ${INCLUDE_Latest_Ray} == true ];then + Update_Makefile xray package/lean/xray + Update_Makefile v2ray package/lean/v2ray + Update_Makefile v2ray-plugin package/lean/v2ray-plugin + fi + if [ ${INCLUDE_SSR_Plus} == true ];then + ExtraPackages git lean helloworld https://github.com/fw876 master + sed -i 's/143/143,25,5222/' package/lean/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr + fi + Replace_File Scripts/AutoBuild_Tools.sh package/base-files/files/bin +} + + +Diy_Part2_Base() { + GET_TARGET_INFO + if [ ${INCLUDE_AutoUpdate} == true ];then + Replace_File Scripts/AutoUpdate.sh package/base-files/files/bin + ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main + sed -i '/luci-app-autoupdate/d' .config > /dev/null 2>&1 + echo "CONFIG_PACKAGE_luci-app-autoupdate=y" >> .config + fi + + echo "Author: ${Author}" + echo "Openwrt Version: ${Openwrt_Version}" + echo "AutoUpdate Version: ${AutoUpdate_Version}" + echo "Router: ${TARGET_PROFILE}" + echo "Github: ${Github_Repo}" + [ -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 + echo "${Github_Repo}" >> package/base-files/files/etc/openwrt_info + echo "${TARGET_PROFILE}" >> 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_Base() { + GET_TARGET_INFO + Default_Firmware="openwrt-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}-squashfs-sysupgrade.bin" + AutoBuild_Firmware="AutoBuild-${TARGET_PROFILE}-${Openwrt_Version}.bin" + AutoBuild_Detail="AutoBuild-${TARGET_PROFILE}-${Openwrt_Version}.detail" + Mkdir 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}" +} + +Mkdir() { + _DIR=${1} + if [ ! -d "${_DIR}" ];then + echo "[$(date "+%H:%M:%S")] Creating new folder [${_DIR}] ..." + mkdir -p ${_DIR} + fi + unset _DIR } ExtraPackages() { @@ -25,7 +84,7 @@ ExtraPackages() { REPO_URL=${4} REPO_BRANCH=${5} - [ -d "package/${PKG_DIR}" ] && mkdir -p package/${PKG_DIR} + Mkdir 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 @@ -34,14 +93,24 @@ ExtraPackages() { echo "[$(date "+%H:%M:%S")] Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..." case "${PKG_PROTO}" in git) + + if [[ -z "${REPO_BRANCH}" ]];then + echo "[$(date "+%H:%M:%S")] Missing important options,skip check out..." + break + fi 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 + ;; + *) + echo "[$(date "+%H:%M:%S")] Wrong option: ${PKG_PROTO} (Can only use git and svn),skip check out..." + break + ;; 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} + mv -f ${PKG_NAME} package/${PKG_DIR} break else [ ${Retry_Times} -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [${PKG_NAME}] ..." && break @@ -51,27 +120,27 @@ ExtraPackages() { sleep 3 fi done + unset PKG_PROTO PKG_DIR PKG_NAME REPO_URL REPO_BRANCH } Replace_File() { FILE_NAME=${1} PATCH_DIR=${GITHUB_WORKSPACE}/openwrt/${2} FILE_RENAME=${3} - [ ! -d "${PATCH_DIR}" ] && mkdir -p "${PATCH_DIR}" - + + Mkdir "${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} ..." + echo "[$(date "+%H:%M:%S")] Moving [${_TYPE2}] ${FILE_NAME} to ${2}/${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 _TYPE1 _TYPE2 + unset FILE_NAME PATCH_DIR FILE_RENAME _RENAME _TYPE1 _TYPE2 } Update_Makefile() { @@ -88,7 +157,7 @@ Update_Makefile() { Source_HASH="$(grep "PKG_HASH:=" ${Makefile} | cut -c11-100)" echo -e "Current ${PKG_NAME} version: ${Source_Version}\nOffical ${PKG_NAME} version: ${Offical_Version}" if [[ ! "${Source_Version}" == "${Offical_Version}" ]];then - echo -e "Update package ${PKG_NAME} [${Source_Version}] to [${Offical_Version}] ..." + echo -e "Updating package ${PKG_NAME} [${Source_Version}] to [${Offical_Version}] ..." sed -i "s?PKG_VERSION:=${Source_Version}?PKG_VERSION:=${Offical_Version}?g" ${Makefile} wget -q "${PKG_DL_URL}${Offical_Version}?" -O /tmp/tmp_file if [[ $? == 0 ]];then