make.sh 3.4 KB

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