make_min_archive.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. #
  3. # FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  4. # Copyright (C) 2005-2016, Anthony Minessale II <anthm@freeswitch.org>
  5. #
  6. # Version: MPL 1.1
  7. #
  8. # The contents of this file are subject to the Mozilla Public License Version
  9. # 1.1 (the "License"); you may not use this file except in compliance with
  10. # the License. You may obtain a copy of the License at
  11. # http://www.mozilla.org/MPL/F
  12. #
  13. # Software distributed under the License is distributed on an "AS IS" basis,
  14. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. # for the specific language governing rights and limitations under the
  16. # License.
  17. #
  18. # The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  19. #
  20. # The Initial Developer of the Original Code is
  21. # Michael Jerris <mike@jerris.com>
  22. # Portions created by the Initial Developer are Copyright (C)
  23. # the Initial Developer. All Rights Reserved.
  24. #
  25. # Contributor(s):
  26. #
  27. # Sergey Safarov <s.safarov@gmail.com>
  28. #
  29. BUILD_ROOT=/tmp/freeswitch
  30. FILELIST=/tmp/filelist
  31. FILELIST_BINARY=/tmp/filelist_binary
  32. WITHOUT_PERL="true"
  33. WITHOUT_PYTHON="true"
  34. WITHOUT_JAVA="true"
  35. TMP_TAR=/tmp/freeswitch_min.tar.gz
  36. IMG_TAR=/tmp/freeswitch_img.tar.gz
  37. clean_build_root() {
  38. rm -Rf $BUILD_ROOT
  39. mkdir -p $BUILD_ROOT
  40. rm -f $TMP_TAR
  41. rm -f $IMG_TAR
  42. }
  43. fs_files_debian() {
  44. local PACKAGES
  45. PACKAGES=$(dpkg-query -f '${binary:Package}\n' -W 'freeswitch*')
  46. PACKAGES="libc6 $PACKAGES"
  47. for pkg in $PACKAGES
  48. do
  49. dpkg-query -L $pkg 2> /dev/null
  50. done
  51. }
  52. extra_files_debian() {
  53. cat << EOF
  54. /etc
  55. /bin
  56. /bin/busybox
  57. /usr/bin
  58. /usr/bin/epmd
  59. /usr/lib
  60. /usr/lib/erlang
  61. /usr/lib/erlang/bin
  62. /usr/lib/erlang/bin/epmd
  63. /usr/lib/erlang/erts-6.2
  64. /usr/lib/erlang/erts-6.2/bin
  65. /usr/lib/erlang/erts-6.2/bin/epmd
  66. EOF
  67. }
  68. sort_filelist() {
  69. sort $FILELIST | uniq > $FILELIST.new
  70. mv -f $FILELIST.new $FILELIST
  71. }
  72. filter_unnecessary_files() {
  73. # excluded following files and directories recursive
  74. # /.
  75. # /lib/systemd/
  76. # /usr/share/doc/
  77. # /usr/share/lintian/
  78. # /usr/share/freeswitch/sounds/
  79. # all "*.flac" files
  80. sed -i \
  81. -e '\|^/\.$|d' \
  82. -e '\|^/lib/systemd|d' \
  83. -e '\|^/usr/share/doc|d' \
  84. -e '\|^/usr/share/lintian|d' \
  85. -e '\|^/usr/share/freeswitch/sounds/|d' \
  86. -e '\|^/.*\.flac$|d' \
  87. -e '\|^/.*/flac$|d' \
  88. $FILELIST
  89. # if disabled Perl and python removing this too
  90. if [ "$WITHOUT_PERL"="true" ];then
  91. sed -i -e '\|^/usr/share/perl5|d' $FILELIST
  92. fi
  93. if [ "$WITHOUT_PYTHON"="true" ];then
  94. sed -i -e '\|^/usr/share/pyshared|d' -e '\|^/usr/share/python-support|d' $FILELIST
  95. fi
  96. if [ "$WITHOUT_JAVA"="true" ];then
  97. sed -i -e '\|^/usr/share/freeswitch/scripts/freeswitch.jar|d' $FILELIST
  98. fi
  99. }
  100. ldd_helper() {
  101. TESTFILE=$1
  102. ldd $TESTFILE 2> /dev/null > /dev/null || return
  103. RESULT=$(ldd $TESTFILE | grep -oP '\s\S+\s\(\S+\)' | sed -e 's/^\s//' -e 's/\s.*$//') #'
  104. # This for tests
  105. # echo $TESTFILE
  106. echo "$RESULT"
  107. }
  108. find_binaries() {
  109. rm -f $FILELIST_BINARY
  110. for f in $(cat $FILELIST)
  111. do
  112. ldd_helper $f >> $FILELIST_BINARY
  113. done
  114. sort $FILELIST_BINARY | sort | uniq | sed -e '/linux-vdso.so.1/d' > $FILELIST_BINARY.new
  115. mv -f $FILELIST_BINARY.new $FILELIST_BINARY
  116. cat $FILELIST_BINARY | xargs realpath > $FILELIST_BINARY.new
  117. cat $FILELIST_BINARY.new >> $FILELIST_BINARY
  118. rm -f $FILELIST_BINARY.new
  119. }
  120. tar_files() {
  121. local TARLIST=/tmp/tarlist
  122. cat $FILELIST > $TARLIST
  123. cat $FILELIST_BINARY >> $TARLIST
  124. tar -czf $TMP_TAR --no-recursion -T $TARLIST
  125. rm -f $TARLIST
  126. }
  127. make_image_tar() {
  128. local CURDIR=`pwd`
  129. cd $BUILD_ROOT
  130. tar xzf $TMP_TAR
  131. find usr/share/freeswitch/conf/* -maxdepth 0 -type d -not -name vanilla -exec rm -Rf {} \;
  132. # Patching config file
  133. patch -p 1 < $CURDIR/freeswitch-config.patch
  134. busybox --install -s bin
  135. tar czf $IMG_TAR *
  136. cd $CURDIR
  137. }
  138. apt-get --assume-yes install busybox patch
  139. clean_build_root
  140. fs_files_debian > $FILELIST
  141. extra_files_debian >> $FILELIST
  142. sort_filelist
  143. filter_unnecessary_files
  144. find_binaries
  145. tar_files
  146. make_image_tar
  147. mv $IMG_TAR .
  148. clean_build_root