diff --git a/.github/workflows/AutoBuild.yml b/.github/workflows/NEWIFI_D2.yml similarity index 94% rename from .github/workflows/AutoBuild.yml rename to .github/workflows/NEWIFI_D2.yml index 93e5f9b..d4a7bb3 100644 --- a/.github/workflows/AutoBuild.yml +++ b/.github/workflows/NEWIFI_D2.yml @@ -6,7 +6,7 @@ # Modify: Hyy2001X #======================================================= -name: AutoBuild +name: AutoBuild-NEWIFI_D2 on: repository_dispatch: @@ -25,12 +25,12 @@ on: env: REPO_URL: https://github.com/coolsnowwolf/lede - CONFIG_FILE: NEWIFI_D2-NIGHTLY.config + CONFIG_FILE: Configs/NEWIFI_D2.config DIY_SCRIPT: Scripts/AutoBuild_DiyScript.sh FUNCTION_SCRIPT: Scripts/AutoBuild_Function.sh UPLOAD_RELEASE: true - UPLOAD_FIRMWARE: true - UPLOAD_BIN_DIR: false + UPLOAD_FIRMWARE: false + UPLOAD_BIN_DIR: true REMOVE_OLD_RELEASE: false REMOVE_WORKFLOW_RUNS: true @@ -96,11 +96,11 @@ jobs: - name: Compile the Openwrt run: | cd openwrt - make -j$(nproc) || make -j1 || make -j1 V=s + make -j$(nproc) || make -j1 V=s - name: Run Diy-Part3 Scripts run: | - echo "## $(date +"%Y%m%d")" > update_log.txt + echo "## $(date +"%Y%m%d")-NEWIFI_D2-NIGHTLY" > update_log.txt cd openwrt source $GITHUB_WORKSPACE/$DIY_SCRIPT source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part3 diff --git a/.github/workflows/x86_64.yml b/.github/workflows/x86_64.yml new file mode 100644 index 0000000..333f355 --- /dev/null +++ b/.github/workflows/x86_64.yml @@ -0,0 +1,167 @@ +#======================================================= +# Description: Build OpenWrt using GitHub Actions +# https://github.com/Hyy2001X/AutoBuild-Actions +# Lisence: MIT +# Author: P3TERX +# Modify: Hyy2001X +#======================================================= + +name: AutoBuild-x86_64 + +on: + repository_dispatch: + workflow_dispatch: + inputs: + ssh: + description: 'SSH connection to Actions' + required: true + default: 'false' + +# schedule: +# - cron: 0 11 * * * + +# watch: +# types: [started] + +env: + REPO_URL: https://github.com/coolsnowwolf/lede + CONFIG_FILE: Configs/x86_64.config + DIY_SCRIPT: Scripts/AutoBuild_DiyScript.sh + FUNCTION_SCRIPT: Scripts/AutoBuild_Function.sh + UPLOAD_RELEASE: true + UPLOAD_FIRMWARE: false + UPLOAD_BIN_DIR: true + REMOVE_OLD_RELEASE: false + REMOVE_WORKFLOW_RUNS: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@main + + - name: Initialization Environment + env: + DEBIAN_FRONTEND: noninteractive + run: | + docker rmi `docker images -q` + echo "Deleting files, please wait ..." + sudo rm -rf \ + /usr/share/dotnet \ + /etc/mysql \ + /etc/php + sudo -E apt-get -y purge \ + azure-cli \ + ghc* \ + zulu* \ + hhvm \ + llvm* \ + firefox \ + google* \ + dotnet* \ + powershell \ + openjdk* \ + mysql* \ + php* + sudo -E apt-get update + sudo -E apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync + sudo -E apt-get -y autoremove --purge + sudo -E apt-get clean + df -h + + - name: Clone Openwrt source code + run: | + git clone -b master $REPO_URL openwrt + ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt + + - name: Run Diy-Part1 Scripts + run: | + chmod +x $DIY_SCRIPT + cd openwrt + source $GITHUB_WORKSPACE/$DIY_SCRIPT + source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part1 + echo "Compile_Date=$(date +%Y%m%d)" > $GITHUB_WORKSPACE/Openwrt.info + echo "Display_Date=$(date +'%Y/%m/%d')" >> $GITHUB_WORKSPACE/Openwrt.info + + - name: Update & Install Feeds + run: | + cd openwrt + ./scripts/feeds update -a + ./scripts/feeds install -a + + - name: Run Diy-Part2 Scripts + run: | + [ -f $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config + cd openwrt + source $GITHUB_WORKSPACE/$DIY_SCRIPT + source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part2 + + - name: SSH connection to Actions + uses: P3TERX/ssh2actions@v1.0.0 + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + + - name: Download Packages + run: | + cd openwrt + make defconfig + make download -j$(nproc) V=s + find dl -size -1024c -exec rm -f {} \; + + - name: Compile the Openwrt + run: | + cd openwrt + make -j$(nproc) || make -j1 V=s + + - name: Run Diy-Part3 Scripts + run: | + echo "## $(date +"%Y%m%d")-x86_64-TEST" > update_log.txt + cd openwrt + source $GITHUB_WORKSPACE/$DIY_SCRIPT + source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && Diy-Part3 + echo "Artifacts_DATE=$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV + df -h + + - name: Upload Firmware to Artifacts + uses: actions/upload-artifact@main + if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() + with: + name: OpenWrt_Firmware_${{ env.Artifacts_DATE }} + path: openwrt/bin/Firmware + + - name: Upload Firmware directory to Artifacts + uses: actions/upload-artifact@main + if: env.UPLOAD_BIN_DIR == 'true' && !cancelled() + with: + name: OpenWrt_bin_${{ env.Artifacts_DATE }} + path: openwrt/bin + + - name: Upload Firmware to Releases + uses: softprops/action-gh-release@v1 + if: env.UPLOAD_RELEASE == 'true' && !cancelled() + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + with: + tag_name: AutoUpdate + body_path: update_log.txt + files: openwrt/bin/Firmware/* + + - name: Remove old Releases + uses: dev-drprasad/delete-older-releases@v0.1.0 + if: env.REMOVE_OLD_RELEASE == 'true' && !cancelled() + with: + keep_latest: 3 + delete_tags: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Remove workflow runs + uses: GitRML/delete-workflow-runs@main + if: env.REMOVE_WORKFLOW_RUNS == 'true' && !cancelled() + with: + retain_days: 1 + keep_minimum_runs: 3 diff --git a/NEWIFI_D2-NIGHTLY.config b/Configs/NEWIFI_D2-NIGHTLY.config similarity index 100% rename from NEWIFI_D2-NIGHTLY.config rename to Configs/NEWIFI_D2-NIGHTLY.config diff --git a/Configs/x86_64.config b/Configs/x86_64.config new file mode 100644 index 0000000..3e67b3b --- /dev/null +++ b/Configs/x86_64.config @@ -0,0 +1,131 @@ +CONFIG_TARGET_x86=y +CONFIG_TARGET_x86_64=y +CONFIG_TARGET_x86_64_DEVICE_generic=y +CONFIG_GRUB_TITLE="AutoBuild Firmware Compiled by Hyy2001" +# CONFIG_VMDK_IMAGES is not set +CONFIG_TARGET_KERNEL_PARTSIZE=16 +CONFIG_TARGET_ROOTFS_PARTSIZE=350 +# CONFIG_GRUB_CONSOLE is not set +CONFIG_TARGET_IMAGES_GZIP=y + +# CONFIG_PACKAGE_kmod-mmc-spi is not set +# CONFIG_PACKAGE_kmod-8139cp is not set +# CONFIG_PACKAGE_kmod-8139too is not set +# CONFIG_PACKAGE_kmod-bnx2 is not set +# CONFIG_PACKAGE_kmod-mlx4-core is not set +# CONFIG_PACKAGE_kmod-mlx5-core is not set +# CONFIG_PACKAGE_kmod-ath10k is not set +# CONFIG_PACKAGE_kmod-ath5k is not set +# CONFIG_PACKAGE_kmod-ath9k is not set +# CONFIG_PACKAGE_kmod-ath9k-htc is not set +# CONFIG_PACKAGE_kmod-rt2800-usb is not set +# CONFIG_PACKAGE_ath10k-firmware-qca9888 is not set +# CONFIG_PACKAGE_ath10k-firmware-qca988x is not set +# CONFIG_PACKAGE_ath10k-firmware-qca9984 is not set +# CONFIG_PACKAGE_brcmfmac-firmware-43602a1-pcie is not set + +CONFIG_PACKAGE_kmod-usb-net=y +CONFIG_PACKAGE_kmod-usb-net-rndis=y +CONFIG_PACKAGE_kmod-usb-net-cdc-ether=y +CONFIG_PACKAGE_kmod-usb-net-ipheth=y +CONFIG_PACKAGE_kmod-usb-net-kaweth=y +CONFIG_PACKAGE_kmod-usb-ehci=y +CONFIG_PACKAGE_kmod-usb-uhci=y +CONFIG_PACKAGE_kmod-usb-ohci=y +CONFIG_PACKAGE_kmod-usb2=y +CONFIG_PACKAGE_kmod-usb3=y + +# CONFIG_PACKAGE_luci-app-adbyby-plus is not set +# CONFIG_PACKAGE_luci-app-accesscontrol is not set +CONFIG_PACKAGE_luci-app-adguardhome=y +CONFIG_PACKAGE_luci-app-argon-config=y +# CONFIG_PACKAGE_luci-app-aria2 is not set +CONFIG_PACKAGE_luci-app-arpbind=y +# CONFIG_PACKAGE_luci-app-baidupcs-web is not set +CONFIG_PACKAGE_luci-app-cifs-mount=y +CONFIG_PACKAGE_luci-app-diskman=y +CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs=y +CONFIG_PACKAGE_luci-app-diskman_INCLUDE_kmod_md_linear=y +CONFIG_PACKAGE_luci-app-diskman_INCLUDE_kmod_md_raid456=y +CONFIG_PACKAGE_luci-app-diskman_INCLUDE_lsblk=y +CONFIG_PACKAGE_luci-app-diskman_INCLUDE_mdadm=y +CONFIG_PACKAGE_luci-app-docker=y +CONFIG_PACKAGE_luci-app-hd-idle=y +# CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set +# CONFIG_PACKAGE_luci-app-kodexplorer is not set +CONFIG_PACKAGE_luci-app-mwan3=y +CONFIG_PACKAGE_luci-app-mwan3helper=y +CONFIG_PACKAGE_luci-app-netdata=y +CONFIG_PACKAGE_luci-app-nfs=y +CONFIG_PACKAGE_luci-app-openclash=y +CONFIG_PACKAGE_luci-app-qbittorrent=y +# CONFIG_PACKAGE_luci-app-rclone is not set +# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_fuse-utils is not set +# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-ng is not set +# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-webui is not set +CONFIG_PACKAGE_luci-app-serverchan=y +CONFIG_PACKAGE_luci-app-smartdns=y +CONFIG_PACKAGE_luci-app-samba=y +CONFIG_PACKAGE_luci-app-socat=y +CONFIG_SOCAT_SSL=y +# CONFIG_PACKAGE_luci-app-softethervpn is not set +CONFIG_PACKAGE_luci-app-sqm=y +CONFIG_PACKAGE_luci-app-shutdown=y + +CONFIG_PACKAGE_luci-app-passwall=y +CONFIG_PACKAGE_luci-app-ssr-plus=y +CONFIG_PACKAGE_luci-app-syncdial=y +# CONFIG_PACKAGE_luci-app-transmission is not set +CONFIG_PACKAGE_luci-app-ttyd=y +CONFIG_PACKAGE_luci-app-uhttpd=y +CONFIG_PACKAGE_luci-app-usb-printer=y +# CONFIG_PACKAGE_luci-app-uugamebooster is not set +# CONFIG_PACKAGE_luci-app-v2ray-server is not set +# CONFIG_PACKAGE_luci-app-verysync is not set +# CONFIG_PACKAGE_luci-app-xlnetacc is not set +CONFIG_PACKAGE_luci-app-wireguard=y +CONFIG_PACKAGE_luci-app-wrtbwmon=y +CONFIG_PACKAGE_luci-app-zerotier=y + +CONFIG_PACKAGE_luci-ssl-openssl=y +CONFIG_PACKAGE_luci-theme-argon=y +CONFIG_PACKAGE_luci-theme-netgear=y + +# CONFIG_PACKAGE_autosamba is not set +# CONFIG_PACKAGE_ariang is not set +CONFIG_PACKAGE_bash=y +CONFIG_PACKAGE_curl=y +CONFIG_PACKAGE_cfdisk=y +CONFIG_PACKAGE_dnsmasq-full=y +CONFIG_PACKAGE_dnsmasq_full_dhcp=y +CONFIG_PACKAGE_ddns-scripts_aliyun=y +CONFIG_PACKAGE_ddns-scripts_dnspod=y +CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4=y +CONFIG_PACKAGE_ddns-scripts_freedns_42_pl=y +CONFIG_PACKAGE_ddns-scripts_godaddy.com-v1=y +CONFIG_PACKAGE_ddns-scripts_no-ip_com=y +CONFIG_PACKAGE_ddns-scripts_nsupdate=y +CONFIG_PACKAGE_ddns-scripts_route53-v1=y +CONFIG_PACKAGE_e2fsprogs=y +CONFIG_PACKAGE_git=y +CONFIG_PACKAGE_git-http=y +CONFIG_PACKAGE_gzip=y +CONFIG_PACKAGE_httping=y +CONFIG_PACKAGE_iperf3=y +CONFIG_PACKAGE_libudev-fbsd=y +CONFIG_PACKAGE_pciutils=y +CONFIG_PACKAGE_ppp-mod-pppol2tp=y +CONFIG_PACKAGE_ppp-mod-pptp=y +CONFIG_PACKAGE_tcpping=y +CONFIG_PACKAGE_unzip=y +CONFIG_PACKAGE_usbutils=y +CONFIG_PACKAGE_open-vm-tools=y +CONFIG_PACKAGE_wget=y +# CONFIG_PACKAGE_hostapd is not set +# CONFIG_PACKAGE_wpad is not set +CONFIG_PACKAGE_xz=y +CONFIG_PACKAGE_xz-utils=y +# CONFIG_UnblockNeteaseMusic_NodeJS is not set +# CONFIG_v2ray-plugin_INCLUDE_GOPROXY is not set +# CONFIG_XRAY_CORE_COMPRESS_GOPROXY is not set +# CONFIG_UnblockNeteaseMusicGo_INCLUDE_GOPROXY is not set diff --git a/Scripts/AutoBuild_DiyScript.sh b/Scripts/AutoBuild_DiyScript.sh index ccc7a62..f5593ff 100644 --- a/Scripts/AutoBuild_DiyScript.sh +++ b/Scripts/AutoBuild_DiyScript.sh @@ -14,7 +14,7 @@ Diy_Core() { INCLUDE_Enable_FirewallPort_53=true INCLUDE_SSR_Plus=true - INCLUDE_Passwall=false + INCLUDE_Passwall=true INCLUDE_HelloWorld=false INCLUDE_Bypass=false INCLUDE_OpenClash=true @@ -22,27 +22,21 @@ Diy_Core() { Diy-Part1() { Diy_Part1_Base - + if [ "${Default_Device}" == "d-team_newifi-d2" ];then Replace_File Customize/system_newifi-d2 package/base-files/files/etc/config system else Replace_File Customize/system_common package/base-files/files/etc/config system fi - + Update_Makefile exfat package/kernel/exfat - # Replace_File Customize/mt76-20210127.mk package/kernel/mt76 Makefile - # rm -rf package/kernel/mt76/patches - - # 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-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 git other luci-app-shutdown https://github.com/Hyy2001X master ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t ExtraPackages git other luci-app-serverchan https://github.com/tty228 master ExtraPackages svn other luci-app-socat https://github.com/Lienol/openwrt-package/trunk diff --git a/Scripts/AutoBuild_Function.sh b/Scripts/AutoBuild_Function.sh index ca0197c..60743d7 100644 --- a/Scripts/AutoBuild_Function.sh +++ b/Scripts/AutoBuild_Function.sh @@ -4,23 +4,44 @@ # AutoBuild Functions GET_TARGET_INFO() { + Home=${GITHUB_WORKSPACE}/openwrt + echo "Home Path: ${Home}" [ -f ${GITHUB_WORKSPACE}/Openwrt.info ] && . ${GITHUB_WORKSPACE}/Openwrt.info 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="Unknown" + [[ -z ${Lede_Version} ]] && Lede_Version="Openwrt" Openwrt_Version="${Lede_Version}-${Compile_Date}" - TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')" + x86_Test="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_(.*)=y/\1/')" + if [[ "${x86_Test}" == "x86_64" ]];then + TARGET_PROFILE="x86_64" + else + TARGET_PROFILE="$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')" + fi [[ -z "${TARGET_PROFILE}" ]] && TARGET_PROFILE="${Default_Device}" + case "${TARGET_PROFILE}" in + x86_64) + grep "CONFIG_TARGET_IMAGES_GZIP=y" ${Home}/.config + if [[ ! $? -ne 0 ]];then + Firmware_sfx="img.gz" + else + Firmware_sfx="img" + fi + ;; + *) + Firmware_sfx="bin" + ;; + esac 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)" + AutoBuild_Info=${GITHUB_WORKSPACE}/openwrt/package/base-files/files/etc/openwrt_info } Diy_Part1_Base() { Diy_Core Mkdir package/lean - [ -f "${GITHUB_WORKSPACE}/Customize/banner" ] && Replace_File Customize/banner package/base-files/files/etc - [ -f "${GITHUB_WORKSPACE}/Customize/mac80211.sh" ] && Replace_File Customize/mac80211.sh package/kernel/mac80211/files/lib/wifi + Replace_File Customize/banner package/base-files/files/etc + Replace_File Customize/mac80211.sh package/kernel/mac80211/files/lib/wifi 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 @@ -56,6 +77,9 @@ Diy_Part1_Base() { Diy_Part2_Base() { Diy_Core GET_TARGET_INFO + Replace_File Customize/uhttpd.po feeds/luci/applications/luci-app-uhttpd/po/zh-cn + Replace_File Customize/webadmin.po package/lean/luci-app-webadmin/po/zh-cn + Replace_File Customize/mwan3.config package/feeds/packages/mwan3/files/etc/config mwan3 if [[ "${INCLUDE_Enable_FirewallPort_53}" == "true" ]];then [ -f "${Default_File}" ] && sed -i "s?iptables?#iptables?g" ${Default_File} > /dev/null 2>&1 fi @@ -71,32 +95,61 @@ Diy_Part2_Base() { else sed -i "s?Openwrt?Openwrt ${Openwrt_Version}?g" package/base-files/files/etc/banner fi - Replace_File Customize/uhttpd.po feeds/luci/applications/luci-app-uhttpd/po/zh-cn - Replace_File Customize/webadmin.po package/lean/luci-app-webadmin/po/zh-cn [[ -z "${Author}" ]] && Author="Unknown" echo "Author: ${Author}" echo "Openwrt Version: ${Openwrt_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 - [ -f "${GITHUB_WORKSPACE}/Customize/mwan3.config" ] && Replace_File Customize/mwan3.config package/feeds/packages/mwan3/files/etc/config mwan3 + echo "${Openwrt_Version}" > ${AutoBuild_Info} + echo "${Github_Repo}" >> ${AutoBuild_Info} + echo "${TARGET_PROFILE}" >> ${AutoBuild_Info} + echo "Firmware Type: ${Firmware_sfx}" + echo "Writting Type: ${Firmware_sfx} to ${AutoBuild_Info} ..." + echo "${Firmware_sfx}" >> ${AutoBuild_Info} + } Diy_Part3_Base() { Diy_Core 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" + Firmware_Path="bin/targets/${TARGET_BOARD}/${TARGET_SUBTARGET}" 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}" + case "${TARGET_PROFILE}" in + x86_64) + cd ${Firmware_Path} + Firmware=openwrt-${TARGET_BOARD}-${TARGET_SUBTARGET}-generic-squashfs-combined + AutoBuild_Firmware="AutoBuild-${TARGET_PROFILE}-${Openwrt_Version}" + if [ -f "${Firmware}${Firmware_sfx}" ];then + _MD5=$(md5sum ${Firmware}${Firmware_sfx} | cut -d ' ' -f1) + _SHA256=$(sha256sum ${Firmware}${Firmware_sfx} | cut -d ' ' -f1) + touch ${Home}/bin/Firmware/${AutoBuild_Firmware}.detail + echo -e "\nMD5:${_MD5}\nSHA256:${_SHA256}" > ${Home}/bin/Firmware/${AutoBuild_Firmware}-Legacy.detail + mv -f ${Firmware}.${Firmware_sfx} ${Home}/bin/Firmware/${AutoBuild_Firmware}-Legacy${Firmware_sfx} + echo "Legacy Firmware is detected !" + fi + if [ -f "${Firmware}-efi${Firmware_sfx}" ];then + _MD5=$(md5sum ${Firmware}-efi${Firmware_sfx} | cut -d ' ' -f1) + _SHA256=$(sha256sum ${Firmware}-efi${Firmware_sfx} | cut -d ' ' -f1) + touch ${Home}/bin/Firmware/${AutoBuild_Firmware}.detail + echo -e "\nMD5:${_MD5}\nSHA256:${_SHA256}" > ${Home}/bin/Firmware/${AutoBuild_Firmware}-UEFI.detail + cp ${Firmware}-efi.${Firmware_sfx} ${Home}/bin/Firmware/${AutoBuild_Firmware}-UEFI${Firmware_sfx} + echo "UEFI Firmware is detected !" + fi + ;; + *) + cd ${Home} + Default_Firmware="openwrt-${TARGET_BOARD}-${TARGET_SUBTARGET}-${TARGET_PROFILE}-squashfs-sysupgrade.${Firmware_sfx}" + AutoBuild_Firmware="AutoBuild-${TARGET_PROFILE}-${Openwrt_Version}.${Firmware_sfx}" + AutoBuild_Detail="AutoBuild-${TARGET_PROFILE}-${Openwrt_Version}.detail" + echo "Firmware: ${AutoBuild_Firmware}" + mv -f ${Firmware_Path}/${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} + ;; + esac + cd ${Home} } Mkdir() { @@ -211,4 +264,4 @@ Update_Makefile() { echo "Package ${PKG_NAME} is not detected,skip update ..." fi unset _process1 _process2 Offical_Version Source_Version -} +} \ No newline at end of file diff --git a/Scripts/AutoUpdate.sh b/Scripts/AutoUpdate.sh index 87b105f..bf0c1b5 100644 --- a/Scripts/AutoUpdate.sh +++ b/Scripts/AutoUpdate.sh @@ -3,18 +3,71 @@ # AutoBuild Module by Hyy2001 # AutoUpdate for Openwrt -Version=V5.0 +Version=V5.1 TIME() { echo -ne "\n[$(date "+%H:%M:%S")] " } +Install_Pkg() { + PKG_NAME=${1} + grep "${PKG_NAME}" /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 "未安装[${PKG_NAME}],是否执行安装?[Y/n]:" Choose + fi + if [[ "${Choose}" == Y ]] || [[ "${Choose}" == y ]];then + TIME && echo -e "开始安装[${PKG_NAME}],请耐心等待...\n" + opkg update > /dev/null 2>&1 + opkg install ${PKG_NAME} + if [[ $? -ne 0 ]];then + TIME && echo "[${PKG_NAME}] 安装失败,请尝试手动安装!" + exit + else + TIME && echo "[${PKG_NAME}] 安装成功!" + fi + else + TIME && echo "用户已取消安装,即将退出更新脚本..." + sleep 2 + exit + fi + fi +} + +opkg list | awk '{print $1}' > /tmp/Package_list Input_Option="$1" Input_Other="$2" CURRENT_Version="$(awk 'NR==1' /etc/openwrt_info)" Github="$(awk 'NR==2' /etc/openwrt_info)" DEFAULT_Device="$(awk 'NR==3' /etc/openwrt_info)" -CURRENT_Device="$(jsonfilter -e '@.model.id' < /etc/board.json | tr ',' '_')" +Firmware_Type="$(awk 'NR==4' /etc/openwrt_info)" +case ${DEFAULT_Device} in +x86_64) + [[ -z ${Firmware_Type} ]] && Firmware_Type="img" + if [[ "${Firmware_Type}" == "img.gz" ]];then + Compressed_x86="1" + else + Compressed_x86="0" + fi + if [ -d /sys/firmware/efi ];then + EFI_Boot="1" + BOOT_Type="-UEFI" + else + EFI_Boot="0" + BOOT_Type="-Legacy" + fi + Firmware_SFX="${BOOT_Type}.${Firmware_Type}" + Firmware_Detail="${BOOT_Type}.detail" + CURRENT_Device="x86_64" +;; +*) + CURRENT_Device="$(jsonfilter -e '@.model.id' < /etc/board.json | tr ',' '_')" + Firmware_SFX=".${Firmware_Type}" + [[ -z ${Firmware_SFX} ]] && Firmware_SFX="bin" + Firmware_Detail=".detail" +esac Github_Download="${Github}/releases/download/AutoUpdate" Author="${Github##*com/}" Github_Tags="https://api.github.com/repos/${Author}/releases/latest" @@ -46,10 +99,10 @@ if [ ! -z "${Check_Disk}" ];then fi else Disk_Number="0" + Disk_Available="0" Download_Path="/tmp" fi [ ! -d "${Download_Path}/Downloads" ] && mkdir -p ${Download_Path}/Downloads - cd /etc clear && echo "Openwrt-AutoUpdate Script ${Version}" if [[ -z "${Input_Option}" ]];then @@ -108,6 +161,11 @@ else echo "固件下载地址: ${Github_Download}" echo "API地址: ${Github_Tags}" echo "作者/仓库: ${Author}" + if [[ ${DEFAULT_Device} == "x86_64" ]];then + echo "EFI 引导: ${EFI_Boot}" + echo "gz 压缩: ${Compressed_x86}" + fi + echo "固件格式: ${Firmware_SFX}" exit ;; *) @@ -130,7 +188,6 @@ else 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 @@ -138,23 +195,7 @@ if [[ ! "${Force_Update}" == "1" ]] && [[ ! "${AutoUpdate_Mode}" == "1" ]];then [ ! "$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 +Install_Pkg wget if [[ -z "${CURRENT_Version}" ]];then TIME && echo "警告: 当前固件版本获取失败!" CURRENT_Version="未知" @@ -167,6 +208,10 @@ fi TIME && echo "正在检查版本更新..." [ ! -f /tmp/Github_Tags ] && touch /tmp/Github_Tags wget -q ${Github_Tags} -O - > /tmp/Github_Tags +if [[ ! "$?" == 0 ]];then + TIME && echo "检查更新失败,请稍后重试!" + exit +fi if [[ ${Stable_Mode} == 1 ]];then GET_Version_Type="-Stable" else @@ -180,8 +225,10 @@ if [[ -z "${GET_FullVersion}" ]] || [[ -z "${GET_Version}" ]];then fi echo -e "\n固件作者: ${Author%/*}" echo "设备名称: ${DEFAULT_Device}" +echo "固件格式: ${Firmware_SFX}" echo -e "\n当前固件版本: ${CURRENT_Version}" echo "云端固件版本: ${GET_Version}" +[[ -z "${Firmware_Type}" ]] && TIME && echo "[固件格式] 获取失败!" && exit Check_Stable_Version=$(echo ${GET_Version} | egrep -o "R[0-9]+.[0-9]+.[0-9]+.[0-9]+") if [[ ! ${Force_Update} == 1 ]];then if [[ "${CURRENT_Version}" == "${Check_Stable_Version}" ]];then @@ -197,8 +244,8 @@ if [[ ! ${Force_Update} == 1 ]];then fi fi Firmware_Info="${GET_FullVersion}" -Firmware="${Firmware_Info}.bin" -Firmware_Detail="${Firmware_Info}.detail" +Firmware="${Firmware_Info}${Firmware_SFX}" +Firmware_Detail="${Firmware_Info}${Firmware_Detail}" echo -e "\n云端固件名称: ${Firmware}" echo "固件下载地址: ${Github_Download}" cd ${Download_Path}/Downloads @@ -221,15 +268,32 @@ 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 获取失败!" + TIME && echo -e "MD5 获取失败!" exit fi if [[ ! "${GET_MD5}" == "${CURRENT_MD5}" ]];then - echo -e "\nMD5 对比失败,请检查网络后重试!" + TIME && echo -e "MD5 对比失败,请检查网络后重试!" exit else TIME && echo -e "MD5 对比通过!" fi +if [[ ${Compressed_x86} == "1" ]];then + TIME && echo "检测到固件为 [.gz] 压缩格式,开始解压固件..." + Install_Pkg gzip + Firmware="${Firmware_Info}${BOOT_Type}.img" + rm -f ${Firmware} > /dev/null 2>&1 + gzip -dk ${Firmware} > /dev/null 2>&1 + if [ -f "${Firmware}" ];then + TIME && echo "固件解压成功,固件名称: ${Firmware}" + else + TIME && echo "固件解压失败,请检查相关信息!" + exit + fi +fi TIME && echo -e "开始更新固件,请耐心等待路由器重启...\n" sleep 3 -sysupgrade ${Upgrade_Options} ${Firmware} \ No newline at end of file +sysupgrade ${Upgrade_Options} ${Firmware} +if [[ $? -ne 0 ]];then + TIME && echo "固件刷写失败,请尝试不保留配置[-n]或手动下载固件!" + exit +fi \ No newline at end of file