make.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
  4. #
  5. # smartdns is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # smartdns is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. CURR_DIR=$(cd $(dirname $0);pwd)
  18. VER="`date +"1.%Y.%m.%d-%H%M"`"
  19. SMARTDNS_DIR=$CURR_DIR/../../
  20. SMARTDNS_CP=$SMARTDNS_DIR/package/copy-smartdns.sh
  21. SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
  22. SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
  23. ADDRESS_CONF=$CURR_DIR/address.conf
  24. BLACKLIST_IP_CONF=$CURR_DIR/blacklist-ip.conf
  25. CUSTOM_CONF=$CURR_DIR/custom.conf
  26. DOMAIN_BLOCK_LIST=$CURR_DIR/domain-block.list
  27. DOMAIN_FORWARDING_LIST=$CURR_DIR/domain-forwarding.list
  28. IS_BUILD_SMARTDNS_UI=0
  29. showhelp()
  30. {
  31. echo "Usage: make [OPTION]"
  32. echo "Options:"
  33. echo " -o output directory."
  34. echo " --arch archtecture."
  35. echo " --ver version."
  36. echo " --with-ui build with smartdns-ui plugin."
  37. echo " -h show this message."
  38. }
  39. build()
  40. {
  41. ROOT=/tmp/smartdns-openwrt
  42. rm -fr $ROOT
  43. mkdir -p $ROOT
  44. cp $CURR_DIR/* $ROOT/ -af
  45. cd $ROOT/
  46. mkdir $ROOT/root/usr/sbin -p
  47. mkdir $ROOT/root/etc/init.d -p
  48. mkdir $ROOT/root/etc/smartdns/ -p
  49. mkdir $ROOT/root/etc/smartdns/domain-set/ -p
  50. mkdir $ROOT/root/etc/smartdns/ip-set/ -p
  51. mkdir $ROOT/root/etc/smartdns/conf.d/ -p
  52. mkdir $ROOT/root/etc/smartdns/download/ -p
  53. cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
  54. cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
  55. cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
  56. cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
  57. cp $DOMAIN_BLOCK_LIST $ROOT/root/etc/smartdns/
  58. cp $DOMAIN_FORWARDING_LIST $ROOT/root/etc/smartdns/
  59. cp $CURR_DIR/files/etc $ROOT/root/ -af
  60. $SMARTDNS_CP $ROOT/root
  61. if [ $? -ne 0 ]; then
  62. echo "copy smartdns file failed."
  63. rm -fr $ROOT/
  64. return 1
  65. fi
  66. if [ $IS_BUILD_SMARTDNS_UI -ne 0 ]; then
  67. mkdir $ROOT/root/usr/lib/smartdns -p
  68. cp $SMARTDNS_DIR/plugin/smartdns-ui/target/smartdns_ui.so $ROOT/root/usr/lib/smartdns/
  69. if [ $? -ne 0 ]; then
  70. echo "copy smartdns_ui.so file failed."
  71. rm -fr $ROOT/
  72. return 1
  73. fi
  74. mkdir $ROOT/root/usr/share/smartdns/wwwroot -p
  75. cp $WORKDIR/smartdns-webui/out/* $ROOT/root/usr/share/smartdns/wwwroot/ -a
  76. if [ $? -ne 0 ]; then
  77. echo "Failed to copy smartdns-ui web files."
  78. rm -fr $ROOT/
  79. return 1
  80. fi
  81. fi
  82. chmod +x $ROOT/root/etc/init.d/smartdns
  83. INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
  84. sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
  85. sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
  86. sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
  87. if [ ! -z "$INST_SIZE" ]; then
  88. echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
  89. fi
  90. if [ "$STATIC" = "yes" ]; then
  91. sed -i "s/Depends:.*/Depends: libc/" $ROOT/control/control
  92. fi
  93. cd $ROOT/control
  94. chmod +x *
  95. tar zcf ../control.tar.gz --owner=0 --group=0 ./
  96. cd $ROOT
  97. tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
  98. tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 ./control.tar.gz ./data.tar.gz ./debian-binary
  99. rm -fr $ROOT/
  100. }
  101. main()
  102. {
  103. OPTS=`getopt -o o:h --long arch:,ver:,with-ui,filearch: \
  104. -n "" -- "$@"`
  105. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  106. # Note the quotes around `$TEMP': they are essential!
  107. eval set -- "$OPTS"
  108. while true; do
  109. case "$1" in
  110. --arch)
  111. ARCH="$2"
  112. shift 2;;
  113. --filearch)
  114. FILEARCH="$2"
  115. shift 2;;
  116. --with-ui)
  117. IS_BUILD_SMARTDNS_UI=1
  118. shift ;;
  119. --ver)
  120. VER="$2"
  121. shift 2;;
  122. -o )
  123. OUTPUTDIR="$2"
  124. shift 2;;
  125. -h | --help )
  126. showhelp
  127. return 0
  128. shift ;;
  129. -- ) shift; break ;;
  130. * ) break ;;
  131. esac
  132. done
  133. if [ -z "$ARCH" ]; then
  134. echo "please input arch."
  135. return 1;
  136. fi
  137. if [ -z "$FILEARCH" ]; then
  138. FILEARCH=$ARCH
  139. fi
  140. if [ -z "$OUTPUTDIR" ]; then
  141. OUTPUTDIR=$CURR_DIR;
  142. fi
  143. build
  144. }
  145. main $@
  146. exit $?