From de568d29ca0cc897f464bdbe11e2eecc6c2b9f62 Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Sun, 15 Nov 2020 01:19:16 +0800 Subject: [PATCH] diy-script: 20201115 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.重构函数 ExtraPackages 代码 2.重命名函数 mv 为 Replace_File 3.恢复 mt76 到旧版本(最新版有问题) 4.更新 ppp 到最新版本 5.优化整体代码 6.尝试修复固件时间不统一的问题 --- Scripts/diy-script.sh | 217 ++++++++++++++++++++---------------------- 1 file changed, 101 insertions(+), 116 deletions(-) diff --git a/Scripts/diy-script.sh b/Scripts/diy-script.sh index 1842978..2bc7029 100644 --- a/Scripts/diy-script.sh +++ b/Scripts/diy-script.sh @@ -6,131 +6,50 @@ Diy_Core() { Author=Hyy2001 Default_Device=d-team_newifi-d2 - -AutoUpdate_Version=`awk 'NR==6' ./package/base-files/files/bin/AutoUpdate.sh | awk -F'[="]+' '/Version/{print $2}'` -Compile_Date=`date +'%Y/%m/%d'` -Compile_Time=`date +'%Y-%m-%d %H:%M:%S'` -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-`date +%Y%m%d`" -} - -GET_TARGET_INFO() { -Diy_Core -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() { -[ -d ./package/lean/$2 ] && rm -rf ./package/lean/$2 -[ -d ./$2 ] && rm -rf ./$2 -Retry_Times=3 -while [ ! -f $2/Makefile ] -do - echo "[$(date "+%H:%M:%S")] Checking out $2 from $3 ..." - case $1 in - git) - git clone -b $4 $3/$2 $2 > /dev/null 2>&1 - ;; - svn) - svn checkout $3/$2 $2 > /dev/null 2>&1 - esac - if [ -f $2/Makefile ] || [ -f $2/README* ];then - echo "[$(date "+%H:%M:%S")] Package $2 is detected!" - case $2 in - OpenClash) - mv -f ./$2/luci-app-openclash ./package/lean - ;; - openwrt-OpenAppFilter) - mv -f ./$2 ./package/lean - ;; - *) - mv -f ./$2 ./package/lean - esac - rm -rf ./$2 > /dev/null 2>&1 - break - else - [ $Retry_Times -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package $1 ..." && break - echo "[$(date "+%H:%M:%S")] [$Retry_Times]Checkout failed,retry in 3s ..." - Retry_Times=$(($Retry_Times - 1)) - rm -rf ./$2 > /dev/null 2>&1 - sleep 3 - fi -done -} - -mv2() { -if [ -f $GITHUB_WORKSPACE/Customize/$1 ];then - echo "[$(date "+%H:%M:%S")] Custom File [$1] is detected!" - if [ -z $2 ];then - Patch_Dir=$GITHUB_WORKSPACE/openwrt - else - Patch_Dir=$GITHUB_WORKSPACE/openwrt/$2 - fi - [ ! -d $Patch_Dir ] && mkdir -p $Patch_Dir - if [ -z $3 ];then - [ -f $Patch_Dir/$1 ] && rm -f $Patch_Dir/$1 > /dev/null 2>&1 - mv -f $GITHUB_WORKSPACE/Customize/$1 $Patch_Dir/$1 - else - [ -f $Patch_Dir/$1 ] && rm -f $Patch_Dir/$3 > /dev/null 2>&1 - mv -f $GITHUB_WORKSPACE/Customize/$1 $Patch_Dir/$3 - fi -else - echo "[$(date "+%H:%M:%S")] Custom File [$1] is not detected!" -fi } Diy-Part1() { [ -f feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default -[ ! -d ./package/lean ] && mkdir ./package/lean +[ ! -d package/lean ] && mkdir package/lean -# mv2 feeds.conf.default -mv2 mac80211.sh package/kernel/mac80211/files/lib/wifi -mv2 system package/base-files/files/etc/config -mv2 AutoUpdate.sh package/base-files/files/bin -mv2 banner package/base-files/files/etc -mv2 mt76.mk package/kernel/mt76 Makefile +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 banner package/base-files/files/etc -# ExtraPackages svn mac80211 https://github.com/openwrt/openwrt/trunk/package/kernel -# rm -rf package/kernel/mac80211 && mv -f package/lean/mac80211 package/kernel -ExtraPackages svn dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services -rm -rf package/network/services/dnsmasq && mv -f package/lean/dnsmasq package/network/services -ExtraPackages svn hostapd https://github.com/openwrt/openwrt/trunk/package/network/services -rm -rf package/network/services/hostapd && mv -f package/lean/hostapd package/network/services -ExtraPackages svn dropbear https://github.com/openwrt/openwrt/trunk/package/network/services -rm -rf package/network/services/dropbear && mv -f package/lean/dropbear package/network/services +ExtraPackages svn network/services dnsmasq 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 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 system opkg https://github.com/openwrt/openwrt/trunk/package/system +#ExtraPackages git kernel mt76 https://github.com/openwrt master -ExtraPackages git luci-app-autoupdate https://github.com/Hyy2001X main -ExtraPackages git luci-theme-argon https://github.com/jerrykuku 18.06 -ExtraPackages git luci-app-argon-config https://github.com/jerrykuku master -ExtraPackages git luci-app-adguardhome https://github.com/Hyy2001X master -ExtraPackages svn luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t -ExtraPackages svn smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t -ExtraPackages git OpenClash https://github.com/vernesong master -ExtraPackages git luci-app-serverchan https://github.com/tty228 master -ExtraPackages svn luci-app-socat https://github.com/xiaorouji/openwrt-package/trunk/lienol -# ExtraPackages git openwrt-upx https://github.com/Hyy2001X master -# ExtraPackages svn luci-app-mentohust https://github.com/project-openwrt/openwrt/trunk/package/ctcgfw -# ExtraPackages svn mentohust https://github.com/project-openwrt/openwrt/trunk/package/ctcgfw -#ExtraPackages svn luci-theme-opentomato https://github.com/kenzok8/openwrt-packages/trunk -#ExtraPackages svn luci-theme-opentomcat https://github.com/kenzok8/openwrt-packages/trunk -# ExtraPackages svn luci-app-adguardhome https://github.com/Lienol/openwrt/trunk/package/diy -# ExtraPackages git luci-app-adguardhome https://github.com/rufengsuixing master -# ExtraPackages git openwrt-OpenAppFilter https://github.com/Lienol 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-app-argon-config https://github.com/jerrykuku master +ExtraPackages git lean luci-app-adguardhome https://github.com/Hyy2001X master +ExtraPackages svn lean luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t +ExtraPackages svn lean smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t +ExtraPackages git lean OpenClash https://github.com/vernesong master +ExtraPackages git lean luci-app-serverchan https://github.com/tty228 master +ExtraPackages svn lean luci-app-socat https://github.com/xiaorouji/openwrt-package/trunk/lienol +# ExtraPackages git lean openwrt-upx https://github.com/Hyy2001X master +# ExtraPackages svn lean luci-app-mentohust https://github.com/project-openwrt/openwrt/trunk/package/ctcgfw +# ExtraPackages svn lean mentohust https://github.com/project-openwrt/openwrt/trunk/package/ctcgfw +# ExtraPackages git lean openwrt-OpenAppFilter https://github.com/Lienol master +# ExtraPackages svn lean AdGuardHome https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t } Diy-Part2() { GET_TARGET_INFO -mv2 mwan3 package/feeds/packages/mwan3/files/etc/config +Replace_File mwan3 package/feeds/packages/mwan3/files/etc/config echo "Author: $Author" -echo "Lede Version: $Openwrt_Version" +echo "Openwrt Version: $Openwrt_Version" echo "AutoUpdate Version: $AutoUpdate_Version" echo "Router: $TARGET_PROFILE" -sed -i "s?$Lede_Version?$Lede_Version Compiled by $Author [$Compile_Date]?g" $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 +sed -i "s?Openwrt?Openwrt $Openwrt_Version / AutoUpdate $AutoUpdate_Version?g" package/base-files/files/etc/banner } Diy-Part3() { @@ -138,13 +57,79 @@ 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 +mkdir -p bin/Firmware echo "Firmware: $AutoBuild_Firmware" -mv ./bin/targets/$TARGET_BOARD/$TARGET_SUBTARGET/$Default_Firmware ./bin/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` +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" -echo "编译日期:$Compile_Time" > ./bin/Firmware/$AutoBuild_Detail -echo -e "\nMD5:$Firmware_MD5\nSHA256:$Firmware_SHA256" >> ./bin/Firmware/$AutoBuild_Detail +touch bin/Firmware/$AutoBuild_Detail +echo -e "\nMD5:$Firmware_MD5\nSHA256:$Firmware_SHA256" >> bin/Firmware/$AutoBuild_Detail +} + +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}') +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/$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] from $REPO_URL ..." + 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")] [$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 $PATCH_DIR +if [ -f $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then + echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is detected!" + if [ -z $FILE_RENAME ];then + [ -f $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$FILE_NAME + mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$1 + else + [ -f $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 }