make.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. PO2LMO=
  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_tool()
  31. {
  32. make -C $ROOT/tool/po2lmo -j
  33. PO2LMO="$ROOT/tool/po2lmo/src/po2lmo"
  34. }
  35. clean_tool()
  36. {
  37. make -C $ROOT/tool/po2lmo clean
  38. }
  39. build()
  40. {
  41. ROOT=/tmp/luci-app-smartdns
  42. rm -fr $ROOT
  43. mkdir -p $ROOT
  44. cp $CURR_DIR/* $ROOT/ -af
  45. cp $CURR_DIR/../tool $ROOT/ -af
  46. cd $ROOT/
  47. build_tool
  48. mkdir $ROOT/root/usr/lib/lua/luci -p
  49. mkdir $ROOT/root/usr/share/rpcd/acl.d/ -p
  50. cp $ROOT/files/luci/i18n $ROOT/root/usr/lib/lua/luci/ -avf
  51. #Generate Language
  52. $PO2LMO $ROOT/files/luci/i18n/smartdns-lite.zh-cn.po $ROOT/root/usr/lib/lua/luci/i18n/smartdns-lite.zh-cn.lmo
  53. rm $ROOT/root/usr/lib/lua/luci/i18n/smartdns-lite.zh-cn.po
  54. chmod +x $ROOT/files/root/etc/init.d/smartdns-lite
  55. cp $ROOT/files/root/* $ROOT/root/ -avf
  56. INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
  57. sed -i "s/^Architecture.*/Architecture: all/g" $ROOT/control/control
  58. sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
  59. if [ ! -z "$INST_SIZE" ]; then
  60. echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
  61. fi
  62. cd $ROOT/control
  63. chmod +x *
  64. tar zcf ../control.tar.gz ./
  65. cd $ROOT
  66. tar zcf $ROOT/data.tar.gz -C root .
  67. tar zcf $OUTPUTDIR/luci-app-smartdns-lite.$VER.$FILEARCH.ipk ./control.tar.gz ./data.tar.gz ./debian-binary
  68. which apk >/dev/null 2>&1
  69. if [ $? -eq 0 ]; then
  70. APK_VER="`echo $VER | sed 's/[-]/-r/'`"
  71. ARCH="`echo $ARCH | sed 's/all/noarch/g'`"
  72. apk mkpkg \
  73. --info "name:luci-app-smartdns-lite" \
  74. --info "version:$APK_VER" \
  75. --info "description:smartdns luci lite" \
  76. --info "arch:$ARCH" \
  77. --info "license:GPL" \
  78. --info "origin: https://github.com/pymumu/smartdns.git" \
  79. --info "depends:libc smartdns" \
  80. --script "post-install:$ROOT/control/postinst" \
  81. --script "pre-deinstall:$ROOT/control/prerm" \
  82. --files "$ROOT/root/" \
  83. --output "$OUTPUTDIR/luci-app-smartdns-lite.$VER.$FILEARCH.apk"
  84. if [ $? -ne 0 ]; then
  85. echo "build apk package failed."
  86. rm -fr $ROOT/
  87. return 1
  88. fi
  89. else
  90. echo "== warning: apk tool not found, skip build apk package. =="
  91. fi
  92. rm -fr $ROOT/
  93. }
  94. main()
  95. {
  96. OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
  97. -n "" -- "$@"`
  98. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  99. # Note the quotes around `$TEMP': they are essential!
  100. eval set -- "$OPTS"
  101. while true; do
  102. case "$1" in
  103. --arch)
  104. ARCH="$2"
  105. shift 2;;
  106. --filearch)
  107. FILEARCH="$2"
  108. shift 2;;
  109. --ver)
  110. VER="$2"
  111. shift 2;;
  112. -o )
  113. OUTPUTDIR="$2"
  114. shift 2;;
  115. -h | --help )
  116. showhelp
  117. return 0
  118. shift ;;
  119. -- ) shift; break ;;
  120. * ) break ;;
  121. esac
  122. done
  123. if [ -z "$ARCH" ]; then
  124. echo "please input arch."
  125. return 1;
  126. fi
  127. if [ -z "$FILEARCH" ]; then
  128. FILEARCH=$ARCH
  129. fi
  130. if [ -z "$OUTPUTDIR" ]; then
  131. OUTPUTDIR=$CURR_DIR;
  132. fi
  133. build
  134. }
  135. main $@
  136. exit $?