make.sh 3.1 KB

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