make.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
  23. SMARTDNS_OPT=$CURR_DIR/smartdns-opt.conf
  24. IS_BUILD_SMARTDNS_UI=0
  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 " --with-ui build with smartdns-ui plugin."
  33. echo " -h show this message."
  34. }
  35. build()
  36. {
  37. ROOT=/tmp/smartdns-optware
  38. rm -fr $ROOT
  39. mkdir -p $ROOT
  40. cp $CURR_DIR/* $ROOT/ -af
  41. cd $ROOT/
  42. mkdir $ROOT/opt/usr/sbin -p
  43. mkdir $ROOT/opt/etc/init.d -p
  44. mkdir $ROOT/opt/etc/smartdns/ -p
  45. cp $SMARTDNS_CONF $ROOT/opt/etc/smartdns/
  46. cp $SMARTDNS_OPT $ROOT/opt/etc/smartdns/
  47. cp $CURR_DIR/S50smartdns $ROOT/opt/etc/init.d/
  48. $SMARTDNS_CP $ROOT/opt /opt
  49. if [ $? -ne 0 ]; then
  50. echo "copy smartdns file failed."
  51. rm -fr $PKG_ROOT
  52. return 1
  53. fi
  54. if [ $? -ne 0 ]; then
  55. echo "copy smartdns file failed."
  56. rm -fr $ROOT/
  57. return 1
  58. fi
  59. if [ $IS_BUILD_SMARTDNS_UI -ne 0 ]; then
  60. mkdir $ROOT/opt/usr/lib/smartdns -p
  61. cp $SMARTDNS_DIR/plugin/smartdns-ui/target/smartdns_ui.so $ROOT/opt/usr/lib/smartdns/
  62. if [ $? -ne 0 ]; then
  63. echo "copy smartdns_ui.so file failed."
  64. rm -fr $ROOT/
  65. return 1
  66. fi
  67. mkdir $ROOT/opt/usr/share/smartdns/wwwroot -p
  68. cp $WORKDIR/smartdns-webui/out/* $ROOT/opt/usr/share/smartdns/wwwroot/ -a
  69. if [ $? -ne 0 ]; then
  70. echo "Failed to copy smartdns-ui web files."
  71. rm -fr $ROOT/
  72. return 1
  73. fi
  74. fi
  75. sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf
  76. sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
  77. sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
  78. cd $ROOT/control
  79. chmod +x *
  80. tar zcf ../control.tar.gz --owner=0 --group=0 ./
  81. cd $ROOT
  82. tar zcf data.tar.gz --owner=0 --group=0 opt
  83. tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 control.tar.gz data.tar.gz debian-binary
  84. rm -fr $ROOT/
  85. }
  86. main()
  87. {
  88. OPTS=`getopt -o o:h --long arch:,ver:,with-ui,filearch: \
  89. -n "" -- "$@"`
  90. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  91. # Note the quotes around `$TEMP': they are essential!
  92. eval set -- "$OPTS"
  93. while true; do
  94. case "$1" in
  95. --arch)
  96. ARCH="$2"
  97. shift 2;;
  98. --filearch)
  99. FILEARCH="$2"
  100. shift 2;;
  101. --with-ui)
  102. IS_BUILD_SMARTDNS_UI=1
  103. shift ;;
  104. --ver)
  105. VER="$2"
  106. shift 2;;
  107. -o )
  108. OUTPUTDIR="$2"
  109. shift 2;;
  110. -h | --help )
  111. showhelp
  112. return 0
  113. shift ;;
  114. -- ) shift; break ;;
  115. * ) break ;;
  116. esac
  117. done
  118. if [ -z "$ARCH" ]; then
  119. echo "please input arch."
  120. return 1;
  121. fi
  122. if [ -z "$FILEARCH" ]; then
  123. FILEARCH=$ARCH
  124. fi
  125. if [ -z "$OUTPUTDIR" ]; then
  126. OUTPUTDIR=$CURR_DIR;
  127. fi
  128. build
  129. }
  130. main $@
  131. exit $?