make.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2018-2025 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_CP=$SMARTDNS_DIR/package/copy-smartdns.sh
  21. SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
  22. IS_BUILD_SMARTDNS_UI=0
  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 " --with-ui build with smartdns-ui plugin."
  31. echo " -h show this message."
  32. }
  33. build()
  34. {
  35. ROOT=/tmp/smartdns-deiban
  36. rm -fr $ROOT
  37. mkdir -p $ROOT
  38. cd $ROOT/
  39. cp $CURR_DIR/DEBIAN $ROOT/ -af
  40. CONTROL=$ROOT/DEBIAN/control
  41. mkdir $ROOT/usr/sbin -p
  42. mkdir $ROOT/etc/smartdns/ -p
  43. mkdir $ROOT/etc/default/ -p
  44. mkdir $ROOT/lib/systemd/system/ -p
  45. pkgver=$(echo ${VER}| sed 's/^1\.//g')
  46. sed -i "s/Version:.*/Version: ${pkgver}/" $ROOT/DEBIAN/control
  47. sed -i "s/Architecture:.*/Architecture: $ARCH/" $ROOT/DEBIAN/control
  48. chmod 0755 $ROOT/DEBIAN/prerm
  49. cp $SMARTDNS_DIR/etc/smartdns/smartdns.conf $ROOT/etc/smartdns/
  50. cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/
  51. cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/
  52. if [ $IS_BUILD_SMARTDNS_UI -eq 1 ]; then
  53. mkdir $ROOT/usr/local/lib/smartdns -p
  54. mkdir $ROOT/usr/share/smartdns/wwwroot -p
  55. cp $SMARTDNS_DIR/plugin/smartdns-ui/target/smartdns_ui.so $ROOT/usr/local/lib/smartdns/smartdns_ui.so -a
  56. if [ $? -ne 0 ]; then
  57. echo "Failed to copy smartdns-ui plugin."
  58. return 1
  59. fi
  60. cp $WORKDIR/smartdns-webui/out/* $ROOT/usr/share/smartdns/wwwroot/ -a
  61. if [ $? -ne 0 ]; then
  62. echo "Failed to copy smartdns-ui plugin."
  63. return 1
  64. fi
  65. else
  66. echo "smartdns-ui plugin not found, skipping copy."
  67. fi
  68. $SMARTDNS_CP $ROOT
  69. if [ $? -ne 0 ]; then
  70. echo "copy smartdns file failed."
  71. return 1
  72. fi
  73. chmod +x $ROOT/usr/sbin/smartdns 2>/dev/null
  74. dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb
  75. rm -fr $ROOT/
  76. }
  77. main()
  78. {
  79. OPTS=`getopt -o o:h --long arch:,ver:,with-ui,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. --with-ui)
  93. IS_BUILD_SMARTDNS_UI=1
  94. shift ;;
  95. --ver)
  96. VER="$2"
  97. shift 2;;
  98. -o )
  99. OUTPUTDIR="$2"
  100. shift 2;;
  101. -h | --help )
  102. showhelp
  103. return 0
  104. shift ;;
  105. -- ) shift; break ;;
  106. * ) break ;;
  107. esac
  108. done
  109. if [ -z "$ARCH" ]; then
  110. echo "please input arch."
  111. return 1;
  112. fi
  113. if [ -z "$FILEARCH" ]; then
  114. FILEARCH=$ARCH
  115. fi
  116. if [ -z "$OUTPUTDIR" ]; then
  117. OUTPUTDIR=$CURR_DIR;
  118. fi
  119. build
  120. }
  121. main $@
  122. exit $?