2
0

FreeSWITCH-debian-raspbian-installer.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/bin/sh
  2. # (C) 2016 Ken Rice <krice@freeswitch.org>
  3. # Licensed as per the MPL1.1
  4. #
  5. ########################################################
  6. # TODO: FreeSWITCH AutoStart
  7. # TODO: Allow Selection of Source or Package Install on Debian
  8. DIALOG=${DIALOG=dialog}
  9. tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
  10. trap "rm -f $tempfile" 0 1 2 5 15
  11. . /etc/os-release
  12. install_prereqs() {
  13. #install the prereqs
  14. echo "Making sure we have the prereqs for this script to run. Please Stand by..."
  15. apt-get update 2>&1 >/dev/null
  16. apt-get install -y curl dialog git ntpdate 2>&1 >/dev/null
  17. # See if ntpd is running if it is, stop it set the current time as rpi has no RTC and this is needed
  18. # for SSL to function properly
  19. if pgrep "ntpd" >/dev/null ; then
  20. /etc/init.d/ntp stop
  21. ntpdate pool.ntp.org
  22. /etc/init.d/ntp start
  23. else
  24. ntpdate pool.ntp.org
  25. fi
  26. }
  27. welcome_screen() {
  28. $DIALOG --title "FreeSWITCH with LetsEncrypt AutoInstaller" --clear \
  29. --msgbox "This Script with automattically Install FreeSWITCH \
  30. On your Debian 8 Jessie Machine, it will also install \
  31. Verto Communicator and use LetsEncrypt for the required \
  32. SSL Certificates needed for Proper WebRTC Communications.\n\n\
  33. Please keep in mind that you will need a proper DNS \
  34. Name pointed at this machine's public IP address along \
  35. with ports 80 and 443 opened on the firewall. \n\n\
  36. Additionally, you will need TCP ports 5060, 5061, 8081, \
  37. 8082 and UDP ports 16384-32768 open on your firewall for \
  38. FreeSWITCH and Verto Communicator for function properly. \n\n\
  39. Press <Enter> to Continue or <ESC> to abort." 19 60
  40. case $? in
  41. 0)
  42. ;;
  43. 255)
  44. exit 1;;
  45. esac
  46. }
  47. fs_ver_select() {
  48. $DIALOG --backtitle "FreeSWITCH Version" \
  49. --title "RADIOLIST BOX" --clear \
  50. --radiolist "Which Version of FreeSWITCH are you installing? \n" 20 61 5 \
  51. "1" "FreeSWITCH 1.7" ON \
  52. "2" "FreeSWITCH 1.6" off 2> $tempfile
  53. retval=$?
  54. choice=`cat $tempfile`
  55. case $retval in
  56. 0)
  57. case $choice in
  58. 1)
  59. FS_REV="master";;
  60. 2)
  61. FS_REV="1.6";;
  62. esac;;
  63. 1)
  64. exit 1;;
  65. 255)
  66. exit 1;;
  67. esac
  68. }
  69. get_network_settings() {
  70. FQDN=`hostname -f`
  71. DOMAIN=`hostname -d`
  72. IPADDR=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'|tail -n 1`
  73. EMAIL="hostmaster@$DOMAIN";
  74. dialog --title "System Setup Information" \
  75. --form "\nVerify or correct the Fully Qualified Domain Name and IP Address of your machine.\nAlso enter a valid Email Address for system and LetsEncrypt email alerts" 25 60 16 \
  76. "FQDN:" 1 1 "$FQDN" 1 25 25 40 \
  77. "IP Address:" 2 1 "$IPADDR" 2 25 25 30 \
  78. "Email Address:" 3 1 "$EMAIL" 3 25 25 40 \
  79. 2> $tempfile
  80. FQDN=`head -n1 $tempfile`
  81. IPADDR=`tail -n2 $tempfile|head -n1`
  82. EMAIL=`tail -n1 $tempfile`
  83. retval=$?
  84. case $retval in
  85. 0)
  86. ;;
  87. 1)
  88. exit 1;;
  89. 255)
  90. exit 1;;
  91. esac
  92. }
  93. is_private_ip() {
  94. PAT='^10\.|^192\.168\.|^169\.254\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.'
  95. echo $IPADDR | egrep "$PAT"
  96. }
  97. verify_ip_fqdn() {
  98. DNSIP=`dig +noall +answer @4.2.2.2 $FQDN | awk '{print $5}'`
  99. dialog --title "NO DNS For this FQDN" --clear \
  100. --menu "The FQDN and IP Address do not match what is available in Public DNS Servers." 15 60 5 \
  101. 1 "Continue installation without LetsEncrypt." 2 "Abort Installation" 2> $tempfile
  102. LE_CHOICE=`cat $tempfile`
  103. if [ "$IPADDR" != "$DNSIP" ]; then
  104. if [ "x$LE_CHOICE" = "x1" ]; then
  105. VIPFQDN=1
  106. else
  107. VIPFQDN=2
  108. fi
  109. else
  110. VIPFQDN=0
  111. fi
  112. }
  113. config_fs_repos() {
  114. curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
  115. if [ "$FS_REV" = "master" ]; then
  116. echo "deb http://files.freeswitch.org/repo/deb/debian-unstable/ jessie main" >/etc/apt/sources.list.d/freeswitch.list
  117. REPO="https://github.com/signalwire/freeswitch.git"
  118. elif [ "$FS_REV" = "1.6" ]; then
  119. echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
  120. REPO="-b v1.6 https://github.com/signalwire/freeswitch.git"
  121. fi
  122. apt-get update 2>&1 >/dev/null
  123. }
  124. get_fs_source() {
  125. echo "REPO = $REPO"
  126. if [ ! -d /usr/src/freeswitch.git ]; then
  127. cd /usr/src
  128. git clone $REPO freeswitch.git
  129. else
  130. cd /usr/src/freeswitch.git
  131. git clean -fdx
  132. git reset --hard origin/$FS_REV
  133. git pull
  134. fi
  135. }
  136. get_letsencrypt() {
  137. if [ ! -d /usr/src/letsencrypt ]; then
  138. cd /usr/src
  139. git clone https://github.com/letsencrypt/letsencrypt.git letsencrypt
  140. else
  141. git clean -fdx
  142. git pull
  143. fi
  144. }
  145. install_certs() {
  146. get_letsencrypt
  147. cd /usr/src/letsencrypt
  148. NEED_CERTS_INSTALL=1
  149. if [ -f /etc/letsencrypt/live/$FQDN/cert.pem ]; then
  150. if openssl x509 -checkend 2592000 -noout -in /etc/letsencrypt/live/$FQDN/cert.pem; then
  151. echo "Skipping LetsEncrypt These Certs are good for atleast 30 days."
  152. NEED_CERTS_INSTALL=0
  153. else
  154. echo "Renewing LetsEncrypt Certs as they will expire in the next 30 days."
  155. ./letsencrypt-auto renew --manual-public-ip-logging-ok
  156. fi
  157. else
  158. echo "Setting up LetsEncrypt and getting you some nice new Certs for this Server."
  159. ./letsencrypt-auto run -d $FQDN --email $EMAIL
  160. fi
  161. # if we dont have the FreeSWITCH Certs Directory, make it
  162. if [ $NEED_CERTS_INSTALL -eq 1 ]; then
  163. if [ ! -d /usr/local/freeswitch/certs ]; then
  164. mkdir -p /usr/local/freeswitch/certs
  165. fi
  166. cat /etc/letsencrypt/live/$FQDN/cert.pem /etc/letsencrypt/live/$FQDN/privkey.pem \
  167. /etc/letsencrypt/live/$FQDN/chain.pem > /usr/local/freeswitch/certs/wss.pem
  168. fi
  169. }
  170. build_fs() {
  171. get_fs_source
  172. #if we already have a FreeSWITCH install from source clean out the old bins
  173. if [ -d /usr/local/freeswitch/bin ]; then
  174. rm -rf /usr/local/freeswitch/{bin,mod,lib}/*
  175. fi
  176. cd /usr/src/freeswitch.git
  177. if [ ! -d /usr/src/freeswitch.git/configure ]; then
  178. ./bootstrap.sh -j
  179. fi
  180. ./configure -C
  181. make -j$JLIMIT install
  182. make uhd-sounds-install
  183. make uhd-moh-install
  184. }
  185. install_vc() {
  186. if [ ! -d /usr/src/freeswitch.git/html5/verto/verto_communicator ]; then
  187. get_fs_source
  188. fi
  189. if [ ! -x /usr/sbin/apache2 ]; then
  190. apt-get update 2>&1 >/dev/null
  191. apt-get install -y apache2
  192. fi
  193. cd /usr/src/freeswitch.git/html5/verto/verto_communicator
  194. apt-get update
  195. apt-get install npm nodejs-legacy -y
  196. npm install -g grunt grunt-cli bower
  197. npm install
  198. bower --allow-root install
  199. grunt build
  200. cp -a dist /var/www/html/vc
  201. }
  202. freeswitch_debian_packages() {
  203. apt-get install -o Dpkg::Progress=1 -y freeswitch-all freeswitch-all-dbg gdb 2>&1 | awk -W interactive '/Progress/ { print }'| \
  204. sed -u 's/[^0-9]//g' | dialog --gauge "Please wait.\n Installing FreeSWITCH..." 10 70 0
  205. }
  206. freeswitch_debian_source() {
  207. apt-get install -o Dpkg::Progress=1 -y freeswitch-video-deps-most \
  208. 2>&1 | awk -W interactive '/Progress/ { print }'| sed -u 's/[^0-9]//g' | \
  209. dialog --gauge "Please wait.\n Installing Build Requirements..." 10 70 0
  210. build_fs
  211. }
  212. freeswitch_raspbian_source() {
  213. apt-get install -o Dpkg::Progress=1 -y autoconf automake devscripts gawk libjpeg-dev libncurses5-dev libtool-bin python-dev \
  214. libtiff5-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev \
  215. libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev libsndfile-dev libopus-dev liblua5.1-0-dev 2>&1 | \
  216. awk -W interactive '/Progress/ { print }'| sed -u 's/[^0-9]//g' | dialog --gauge "Please wait.\n Installing Build Requirements..." 10 70 0
  217. build_fs
  218. }
  219. # install_prereqs
  220. welcome_screen
  221. fs_ver_select
  222. get_network_settings
  223. if [ "$ID" = "debian" ]; then
  224. ## These only work on Jessie at this time
  225. config_fs_repos
  226. freeswitch_debian_source
  227. elif [ "$ID" = "raspbian" ]; then
  228. JLIMIT="3"
  229. freeswitch_raspbian_source
  230. fi
  231. install_vc
  232. PRIVIP=$(is_private_ip)
  233. if [ "x$PRIVIP" != "x$IPADDR" ]; then
  234. verify_ip_fqdn
  235. if [ $VIPFQDN -eq 2 ]; then
  236. exit 1;
  237. elif [ $VIPFQDN -eq 1 ]; then
  238. echo "Skipping LetsEncrypt\n"
  239. else
  240. get_letsencrypt
  241. install_certs
  242. fi
  243. else
  244. echo "Skipping LetsEncrypt. Since we are on a Private IP Address";
  245. fi