make.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. 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. sed -i "s/Version:.*/Version: $VER/" $ROOT/DEBIAN/control
  43. sed -i "s/Architecture:.*/Architecture: $ARCH/" $ROOT/DEBIAN/control
  44. chmod 0755 $ROOT/DEBIAN/prerm
  45. cp $SMARTDNS_DIR/etc/smartdns/smartdns.conf $ROOT/etc/smartdns/
  46. cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/
  47. cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/
  48. cp $SMARTDNS_DIR/src/smartdns $ROOT/usr/sbin
  49. if [ $? -ne 0 ]; then
  50. echo "copy smartdns file failed."
  51. return 1
  52. fi
  53. chmod +x $ROOT/usr/sbin/smartdns
  54. dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb
  55. rm -fr $ROOT/
  56. }
  57. main()
  58. {
  59. OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
  60. -n "" -- "$@"`
  61. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  62. # Note the quotes around `$TEMP': they are essential!
  63. eval set -- "$OPTS"
  64. while true; do
  65. case "$1" in
  66. --arch)
  67. ARCH="$2"
  68. shift 2;;
  69. --filearch)
  70. FILEARCH="$2"
  71. shift 2;;
  72. --ver)
  73. VER="$2"
  74. shift 2;;
  75. -o )
  76. OUTPUTDIR="$2"
  77. shift 2;;
  78. -h | --help )
  79. showhelp
  80. return 0
  81. shift ;;
  82. -- ) shift; break ;;
  83. * ) break ;;
  84. esac
  85. done
  86. if [ -z "$ARCH" ]; then
  87. echo "please input arch."
  88. return 1;
  89. fi
  90. if [ -z "$FILEARCH" ]; then
  91. FILEARCH=$ARCH
  92. fi
  93. if [ -z "$OUTPUTDIR" ]; then
  94. OUTPUTDIR=$CURR_DIR;
  95. fi
  96. build
  97. }
  98. main $@
  99. exit $?