make.sh 2.6 KB

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