docker-entrypoint.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. BASEURL=http://files.freeswitch.org
  30. PID_FILE=/var/run/freeswitch/freeswitch.pid
  31. get_password() {
  32. < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-12};echo;
  33. }
  34. get_sound_version() {
  35. local SOUND_TYPE=$1
  36. grep "$SOUND_TYPE" sounds_version.txt | sed -E "s/$SOUND_TYPE\s+//"
  37. }
  38. wget_helper() {
  39. local SOUND_FILE=$1
  40. grep -q $SOUND_FILE /usr/share/freeswitch/sounds/soundfiles_present.txt 2> /dev/null
  41. if [ "$?" -eq 0 ]; then
  42. echo "Skipping download of $SOUND_FILE. Already present"
  43. return
  44. fi
  45. wget $BASEURL/$SOUND_FILE
  46. if [ -f $SOUND_FILE ]; then
  47. echo $SOUND_FILE >> /usr/share/freeswitch/sounds/soundfiles_present.txt
  48. fi
  49. }
  50. download_sound_rates() {
  51. local i
  52. local f
  53. local SOUND_TYPE=$1
  54. local SOUND_VERSION=$2
  55. for i in $SOUND_RATES
  56. do
  57. f=freeswitch-sounds-$SOUND_TYPE-$i-$SOUND_VERSION.tar.gz
  58. echo "Downloading $f"
  59. wget_helper $f
  60. done
  61. }
  62. download_sound_types() {
  63. local i
  64. local SOUND_VERSION
  65. for i in $SOUND_TYPES
  66. do
  67. SOUND_VERSION=$(get_sound_version $i)
  68. download_sound_rates $i $SOUND_VERSION
  69. done
  70. }
  71. extract_sound_files() {
  72. local SOUND_FILES=freeswitch-sounds-*.tar.gz
  73. for f in $SOUND_FILES
  74. do
  75. if [ -f $f ]; then
  76. echo "Extracting file $f"
  77. tar xzf $f -C /usr/share/freeswitch/sounds/
  78. fi
  79. done
  80. }
  81. delete_archives() {
  82. local FILES_COUNT=$(ls -1 freeswitch-sounds-*.tar.gz 2> /dev/null | wc -l)
  83. if [ "$FILES_COUNT" -ne 0 ]; then
  84. echo "Removing downloaded 'tar.gz' archives"
  85. rm -f freeswitch-sounds-*.tar.gz
  86. fi
  87. }
  88. SOUND_RATES=$(echo "$SOUND_RATES" | sed -e 's/:/\n/g')
  89. SOUND_TYPES=$(echo "$SOUND_TYPES" | sed -e 's/:/\n/g')
  90. if [ -z "$SOUND_RATES" -o -z "$SOUND_TYPES" ]; then
  91. echo "Environment variables 'SOUND_RATES' or 'SOUND_TYPES' not defined. Skipping sound files checking."
  92. else
  93. download_sound_types
  94. extract_sound_files
  95. delete_archives
  96. fi
  97. if [ "$EPMD"="true" ]; then
  98. /usr/bin/epmd -daemon
  99. fi
  100. if [ ! -f "/etc/freeswitch/freeswitch.xml" ]; then
  101. SIP_PASSWORD=$(get_password)
  102. mkdir -p /etc/freeswitch
  103. cp -varf /usr/share/freeswitch/conf/vanilla/* /etc/freeswitch/
  104. sed -i -e "s/default_password=.*\?/default_password=$SIP_PASSWORD\"/" /etc/freeswitch/vars.xml
  105. echo "New FreeSwitch password for SIP calls set to '$SIP_PASSWORD'"
  106. fi
  107. trap '/usr/bin/freeswitch -stop' SIGTERM
  108. /usr/bin/freeswitch -nc -nf -nonat &
  109. pid="$!"
  110. wait $pid
  111. exit 0