compile.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #/bin/bash
  2. echo
  3. echo
  4. echo "本脚本仅适用于在Ubuntu环境下编译 https://github.com/garypang13/Actions-OpenWrt"
  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 libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler ccache xsltproc rename antlr3 gperf curl screen upx
  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. K2p
  35. 3. K2p 32M
  36. 4. RedMi_AC2100
  37. 5. r2s
  38. 6. r4s
  39. 7. newifi-d2
  40. 8. Rpi-4B
  41. 9. Exit
  42. "
  43. while :; do
  44. read -p "你想要编译哪个固件? " CHOOSE
  45. case $CHOOSE in
  46. 1)
  47. firmware="x86_64"
  48. break
  49. ;;
  50. 2)
  51. firmware="phicomm-k2p"
  52. break
  53. ;;
  54. 3)
  55. firmware="k2p-32m-usb"
  56. break
  57. ;;
  58. 4)
  59. firmware="redmi-ac2100"
  60. break
  61. ;;
  62. 5)
  63. firmware="nanopi-r2s"
  64. break
  65. ;;
  66. 6)
  67. firmware="nanopi-r4s"
  68. break
  69. ;;
  70. 7)
  71. firmware="newifi-d2"
  72. break
  73. ;;
  74. 8)
  75. firmware="Rpi-4B"
  76. break
  77. ;;
  78. 9) exit 0
  79. ;;
  80. esac
  81. done
  82. git clone -b openwrt-21.02 --depth 1 https://github.com/openwrt/openwrt
  83. svn co https://github.com/garypang13/OpenWrt/trunk/devices openwrt/devices
  84. if [[ $firmware =~ (redmi-ac2100|phicomm-k2p|newifi-d2|k2p-32m-usb|XY-C5|xiaomi-r3p) ]]; then
  85. cd openwrt
  86. wget -cO sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/21.02-SNAPSHOT/targets/ramips/mt7621/openwrt-sdk-21.02-SNAPSHOT-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  87. elif [[ $firmware =~ (nanopi-r2s|nanopi-r4s) ]]; then
  88. cd openwrt
  89. wget -cO sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/21.02-SNAPSHOT/targets/rockchip/armv8/openwrt-sdk-21.02-SNAPSHOT-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  90. elif [[ $firmware == "x86_64" ]]; then
  91. cd openwrt
  92. wget -cO sdk.tar.xz https://mirrors.cloud.tencent.com/openwrt/releases/21.02-SNAPSHOT/targets/x86/64/openwrt-sdk-21.02-SNAPSHOT-x86-64_gcc-8.4.0_musl.Linux-x86_64.tar.xz
  93. elif [[ $firmware == "Rpi-4B" ]]; then
  94. cd openwrt
  95. wget -cO 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
  96. fi
  97. read -p "请输入后台地址 [回车默认10.0.0.1]: " ip
  98. ip=${ip:-"10.0.0.1"}
  99. echo "您的后台地址为: $ip"
  100. cp -rf devices/common/* ./
  101. cp -rf devices/$firmware/* ./
  102. ./scripts/feeds update -a
  103. cp -Rf ./diy/* ./
  104. if [ -f "devices/common/diy.sh" ]; then
  105. chmod +x devices/common/diy.sh
  106. /bin/bash "devices/common/diy.sh"
  107. fi
  108. if [ -f "devices/$firmware/diy.sh" ]; then
  109. chmod +x devices/$firmware/diy.sh
  110. /bin/bash "devices/$firmware/diy.sh"
  111. fi
  112. if [ -f "devices/common/default-settings" ]; then
  113. sed -i 's/10.0.0.1/$ip/' devices/common/default-settings
  114. cp -f devices/common/default-settings package/*/*/default-settings/files/uci.defaults
  115. fi
  116. if [ -f "devices/$firmware/default-settings" ]; then
  117. sed -i 's/10.0.0.1/$ip/' devices/$firmware/default-settings
  118. cat -f devices/$firmware/default-settings >> package/*/*/default-settings/files/uci.defaults
  119. fi
  120. if [ -n "$(ls -A "devices/common/patches" 2>/dev/null)" ]; then
  121. find "devices/common/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  122. fi
  123. if [ -n "$(ls -A "devices/$firmware/patches" 2>/dev/null)" ]; then
  124. find "devices/$firmware/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  125. fi
  126. cp devices/common/.config .config
  127. echo >> .config
  128. cat devices/$firmware/.config >> .config
  129. make menuconfig
  130. echo
  131. echo
  132. echo
  133. echo " *****5秒后开始编译*****
  134. 1.你可以随时按Ctrl+C停止编译
  135. 3.大陆用户编译前请准备好梯子,使用大陆白名单或全局模式"
  136. echo
  137. echo
  138. echo
  139. sleep 3s
  140. make -j$(($(nproc)+1)) download -j$(($(nproc)+1)) &
  141. make -j$(($(nproc)+1)) || make -j1 V=s
  142. if [ "$?" == "0" ]; then
  143. echo "
  144. 编译完成~~~
  145. 初始后台地址: $ip
  146. 初始用户名密码: root root
  147. "
  148. fi