make.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_BIN=$SMARTDNS_DIR/src/smartdns
  21. SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
  22. ADDRESS_CONF=$CURR_DIR/address.conf
  23. BLACKLIST_IP_CONF=$CURR_DIR/blacklist-ip.conf
  24. CUSTOM_CONF=$CURR_DIR/custom.conf
  25. DOMAIN_BLOCK_LIST=$CURR_DIR/domain-block.list
  26. DOMAIN_FORWARDING_LIST=$CURR_DIR/domain-forwarding.list
  27. showhelp()
  28. {
  29. echo "Usage: make [OPTION]"
  30. echo "Options:"
  31. echo " -o output directory."
  32. echo " --arch archtecture."
  33. echo " --ver version."
  34. echo " -h show this message."
  35. }
  36. build()
  37. {
  38. ROOT=/tmp/smartdns-openwrt
  39. rm -fr $ROOT
  40. mkdir -p $ROOT
  41. cp $CURR_DIR/* $ROOT/ -af
  42. cd $ROOT/
  43. mkdir $ROOT/root/usr/sbin -p
  44. mkdir $ROOT/root/etc/init.d -p
  45. mkdir $ROOT/root/etc/smartdns/ -p
  46. mkdir $ROOT/root/etc/smartdns/domain-set/ -p
  47. mkdir $ROOT/root/etc/smartdns/ip-set/ -p
  48. mkdir $ROOT/root/etc/smartdns/conf.d/ -p
  49. mkdir $ROOT/root/etc/smartdns/download/ -p
  50. cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
  51. cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
  52. cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
  53. cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
  54. cp $DOMAIN_BLOCK_LIST $ROOT/root/etc/smartdns/
  55. cp $DOMAIN_FORWARDING_LIST $ROOT/root/etc/smartdns/
  56. cp $CURR_DIR/files/etc $ROOT/root/ -af
  57. cp $SMARTDNS_BIN $ROOT/root/usr/sbin
  58. if [ $? -ne 0 ]; then
  59. echo "copy smartdns file failed."
  60. rm -fr $ROOT/
  61. return 1
  62. fi
  63. chmod +x $ROOT/root/etc/init.d/smartdns
  64. INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
  65. sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
  66. sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
  67. sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
  68. if [ ! -z "$INST_SIZE" ]; then
  69. echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
  70. fi
  71. if [ "$STATIC" = "yes" ]; then
  72. sed -i "s/Depends:.*/Depends: libc/" $ROOT/control/control
  73. fi
  74. cd $ROOT/control
  75. chmod +x *
  76. tar zcf ../control.tar.gz --owner=0 --group=0 ./
  77. cd $ROOT
  78. tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
  79. tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 ./control.tar.gz ./data.tar.gz ./debian-binary
  80. rm -fr $ROOT/
  81. }
  82. main()
  83. {
  84. OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
  85. -n "" -- "$@"`
  86. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  87. # Note the quotes around `$TEMP': they are essential!
  88. eval set -- "$OPTS"
  89. while true; do
  90. case "$1" in
  91. --arch)
  92. ARCH="$2"
  93. shift 2;;
  94. --filearch)
  95. FILEARCH="$2"
  96. shift 2;;
  97. --ver)
  98. VER="$2"
  99. shift 2;;
  100. -o )
  101. OUTPUTDIR="$2"
  102. shift 2;;
  103. -h | --help )
  104. showhelp
  105. return 0
  106. shift ;;
  107. -- ) shift; break ;;
  108. * ) break ;;
  109. esac
  110. done
  111. if [ -z "$ARCH" ]; then
  112. echo "please input arch."
  113. return 1;
  114. fi
  115. if [ -z "$FILEARCH" ]; then
  116. FILEARCH=$ARCH
  117. fi
  118. if [ -z "$OUTPUTDIR" ]; then
  119. OUTPUTDIR=$CURR_DIR;
  120. fi
  121. build
  122. }
  123. main $@
  124. exit $?