make.sh 2.8 KB

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