recompile.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #/bin/bash
  2. echo
  3. echo
  4. echo "本脚本仅适用于在Ubuntu环境下编译 https://github.com/garypang13/Actions-OpenWrt"
  5. echo
  6. echo
  7. if [ "$USER" == "root" ]; then
  8. echo
  9. echo
  10. echo "请勿使用root用户编译,换一个普通用户吧~~"
  11. sleep 3s
  12. exit 0
  13. fi
  14. echo
  15. echo
  16. clear
  17. rm -Rf openwrt/common openwrt/files openwrt/devices
  18. svn co https://github.com/garypang13/Actions-OpenWrt/trunk/devices openwrt/devices
  19. cd openwrt
  20. git checkout .
  21. git pull
  22. [ $(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/') == generic ] && {
  23. firmware=$(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_.*=y/\1/')
  24. } || { firmware=$(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
  25. }
  26. if [ $firmware == "xiaomi_redmi-router-ac2100" ]; then
  27. firmware="redmi-ac2100"
  28. elif [ $firmware == "phicomm_k2p" ]; then
  29. firmware="phicomm-k2p"
  30. elif [ $firmware == "x86_64" ]; then
  31. firmware="x86_64"
  32. elif [ $firmware == "friendlyarm_nanopi-r2s" ]; then
  33. firmware="nanopi-r2s"
  34. elif [ $firmware == "friendlyarm_nanopi-r4s" ]; then
  35. firmware="nanopi-r4s"
  36. elif [ $firmware == "rpi-4" ]; then
  37. firmware="Rpi-4B"
  38. elif [ $firmware == "d-team_newifi-d2" ]; then
  39. firmware="newifi-d2"
  40. else
  41. echo "无法识别固件类型,请退出"
  42. fi
  43. echo
  44. read -p "请输入后台地址 [回车默认10.0.0.1]: " ip
  45. ip=${ip:-"10.0.0.1"}
  46. echo "您的后台地址为: $ip"
  47. rm -Rf feeds package/feeds common files diy tmp
  48. make clean
  49. [ -f ".config" ] && mv .config .config.bak
  50. cp -rf devices/common/* ./
  51. cp -rf devices/$firmware/* ./
  52. ./scripts/feeds update -a
  53. cp -Rf ./diy/* ./
  54. if [ -f "devices/common/diy.sh" ]; then
  55. chmod +x devices/common/diy.sh
  56. /bin/bash "devices/common/diy.sh"
  57. fi
  58. if [ -f "devices/$firmware/diy.sh" ]; then
  59. chmod +x devices/$firmware/diy.sh
  60. /bin/bash "devices/$firmware/diy.sh"
  61. fi
  62. if [ -f "devices/common/default-settings" ]; then
  63. sed -i 's/10.0.0.1/$ip/' devices/common/default-settings
  64. cp -f devices/common/default-settings package/*/*/default-settings/files/uci.defaults
  65. fi
  66. if [ -f "devices/$firmware/default-settings" ]; then
  67. sed -i 's/10.0.0.1/$ip/' devices/$firmware/default-settings
  68. cat devices/$firmware/default-settings >> package/*/*/default-settings/files/uci.defaults
  69. fi
  70. if [ -n "$(ls -A "devices/common/patches" 2>/dev/null)" ]; then
  71. find "devices/common/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  72. fi
  73. if [ -n "$(ls -A "devices/$firmware/patches" 2>/dev/null)" ]; then
  74. find "devices/$firmware/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 --forward"
  75. fi
  76. [ -f ".config.bak" ] && cp -f .config.bak .config || {
  77. cp -f devices/common/.config .config
  78. echo >> .config
  79. cat devices/$firmware/.config >> .config
  80. }
  81. [ firmware == "other" ] || {
  82. while true; do
  83. read -p "是否增删插件? [y/N]: " YN
  84. case ${YN:-N} in
  85. [Yy])
  86. make menuconfig
  87. echo ""
  88. ;;
  89. [Nn])
  90. make defconfig
  91. break
  92. ;;
  93. esac
  94. done
  95. }
  96. echo
  97. echo
  98. echo " *****5秒后开始编译*****
  99. 1.你可以随时按Ctrl+C停止编译
  100. 3.大陆用户编译前请准备好梯子,使用大陆白名单或全局模式"
  101. echo
  102. echo
  103. sleep 3s
  104. sed -i 's,$(STAGING_DIR_HOST)/bin/upx,upx,' package/feeds/custom/*/Makefile
  105. make -j$(($(nproc)+1)) download v=s ; make -j$(($(nproc)+1)) || make -j1 V=s
  106. echo "
  107. 编译完成~~~
  108. 初始后台地址: $ip
  109. 初始用户名密码: root root
  110. "