make.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. cd $ROOT/control
  70. chmod +x *
  71. tar zcf ../control.tar.gz --owner=0 --group=0 ./
  72. cd $ROOT
  73. tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
  74. tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 ./control.tar.gz ./data.tar.gz ./debian-binary
  75. rm -fr $ROOT/
  76. }
  77. main()
  78. {
  79. OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
  80. -n "" -- "$@"`
  81. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  82. # Note the quotes around `$TEMP': they are essential!
  83. eval set -- "$OPTS"
  84. while true; do
  85. case "$1" in
  86. --arch)
  87. ARCH="$2"
  88. shift 2;;
  89. --filearch)
  90. FILEARCH="$2"
  91. shift 2;;
  92. --ver)
  93. VER="$2"
  94. shift 2;;
  95. -o )
  96. OUTPUTDIR="$2"
  97. shift 2;;
  98. -h | --help )
  99. showhelp
  100. return 0
  101. shift ;;
  102. -- ) shift; break ;;
  103. * ) break ;;
  104. esac
  105. done
  106. if [ -z "$ARCH" ]; then
  107. echo "please input arch."
  108. return 1;
  109. fi
  110. if [ -z "$FILEARCH" ]; then
  111. FILEARCH=$ARCH
  112. fi
  113. if [ -z "$OUTPUTDIR" ]; then
  114. OUTPUTDIR=$CURR_DIR;
  115. fi
  116. build
  117. }
  118. main $@
  119. exit $?