compile.sh 4.7 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. XY-C5
  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="XY-C5"
  76. break
  77. ;;
  78. 9) exit 0
  79. ;;
  80. esac
  81. done
  82. if [[ $firmware =~ (redmi-ac2100|phicomm-k2p|newifi-d2|k2p-32m-usb|XY-C5|xiaomi-r3p) ]]; then
  83. git clone -b openwrt-21.02 --depth 1 https://github.com/openwrt/openwrt
  84. svn co https://github.com/garypang13/Actions-OpenWrt/trunk/devices openwrt/devices
  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. git clone -b openwrt-21.02 --depth 1 https://github.com/openwrt/openwrt
  89. svn co https://github.com/garypang13/Actions-OpenWrt/trunk/devices openwrt/devices
  90. cd openwrt
  91. 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
  92. elif [[ $firmware == "x86_64" ]]; then
  93. git clone -b openwrt-21.02 --depth 1 https://github.com/openwrt/openwrt
  94. svn co https://github.com/garypang13/Actions-OpenWrt/trunk/devices openwrt/devices
  95. cd openwrt
  96. 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
  97. fi
  98. read -p "请输入后台地址 [回车默认10.0.0.1]: " ip
  99. ip=${ip:-"10.0.0.1"}
  100. echo "您的后台地址为: $ip"
  101. cp -rf devices/common/* ./
  102. cp -rf devices/$firmware/* ./
  103. ./scripts/feeds update -a
  104. cp -Rf ./diy/* ./
  105. if [ -f "devices/common/diy.sh" ]; then
  106. chmod +x devices/common/diy.sh
  107. /bin/bash "devices/common/diy.sh"
  108. fi
  109. if [ -f "devices/$firmware/diy.sh" ]; then
  110. chmod +x devices/$firmware/diy.sh
  111. /bin/bash "devices/$firmware/diy.sh"
  112. fi
  113. if [ -f "devices/common/default-settings" ]; then
  114. sed -i 's/10.0.0.1/$ip/' devices/common/default-settings
  115. cp -f devices/common/default-settings package/*/*/default-settings/files/uci.defaults
  116. fi
  117. if [ -f "devices/$firmware/default-settings" ]; then
  118. sed -i 's/10.0.0.1/$ip/' devices/$firmware/default-settings
  119. cat -f devices/$firmware/default-settings >> package/*/*/default-settings/files/uci.defaults
  120. fi
  121. if [ -n "$(ls -A "devices/common/patches" 2>/dev/null)" ]; then
  122. find "devices/common/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  123. fi
  124. if [ -n "$(ls -A "devices/$firmware/patches" 2>/dev/null)" ]; then
  125. find "devices/$firmware/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  126. fi
  127. cp devices/common/.config .config
  128. echo >> .config
  129. cat devices/$firmware/.config >> .config
  130. make menuconfig
  131. echo
  132. echo
  133. echo
  134. echo " *****5秒后开始编译*****
  135. 1.你可以随时按Ctrl+C停止编译
  136. 3.大陆用户编译前请准备好梯子,使用大陆白名单或全局模式"
  137. echo
  138. echo
  139. echo
  140. sleep 3s
  141. make -j$(($(nproc)+1)) download -j$(($(nproc)+1)) &
  142. make -j$(($(nproc)+1)) || make -j1 V=s
  143. if [ "$?" == "0" ]; then
  144. echo "
  145. 编译完成~~~
  146. 初始后台地址: $ip
  147. 初始用户名密码: root root
  148. "
  149. fi