build.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #/bin/bash
  2. echo
  3. echo
  4. echo "本脚本仅适用于在Ubuntu环境下编译 https://github.com/kiddin9/OpenWrt_x86-r2s-r4s"
  5. echo
  6. echo
  7. sleep 2s
  8. sudo apt-get update
  9. sudo apt-get upgrade
  10. sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc-s1 libc6-dev-i386 subversion flex uglifyjs gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils libelf-dev autoconf automake libtool autopoint device-tree-compiler ccache xsltproc rename antlr3 gperf curl screen upx-ucl jq
  11. clear
  12. echo
  13. echo
  14. echo
  15. echo "|*******************************************|"
  16. echo "| |"
  17. echo "| |"
  18. echo "| 基本环境部署完成...... |"
  19. echo "| |"
  20. echo "| |"
  21. echo "|*******************************************|"
  22. echo
  23. echo
  24. if [ "$USER" == "root" ]; then
  25. echo
  26. echo
  27. echo "请勿使用root用户编译,换一个普通用户吧~~"
  28. sleep 3s
  29. exit 0
  30. fi
  31. rm -Rf openwrt
  32. echo "
  33. 1. X86_64
  34. 2. r2s
  35. 3. r4s
  36. 4. Rpi-4B
  37. 5. Exit
  38. "
  39. while :; do
  40. read -p "你想要编译哪个固件? " CHOOSE
  41. case $CHOOSE in
  42. 1)
  43. firmware="x86_64"
  44. break
  45. ;;
  46. 2)
  47. firmware="nanopi-r2s"
  48. break
  49. ;;
  50. 3)
  51. firmware="nanopi-r4s"
  52. break
  53. ;;
  54. 4)
  55. firmware="Rpi-4B"
  56. break
  57. ;;
  58. 5) exit 0
  59. ;;
  60. esac
  61. done
  62. REPO_BRANCH="$(curl -s https://api.github.com/repos/openwrt/openwrt/tags | jq -r '.[].name' | grep v21 | head -n 1 | sed -e 's/v//')"
  63. git clone -b v$REPO_BRANCH https://github.com/openwrt/openwrt
  64. svn export https://github.com/kiddin9/OpenWrt_x86-r2s-r4s/trunk/devices openwrt/devices
  65. cd openwrt
  66. if [[ $firmware == "x86_64" ]]; then
  67. curl -fL -o sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/$REPO_BRANCH/targets/x86/64/openwrt-sdk-$REPO_BRANCH-x86-64_gcc-8.4.0_musl.Linux-x86_64.tar.xz || curl -fL -o sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/x86/64/openwrt-sdk-21.02-SNAPSHOT-x86-64_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  68. elif [[ $firmware == nanopi-* ]]; then
  69. curl -fL -o sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/$REPO_BRANCH/targets/rockchip/armv8/openwrt-sdk-$REPO_BRANCH-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz || curl -fL -o sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/rockchip/armv8/openwrt-sdk-21.02-SNAPSHOT-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  70. elif [[ $firmware == "Rpi-4B" ]]; then
  71. curl -fL -o sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/$REPO_BRANCH/targets/bcm27xx/bcm2711/openwrt-sdk-$REPO_BRANCH-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-x86_64.tar.xz || curl -fL -o sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/bcm27xx/bcm2711/openwrt-sdk-21.02-SNAPSHOT-bcm27xx-bcm2711_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  72. fi
  73. read -p "请输入后台地址 [回车默认10.0.0.1]: " ip
  74. ip=${ip:-"10.0.0.1"}
  75. echo "您的后台地址为: $ip"
  76. cp -rf devices/common/* ./
  77. cp -rf devices/$firmware/* ./
  78. if [ -f "devices/common/diy.sh" ]; then
  79. chmod +x devices/common/diy.sh
  80. /bin/bash "devices/common/diy.sh"
  81. fi
  82. if [ -f "devices/$firmware/diy.sh" ]; then
  83. chmod +x devices/$firmware/diy.sh
  84. /bin/bash "devices/$firmware/diy.sh"
  85. fi
  86. cp -Rf ./diy/* ./
  87. if [ -f "devices/common/default-settings" ]; then
  88. sed -i 's/10.0.0.1/$ip/' package/*/*/my-default-settings/files/uci.defaults
  89. fi
  90. if [ -f "devices/$firmware/default-settings" ]; then
  91. sed -i "s/10.0.0.1/$ip/" devices/$firmware/default-settings
  92. cat devices/$firmware/default-settings >> package/*/*/my-default-settings/files/uci.defaults
  93. fi
  94. if [ -n "$(ls -A "devices/common/patches" 2>/dev/null)" ]; then
  95. find "devices/common/patches" -type f -name '*.patch' ! -name '*.revert.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  96. fi
  97. if [ -n "$(ls -A "devices/$firmware/patches" 2>/dev/null)" ]; then
  98. find "devices/$firmware/patches" -type f -name '*.patch' ! -name '*.revert.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  99. fi
  100. cp devices/common/.config .config
  101. echo >> .config
  102. cat devices/$firmware/.config >> .config
  103. make defconfig
  104. for i in $(make --file=preset_pkg.mk presetpkg); do
  105. sed -i "\$a CONFIG_PACKAGE_$i=y" .config
  106. done
  107. make menuconfig
  108. echo
  109. echo
  110. echo
  111. echo " *****5秒后开始编译*****
  112. 1.你可以随时按Ctrl+C停止编译
  113. 3.大陆用户编译前请准备好梯子,使用大陆白名单或全局模式"
  114. echo
  115. echo
  116. echo
  117. sleep 3s
  118. make -j$(($(nproc)+1)) download -j$(($(nproc)+1)) &
  119. make -j$(($(nproc)+1)) || make -j1 V=s
  120. if [ "$?" == "0" ]; then
  121. echo "
  122. 编译完成~~~
  123. 初始后台地址: $ip
  124. 初始用户名密码: root root
  125. "
  126. fi