优化函数、代码

This commit is contained in:
Hyy2001X 2021-01-11 21:44:45 +08:00
parent e838426ecd
commit e8a6205c9f
2 changed files with 86 additions and 38 deletions

View File

@ -6,18 +6,15 @@
Diy_Core() { Diy_Core() {
Author=Hyy2001 Author=Hyy2001
Default_Device=d-team_newifi-d2 Default_Device=d-team_newifi-d2
INCLUDE_AutoUpdate=true
INCLUDE_SSR_Plus=true
INCLUDE_Latest_Ray=true
} }
Diy-Part1() { Diy-Part1() {
# [ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default Diy_Part1_Base
[ ! -d package/lean ] && mkdir -p package/lean
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/mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File Customize/system package/base-files/files/etc/config Replace_File Customize/system package/base-files/files/etc/config
Replace_File Customize/banner package/base-files/files/etc 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 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 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 svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
ExtraPackages git lean helloworld https://github.com/fw876 master 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 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-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
@ -41,28 +37,11 @@ Diy-Part1() {
} }
Diy-Part2() { Diy-Part2() {
GET_TARGET_INFO Diy_Part2_Base
Replace_File Customize/mwan3.config package/feeds/packages/mwan3/files/etc/config mwan3 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 # 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() { Diy-Part3() {
GET_TARGET_INFO Diy_Part3_Base
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}"
}

View File

@ -16,6 +16,65 @@ GET_TARGET_INFO() {
[ -z "${TARGET_PROFILE}" ] && TARGET_PROFILE="${Default_Device}" [ -z "${TARGET_PROFILE}" ] && TARGET_PROFILE="${Default_Device}"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config) TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{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() { ExtraPackages() {
@ -25,7 +84,7 @@ ExtraPackages() {
REPO_URL=${4} REPO_URL=${4}
REPO_BRANCH=${5} 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 "package/${PKG_DIR}/${PKG_NAME}" ] && rm -rf package/${PKG_DIR}/${PKG_NAME}
[ -d "${PKG_NAME}" ] && rm -rf ${PKG_NAME} [ -d "${PKG_NAME}" ] && rm -rf ${PKG_NAME}
Retry_Times=3 Retry_Times=3
@ -34,14 +93,24 @@ ExtraPackages() {
echo "[$(date "+%H:%M:%S")] Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..." echo "[$(date "+%H:%M:%S")] Checking out package [${PKG_NAME}] to package/${PKG_DIR} ..."
case "${PKG_PROTO}" in case "${PKG_PROTO}" in
git) 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 git clone -b ${REPO_BRANCH} ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1
;; ;;
svn) svn)
svn checkout ${REPO_URL}/${PKG_NAME} ${PKG_NAME} > /dev/null 2>&1 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 esac
if [ -f ${PKG_NAME}/Makefile ] || [ -f ${PKG_NAME}/README* ];then if [ -f ${PKG_NAME}/Makefile ] || [ -f ${PKG_NAME}/README* ];then
echo "[$(date "+%H:%M:%S")] Package [${PKG_NAME}] is detected!" echo "[$(date "+%H:%M:%S")] Package [${PKG_NAME}] is detected!"
mv ${PKG_NAME} package/${PKG_DIR} mv -f ${PKG_NAME} package/${PKG_DIR}
break break
else else
[ ${Retry_Times} -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [${PKG_NAME}] ..." && break [ ${Retry_Times} -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [${PKG_NAME}] ..." && break
@ -51,27 +120,27 @@ ExtraPackages() {
sleep 3 sleep 3
fi fi
done done
unset PKG_PROTO PKG_DIR PKG_NAME REPO_URL REPO_BRANCH
} }
Replace_File() { Replace_File() {
FILE_NAME=${1} FILE_NAME=${1}
PATCH_DIR=${GITHUB_WORKSPACE}/openwrt/${2} PATCH_DIR=${GITHUB_WORKSPACE}/openwrt/${2}
FILE_RENAME=${3} FILE_RENAME=${3}
[ ! -d "${PATCH_DIR}" ] && mkdir -p "${PATCH_DIR}"
Mkdir "${PATCH_DIR}"
[ -f "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="f" && _TYPE2="File" [ -f "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="f" && _TYPE2="File"
[ -d "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="d" && _TYPE2="Folder" [ -d "${GITHUB_WORKSPACE}/${FILE_NAME}" ] && _TYPE1="d" && _TYPE2="Folder"
if [ -e "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then if [ -e "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then
[[ ! -z "${FILE_RENAME}" ]] && _RENAME="${FILE_RENAME}" || _RENAME="" [[ ! -z "${FILE_RENAME}" ]] && _RENAME="${FILE_RENAME}" || _RENAME=""
if [ -${_TYPE1} "${GITHUB_WORKSPACE}/${FILE_NAME}" ];then 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} mv -f ${GITHUB_WORKSPACE}/${FILE_NAME} ${PATCH_DIR}/${_RENAME}
else else
echo "[$(date "+%H:%M:%S")] Customize ${_TYPE2} [${FILE_NAME}] is not detected,skip move ..." echo "[$(date "+%H:%M:%S")] Customize ${_TYPE2} [${FILE_NAME}] is not detected,skip move ..."
fi fi
fi fi
unset _RENAME _TYPE1 _TYPE2 unset FILE_NAME PATCH_DIR FILE_RENAME _RENAME _TYPE1 _TYPE2
} }
Update_Makefile() { Update_Makefile() {
@ -88,7 +157,7 @@ Update_Makefile() {
Source_HASH="$(grep "PKG_HASH:=" ${Makefile} | cut -c11-100)" Source_HASH="$(grep "PKG_HASH:=" ${Makefile} | cut -c11-100)"
echo -e "Current ${PKG_NAME} version: ${Source_Version}\nOffical ${PKG_NAME} version: ${Offical_Version}" echo -e "Current ${PKG_NAME} version: ${Source_Version}\nOffical ${PKG_NAME} version: ${Offical_Version}"
if [[ ! "${Source_Version}" == "${Offical_Version}" ]];then 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} sed -i "s?PKG_VERSION:=${Source_Version}?PKG_VERSION:=${Offical_Version}?g" ${Makefile}
wget -q "${PKG_DL_URL}${Offical_Version}?" -O /tmp/tmp_file wget -q "${PKG_DL_URL}${Offical_Version}?" -O /tmp/tmp_file
if [[ $? == 0 ]];then if [[ $? == 0 ]];then