make.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2018-2023 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/conf.d/ -p
  48. cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
  49. cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
  50. cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
  51. cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
  52. cp $DOMAIN_BLOCK_LIST $ROOT/root/etc/smartdns/
  53. cp $DOMAIN_FORWARDING_LIST $ROOT/root/etc/smartdns/
  54. cp $CURR_DIR/files/etc $ROOT/root/ -af
  55. cp $SMARTDNS_BIN $ROOT/root/usr/sbin
  56. if [ $? -ne 0 ]; then
  57. echo "copy smartdns file failed."
  58. rm -fr $ROOT/
  59. return 1
  60. fi
  61. chmod +x $ROOT/root/etc/init.d/smartdns
  62. INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
  63. sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
  64. sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
  65. sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
  66. if [ ! -z "$INST_SIZE" ]; then
  67. echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
  68. fi
  69. if [ "$STATIC" = "yes" ]; then
  70. sed -i "s/Depends:.*/Depends: libc/" $ROOT/control/control
  71. fi
  72. cd $ROOT/control
  73. chmod +x *
  74. tar zcf ../control.tar.gz --owner=0 --group=0 ./
  75. cd $ROOT
  76. tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
  77. tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 ./control.tar.gz ./data.tar.gz ./debian-binary
  78. rm -fr $ROOT/
  79. }
  80. main()
  81. {
  82. OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
  83. -n "" -- "$@"`
  84. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  85. # Note the quotes around `$TEMP': they are essential!
  86. eval set -- "$OPTS"
  87. while true; do
  88. case "$1" in
  89. --arch)
  90. ARCH="$2"
  91. shift 2;;
  92. --filearch)
  93. FILEARCH="$2"
  94. shift 2;;
  95. --ver)
  96. VER="$2"
  97. shift 2;;
  98. -o )
  99. OUTPUTDIR="$2"
  100. shift 2;;
  101. -h | --help )
  102. showhelp
  103. return 0
  104. shift ;;
  105. -- ) shift; break ;;
  106. * ) break ;;
  107. esac
  108. done
  109. if [ -z "$ARCH" ]; then
  110. echo "please input arch."
  111. return 1;
  112. fi
  113. if [ -z "$FILEARCH" ]; then
  114. FILEARCH=$ARCH
  115. fi
  116. if [ -z "$OUTPUTDIR" ]; then
  117. OUTPUTDIR=$CURR_DIR;
  118. fi
  119. build
  120. }
  121. main $@
  122. exit $?