recompile.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #/bin/bash
  2. echo
  3. echo
  4. echo "本脚本仅适用于在Ubuntu环境下编译 https://github.com/kiddin9/OpenWrt_x86-r2s-r4s"
  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 export https://github.com/kiddin9/OpenWrt_x86-r2s-r4s/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 == "x86_64" ]; then
  27. firmware="x86_64"
  28. elif [ $firmware == "friendlyarm_nanopi-r2s" ]; then
  29. firmware="nanopi-r2s"
  30. elif [ $firmware == "friendlyarm_nanopi-r4s" ]; then
  31. firmware="nanopi-r4s"
  32. elif [ $firmware == "rpi-4" ]; then
  33. firmware="Rpi-4B"
  34. elif [ $firmware == "d-team_newifi-d2" ]; then
  35. firmware="newifi-d2"
  36. else
  37. echo "无法识别固件类型,请退出"
  38. fi
  39. echo
  40. read -p "请输入后台地址 [回车默认10.0.0.1]: " ip
  41. ip=${ip:-"10.0.0.1"}
  42. echo "您的后台地址为: $ip"
  43. rm -Rf feeds package/feeds common files diy tmp
  44. make clean
  45. [ -f ".config" ] && mv .config .config.bak
  46. cp -rf devices/common/* ./
  47. cp -rf devices/$firmware/* ./
  48. ./scripts/feeds update -a
  49. cp -Rf ./diy/* ./
  50. if [ -f "devices/common/diy.sh" ]; then
  51. chmod +x devices/common/diy.sh
  52. /bin/bash "devices/common/diy.sh"
  53. fi
  54. if [ -f "devices/$firmware/diy.sh" ]; then
  55. chmod +x devices/$firmware/diy.sh
  56. /bin/bash "devices/$firmware/diy.sh"
  57. fi
  58. if [ -f "devices/common/default-settings" ]; then
  59. sed -i 's/10.0.0.1/$ip/' devices/common/default-settings
  60. cp -f devices/common/default-settings package/*/*/default-settings/files/uci.defaults
  61. fi
  62. if [ -f "devices/$firmware/default-settings" ]; then
  63. sed -i 's/10.0.0.1/$ip/' devices/$firmware/default-settings
  64. cat devices/$firmware/default-settings >> package/*/*/default-settings/files/uci.defaults
  65. fi
  66. if [ -n "$(ls -A "devices/common/patches" 2>/dev/null)" ]; then
  67. 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"
  68. fi
  69. if [ -n "$(ls -A "devices/$firmware/patches" 2>/dev/null)" ]; then
  70. 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"
  71. fi
  72. [ -f ".config.bak" ] && cp -f .config.bak .config || {
  73. cp -f devices/common/.config .config
  74. echo >> .config
  75. cat devices/$firmware/.config >> .config
  76. }
  77. [ firmware == "other" ] || {
  78. while true; do
  79. read -p "是否增删插件? [y/N]: " YN
  80. case ${YN:-N} in
  81. [Yy])
  82. make menuconfig
  83. echo ""
  84. ;;
  85. [Nn])
  86. make defconfig
  87. break
  88. ;;
  89. esac
  90. done
  91. }
  92. echo
  93. echo
  94. echo " *****5秒后开始编译*****
  95. 1.你可以随时按Ctrl+C停止编译
  96. 3.大陆用户编译前请准备好梯子,使用大陆白名单或全局模式"
  97. echo
  98. echo
  99. sleep 3s
  100. sed -i 's,$(STAGING_DIR_HOST)/bin/upx,upx,' package/feeds/custom/*/Makefile
  101. make -j$(($(nproc)+1)) download v=s ; make -j$(($(nproc)+1)) || make -j1 V=s
  102. echo "
  103. 编译完成~~~
  104. 初始后台地址: $ip
  105. 初始用户名密码: root root
  106. "