install_fusionpbx.sh 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  1. #!/bin/bash
  2. # install_fusionpbx
  3. LICENSE=$( cat << DELIM
  4. #------------------------------------------------------------------------------
  5. #
  6. # "THE WAF LICENSE" (version 1)
  7. # This is the Wife Acceptance Factor (WAF) License.
  8. # jamesdotfsatstubbornrosesd0tcom wrote this file. As long as you retain this
  9. # notice you can do whatever you want with it. If you appreciate the work,
  10. # please consider purchasing something from my wife's wishlist. That pays
  11. # bigger dividends to this coder than anything else I can think of ;). It also
  12. # keeps her happy while she's being ignored; so I can work on this stuff.
  13. # James Rose
  14. #
  15. # latest wishlist: http://www.stubbornroses.com/waf.html
  16. #
  17. # Credit: Based off of the BEER-WARE LICENSE (REVISION 42) by Poul-Henning Kamp
  18. #
  19. # Contributor(s):
  20. # Gill Abada <[email protected]>
  21. # Mark J Crane <[email protected]>
  22. # Andrew Stanaitis <[email protected]>
  23. #------------------------------------------------------------------------------
  24. DELIM
  25. )
  26. #---------
  27. #VARIABLES
  28. #---------
  29. #Variables are for the auto installation option.
  30. #for apache set to a, for nginx/php-fpm set to n -> for an auto install, user mode will prompt
  31. APACHENGINX=n
  32. # for mysql set m. for sqlite set s. for postgresql set p
  33. SQLITEMYSQL=p
  34. # for postgresql v 9.0 (from ppa) set to 9
  35. # must set SQLITEMYSQL to p
  36. POSTGRES9=9
  37. # to start FreeSWITCH with -nonat option set SETNONAT to y
  38. SETNONAT=y
  39. # rm -Rf /opt? A default install doesn't have /opt so no worries
  40. # if you do, set to no, and it will link /usr/local/freeswitch to /opt/freeswitch
  41. #REMOVED OPTION
  42. #RMOPT=y
  43. # use freedtm/dahdi? y/n
  44. DO_DAHDI=n
  45. # default distro
  46. #DISTRO=precise
  47. #DISTRO=squeeze
  48. #DISTRO=precise
  49. #DISTRO=lucid
  50. #DISTRO=wheezy
  51. DISTRO=jessie
  52. #below is a list of modules we want to add to provide functionality for FusionPBX
  53. #don't worry about the applications/mod_ format. This script will find that in modules.conf
  54. #PAY ATTENTION TO THE SPACES POST AND PRE PARENTHESIS
  55. # mod_shout removed
  56. if [ $DO_DAHDI == "y" ]; then
  57. modules_add=( mod_curl ../../libs/freetdm/mod_freetdm mod_spandsp mod_dingaling mod_portaudio mod_callcenter mod_lcr mod_cidlookup mod_flite mod_memcache mod_codec2 mod_pocketsphinx mod_xml_cdr mod_say_es mod_say_en )
  58. else
  59. modules_add=( mod_curl mod_spandsp mod_dingaling mod_callcenter mod_lcr mod_cidlookup mod_memcache mod_codec2 mod_pocketsphinx mod_xml_cdr mod_say_es mod_say_en )
  60. fi
  61. #-------
  62. #DEFINES
  63. #-------
  64. VERSION="Version - using subversion, no longer keeping track. WAF License"
  65. FSGIT=https://freeswitch.org/stash/scm/fs/freeswitch.git
  66. FSSTABLE=true
  67. FSStablefile=freeswitch-1.6.6
  68. FSStableVer="v1.6"
  69. FSDB=p
  70. #right now, make -j not working. see: jira FS-3005
  71. CORES=$(/bin/grep processor -c /proc/cpuinfo)
  72. #CORES=1
  73. FQDN=$(hostname -f)
  74. #SRCPATH="/usr/src/freeswitch" #DEFAULT
  75. SRCPATH="/usr/src/freeswitch"
  76. #EN_PATH="/usr/local/freeswitch/conf/autoload_configs" #DEFAULT
  77. EN_PATH="/usr/local/freeswitch/conf/autoload_configs"
  78. WWW_PATH="/var/www"
  79. #used for Apache
  80. #WWW_PATH="/var/www/html"
  81. GUI_NAME=fusionpbx
  82. INST_FPBX=git
  83. #INST_FPBX=svn
  84. #INST_FPBX=tgz
  85. #full path required
  86. #TGZ_FILE="/home/coltpbx/fusionpbx-1.2.1.tar.gz"
  87. FUSIONPBX_GIT_SERVER=https://github.com
  88. FUSIONPBX_GIT_CONTRIBUTER=fusionpbx
  89. FUSIONPBX_GIT_PROJECT=fusionpbx
  90. FUSIONPBX_GIT_ASKBRANCH=0
  91. FSREV=false
  92. #IF FSCHECKOUTVER is true, FSSTABLE needs to be false
  93. FSCHECKOUTVER=false
  94. FPBXREV="1876"
  95. FBPXCHECKOUTVER=false
  96. #dev
  97. #URLSCRIPT="http://fusionpbx.googlecode.com/svn/branches/dev/scripts/install/ubuntu/install_fusionpbx.sh"
  98. #trunk
  99. #URLSCRIPT="https://fusionpbx.googlecode.com/svn/trunk/scripts/install/ubuntu/install_fusionpbx.sh"
  100. URLSCRIPT="https://raw.githubusercontent.com/fusionpbx/fusionpbx-scripts/master/install/debian/install_fusionpbx.sh"
  101. INSFUSION=0
  102. INSFREESWITCH=0
  103. UPGFUSION=0
  104. UPGFREESWITCH=0
  105. #---------
  106. # NOTES
  107. #---------
  108. # This Script installs or upgrades FreeSWITCH and FusionPBX on a fresh install of
  109. # Ubuntu 10.04 LTS [lucid]. It tries to edit all appropriate files, and
  110. # set the permissions correctly.
  111. #When you install ubuntu, you should select the "Manual package selection" option.
  112. #This way we can keep the install to the bare minimum. This script will install
  113. #everything you need (and nothing) - hopefully, you don't. Just quit tasksel
  114. #---------
  115. #FUNCTIONS
  116. #---------
  117. function nativepgsql {
  118. /bin/echo
  119. /bin/echo "By default, FreeSWITCH is using sqlite, until we tell it not to."
  120. /bin/echo "FreeSWITCH can be configured to use postgresql natively, but it is"
  121. /bin/echo "not always advantageous to do so."
  122. read -p " Use Postgres (p) or Sqlite (s) [p/S]? " FSDB
  123. case $FSDB in
  124. [pP])
  125. #tell FS about the postgresql database...
  126. echo " Please type in the password for the freeswitch database you configured below."
  127. read -p "Password: " FSDBPASS
  128. FPATH="/var/www/fusionpbx/resources/templates/conf"
  129. /bin/echo "setting switch.conf.xml"
  130. sed -i $FPATH/autoload_configs/switch.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  131. cat >> $FPATH/autoload_configs/switch.conf.xml <<EOF
  132. <param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=fusionpbx password=$FSDBPASS options='-c client_min_messages=NOTICE' application_name='freeswitch'" />
  133. </settings>
  134. </configuration>
  135. EOF
  136. /bin/echo "setting callcenter.conf.xml"
  137. sed -i $FPATH/autoload_configs/callcenter.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  138. cat >> $FPATH/autoload_configs/callcenter.conf.xml <<EOF
  139. <param name="odbc-dsn" value="\$\${dsn}"/>
  140. </settings>
  141. </configuration>
  142. EOF
  143. /bin/echo "setting fifo.conf.xml"
  144. sed -i $FPATH/autoload_configs/fifo.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  145. cat >> $FPATH/autoload_configs/fifo.conf.xml <<EOF
  146. <param name="odbc-dsn" value="\$\${dsn}"/>
  147. </settings>
  148. </configuration>
  149. EOF
  150. /bin/echo "setting internal.conf.xml"
  151. sed -i $FPATH/sip_profiles/internal.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  152. cat >> $FPATH/sip_profiles/internal.xml <<EOF
  153. <param name="odbc-dsn" value="\$\${dsn}"/>
  154. </settings>
  155. </configuration>
  156. EOF
  157. /bin/echo "setting external.conf.xml"
  158. sed -i $FPATH/sip_profiles/external.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  159. cat >> $FPATH/sip_profiles/external.xml <<EOF
  160. <param name="odbc-dsn" value="\$\${dsn}"/>
  161. </settings>
  162. </configuration>
  163. EOF
  164. /bin/echo "setting db.conf.xml"
  165. sed -i $FPATH/autoload_configs/db.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
  166. cat >> $FPATH/autoload_configs/db.conf.xml <<EOF
  167. <param name="odbc-dsn" value="\$\${dsn}"/>
  168. </settings>
  169. </configuration>
  170. EOF
  171. ;;
  172. *)
  173. /bin/echo "Ok, using sqlite, nothing more to do here."
  174. ;;
  175. esac
  176. }
  177. function nginxconfig {
  178. apt-get install -y ssl-cert
  179. ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
  180. ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
  181. ln -s /etc/ssl/certs/nginx.crt $WWW_PATH/$GUI_NAME/$HOSTNAME.crt
  182. #don't forget to escape 'DELIM'. otherwise the $fastcgi part
  183. #gets escaped.
  184. #manually escaping now. needs variables....
  185. /bin/cat > /etc/nginx/sites-available/$GUI_NAME <<DELIM
  186. server {
  187. listen 127.0.0.1:80;
  188. server_name 127.0.0.1;
  189. access_log /var/log/nginx/access.log;
  190. error_log /var/log/nginx/error.log;
  191. client_max_body_size 10M;
  192. client_body_buffer_size 128k;
  193. location / {
  194. root $WWW_PATH/$GUI_NAME;
  195. index index.php;
  196. }
  197. location ~ \.php$ {
  198. fastcgi_pass unix:/var/run/php5-fpm.sock;
  199. #fastcgi_pass 127.0.0.1:9000;
  200. fastcgi_index index.php;
  201. include fastcgi_params;
  202. fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
  203. }
  204. # Disable viewing .htaccess & .htpassword & .db
  205. location ~ .htaccess {
  206. deny all;
  207. }
  208. location ~ .htpassword {
  209. deny all;
  210. }
  211. location ~^.+.(db)$ {
  212. deny all;
  213. }
  214. }
  215. server {
  216. listen 80;
  217. server_name $GUI_NAME;
  218. #grandstream
  219. rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=\$1;
  220. #aastra
  221. #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=\$1 last;
  222. #yealink common
  223. rewrite "^.*/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=\$1\$2;
  224. #yealink mac
  225. rewrite "^.*/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=\$1 last;
  226. #polycom
  227. rewrite "^.*/provision/000000000000.cfg$" "/app/provison/?mac=\$1&file=%7b%24mac%7d.cfg";
  228. #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
  229. rewrite "^.*/provision/features.cfg$" /app/provision/?mac=\$1&file=features.cfg;
  230. rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=\$1&file=sip.cfg;
  231. rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=\$1;
  232. rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=\$1&file=%7b%24mac%7d-registration.cfg";
  233. rewrite "^.*/provision/([A-Fa-f0-9]{12})-site.cfg$" /app/provision/?mac=\$1&file=site.cfg;
  234. rewrite "^.*/provision/([A-Fa-f0-9]{12})-web.cfg$" /app/provision/?mac=\$1&file=web.cfg;
  235. if (\$uri !~* ^.*provision.*$) {
  236. rewrite ^(.*) https://\$host\$1 permanent;
  237. break;
  238. }
  239. access_log /var/log/nginx/access.log;
  240. error_log /var/log/nginx/error.log;
  241. client_max_body_size 10M;
  242. client_body_buffer_size 128k;
  243. location / {
  244. root $WWW_PATH/$GUI_NAME;
  245. index index.php;
  246. }
  247. location ~ \.php$ {
  248. fastcgi_pass unix:/var/run/php5-fpm.sock;
  249. #fastcgi_pass 127.0.0.1:9000;
  250. fastcgi_index index.php;
  251. include fastcgi_params;
  252. fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
  253. }
  254. # Disable viewing .htaccess & .htpassword & .db
  255. location ~ .htaccess {
  256. deny all;
  257. }
  258. location ~ .htpassword {
  259. deny all;
  260. }
  261. location ~^.+.(db)$ {
  262. deny all;
  263. }
  264. }
  265. server {
  266. listen 443;
  267. server_name $GUI_NAME;
  268. ssl on;
  269. ssl_certificate /etc/ssl/certs/nginx.crt;
  270. ssl_certificate_key /etc/ssl/private/nginx.key;
  271. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  272. ssl_ciphers HIGH:!ADH:!MD5;
  273. #grandstream
  274. rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=\$1;
  275. #aastra
  276. #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=\$1 last;
  277. #yealink common
  278. rewrite "^.*/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=\$1\$2;
  279. #yealink mac
  280. rewrite "^.*/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=\$1 last;
  281. #polycom
  282. rewrite "^.*/provision/000000000000.cfg$" "/app/provison/?mac=\$1&file=%7b%24mac%7d.cfg";
  283. #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
  284. rewrite "^.*/provision/features.cfg$" /app/provision/?mac=\$1&file=features.cfg;
  285. rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=\$1&file=sip.cfg;
  286. rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=\$1;
  287. rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=\$1&file=%7b%24mac%7d-registration.cfg";
  288. rewrite "^.*/provision/([A-Fa-f0-9]{12})-site.cfg$" /app/provision/?mac=\$1&file=site.cfg;
  289. rewrite "^.*/provision/([A-Fa-f0-9]{12})-web.cfg$" /app/provision/?mac=\$1&file=web.cfg;
  290. access_log /var/log/nginx/access.log;
  291. error_log /var/log/nginx/error.log;
  292. client_max_body_size 10M;
  293. client_body_buffer_size 128k;
  294. location / {
  295. root $WWW_PATH/$GUI_NAME;
  296. index index.php;
  297. }
  298. location ~ \.php$ {
  299. fastcgi_pass unix:/var/run/php5-fpm.sock;
  300. #fastcgi_pass 127.0.0.1:9000;
  301. fastcgi_index index.php;
  302. include fastcgi_params;
  303. fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
  304. }
  305. # Disable viewing .htaccess & .htpassword & .db
  306. location ~ .htaccess {
  307. deny all;
  308. }
  309. location ~ .htpassword {
  310. deny all;
  311. }
  312. location ~^.+.(db)$ {
  313. deny all;
  314. }
  315. }
  316. DELIM
  317. /bin/ln -s /etc/nginx/sites-available/$GUI_NAME /etc/nginx/sites-enabled/$GUI_NAME
  318. /bin/echo "document root for nginx is:"
  319. /bin/echo " $WWW_PATH/$GUI_NAME"
  320. /bin/echo " php has an upload file size limit of 10 MegaBytes"
  321. /bin/echo
  322. /bin/echo "now install FusionPBX. This should go fast."
  323. /bin/echo
  324. #nginx install doesn't create /var/www
  325. /bin/mkdir $WWW_PATH
  326. /bin/chown -R www-data:www-data $WWW_PATH
  327. /bin/chmod -R 775 $WWW_PATH
  328. /etc/init.d/php5-fpm
  329. /etc/init.d/nginx restart
  330. }
  331. function start_freeswitch {
  332. /usr/sbin/service freeswitch start
  333. echo Waiting for freeswitch to start ...;
  334. sleep 10;
  335. echo ... Continuing;
  336. }
  337. function fusionfail2ban {
  338. /bin/cat > /etc/fail2ban/filter.d/$GUI_NAME.conf <<'DELIM'
  339. # Fail2Ban configuration file
  340. #
  341. # Author: soapee01
  342. #
  343. [Definition]
  344. # Option: failregex
  345. # Notes.: regex to match the password failures messages in the logfile. The
  346. # host must be matched by a group named "host". The tag "<HOST>" can
  347. # be used for standard IP/hostname matching and is only an alias for
  348. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  349. # Values: TEXT
  350. #
  351. #failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
  352. #[hostname] variable doesn't seem to work in every case. Do this instead:
  353. failregex = .* FusionPBX: \[<HOST>\] authentication failed for
  354. = .* FusionPBX: \[<HOST>\] provision attempt bad password for
  355. # Option: ignoreregex
  356. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  357. # Values: TEXT
  358. #
  359. ignoreregex =
  360. DELIM
  361. /bin/grep -i $GUI_NAME /etc/fail2ban/jail.local > /dev/null
  362. if [ $? -eq 0 ]; then
  363. /bin/echo "FusionPBX Jail already set"
  364. else
  365. /bin/cat >> /etc/fail2ban/jail.local <<DELIM
  366. [$GUI_NAME]
  367. enabled = true
  368. port = 80,443
  369. protocol = tcp
  370. filter = $GUI_NAME
  371. logpath = /var/log/auth.log
  372. action = iptables-allports[name=$GUI_NAME, protocol=all]
  373. # sendmail-whois[name=$GUI_NAME, dest=root, [email protected]] #no smtp server installed
  374. maxretry = 5
  375. findtime = 600
  376. bantime = 600
  377. DELIM
  378. fi
  379. }
  380. function www_permissions {
  381. #consider not stopping here... it's causing some significant delays, or just pause until it starts back up...
  382. #/etc/init.d/freeswitch stop
  383. /usr/sbin/adduser www-data audio
  384. /usr/sbin/adduser www-data dialout
  385. /bin/echo "setting FreeSWITCH owned by www-data.www-data"
  386. /bin/chown -R www-data.www-data /usr/local/freeswitch
  387. #remove 'other' permissions on freeswitch
  388. /bin/chmod -R o-rwx /usr/local/freeswitch/
  389. #set FreeSWITCH directories full permissions for user/group with group sticky
  390. /bin/echo "Setting group ID sticky for FreeSWITCH"
  391. /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
  392. #make sure FreeSWITCH directories have group write
  393. /bin/echo "Setting Group Write for FreeSWITCH files"
  394. /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  395. #make sure FreeSWITCH files have group write
  396. /bin/echo "Setting Group Write for FreeSWITCH directories"
  397. /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  398. /bin/echo "setting FusionPBX owned by www-data.www-data just in case"
  399. if [ -e /var/www/fusionpbx ]; then
  400. /bin/chown -R www-data.www-data /var/www/fusionpbx
  401. fi
  402. /bin/echo "Changing /etc/init.d/freeswitch to start with user www-data"
  403. /bin/sed -i -e s,'USER=freeswitch','USER=www-data', /etc/init.d/freeswitch
  404. #/etc/init.d/freeswitch start
  405. }
  406. function finish_fpbx_install_permissions {
  407. /bin/echo
  408. /bin/echo "The FusionPBX installation changed permissions of /usr/local/freeswitch/storage"
  409. /bin/echo " Waiting on you to finish installation (via browser), I'll clean up"
  410. /bin/echo -ne " the last bit of permissions when you finish."
  411. /bin/echo "Waiting on $WWW_PATH/$GUI_NAME/resources/config.php"
  412. while [ ! -e $WWW_PATH/$GUI_NAME/resources/config.php ]
  413. do
  414. /bin/echo -ne '.'
  415. sleep 1
  416. done
  417. /bin/echo
  418. /bin/echo "$WWW_PATH/$GUI_NAME/resources/config.php Found!"
  419. /bin/echo " Waiting 5 more seconds to be sure. "
  420. SLEEPTIME=0
  421. while [ "$SLEEPTIME" -lt 5 ]
  422. do
  423. /bin/echo -ne '.'
  424. sleep 1
  425. let "SLEEPTIME = $SLEEPTIME + 1"
  426. done
  427. /bin/echo " Fixing..."
  428. /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  429. /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  430. /bin/echo " FIXED"
  431. }
  432. function build_modules {
  433. #bandaid
  434. sed -i -e "s/applications\/mod_voicemail_ivr/#applications\/mod_voicemail_ivr/" $SRCPATH/modules.conf
  435. #------------
  436. # new way v2
  437. #------------
  438. #find the default modules - redundant really...
  439. modules_comp_default=( `/bin/grep -v ^$ /usr/src/freeswitch/modules.conf |/bin/grep -v ^# | /usr/bin/tr '\n' ' '` )
  440. #add the directory prefixes to the modules in array so the modules we wish to add will compile
  441. module_count=`echo ${#modules_add[@]}`
  442. index=0
  443. while [ "$index" -lt "$module_count" ]
  444. do
  445. modules_compile_add[$index]=`/bin/grep ${modules_add[$index]} $SRCPATH/modules.conf | sed -e "s/#//g"`
  446. let "index = $index + 1"
  447. done
  448. modules_compile=( ${modules_comp_default[*]} ${modules_compile_add[*]} )
  449. #BUILD MODULES.CONF for COMPILER
  450. echo
  451. echo
  452. echo "Now enabling modules for compile in $SRCPATH/modules.conf"
  453. index=0
  454. module_count=`echo ${#modules_compile[@]}`
  455. #get rid of funky spacing in modules.conf
  456. /bin/sed -i -e "s/ *//g" $SRCPATH/modules.conf
  457. while [ "$index" -lt "$module_count" ]
  458. do
  459. grep ${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
  460. if [ $? -eq 0 ]; then
  461. #module is present in file. see if we need to enable it
  462. grep '#'${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
  463. if [ $? -eq 0 ]; then
  464. /bin/sed -i -e s,'#'${modules_compile[$index]},${modules_compile[$index]}, $SRCPATH/modules.conf
  465. /bin/echo " [ENABLED] ${modules_compile[$index]}"
  466. else
  467. /bin/echo " ${modules_compile[$index]} ALREADY ENABLED!"
  468. fi
  469. else
  470. #module is not present. Add to end of file
  471. #/bin/echo "did not find ${modules_compile[$index]}"
  472. /bin/echo ${modules_compile[$index]} >> $SRCPATH/modules.conf
  473. /bin/echo " [ADDED] ${modules_compile[$index]}"
  474. fi
  475. let "index = $index + 1"
  476. done
  477. #--------------
  478. #end new way v2
  479. #--------------
  480. }
  481. function enable_modules {
  482. #------------
  483. # new way v2
  484. #------------
  485. #ENABLE MODULES for FreeSWITCH
  486. #
  487. echo
  488. echo
  489. echo "Now enabling modules for FreeSWITCH in $EN_PATH/modules.conf.xml"
  490. index=0
  491. module_count=`echo ${#modules_add[@]}`
  492. #get rid of any funky whitespace
  493. /bin/sed -i -e s,'<!-- *<','<!--<', -e s,'> *-->','>-->', $EN_PATH/modules.conf.xml
  494. while [ "$index" -lt "$module_count" ]
  495. do
  496. #more strangness to take care of, example:
  497. #Now enabling modules for FreeSWITCH in /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
  498. #[ADDED] ../../libs/freetdm/mod_freetdm
  499. modules_add[$index]=`/bin/echo ${modules_add[$index]} | /bin/sed -e 's/.*mod_/mod_/'`
  500. grep ${modules_add[$index]} $EN_PATH/modules.conf.xml > /dev/null
  501. if [ $? -eq 0 ]; then
  502. #module is present in file, see if we need to enable it.
  503. grep '<!--<load module="'${modules_add[$index]}'"/>-->' $EN_PATH/modules.conf.xml > /dev/null
  504. if [ $? -eq 0 ]; then
  505. #/bin/echo "found ${modules_compile[$index]}"
  506. /bin/sed -i -e s,'<!--<load module="'${modules_add[$index]}'"/>-->','<load module="'${modules_add[$index]}'"/>', \
  507. $EN_PATH/modules.conf.xml
  508. /bin/echo " [ENABLED] ${modules_add[$index]}"
  509. else
  510. /bin/echo " ${modules_add[$index]} ALREADY ENABLED!"
  511. fi
  512. else
  513. #not in file. we need to add, and will do so below <modules> tag at top of file
  514. /bin/sed -i -e s,'<modules>','&\n <load module="'${modules_add[$index]}'"/>', $EN_PATH/modules.conf.xml
  515. /bin/echo " [ADDED] ${modules_add[$index]}"
  516. fi
  517. let "index = $index + 1"
  518. done
  519. #--------------
  520. #end new way v2
  521. #--------------
  522. }
  523. function freeswitch_logfiles {
  524. /bin/echo
  525. /bin/echo "logrotate not happy with FS: see http://wiki.fusionpbx.com/index.php?title=RotateFSLogs doing differently now..."
  526. /bin/echo " SEE: /etc/cron.daily/freeswitch_log_rotation"
  527. /bin/cat > /etc/cron.daily/freeswitch_log_rotation <<'DELIM'
  528. #!/bin/bash
  529. # logrotate replacement script
  530. # put in /etc/cron.daily
  531. # don't forget to make it executable
  532. # you might consider changing /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml
  533. # <param name="rollover" value="0"/>
  534. #number of days of logs to keep
  535. NUMBERDAYS=30
  536. FSPATH="/usr/local/freeswitch"
  537. $FSPATH/bin/fs_cli -x "fsctl send_sighup" |grep '+OK' >/tmp/rotateFSlogs
  538. if [ $? -eq 0 ]; then
  539. #-cmin 2 could bite us (leave some files uncompressed, eg 11M auto-rotate). Maybe -1440 is better?
  540. find $FSPATH/log/ -name "freeswitch.log.*" -cmin -2 -exec gzip {} \;
  541. find $FSPATH/log/ -name "freeswitch.log.*.gz" -mtime +$NUMBERDAYS -exec /bin/rm {} \;
  542. chown www-data.www-data $FSPATH/log/freeswitch.log
  543. chmod 660 $FSPATH/log/freeswitch.log
  544. logger FreeSWITCH Logs rotated
  545. /bin/rm /tmp/rotateFSlogs
  546. else
  547. logger FreeSWITCH Log Rotation Script FAILED
  548. mail -s '$HOST FS Log Rotate Error' root < /tmp/rotateFSlogs
  549. /bin/rm /tmp/rotateFSlogs
  550. fi
  551. DELIM
  552. /bin/chmod 755 /etc/cron.daily/freeswitch_log_rotation
  553. /bin/echo "Now dropping 10MB limit from FreeSWITCH"
  554. /bin/echo " This is so the rotation/compression part of the cron script"
  555. /bin/echo " will work properly."
  556. /bin/echo " SEE: /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml"
  557. # <param name="rollover" value="10485760"/>
  558. /bin/sed /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml -i -e s,\<param.*name\=\"rollover\".*value\=\"10485760\".*/\>,\<\!\-\-\<param\ name\=\"rollover\"\ value\=\"10485760\"/\>\ INSTALL_SCRIPT\-\-\>,g
  559. }
  560. case $1 in
  561. fix-https)
  562. nginxconfig
  563. ;;
  564. fix-permissions)
  565. /etc/init.d/freeswitch stop
  566. www_permissions
  567. /etc/init.d/freeswitch start
  568. ;;
  569. install-freeswitch)
  570. INSFUSION=0
  571. INSFREESWITCH=1
  572. UPGFUSION=0
  573. UPGFREESWITCH=0
  574. ;;
  575. install-fusionpbx)
  576. INSFUSION=1
  577. INSFREESWITCH=0
  578. UPGFUSION=0
  579. UPGFREESWITCH=0
  580. ;;
  581. install-both)
  582. INSFUSION=1
  583. INSFREESWITCH=1
  584. UPGFUSION=0
  585. UPGFREESWITCH=0
  586. ;;
  587. upgrade-fusionpbx)
  588. INSFUSION=0
  589. INSFREESWITCH=0
  590. UPGFUSION=1
  591. UPGFREESWITCH=0
  592. ;;
  593. upgrade-freeswitch)
  594. INSFUSION=0
  595. INSFREESWITCH=0
  596. UPGFUSION=0
  597. UPGFREESWITCH=1
  598. ;;
  599. upgrade-both)
  600. INSFUSION=0
  601. INSFREESWITCH=0
  602. UPGFUSION=1
  603. UPGFREESWITCH=1
  604. ;;
  605. version)
  606. /bin/echo " "$VERSION
  607. /bin/echo
  608. /bin/echo "$LICENSE"
  609. exit 0
  610. ;;
  611. -v)
  612. /bin/echo " "$VERSION
  613. /bin/echo
  614. /bin/echo "$LICENSE"
  615. exit 0
  616. ;;
  617. --version)
  618. /bin/echo " "$VERSION
  619. /bin/echo
  620. /bin/echo "$LICENSE"
  621. exit 0
  622. ;;
  623. *)
  624. /bin/echo
  625. /bin/echo "This script should be called as:"
  626. /bin/echo " install_fusionpbx option1 option2"
  627. /bin/echo
  628. /bin/echo " option1:"
  629. /bin/echo " install-freeswitch"
  630. /bin/echo " install-fusionpbx"
  631. /bin/echo " install-both"
  632. /bin/echo " upgrade-freeswitch"
  633. /bin/echo " upgrade-fusionpbx"
  634. /bin/echo " fix-https"
  635. /bin/echo " fix-permissions"
  636. /bin/echo " version|--version|-v"
  637. /bin/echo
  638. /bin/echo " option2:"
  639. /bin/echo " user: option waits in certain places for the user to check for errors"
  640. /bin/echo " it is interactive and prompts you about what to install"
  641. /bin/echo " auto: tries an automatic install. Get a cup of coffee, this will"
  642. /bin/echo " take a while. FOR THE BRAVE!"
  643. /bin/echo
  644. /bin/echo " EXAMPLE"
  645. /bin/echo " install_fusionpbx install-both user"
  646. /bin/echo
  647. exit 0
  648. ;;
  649. esac
  650. case $2 in
  651. user)
  652. DEBUG=1
  653. ;;
  654. auto)
  655. DEBUG=0
  656. ;;
  657. *)
  658. /bin/echo
  659. /bin/echo "This script should be called as:"
  660. /bin/echo " install_fusionpbx option1 option2"
  661. /bin/echo
  662. /bin/echo " option1:"
  663. /bin/echo " install-freeswitch"
  664. /bin/echo " install-fusionpbx"
  665. /bin/echo " install-both"
  666. /bin/echo " upgrade-freeswitch"
  667. /bin/echo " upgrade-fusionpbx"
  668. /bin/echo " fix-https"
  669. /bin/echo " fix-permissions"
  670. /bin/echo " version|--version|-v"
  671. /bin/echo
  672. /bin/echo " option2:"
  673. /bin/echo " user: option waits in certain places for the user to check for errors"
  674. /bin/echo " it is interactive and prompts you about what to install"
  675. /bin/echo " auto: tries an automatic install. Get a cup of coffee, this will"
  676. /bin/echo " take a while. FOR THE BRAVE!"
  677. /bin/echo
  678. /bin/echo " EXAMPLE"
  679. /bin/echo " install_fusionpbx install-both user"
  680. /bin/echo
  681. exit 0
  682. ;;
  683. esac
  684. #---------------------
  685. # ENVIRONMENT CHECKS
  686. #---------------------
  687. #check for root
  688. if [ $EUID -ne 0 ]; then
  689. /bin/echo "This script must be run as root" 1>&2
  690. exit 1
  691. fi
  692. echo "Good, you are root."
  693. if [ ! -s /usr/bin/lsb_release ]; then
  694. /bin/echo "Tell your upstream distro to include lsb_release"
  695. /bin/echo
  696. apt-get upgrade && apt-get -y install lsb-release
  697. fi
  698. #check for internet connection
  699. /usr/bin/wget -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
  700. if [ ! -s /tmp/index.google ]; then
  701. echo "No Internet connection. Exiting."
  702. /bin/rm /tmp/index.google
  703. #exit 1
  704. else
  705. echo "Internet connection is working, continuing!"
  706. /bin/rm /tmp/index.google
  707. fi
  708. ##/bin/grep -i lucid /etc/lsb-release > /dev/null
  709. #lsb_release -c |grep -i lucid > /dev/null
  710. DISTRO_DETECT=$(lsb_release -c |sed -e s/Codename://g |sed -r 's/\s+//g')
  711. case $DISTRO_DETECT in
  712. lucid)
  713. #if [ $? -eq 0 ]; then
  714. DISTRO=lucid
  715. /bin/echo "Good, you're running Ubuntu 10.04 LTS codename Lucid"
  716. /bin/echo
  717. ;;
  718. #else
  719. # lsb_release -c |grep -i squeeze > /dev/null
  720. # if [ $? -eq 0 ]; then
  721. squeeze)
  722. DISTRO=squeeze
  723. /bin/echo "OK you're running Debian Squeeze. This script is known to work"
  724. /bin/echo " with apache/nginx and mysql|sqlite|postgres8 options"
  725. /bin/echo " Please consider providing feedback on repositories for nginx"
  726. /bin/echo " and php-fpm."
  727. /bin/echo
  728. CONTINUE=YES
  729. # fi
  730. ;;
  731. # lsb_release -c |grep -i wheezy > /dev/null
  732. # if [ $? -eq 0 ]; then
  733. wheezy)
  734. DISTRO=wheezy
  735. /bin/echo "OK you're running Debian Wheezy. This script is known to work"
  736. /bin/echo " with apache/nginx and sqlite|postgres9.4 options"
  737. /bin/echo " Please consider providing feedback on whether or not this works."
  738. /bin/echo
  739. CONTINUE=YES
  740. # fi
  741. ;;
  742. # lsb_release -c |grep -i precise > /dev/null
  743. # if [ $? -eq 0 ]; then
  744. precise)
  745. DISTRO=precise
  746. /bin/echo "OK you're running Ubuntu 12.04 LTS [precise]. This script is"
  747. /bin/echo " works fine."
  748. /bin/echo
  749. CONTINUE=YES
  750. ;;
  751. jessie)
  752. DISTRO=jessie
  753. /bin/echo "OK you're running Debian Jessie. This script is known to work"
  754. /bin/echo " with apache/nginx and sqlite|postgres9.4 options"
  755. /bin/echo " Please consider providing feedback on whether or not this works."
  756. /bin/echo
  757. CONTINUE=YES
  758. ;;
  759. # else
  760. *)
  761. /bin/echo "This script was written for Ubuntu 10.04 LTS codename Lucid, 12.04 LTS and Debian Squeeze"
  762. /bin/echo
  763. /bin/echo "Your OS appears to be:"
  764. lsb_release -a
  765. read -p "Do you want to continue [y|n]? " CONTINUE
  766. case "$CONTINUE" in
  767. [yY]*)
  768. /bin/echo "Ok, this doesn't always work..,"
  769. /bin/echo " but we'll give it a go."
  770. #set the default to try to install like precise instead of lucid. PPA's aren't required for wheezy or precise going forward...
  771. DISTRO=precise
  772. ;;
  773. *)
  774. /bin/echo "Quitting."
  775. exit 1
  776. ;;
  777. esac
  778. ;;
  779. # fi
  780. #fi
  781. esac
  782. #Check for new version
  783. WHEREAMI=$(echo "`pwd`/`basename $0`")
  784. wget $URLSCRIPT -O /tmp/install_fusionpbx.latest
  785. CURMD5=$(md5sum "$WHEREAMI" | sed -e "s/\ .*//")
  786. echo "The md5sum of the current script is: $CURMD5"
  787. NEWMD5=$(md5sum /tmp/install_fusionpbx.latest | sed -e "s/\ .*//")
  788. echo "The md5sum of the latest script is: $NEWMD5"
  789. if [[ "$CURMD5" == "$NEWMD5" ]]; then
  790. echo "files are the same, continuing"
  791. else
  792. echo "There is a new version of this script."
  793. echo " It is PROBABLY a good idea use the new version"
  794. echo " the new file is saved in /tmp/install_fusionpbx.latest"
  795. echo " to see the difference, run:"
  796. echo " diff -y /tmp/install_fusionpbx.latest $WHEREAMI"
  797. read -p "Continue with the current script [y/N]? " YESNO
  798. case $YESNO in
  799. [Yy]*)
  800. echo "OK, Continuing"
  801. echo " Deleting newest script in /tmp"
  802. rm /tmp/install_fusionpbx.latest
  803. ;;
  804. *)
  805. ;;
  806. esac
  807. fi
  808. #----------------------
  809. #END ENVIRONMENT CHECKS
  810. #----------------------
  811. #---------------------------------------
  812. # INSTALL FREESWITCH
  813. #---------------------------------------
  814. if [ $INSFREESWITCH -eq 1 ]; then
  815. /bin/echo "Upgrading the system, and adding the necessary dependencies for a FreeSWITCH compile"
  816. if [ $DEBUG -eq 1 ]; then
  817. /bin/echo
  818. read -p "Press Enter to continue..."
  819. fi
  820. /usr/bin/apt-get update
  821. /usr/bin/apt-get -y upgrade
  822. if [ $DISTRO == "precise" ]; then
  823. /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
  824. autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
  825. python-dev pkg-config libtiff4-dev php5-curl php5-imap php5-mcrypt lame \
  826. libperl-dev libgdbm-dev gettext libssl-dev \
  827. libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev \
  828. libsqlite3-dev libedit-dev libgdbm-dev libmemcached-dev \
  829. screen htop pkg-config bzip2 curl ntp memcached libldns-dev \
  830. time bison unixodbc libmyodbc unixodbc-dev libtiff-tools
  831. elif [ $DISTRO == "wheezy" ]; then
  832. /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
  833. autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
  834. python-dev pkg-config libtiff5-dev libldns-dev \
  835. libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
  836. libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libpq-dev \
  837. screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
  838. time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev
  839. elif [ $DISTRO == "jessie" ]; then
  840. /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
  841. autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
  842. python-dev pkg-config libtiff5-dev libldns-dev \
  843. libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
  844. libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libpq-dev \
  845. screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
  846. time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev libtool-bin
  847. else
  848. /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
  849. python-dev pkg-config libtiff5-dev libldns-dev \
  850. libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
  851. libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev \
  852. autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev libjpeg62-dev \
  853. screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
  854. time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev
  855. fi
  856. ##1.6 stuff
  857. echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
  858. wget -O - http://files.freeswitch.org/repo/deb/freeswitch-1.6/key.gpg |apt-key add -
  859. /usr/bin/apt-get update
  860. /usr/bin/apt-get -y install --force-yes liblua5.2-0 liblua5.2-dev libopus-dev libcodec2-dev libyuv-dev libopus-dev libsndfile-dev libvpx-dev libvpx2-dev yasm
  861. #added libgnutls-dev libgnutls26 for dingaling...
  862. #gnutls no longer required for dingaling (git around oct 17 per mailing list..)
  863. # removed libgnutls-dev libgnutls26
  864. if [ $DO_DAHDI == "y" ]; then
  865. #add stuff for free_tdm/dahdi
  866. apt-get -y install linux-headers-`uname -r`
  867. #add the headers so dahdi can build the modules...
  868. apt-get -y install dahdi
  869. fi
  870. LDRUN=0
  871. /bin/echo -ne "Waiting on ldconfig to finish so bootstrap will work"
  872. while [ $LDRUN -eq 0 ]
  873. do
  874. echo -ne "."
  875. sleep 1
  876. /usr/bin/pgrep -f ldconfig > /dev/null
  877. LDRUN=$?
  878. done
  879. /bin/echo
  880. /bin/echo
  881. /bin/echo "ldconfig is finished"
  882. /bin/echo
  883. if [ ! -e /tmp/install_fusion_status ]; then
  884. touch /tmp/install_fusion_status
  885. fi
  886. if [ $DEBUG -eq 1 ]; then
  887. /bin/echo
  888. read -p "Press Enter to continue check for errors"
  889. fi
  890. #-----------------
  891. # Databases
  892. #-----------------
  893. #Lets ask... sqlite or postgresql -- for user option only
  894. if [ $DEBUG -eq 1 ]; then
  895. /bin/echo "New Option..."
  896. /bin/echo " FreeSWITCH now has native support for PostgreSQL (no more odbc in the core)"
  897. /bin/echo " also note that freeswitch is now compiled with zrtp support"
  898. /bin/echo
  899. read -p " Would you like to install PostgreSQL or stay with Sqlite (p/S)? " SQLITEMYSQL
  900. case "$SQLITEMYSQL" in
  901. [pP]*)
  902. if [ $DISTRO = "wheezy" ]; then
  903. echo "wheezy is PostgreSQL 9.4 by default"
  904. POSTGRES9=9
  905. elif [ $DISTRO = "jessie" ]; then
  906. echo "jessie is PostgreSQL 9.4 by default"
  907. POSTGRES9=9
  908. else
  909. /bin/echo
  910. /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
  911. /bin/echo " or verion 9 from PPA?"
  912. /bin/echo
  913. read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
  914. fi
  915. echo
  916. ;;
  917. esac
  918. fi
  919. case "$SQLITEMYSQL" in
  920. [Pp]*)
  921. /bin/echo -ne "Installing PostgeSQL"
  922. /bin/echo "DISTRO IS $DISTRO space"
  923. if [ $POSTGRES9 == "9" ]; then
  924. /bin/echo " version 9.x"
  925. if [ $DISTRO = "squeeze" ]; then
  926. #add squeeze repo
  927. /bin/echo "Adding debian backports for postgres9.1"
  928. /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
  929. /usr/bin/apt-get update
  930. /usr/bin/apt-get -y -t squeeze-backports install postgresql-9.1 libpq-dev
  931. elif [ $DISTRO = "precise" ]; then
  932. POSTGRES9=9
  933. #update repository for postgres 9.4 ...
  934. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  935. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
  936. /usr/bin/apt-get update
  937. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev
  938. elif [ $DISTRO = "wheezy" ]; then
  939. POSTGRES9=9
  940. #update repository for postgres 9.4 ...
  941. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  942. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
  943. /usr/bin/apt-get update
  944. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  945. elif [ $DISTRO = "jessie" ]; then
  946. POSTGRES9=9
  947. /usr/bin/apt-get update
  948. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  949. service postgresql status |grep down
  950. if [ $? -eq 0 ]; then
  951. echo "The postgresql service is not running"
  952. echo "It may have not detected the locale correctly"
  953. echo "In another screen you should create a new cluster"
  954. echo " example:"
  955. echo " pg_createcluster --locale en_US.UTF-8 --start 9.3 main"
  956. echo " then see if it is running with 'service postgresql status'"
  957. read -p " this script will pause until this issue is resolved"
  958. fi
  959. else
  960. #add the ppa
  961. /usr/bin/apt-add-repository ppa:pitti/postgresql
  962. /usr/bin/apt-get update
  963. /usr/bin/apt-get -y install postgresql-9.3 libpq-dev
  964. fi
  965. else
  966. /bin/echo " version 8.4"
  967. /usr/bin/apt-get -y install postgresql libpq-dev
  968. #The following NEW packages will be installed:
  969. # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
  970. # postgresql-client-common postgresql-common
  971. fi
  972. #Fix pg_hba.conf
  973. cat > `find / -name pg_hba.conf` <<EOF
  974. # TYPE DATABASE USER ADDRESS METHOD
  975. # Database administrative login by Unix domain socket
  976. local all postgres peer
  977. local fusionpbx all md5
  978. local freeswitch all md5
  979. # "local" is for Unix domain socket connections only
  980. local all all peer
  981. # IPv4 local connections:
  982. host all all 127.0.0.1/32 md5
  983. # IPv6 local connections:
  984. host all all ::1/128 md5
  985. EOF
  986. /etc/init.d/postgresql restart
  987. /bin/su -l postgres -c "/usr/bin/createuser -s -e fusionpbx"
  988. #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O fusionpbx freeswitch"
  989. /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O fusionpbx freeswitch"
  990. PGSQLPASSWORD="dummy"
  991. PGSQLPASSWORD2="dummy2"
  992. while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
  993. /bin/echo
  994. /bin/echo
  995. /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
  996. /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
  997. /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
  998. /bin/echo "psql. THE COMMAND USED IS:"
  999. /bin/echo
  1000. /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER fusionpbx with PASSWORD \$PGSQLPASSWORD;' | psql freeswitch\""
  1001. /bin/echo
  1002. /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
  1003. /bin/echo
  1004. /bin/echo "The pgsql username is fusionpbx"
  1005. /bin/echo "The pgsql database name is freeswitch"
  1006. /bin/echo "Please provide a password for the fusionpbx user"
  1007. #/bin/stty -echo
  1008. read -s -p " Password: " PGSQLPASSWORD
  1009. /bin/echo
  1010. /bin/echo "Let's repeat that"
  1011. read -s -p " Password: " PGSQLPASSWORD2
  1012. /bin/echo
  1013. #/bin/stty echo
  1014. done
  1015. /bin/su -l postgres -c "/bin/echo \"ALTER USER fusionpbx with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql freeswitch"
  1016. /bin/echo "overwriting pgsql password variable with random data"
  1017. PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
  1018. PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
  1019. ;;
  1020. *)
  1021. #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
  1022. /bin/echo "SQLITE is chosen. already done. nothing left to install..."
  1023. ;;
  1024. esac
  1025. #------------------------
  1026. # GIT FREESWITCH
  1027. #------------------------
  1028. /bin/grep 'git_done' /tmp/install_fusion_status > /dev/null
  1029. if [ $? -eq 0 ]; then
  1030. /bin/echo "Git Already Done. Skipping"
  1031. else
  1032. cd /usr/src
  1033. if [ "$FSSTABLE" == true ]; then
  1034. echo "installing $FSStableVer of FreeSWITCH"
  1035. /usr/bin/git clone $FSGIT
  1036. cd /usr/src/freeswitch
  1037. /usr/bin/git checkout $FSStableVer
  1038. if [ $? -ne 0 ]; then
  1039. #git had an error
  1040. /bin/echo "GIT ERROR"
  1041. exit 1
  1042. fi
  1043. elif [ "$FSSTABLE" == file ]; then
  1044. echo "installing $FSStablefile of FreeSWITCH"
  1045. wget http://files.freeswitch.org/freeswitch-releases/$FSStablefile.tar.gz
  1046. tar -zxvf $FSStablefile.tar.gz
  1047. mkdir freeswitch
  1048. cp -R $FSStablefile/* /usr/src/freeswitch/
  1049. cd /usr/src/freeswitch
  1050. else
  1051. echo "going dev branch."
  1052. /usr/bin/git clone $FSGIT
  1053. if [ $? -ne 0 ]; then
  1054. #git had an error
  1055. /bin/echo "GIT ERROR"
  1056. exit 1
  1057. fi
  1058. if [ $FSCHECKOUTVER == true ]; then
  1059. echo "OK we'll check out FreeSWITCH version $FSREV"
  1060. cd /usr/src/freeswitch
  1061. /usr/bin/git checkout $FSREV
  1062. if [ $? -ne 0 ]; then
  1063. #git checkout had an error
  1064. /bin/echo "GIT CHECKOUT ERROR"
  1065. exit 1
  1066. fi
  1067. fi
  1068. /bin/echo "git_done" >> /tmp/install_fusion_status
  1069. fi
  1070. fi
  1071. if [ -e /usr/src/FreeSWITCH ]; then
  1072. /bin/ln -s /usr/src/FreeSWITCH /usr/src/freeswitch
  1073. elif [ -e /usr/src/freeswitch.git ]; then
  1074. /bin/ln -s /usr/src/freeswitch.git /usr/src/freeswitch
  1075. fi
  1076. if [ $DEBUG -eq 1 ]; then
  1077. /bin/echo
  1078. read -p "Press Enter to continue (check for errors)"
  1079. fi
  1080. #------------------------
  1081. # BOOTSTRAP FREESWITCH
  1082. #------------------------
  1083. /bin/grep 'bootstrap_done' /tmp/install_fusion_status > /dev/null
  1084. if [ $? -eq 0 ]; then
  1085. /bin/echo "Bootstrap already done. skipping"
  1086. elif [ "$FSSTABLE" == file ]; then
  1087. echo "bootstrap not required"
  1088. else
  1089. #Attempt to fix build on 1.6.6
  1090. sed -i "40i m4_include(m4/memmove.m4)" /usr/src/freeswitch/libs/spandsp/configure.ac
  1091. cat > /usr/src/freeswitch/libs/spandsp/m4/memmove.m4 <<EOF
  1092. AC_DEFUN([AC_FUNC_MEMMOVE],
  1093. [AC_CHECK_FUNCS(memmove)
  1094. AC_MSG_CHECKING(for working memmove)
  1095. AC_CACHE_VAL(ac_cv_have_working_memmove,
  1096. [AC_TRY_RUN(
  1097. [#include <stdio.h>
  1098. int main(void)
  1099. {
  1100. char buf[10];
  1101. strcpy (buf, "01234567");
  1102. memmove (buf, buf + 2, 3);
  1103. if (strcmp (buf, "23434567"))
  1104. exit (1);
  1105. strcpy (buf, "01234567");
  1106. memmove (buf + 2, buf, 3);
  1107. if (strcmp (buf, "01012567"))
  1108. exit (1);
  1109. exit (0);
  1110. }], ac_cv_have_working_memmove=yes, ac_cv_have_working_memmove=no, ac_cv_have_working_memmove=cross)])
  1111. AC_MSG_RESULT([$ac_cv_have_working_memmove])
  1112. if test x$ac_cv_have_working_memmove != "xyes"; then
  1113. AC_LIBOBJ(memmove)
  1114. AC_MSG_WARN([Replacing missing/broken memmove.])
  1115. AC_DEFINE(PREFER_PORTABLE_MEMMOVE, 1, "enable replacement memmove if system memmove is broken or missing")
  1116. fi])
  1117. EOF
  1118. #might see about -j option to bootstrap.sh
  1119. /etc/init.d/ssh start
  1120. cd /usr/src/freeswitch
  1121. /bin/echo
  1122. /bin/echo "FreeSWITCH Downloaded"
  1123. /bin/echo
  1124. /bin/echo "Bootstrapping."
  1125. /bin/echo
  1126. #next line failed (couldn't find file) not sure why.
  1127. #it did run fine a second time. Go figure (really).
  1128. #ldconfig culprit?
  1129. if [ $CORES -gt 1 ]; then
  1130. /bin/echo " multicore processor detected. Starting Bootstrap with -j"
  1131. if [ $DEBUG -eq 1 ]; then
  1132. /bin/echo
  1133. read -p "Press Enter to continue (check for errors)"
  1134. fi
  1135. /usr/src/freeswitch/bootstrap.sh -j
  1136. else
  1137. /bin/echo " singlecore processor detected. Starting Bootstrap sans -j"
  1138. if [ $DEBUG -eq 1 ]; then
  1139. /bin/echo
  1140. read -p "Press Enter to continue (check for errors)"
  1141. fi
  1142. /usr/src/freeswitch/bootstrap.sh
  1143. fi
  1144. if [ $? -ne 0 ]; then
  1145. #bootstrap had an error
  1146. /bin/echo "BOOTSTRAP ERROR"
  1147. exit 1
  1148. else
  1149. /bin/echo "bootstrap_done" >> /tmp/install_fusion_status
  1150. fi
  1151. fi
  1152. if [ $DEBUG -eq 1 ]; then
  1153. /bin/echo
  1154. read -p "Press Enter to continue (check for errors)"
  1155. fi
  1156. #------------------------
  1157. # build modules.conf
  1158. #------------------------
  1159. /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
  1160. if [ $? -eq 0 ]; then
  1161. /bin/echo "Modules.conf Already edited"
  1162. else
  1163. #file exists and has been edited
  1164. build_modules
  1165. #check exit status
  1166. if [ $? -ne 0 ]; then
  1167. #previous had an error
  1168. /bin/echo "ERROR: Failed to enable build modules in modules.conf."
  1169. exit 1
  1170. else
  1171. /bin/echo "build_modules" >> /tmp/install_fusion_status
  1172. fi
  1173. fi
  1174. if [ $DEBUG -eq 1 ]; then
  1175. /bin/echo
  1176. read -p "Press Enter to continue (check for errors)"
  1177. fi
  1178. #------------------------
  1179. # CONFIGURE FREESWITCH
  1180. #------------------------
  1181. /bin/grep 'config_done' /tmp/install_fusion_status > /dev/null
  1182. if [ $? -eq 0 ]; then
  1183. /bin/echo "FreeSWITCH already Configured! Skipping."
  1184. else
  1185. /bin/echo
  1186. /bin/echo -ne "Configuring FreeSWITCH. This will take a while [~15 minutes]"
  1187. /bin/sleep 1
  1188. /bin/echo -ne " ."
  1189. /bin/sleep 1
  1190. /bin/echo -ne " ."
  1191. /bin/sleep 1
  1192. /bin/echo -ne " ."
  1193. case "$FSDB" in
  1194. [Pp]*)
  1195. #/usr/src/freeswitch/configure --enable-core-pgsql-support --enable-zrtp
  1196. #zrtp busted atm.
  1197. /usr/src/freeswitch/configure --enable-core-pgsql-support
  1198. ;;
  1199. *)
  1200. #/usr/src/freeswitch/configure --enable-zrtp
  1201. #zrtp busted atm
  1202. /usr/src/freeswitch/configure
  1203. ;;
  1204. esac
  1205. if [ $? -ne 0 ]; then
  1206. #previous had an error
  1207. /bin/echo "ERROR: FreeSWITCH Configure ERROR."
  1208. exit 1
  1209. else
  1210. /bin/echo "config_done" >> /tmp/install_fusion_status
  1211. fi
  1212. fi
  1213. if [ $DEBUG -eq 1 ]; then
  1214. /bin/echo
  1215. read -p "Press Enter to continue (check for errors)"
  1216. fi
  1217. if [ -a /etc/init.d/freeswitch ]; then
  1218. /bin/echo " In case of an install where FS exists (iso), stop FS"
  1219. /etc/init.d/freeswitch stop
  1220. fi
  1221. #------------------------
  1222. # COMPILE FREESWITCH
  1223. #------------------------
  1224. /bin/grep 'compile_done' /tmp/install_fusion_status > /dev/null
  1225. if [ $? -eq 0 ]; then
  1226. /bin/echo "FreeSWITCH already Compiled! Skipping."
  1227. else
  1228. #might see about -j cores option to make...
  1229. /bin/echo
  1230. /bin/echo -ne "Compiling FreeSWITCH. This might take a while [~30 minutes]"
  1231. /bin/sleep 1
  1232. /bin/echo -ne "."
  1233. /bin/sleep 1
  1234. /bin/echo -ne "."
  1235. /bin/sleep 1
  1236. /bin/echo -ne "."
  1237. #making sure pwd is correct
  1238. cd /usr/src/freeswitch
  1239. if [ $CORES -gt 1 ]; then
  1240. /bin/echo " multicore processor detected. Compiling with -j $CORES"
  1241. #per anthm compile the freeswitch core first, then the modules.
  1242. /usr/bin/make -j $CORES core
  1243. /usr/bin/make -j $CORES
  1244. else
  1245. /bin/echo " singlecore processor detected. Starting compile sans -j"
  1246. /usr/bin/make
  1247. fi
  1248. if [ $? -ne 0 ]; then
  1249. #previous had an error
  1250. /bin/echo "ERROR: FreeSWITCH Build Failure."
  1251. exit 1
  1252. else
  1253. /bin/echo "compile_done" >> /tmp/install_fusion_status
  1254. fi
  1255. fi
  1256. if [ $DEBUG -eq 1 ]; then
  1257. /bin/echo
  1258. read -p "Press Enter to continue (check for errors)"
  1259. fi
  1260. #------------------------
  1261. # INSTALL FREESWITCH
  1262. #------------------------
  1263. /bin/grep 'install_done' /tmp/install_fusion_status > /dev/null
  1264. if [ $? -eq 0 ]; then
  1265. /bin/echo "FreeSWITCH already Installed! Skipping."
  1266. else
  1267. #dingaling/ubuntu has an issue. let's edit the file...
  1268. #"--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
  1269. #tls no longer required for dingaling, so this weird issue doesn't happen. now uses openssl.
  1270. # /bin/grep 'lgnutls' /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la > /dev/null
  1271. # if [ $? -eq 0 ]; then
  1272. # /bin/echo "dingaling fix already applied."
  1273. # else
  1274. # /bin/sed -i -e s,'--mode=relink gcc','--mode=relink gcc -lgnutls', /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
  1275. # fi
  1276. cd /usr/src/freeswitch
  1277. if [ $CORES -gt 1 ]; then
  1278. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1279. /usr/bin/make -j $CORES install
  1280. else
  1281. /bin/echo " singlecore processor detected. Starting install sans -j"
  1282. /usr/bin/make install
  1283. fi
  1284. #/usr/bin/make install
  1285. if [ $? -ne 0 ]; then
  1286. #previous had an error
  1287. /bin/echo "ERROR: FreeSWITCH INSTALL Failure."
  1288. exit 1
  1289. else
  1290. /bin/echo "install_done" >> /tmp/install_fusion_status
  1291. fi
  1292. fi
  1293. #------------------------
  1294. # FREESWITCH HD SOUNDS
  1295. #------------------------
  1296. /bin/grep 'sounds_done' /tmp/install_fusion_status > /dev/null
  1297. if [ $? -eq 0 ]; then
  1298. /bin/echo "FreeSWITCH HD SOUNDS DONE! Skipping."
  1299. else
  1300. /bin/echo
  1301. /bin/echo -ne "Installing FreeSWITCH HD sounds (16/8khz). This will take a while [~10 minutes]"
  1302. /bin/sleep 1
  1303. /bin/echo -ne "."
  1304. /bin/sleep 1
  1305. /bin/echo -ne "."
  1306. /bin/sleep 1
  1307. /bin/echo "."
  1308. cd /usr/src/freeswitch
  1309. if [ $CORES -gt 1 ]; then
  1310. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1311. /usr/bin/make -j $CORES hd-sounds-install
  1312. else
  1313. /bin/echo " singlecore processor detected. Starting install sans -j"
  1314. /usr/bin/make hd-sounds-install
  1315. fi
  1316. #/usr/bin/make hd-sounds-install
  1317. if [ $? -ne 0 ]; then
  1318. #previous had an error
  1319. /bin/echo "ERROR: FreeSWITCH make cdsounds-install ERROR."
  1320. exit 1
  1321. else
  1322. /bin/echo "sounds_done" >> /tmp/install_fusion_status
  1323. fi
  1324. fi
  1325. if [ $DEBUG -eq 1 ]; then
  1326. /bin/echo
  1327. read -p "Press Enter to continue (check for errors)"
  1328. fi
  1329. #------------------------
  1330. # FREESWITCH MOH
  1331. #------------------------
  1332. /bin/grep 'moh_done' /tmp/install_fusion_status > /dev/null
  1333. if [ $? -eq 0 ]; then
  1334. /bin/echo "FreeSWITCH MOH DONE! Skipping."
  1335. else
  1336. /bin/echo
  1337. /bin/echo -ne "Installing FreeSWITCH HD Music On Hold sounds (16/8kHz). This will take a while [~10 minutes]"
  1338. /bin/sleep 1
  1339. /bin/echo -ne "."
  1340. /bin/sleep 1
  1341. /bin/echo -ne "."
  1342. /bin/sleep 1
  1343. /bin/echo "."
  1344. cd /usr/src/freeswitch
  1345. if [ $CORES -gt 1 ]; then
  1346. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1347. /usr/bin/make -j $CORES hd-moh-install
  1348. else
  1349. /bin/echo " singlecore processor detected. Starting install sans -j"
  1350. /usr/bin/make hd-moh-install
  1351. fi
  1352. #/usr/bin/make hd-moh-install
  1353. if [ $? -ne 0 ]; then
  1354. #previous had an error
  1355. /bin/echo "ERROR: FreeSWITCH make cd-moh-install ERROR."
  1356. exit 1
  1357. else
  1358. /bin/echo "moh_done" >> /tmp/install_fusion_status
  1359. fi
  1360. fi
  1361. if [ $DEBUG -eq 1 ]; then
  1362. /bin/echo
  1363. read -p "Press Enter to continue (check for errors)"
  1364. fi
  1365. #------------------------
  1366. # FREESWITCH INIT
  1367. #------------------------
  1368. #no need for tmp file. already handled...
  1369. /bin/echo
  1370. /bin/echo "Configuring /etc/init.d/freeswitch"
  1371. /bin/grep local /etc/init.d/freeswitch > /dev/null
  1372. if [ $? -eq 0 ]; then
  1373. #file exists and has been edited
  1374. /bin/echo "/etc/init.d/freeswitch already edited, skipping"
  1375. elif [ -e /usr/src/freeswitch/debian/freeswitch.init ]; then
  1376. /bin/sed /usr/src/freeswitch/debian/freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
  1377. else
  1378. /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
  1379. #DAEMON
  1380. /bin/sed -i /etc/init.d/freeswitch -e s,^DAEMON=.*,DAEMON=/usr/local/freeswitch/bin/freeswitch,
  1381. #DAEMON_ARGS
  1382. /bin/sed -i /etc/init.d/freeswitch -e s,'^DAEMON_ARGS=.*','DAEMON_ARGS="-u www-data -g www-data -rp -nc -nonat"',
  1383. #PIDFILE
  1384. /bin/sed -i /etc/init.d/freeswitch -e s,^PIDFILE=.*,PIDFILE=/usr/local/freeswitch/run/\$NAME.pid,
  1385. #WORKDIR
  1386. /bin/sed -i /etc/init.d/freeswitch -e s,^WORKDIR=.*,WORKDIR=/usr/local/freeswitch/lib/,
  1387. fi
  1388. if [ $? -ne 0 ]; then
  1389. #previous had an error
  1390. /bin/echo "ERROR: Couldn't edit FreeSWITCH init script."
  1391. exit 1
  1392. fi
  1393. /bin/chmod 755 /etc/init.d/freeswitch
  1394. /bin/echo "enabling FreeSWITCH to start at boot"
  1395. /bin/mkdir /etc/freeswitch
  1396. /bin/touch /etc/freeswitch/freeswitch.xml
  1397. /bin/grep true /etc/default/freeswitch > /dev/null
  1398. if [ $? -eq 0 ]; then
  1399. #file exists and has been edited
  1400. /bin/echo "/etc/default/freeswitch already edited, skipping"
  1401. else
  1402. if [ -e /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default ]; then
  1403. /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default -e s,false,true, > /etc/default/freeswitch
  1404. if [ $? -ne 0 ]; then
  1405. #previous had an error
  1406. /bin/echo "ERROR: Couldn't edit freeswitch RC script."
  1407. exit 1
  1408. fi
  1409. else
  1410. /bin/sed /usr/src/freeswitch/debian/freeswitch.default -e s,false,true, > /etc/default/freeswitch
  1411. if [ $? -ne 0 ]; then
  1412. #previous had an error
  1413. /bin/echo "ERROR: Couldn't edit freeswitch RC script."
  1414. exit 1
  1415. fi
  1416. fi
  1417. if [ $DEBUG -eq 1 ]; then
  1418. /bin/echo "Checking for a public IP Address..."
  1419. PUBLICIP=no
  1420. #turn off the auto-nat when we start freeswitch.
  1421. #nasty syntax. searches for 10.a.b.c or 192.168.x.y addresses in ifconfig.
  1422. /sbin/ifconfig | \
  1423. /bin/grep 'inet addr:' | \
  1424. /usr/bin/cut -d: -f2 | \
  1425. /usr/bin/awk '{ print $1}' | \
  1426. while read IPADDR; do
  1427. echo "$IPADDR" | \
  1428. /bin/grep -e '^10\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
  1429. -e '^192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
  1430. -e '^127.0.0.1$'
  1431. #-e '^172\.[16-31]\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
  1432. if [ $? -ne 0 ]; then
  1433. PUBLICIP=yes
  1434. fi
  1435. done
  1436. case "$PUBLICIP" in
  1437. [Yy]*)
  1438. if [ $DEBUG -eq 1 ]; then
  1439. /bin/echo "You appear to have a public IP address."
  1440. /bin/echo " I can make sure FreeSWITCH starts with"
  1441. /bin/echo " the -nonat option (starts quicker)."
  1442. /bin/echo
  1443. read -p "Would you like for me to do this (y/n)? " SETNONAT
  1444. fi
  1445. ;;
  1446. *)
  1447. /bin/echo "Dynamic IP. leaving FreeSWITCH for aggressive nat"
  1448. SETNONAT=no
  1449. ;;
  1450. esac
  1451. fi
  1452. case "$SETNONAT" in
  1453. [Yy]*)
  1454. /bin/sed /etc/default/freeswitch -i -e s,'FREESWITCH_PARAMS="-nc"','FREESWITCH_PARAMS="-nc -nonat -reincarnate"',
  1455. /bin/echo "init script set to start 'freeswitch -nc -nonat'"
  1456. ;;
  1457. *)
  1458. /bin/echo "OK, not using -nonat option."
  1459. ;;
  1460. esac
  1461. /bin/echo
  1462. /usr/sbin/update-rc.d -f freeswitch defaults
  1463. fi
  1464. /bin/echo
  1465. #don't do this. If freeswitch is a machine name, it really screws this test. It
  1466. #won't hurt to adduser a second time anyhow.
  1467. #/bin/grep freeswitch /etc/passwd > /dev/null
  1468. #if [ $? -eq 0 ]; then
  1469. #user already exists
  1470. # /bin/echo "FreeSWITCH user already exists, skipping..."
  1471. #else
  1472. /bin/echo "adding freeswitch user"
  1473. /usr/sbin/adduser --disabled-password --quiet --system \
  1474. --home /usr/local/freeswitch \
  1475. --gecos "FreeSWITCH Voice Platform" --ingroup daemon \
  1476. freeswitch
  1477. if [ $? -ne 0 ]; then
  1478. #previous had an error
  1479. /bin/echo "ERROR: Failed adding freeswitch user."
  1480. exit 1
  1481. fi
  1482. #fi
  1483. /usr/sbin/adduser freeswitch audio
  1484. /usr/sbin/groupadd freeswitch
  1485. if [ $DO_DAHDI == "y" ]; then
  1486. #dialout for dahdi
  1487. /usr/sbin/adduser freeswitch dialout
  1488. fi
  1489. /bin/chown -R freeswitch:daemon /usr/local/freeswitch/
  1490. /bin/echo "removing 'other' permissions on freeswitch"
  1491. /bin/chmod -R o-rwx /usr/local/freeswitch/
  1492. /bin/echo
  1493. cd /usr/local/
  1494. /bin/chown -R freeswitch:daemon /usr/local/freeswitch
  1495. /bin/echo "FreeSWITCH directories now owned by freeswitch.daemon"
  1496. /usr/bin/find freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
  1497. /bin/echo "FreeSWITCH directories now sticky group. This will cause any files created"
  1498. /bin/echo " to default to the daemon group so FreeSWITCH can read them"
  1499. /bin/echo
  1500. #/bin/echo "removing /opt blindly (hope nothing is there) and linking it"
  1501. #/bin/echo " to /usr/local so FusionPBX won't complain"
  1502. #Opt might have been created due to a type in adduser freeswitch (home was /opt) check...
  1503. #this looks to be the case.
  1504. #the latest FusionBPX is correctly detecting /usr/local/freeswitch
  1505. # probably always did.
  1506. #let's try removing opt altogether...
  1507. #/bin/echo
  1508. /bin/ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
  1509. #if [ $DEBUG -eq 1 ]; then
  1510. # /bin/echo "FreeSWITCH was installed to /usr/local."
  1511. # /bin/echo " normally we don't want to see /opt"
  1512. # /bin/echo " since FusionPBX. tries to find it"
  1513. # /bin/echo " and you end up with having to symlink"
  1514. # /bin/echo " /usr/local/freeswitch to /opt/freeswitch"
  1515. # /bin/echo
  1516. # /bin/echo " It would be easier to blow /opt away; but"
  1517. # /bin/echo " this may not be a fresh Ubuntu install."
  1518. # /bin/echo
  1519. # read -p "Can I 'rm -Rf /opt (Y/n)? " RMOPT
  1520. #fi
  1521. #case "$RMOPT" in
  1522. #[Yy]*)
  1523. # /bin/rm -Rf /opt
  1524. #;;
  1525. #*)
  1526. #/bin/echo "OK, linking /usr/local/freeswitch to /opt/freeswitch"
  1527. #/bin/ln -s /usr/local/freeswitch /opt/freeswitch
  1528. #;;
  1529. #esac
  1530. if [ $DEBUG -eq 1 ]; then
  1531. /bin/echo
  1532. /bin/echo "Press Enter to continue (check for errors)"
  1533. read
  1534. fi
  1535. #------------------------
  1536. # enable modules.conf.xml
  1537. #------------------------
  1538. /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
  1539. if [ $? -eq 0 ]; then
  1540. /bin/echo "Modules.conf.xml Already enabled"
  1541. else
  1542. #file exists and has been edited
  1543. enable_modules
  1544. #check exit status
  1545. if [ $? -ne 0 ]; then
  1546. #previous had an error
  1547. /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
  1548. exit 1
  1549. else
  1550. /bin/echo "enable_modules" >> /tmp/install_fusion_status
  1551. fi
  1552. fi
  1553. if [ $DEBUG -eq 1 ]; then
  1554. /bin/echo
  1555. read -p "Press Enter to continue (check for errors)"
  1556. fi
  1557. #-----------------
  1558. #Setup logrotate
  1559. #-----------------
  1560. # if [ -a /etc/logrotate.d/freeswitch ]; then
  1561. if [ -a /etc/cron.daily/freeswitch_log_rotation ]; then
  1562. /bin/echo "Logrotate for FreeSWITCH Already Done!"
  1563. #call log script creation function
  1564. freeswitch_logfiles
  1565. fi
  1566. #-----------------
  1567. #harden FreeSWITCH
  1568. #-----------------
  1569. /bin/echo -ne "HARDENING"
  1570. sleep 1
  1571. /bin/echo -ne " ."
  1572. sleep 1
  1573. /bin/echo -ne " ."
  1574. sleep 1
  1575. /bin/echo -ne " ."
  1576. /usr/bin/apt-get -y install fail2ban
  1577. /bin/echo
  1578. /bin/echo "Checking log-auth-failures"
  1579. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml > /dev/null
  1580. if [ $? -eq 0 ]; then
  1581. #see if it's uncommented
  1582. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml | /bin/grep '<!--' > /dev/null
  1583. if [ $? -eq 1 ]; then
  1584. #Check for true
  1585. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
  1586. if [ $? -eq 0 ]; then
  1587. /bin/echo " [ENABLED] log-auth-failures - Already Done!"
  1588. else
  1589. #it's false and uncommented, change it to true
  1590. /bin/sed -i -e s,'<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
  1591. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1592. /bin/echo " [ENABLED] log-auth-failures - Was False!"
  1593. fi
  1594. else
  1595. # It's commented
  1596. # check for true
  1597. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
  1598. if [ $? -eq 0 ]; then
  1599. #it's commented and true
  1600. /bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
  1601. -e s,'<param name="log-auth-failures" value="true"/> *-->','<param name="log-auth-failures" value="true"/>', \
  1602. -e s,'<!--<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
  1603. -e s,'<param name="log-auth-failures" value="true"/>-->','<param name="log-auth-failures" value="true"/>', \
  1604. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1605. /bin/echo " [ENABLED] log-auth-failures - Was Commented!"
  1606. else
  1607. #it's commented and false.
  1608. /bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
  1609. -e s,'<param name="log-auth-failures" value="false"/> *-->','<param name="log-auth-failures" value="true"/>', \
  1610. -e s,'<!--<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
  1611. -e s,'<param name="log-auth-failures" value="false"/>-->','<param name="log-auth-failures" value="true"/>', \
  1612. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1613. /bin/echo " [ENABLED] log-auth-failures - Was Commented and False!"
  1614. fi
  1615. fi
  1616. else
  1617. #It's not present...
  1618. /bin/sed -i -e s,'<settings>','&\n <param name="log-auth-failures" value="true"/>', \
  1619. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1620. /bin/echo " [ENABLED] log-auth-failures - Wasn't there!"
  1621. fi
  1622. if [ -a /etc/fail2ban/filter.d/freeswitch.conf ]; then
  1623. /bin/echo "fail2ban filter for freeswitch already done!"
  1624. else
  1625. /bin/cat > /etc/fail2ban/filter.d/freeswitch.conf <<"DELIM"
  1626. # Fail2Ban configuration file
  1627. #
  1628. # Author: Rupa SChomaker
  1629. #
  1630. [Definition]
  1631. # Option: failregex
  1632. # Notes.: regex to match the password failures messages in the logfile. The
  1633. # host must be matched by a group named "host". The tag "<HOST>" can
  1634. # be used for standard IP/hostname matching and is only an alias for
  1635. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  1636. # Values: TEXT
  1637. #
  1638. failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1639. \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1640. # Option: ignoreregex
  1641. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  1642. # Values: TEXT
  1643. #
  1644. ignoreregex =
  1645. DELIM
  1646. fi
  1647. if [ -a /etc/fail2ban/filter.d/freeswitch-dos.conf ]; then
  1648. /bin/echo "fail2ban filter for freeswitch-dos already done!"
  1649. else
  1650. /bin/cat > /etc/fail2ban/filter.d/freeswitch-dos.conf <<"DELIM"
  1651. # Fail2Ban configuration file
  1652. #
  1653. # Author: soapee01
  1654. #
  1655. [Definition]
  1656. # Option: failregex
  1657. # Notes.: regex to match the password failures messages in the logfile. The
  1658. # host must be matched by a group named "host". The tag "<HOST>" can
  1659. # be used for standard IP/hostname matching and is only an alias for
  1660. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  1661. # Values: TEXT
  1662. #
  1663. failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1664. # Option: ignoreregex
  1665. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  1666. # Values: TEXT
  1667. #
  1668. ignoreregex =
  1669. DELIM
  1670. fi
  1671. #see if we've done this before (as in an ISO was made
  1672. #with this script but the source wasn't included
  1673. #so we have to reinstall...
  1674. /bin/grep freeswitch /etc/fail2ban/jail.local > /dev/null
  1675. if [ $? -ne 0 ]; then
  1676. #add the following stanzas to the end of our file (don't overwrite)
  1677. /bin/cat >> /etc/fail2ban/jail.local <<'DELIM'
  1678. [freeswitch-tcp]
  1679. enabled = true
  1680. port = 5060,5061,5080,5081
  1681. protocol = tcp
  1682. filter = freeswitch
  1683. logpath = /usr/local/freeswitch/log/freeswitch.log
  1684. action = iptables-allports[name=freeswitch-tcp, protocol=all]
  1685. maxretry = 5
  1686. findtime = 600
  1687. bantime = 600
  1688. # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
  1689. [freeswitch-udp]
  1690. enabled = true
  1691. port = 5060,5061,5080,5081
  1692. protocol = udp
  1693. filter = freeswitch
  1694. logpath = /usr/local/freeswitch/log/freeswitch.log
  1695. action = iptables-allports[name=freeswitch-udp, protocol=all]
  1696. maxretry = 5
  1697. findtime = 600
  1698. bantime = 600
  1699. # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
  1700. [freeswitch-dos]
  1701. enabled = true
  1702. port = 5060,5061,5080,5081
  1703. protocol = udp
  1704. filter = freeswitch-dos
  1705. logpath = /usr/local/freeswitch/log/freeswitch.log
  1706. action = iptables-allports[name=freeswitch-dos, protocol=all]
  1707. maxretry = 50
  1708. findtime = 30
  1709. bantime = 6000
  1710. DELIM
  1711. else
  1712. /bin/echo"fail2ban jail.local for freeswitch already done!"
  1713. fi
  1714. #problem with the way ubuntu logs ssh failures [fail2ban]
  1715. # Failed password for root from 1.2.3.4 port 22 ssh2
  1716. # last message repeated 5 times
  1717. # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
  1718. /bin/echo "Turning off RepeatedMsgReduction in /etc/rsyslog.conf"
  1719. #not sure what the deal is with the single quotes here. Fixed in v4.4.0
  1720. #/bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
  1721. /bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
  1722. /etc/init.d/rsyslog restart
  1723. #bug in fail2ban. If you see this error
  1724. #2011-02-27 14:11:42,326 fail2ban.actions.action: ERROR iptables -N fail2ban-freeswitch-tcp
  1725. #http://www.fail2ban.org/wiki/index.php/Fail2ban_talk:Community_Portal#fail2ban.action.action_ERROR_on_startup.2Frestart
  1726. /bin/grep -A 1 'time.sleep(0\.1)' /usr/bin/fail2ban-client |/bin/grep beautifier > /dev/null
  1727. if [ $? -ne 0 ]; then
  1728. /bin/sed -i -e s,beautifier\.setInputCmd\(c\),'time.sleep\(0\.1\)\n\t\t\tbeautifier.setInputCmd\(c\)', /usr/bin/fail2ban-client
  1729. #this does slow the restart down quite a bit.
  1730. else
  1731. /bin/echo ' time.sleep(0.1) already added to /usr/bin/fail2ban-client'
  1732. fi
  1733. #still may have a problem with logrotate causing missing new FS log files.
  1734. #should see log lines such as:
  1735. #2011-02-13 06:37:59,889 fail2ban.filter : INFO Log rotation detected for /usr/local/freeswitch/log/freeswitch.log
  1736. /etc/init.d/freeswitch start
  1737. if [ $DISTRO == "jessie" ]; then
  1738. sleep 5
  1739. /bin/systemctl restart fail2ban.service
  1740. else
  1741. /etc/init.d/fail2ban restart
  1742. fi
  1743. /bin/echo " fail2ban for ssh enabled by default"
  1744. /bin/echo " Default is 3 failures before your IP gets blocked for 600 seconds"
  1745. /bin/echo " SEE http://wiki.freeswitch.org/wiki/Fail2ban"
  1746. /bin/echo
  1747. /bin/echo
  1748. /bin/echo "FreeSWITCH Installation Completed. Have Fun!"
  1749. /bin/echo
  1750. fi
  1751. #---------------------------------------
  1752. # DONE INSTALLING FREESWITCH
  1753. #---------------------------------------
  1754. #---------------------------------------
  1755. # INSTALL FUSIONPBX
  1756. #---------------------------------------
  1757. if [ $INSFUSION -eq 1 ]; then
  1758. /bin/echo "FYI, we will need to change ownership of all FreeSWITCH"
  1759. /bin/echo " Directories to www-data.www-data"
  1760. /bin/echo " We will also need to change the init script to"
  1761. /bin/echo " start FreeSWITCH as the www-data user."
  1762. /bin/echo
  1763. /bin/echo "This is a workaround to FreeSWITCH jira FS-3016"
  1764. /bin/echo " The better way would be to have FreeSWITCH and FusionPBX"
  1765. /bin/echo " share group permissions; unfortunately, FreeSWITCH writes"
  1766. /bin/echo " log files, voicemail, etc with group permissions off."
  1767. /bin/echo
  1768. /bin/echo "This behavior is hard coded into FreeSWITCH."
  1769. /bin/echo " For now, you need to be aware that if an"
  1770. /bin/echo " exploit is found for apache2 or nginx"
  1771. /bin/echo " The attacker would have access to the entire"
  1772. /bin/echo " FreeSWITCH directory. This isn't quite as bad as it seems though."
  1773. /bin/echo " since simply having access to configuration can do damage"
  1774. /bin/echo "Watch your logfiles."
  1775. #read -p " press enter to continue."
  1776. /bin/echo
  1777. /bin/echo "Stopping FreeSWITCH..."
  1778. /etc/init.d/freeswitch stop
  1779. www_permissions
  1780. #Lets ask... nginx or apache -- for user option only
  1781. if [ $DEBUG -eq 1 ]; then
  1782. /bin/echo "New Option..."
  1783. read -p "Would you prefer Apache or Ngnix [nginx and php-fpm from ppa repos] (a/N)? " APACHENGINX
  1784. fi
  1785. #remastersys iso ditches the apt data. have to update
  1786. /usr/bin/apt-get update
  1787. #get reqs for both
  1788. /usr/bin/apt-get -y install git-core python-software-properties subversion ghostscript
  1789. #provides apt-add-repository
  1790. #installs python-software-properties unattended-upgrades
  1791. #/usr/bin/apt-get -y install ppa-purge #in backports. don't want that repo
  1792. if [ ! -e /usr/sbin/ppa-purge ]; then
  1793. /usr/bin/wget http://us.archive.ubuntu.com/ubuntu/pool/universe/p/ppa-purge/ppa-purge_0+bzr46.1~lucid1_all.deb -O /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
  1794. /usr/bin/dpkg -i /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
  1795. fi
  1796. /usr/bin/apt-get -y install sqlite php5-cli php5-sqlite php5-odbc
  1797. if [ $DISTRO = "precise" ]; then
  1798. /usr/bin/apt-get -y install php-db
  1799. fi
  1800. if [ $DISTRO = "wheezy" ]; then
  1801. /usr/bin/apt-get -y install php5-sqlite php-db
  1802. fi
  1803. if [ $DISTRO = "jessie" ]; then
  1804. /usr/bin/apt-get -y install php5-sqlite php-db
  1805. fi
  1806. #-----------------
  1807. # Apache
  1808. #-----------------
  1809. case "$APACHENGINX" in
  1810. [Aa]*)
  1811. #if [ $APACHENGINX == "a" ]; then
  1812. if [ -e /usr/sbin/nginx ]; then
  1813. #nginx is installed.
  1814. /bin/echo
  1815. /bin/echo "Nginx is installed, and you selected apache2."
  1816. if [ $DEBUG -eq 1 ]; then
  1817. /bin/echo
  1818. /bin/echo " We need to remove nginx/php5-fpm. The packages"
  1819. /bin/echo " are not purged, so configuration files will stay."
  1820. /bin/echo
  1821. read -p " Do you want to remove nginx/php5-fpm and install apache2 (y/n)? " YESNO
  1822. else
  1823. YESNO=y
  1824. fi
  1825. case "$YESNO" in
  1826. [Yy]*)
  1827. /bin/grep brianmercer /etc/apt/sources.list > /dev/null
  1828. if [ $? -eq 0 ]; then
  1829. /bin/echo "php-fpm ppa already add the old way. Fixing"
  1830. /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
  1831. fi
  1832. /bin/grep nginx /etc/apt/sources.list > /dev/null
  1833. if [ $? -ne 0 ]; then
  1834. /bin/echo "nginx ppa already add the old way. Fixing"
  1835. /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
  1836. fi
  1837. #remove ppa's
  1838. /usr/sbin/ppa-purge ppa:brianmercer/php
  1839. /usr/sbin/ppa-purge ppa:nginx/stable
  1840. #remove packages
  1841. /usr/bin/apt-get -y remove nginx nginx-full libevent-1.4-2 libt1-5 \
  1842. php-apc php-pear php5-fpm php5-gd php5-memcache
  1843. #ttf-dejavu-core fontconfig-config libfontconfig1 libxpm4 #removes x/gnome
  1844. #libxslt1.1 libxslt1.1 #removes midori
  1845. #libgd2-xpm #removed by ppa-purge
  1846. #libgd2-noxpm #removed by ppa-purge
  1847. /usr/bin/apt-get clean
  1848. /usr/bin/apt-get update
  1849. #re-install removed packages
  1850. /usr/bin/apt-get -y install libgd2-noxpm
  1851. /bin/echo " NGINX/PHP5-FPM REMOVED!"
  1852. ;;
  1853. *)
  1854. /bin/echo "OK. We'll stop. Exiting!"
  1855. exit 1
  1856. ;;
  1857. esac
  1858. fi
  1859. /usr/bin/apt-get -y install apache2 libapache2-mod-php5
  1860. #installs:
  1861. #apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
  1862. # /bin/grep fusionpbx /etc/apache2/sites-enabled/000-default > /dev/null
  1863. # if [ $? -ne 0 ]; then
  1864. if [ ! -e /etc/apache2/sites-enabled/$GUI_NAME ]; then
  1865. #disable the default 000-default site
  1866. /usr/sbin/a2dissite default
  1867. #let's use a heredoc now, and do this the right way. #no 'quotes' with variables
  1868. /bin/cat >> /etc/apache2/sites-available/$GUI_NAME <<DELIM
  1869. <VirtualHost *:80>
  1870. ServerAdmin webmaster@localhost
  1871. ServerName $FQDN
  1872. DocumentRoot $WWW_PATH/$GUI_NAME
  1873. <Directory />
  1874. Options FollowSymLinks
  1875. AllowOverride None
  1876. </Directory>
  1877. <Directory $WWW_PATH/$GUI_NAME/>
  1878. Options Indexes FollowSymLinks MultiViews
  1879. AllowOverride None
  1880. Order allow,deny
  1881. allow from all
  1882. </Directory>
  1883. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1884. <Directory "/usr/lib/cgi-bin">
  1885. AllowOverride None
  1886. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1887. Order allow,deny
  1888. Allow from all
  1889. </Directory>
  1890. ErrorLog /var/log/apache2/error.log
  1891. # Possible values include: debug, info, notice, warn, error, crit,
  1892. # alert, emerg.
  1893. LogLevel warn
  1894. CustomLog /var/log/apache2/access.log combined
  1895. Alias /doc/ "/usr/share/doc/"
  1896. <Directory "/usr/share/doc/">
  1897. Options Indexes MultiViews FollowSymLinks
  1898. AllowOverride None
  1899. Order deny,allow
  1900. Deny from all
  1901. Allow from 127.0.0.0/255.0.0.0 ::1/128
  1902. </Directory>
  1903. </VirtualHost>
  1904. DELIM
  1905. /usr/sbin/a2ensite $GUI_NAME
  1906. /bin/cat >> /etc/apache2/conf.d/securedb.conf <<'DELIM'
  1907. #
  1908. # The following lines prevent .db files from being
  1909. # viewed by Web clients.
  1910. #
  1911. <Files ~ "^.*\.db">
  1912. Order allow,deny
  1913. Deny from all
  1914. Satisfy all
  1915. </Files>
  1916. DELIM
  1917. /etc/init.d/apache2 restart
  1918. # /bin/sed -i -e s,"DocumentRoot /var/www","DocumentRoot /var/www/fusionpbx", \
  1919. # -e s,"<Directory /var/www/>","<Directory /var/www/fusionpbx/>", \
  1920. # /etc/apache2/sites-enabled/000-default
  1921. if [ $? -ne 0 ]; then
  1922. #previous had an error
  1923. # /bin/echo "ERROR: Failed edit of /etc/apache2/sites-enabled/000-default"
  1924. /bin/echo "ERROR: Failed addtion of /etc/apache2/sites-enabled/$GUI_NAME"
  1925. exit 1
  1926. else
  1927. # /bin/echo "/etc/apache2/sites-enabled/000-default modified."
  1928. /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME added."
  1929. /bin/echo " Root www directory is now $WWW_PATH/$GUI_NAME"
  1930. fi
  1931. else
  1932. /bin/echo
  1933. #/bin/echo "/etc/apache2/sites-enabled/000-default already edited. Skipping..."
  1934. /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME already there. Skipping..."
  1935. fi
  1936. /bin/grep 10M /etc/php5/apache2/php.ini > /dev/null
  1937. if [ $? -ne 0 ]; then
  1938. /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", /etc/php5/apache2/php.ini
  1939. if [ $? -ne 0 ]; then
  1940. #previous had an error
  1941. /bin/echo "ERROR: failed edit of /etc/php5/apache2/php.ini upload_max_filesize = 10M."
  1942. exit 1
  1943. fi
  1944. else
  1945. /bin/echo
  1946. /bin/echo "/etc/php5/apache2/php.ini already edited. Skipping..."
  1947. fi
  1948. /bin/echo "document root for apache2 is:"
  1949. /bin/echo " $WWW_PATH/$GUI_NAME"
  1950. /bin/echo " php has an upload file size limit of 10 MegaBytes"
  1951. /bin/echo
  1952. /bin/echo "now install FusionPBX. This should go fast."
  1953. /bin/echo
  1954. ;;
  1955. #-----------------
  1956. # Apache Done
  1957. #-----------------
  1958. #-----------------
  1959. # NGINX
  1960. #-----------------
  1961. *)
  1962. #elif [ $APACHENGINX == "n" ] || [ $APACHENGINX == "N" ] || [ $APACHENGINX == "" ]; then
  1963. # ^ would be almost there. empty read isn't caught. switching to case. more flexible...
  1964. if [ -e /usr/sbin/apache2 ]; then
  1965. #apache2 is installed.
  1966. /bin/echo
  1967. /bin/echo "Apache2 is installed, and you selected nginx/php5-fpm."
  1968. if [ $DEBUG -eq 1 ]; then
  1969. /bin/echo
  1970. /bin/echo " We need to remove apache2, and php5. The packages"
  1971. /bin/echo " are not purged, so configuration files will stay."
  1972. /bin/echo
  1973. /bin/echo " Do you want to remove apache2/php5 and install "
  1974. read -p " nginx/php5-fpm (y/n)? " YESNO
  1975. else
  1976. YESNO=y
  1977. fi
  1978. case "$YESNO" in
  1979. [Yy]*)
  1980. #remove packages
  1981. /usr/bin/apt-get -y remove apache2 apache2-mpm-prefork apache2-utils apache2.2-bin \
  1982. apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 \
  1983. libaprutil1-ldap ssl-cert
  1984. /bin/echo " APACHE2 REMOVED!"
  1985. #removing libapr removes subversion!
  1986. /usr/bin/apt-get -y install subversion
  1987. ;;
  1988. *)
  1989. /bin/echo "OK. We'll stop. Exiting!"
  1990. exit 1
  1991. ;;
  1992. esac
  1993. fi
  1994. if [ $DISTRO = "squeeze" ]; then
  1995. #setup debian repos for nginx/php5-fpm
  1996. /bin/echo "adding dotdeb repository for php5-fpm and nginx"
  1997. /bin/echo "deb http://packages.dotdeb.org squeeze all" > /etc/apt/sources.list.d/squeeze-dotdeb.list
  1998. /usr/bin/wget -O /tmp/dotdeb.gpg http://www.dotdeb.org/dotdeb.gpg
  1999. /bin/cat /tmp/dotdeb.gpg | apt-key add -
  2000. /bin/rm /tmp/dotdeb.gpg
  2001. /usr/bin/apt-get update
  2002. elif [ $DISTRO = "wheezy" ]; then
  2003. #included in main repo we have nginx [nginx-full] and php5-fpm
  2004. echo "already in Debian 7.x [wheezy], nothing to add."
  2005. elif [ $DISTRO = "jessie" ]; then
  2006. #included in main repo we have nginx [nginx-full] and php5-fpm
  2007. echo "already in Debian 8.x [jessie], nothing to add."
  2008. elif [ $DISTRO = "precise" ]; then
  2009. #included in main repo we have nginx [nginx-full] and php5-fpm
  2010. echo "already in 12.04 LTS [precise], nothing to add."
  2011. else
  2012. #add-apt-repository ppa:brianmercer/php // apt-get -y install python-software-properties
  2013. #Add php5-fpm ppa to the list
  2014. /bin/grep brianmercer /etc/apt/sources.list > /dev/null
  2015. if [ $? -eq 0 ]; then
  2016. /bin/echo "php-fpm ppa already add the old way. Fixing"
  2017. /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
  2018. /usr/bin/apt-add-repository ppa:brianmercer/php
  2019. elif [ ! -e /etc/apt/sources.list.d./brianmercer-php-lucid.list ]; then
  2020. /bin/echo "Adding PPA for php-fpm"
  2021. #/bin/echo "deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucidmain" >> /etc/apt/sources.list
  2022. #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F
  2023. /usr/bin/apt-add-repository ppa:brianmercer/php
  2024. else
  2025. /bin/echo "php-fpm ppa already added."
  2026. fi
  2027. #Add NGINX-ppa to src list.
  2028. /bin/grep nginx /etc/apt/sources.list > /dev/null
  2029. if [ $? -ne 0 ]; then
  2030. /bin/echo "nginx ppa already add the old way. Fixing"
  2031. /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
  2032. /usr/bin/apt-add-repository ppa:nginx/stable
  2033. elif [ ! -e /etc/apt/sources.list.d./nginx-stable-lucid.list ]; then
  2034. /bin/echo "Adding PPA for latest nginx"
  2035. /usr/bin/apt-add-repository ppa:nginx/stable
  2036. #/bin/echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
  2037. #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
  2038. else
  2039. /bin/echo "nginx ppa already added"
  2040. fi
  2041. fi
  2042. /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y
  2043. /usr/bin/apt-get -y install nginx
  2044. #installs libgd2-noxpm libxslt1.1 nginx nginx-full
  2045. if [ $DISTRO = "squeeze" ]; then
  2046. /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php5-apc php5-sqlite php5-json
  2047. else
  2048. #should work for precise
  2049. /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php-apc php5-json
  2050. fi
  2051. if [ $DISTRO = "squeeze" ]; then
  2052. PHPINIFILE="/etc/php5/fpm/php.ini"
  2053. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2054. elif [ $DISTRO = "precise" ]; then
  2055. PHPINIFILE="/etc/php5/fpm/php.ini"
  2056. #also exists, but www.conf used by default...
  2057. #PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2058. #max_children set in /etc/php5/fpm/pool.d/www.conf
  2059. PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
  2060. elif [ $DISTRO = "lucid" ]; then
  2061. #lucid ppa conf files changed 1/20/2013
  2062. PHPINIFILE="/etc/php5/fpm/php.ini"
  2063. PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
  2064. elif [ $DISTRO = "wheezy" ]; then
  2065. PHPINIFILE="/etc/php5/fpm/php.ini"
  2066. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2067. elif [ $DISTRO = "jessie" ]; then
  2068. PHPINIFILE="/etc/php5/fpm/php.ini"
  2069. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2070. else
  2071. PHPINIFILE="/etc/php5/fpm/php.ini"
  2072. PHPCONFFILE="/etc/php5/fpm/php5-fpm.conf"
  2073. fi
  2074. /bin/grep 10M $PHPINIFILE > /dev/null
  2075. if [ $? -ne 0 ]; then
  2076. /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", $PHPINIFILE
  2077. if [ $? -ne 0 ]; then
  2078. #previous had an error
  2079. /bin/echo "ERROR: failed edit of $PHPINIFILE upload_max_filesize = 10M."
  2080. exit 1
  2081. fi
  2082. else
  2083. /bin/echo
  2084. /bin/echo "/etc/php5/fpm/php.ini already edited. Skipping..."
  2085. fi
  2086. #change to socket
  2087. grep "listen = 127.0.0.1:9000" $PHPCONFFILE |grep \;
  2088. if [ $? -ne 0 ]; then
  2089. /bin/sed -i $PHPCONFFILE -e s,listen\ \=\ 127\.0\.0\.\1\:9000,listen\ \=\ \/var\/run\/php5-fpm.sock,
  2090. fi
  2091. #uncomment lines that are needed for unix socket
  2092. /bin/sed -i -e s,";listen.owner","listen.owner", $PHPCONFFILE
  2093. /bin/sed -i -e s,";listen.group","listen.group", $PHPCONFFILE
  2094. /bin/sed -i -e s,";listen.mode","listen.mode", $PHPCONFFILE
  2095. ##Applying fix for cgi.fix_pathinfo
  2096. /bin/grep 'cgi\.fix_pathinfo=0' $PHPINIFILE > /dev/null
  2097. if [ $? -ne 0 ]; then
  2098. /bin/sed -i -e s,';cgi\.fix_pathinfo=1','cgi\.fix_pathinfo=0', $PHPINIFILE
  2099. if [ $? -ne 0 ]; then
  2100. /bin/echo "ERROR: failed edit of $PHPINIFILE cgi.fix_pathinfo=0"
  2101. exit 1
  2102. fi
  2103. else
  2104. /bin/echo
  2105. /bin/echo "/etc/php5/fpm/php.ini already edited for cgi.fix_pathinfo. Skipping..."
  2106. fi
  2107. #We don't need so many php children. 1 per core should be fine FOR NOW.
  2108. #/bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", /etc/php5/fpm/php5-fpm.conf
  2109. /bin/grep "pm.max_children = 4" $PHPCONFFILE > /dev/null
  2110. if [ $? -ne 0 ]; then
  2111. /bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", $PHPCONFFILE
  2112. if [ $? -ne 0 ]; then
  2113. #previous had an error
  2114. /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_children = 4"
  2115. exit 1
  2116. fi
  2117. else
  2118. /bin/echo
  2119. /bin/echo "$PHPCONFFILE [children] already edited. Skipping..."
  2120. fi
  2121. #max_servers must be <= max_children
  2122. /bin/grep "pm.max_spare_servers = 4" $PHPCONFFILE > /dev/null
  2123. if [ $? -ne 0 ]; then
  2124. /bin/sed -i -e s,"pm.max_spare_servers = 6","pm.max_spare_servers = 4", $PHPCONFFILE
  2125. if [ $? -ne 0 ]; then
  2126. #previous had an error
  2127. /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_spare_servers = 4"
  2128. exit 1
  2129. fi
  2130. else
  2131. /bin/echo
  2132. /bin/echo "pm.max_spare_servers not changed"
  2133. fi
  2134. #update auto-starts ###PHP5-fpm and nginx are wrong??
  2135. update-rc.d php5-fpm enable
  2136. /etc/init.d/php5-fpm start
  2137. ##setup niginx for fusionpbx & phpmyadmin!
  2138. update-rc.d nginx enable
  2139. /etc/init.d/nginx start
  2140. #NGINX server config:
  2141. rm /etc/nginx/sites-enabled/default
  2142. /bin/grep '.db' /etc/nginx/sites-available/$GUI_NAME >> /dev/null
  2143. if [ $? -ne 0 ]; then
  2144. /bin/echo "Nginx insecure previous installation"
  2145. /bin/echo " allows http access to FusionPBX database"
  2146. /bin/echo " FIXING..."
  2147. /bin/rm /etc/nginx/sites-available/$GUI_NAME
  2148. fi
  2149. if [ -a /etc/nginx/sites-available/$GUI_NAME ]; then
  2150. /bin/echo "/etc/nginx/sites-available/$GUI_NAME already exists... skipping"
  2151. else
  2152. nginxconfig
  2153. fi
  2154. if [ $DISTRO = "lucid" ]; then
  2155. /bin/grep fastcgi_param.*HTTPS.*\$https\; /etc/nginx/fastcgi_params
  2156. if [ $? -eq 0 ]; then
  2157. echo "Fixing a weird nginx fastcgi_parm issue"
  2158. echo " you can also add the following stanzas to"
  2159. echo " your /etc/nginx/sites-enabled/$GUI_NAME file"
  2160. echo " set $https off; #for listen 80 and listen localhost"
  2161. echo " set $https on; #for listen 443"
  2162. /bin/sed -i /etc/nginx/fastcgi_params -e s/fastcgi_param.*HTTPS.*\$https\;/#fastcgi_param\ HTTPS\ \$https\;/
  2163. fi
  2164. fi
  2165. ;;
  2166. esac
  2167. #-----------------
  2168. # NGINX Done
  2169. #-----------------
  2170. #else
  2171. # /bin/echo "Didn't catch that. exiting"
  2172. # exit 1
  2173. #fi
  2174. cd $WWW_PATH
  2175. if [ $DEBUG -eq 1 ]; then
  2176. /bin/echo
  2177. /bin/echo "Press Enter to continue (check for errors)"
  2178. read
  2179. fi
  2180. /bin/echo "Stopping FreeSWITCH..."
  2181. /usr/sbin/service freeswitch stop
  2182. if [[ "$INST_FPBX" == "svn" ]]; then
  2183. if [ $FBPXCHECKOUTVER == true ]; then
  2184. /bin/echo "Going to install FusionPBX SVN Rev $FPBXREV"
  2185. /usr/bin/svn checkout -r r$FPBXREV $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2186. else
  2187. /bin/echo "Going to install FusionPBX latest SVN!"
  2188. #removed -r r1877 r1877 from new install
  2189. /usr/bin/svn checkout $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2190. fi
  2191. elif [ $INST_FPBX == tgz ]; then
  2192. /bin/tar -C $WWW_PATH -xzvf $TGZ_FILE
  2193. elif [ $INST_FPBX == git ]; then
  2194. FUSIONPBX_GIT="$FUSIONPBX_GIT_SERVER/$FUSIONPBX_GIT_CONTRIBUTER/$FUSIONPBX_GIT_PROJECT";
  2195. /usr/bin/git clone $FUSIONPBX_GIT
  2196. cd $GUI_NAME;
  2197. if [ $FUSIONPBX_GIT_ASKBRANCH == 1 ]
  2198. then
  2199. branches=()
  2200. eval eval "$(/usr/bin/git for-each-ref --shell --format='branches+=(%(refname:short))' refs/remotes/ | perl -l -wpe "s{'\w+/}{'}")"
  2201. for id in "${!branches[@]}";
  2202. do
  2203. branch=${branches[$id]};
  2204. printf "[%s] %s" $id $branch;
  2205. if [ $branch == 'master' ];
  2206. then
  2207. printf " *default";
  2208. default_branch=$id;
  2209. fi
  2210. printf "\n";
  2211. done
  2212. while true;
  2213. do
  2214. read -p "Which branch would you like to use? " branch
  2215. if [[ -z $branch ]];
  2216. then branch=$default_branch;
  2217. fi;
  2218. if [[ -n "${branches[$branch]}" ]];
  2219. then break;
  2220. fi;
  2221. echo "Please choose a existing branch.";
  2222. done
  2223. /usr/bin/git checkout "${branches[$branch]}"
  2224. fi;
  2225. fi
  2226. if [ ! -e $WWW_PATH/$GUI_NAME ]; then
  2227. /bin/mv $WWW_PATH/fusionpbx $WWW_PATH/$GUI_NAME
  2228. fi
  2229. /usr/sbin/adduser freeswitch www-data
  2230. /usr/sbin/adduser www-data daemon
  2231. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2232. /bin/echo "freeswitch is now a member of the www-data group"
  2233. /bin/echo " www-data is now a member of the daemon group"
  2234. /usr/bin/find $WWW_PATH/$GUI_NAME -type f -exec /bin/chmod 644 {} \;
  2235. /usr/bin/find $WWW_PATH/$GUI_NAME -type d -exec /bin/chmod 755 {} \;
  2236. if [ $DEBUG -eq 1 ]; then
  2237. /bin/echo
  2238. /bin/echo "Press Enter to continue (check for errors)"
  2239. read
  2240. fi
  2241. if [ $APACHENGINX == "a" ]; then
  2242. /etc/init.d/apache2 restart
  2243. elif [ $APACHENGINX == "n" ]; then
  2244. /etc/init.d/nginx restart
  2245. fi
  2246. /bin/echo "FusionPBX install needs Write permissions on group to remove files"
  2247. /bin/echo "The daemon group (of which www-data is a member) can now edit all files"
  2248. /bin/echo " in your FreeSWITCH installation. This may or may not be desirable"
  2249. /bin/echo
  2250. /bin/echo "if you want to change this, run (as root)"
  2251. /bin/echo " /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g-w {} \;"
  2252. /bin/echo " /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g-w {} \;"
  2253. /bin/echo " however; FusionPBX won't be able to make changes anymore"
  2254. /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  2255. /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  2256. # /bin/echo "go to the web address in your browser to finish configuration"
  2257. # /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2258. # /bin/echo "don't forget to start FreeSWITCH after the install!"
  2259. # /bin/echo "/etc/init.d/freeswitch start"
  2260. #FreeSWITCH needs read access to scripts in /var/www/fusionpbx/secure
  2261. #per mcrane on IRC
  2262. #mcrane: the easiest way to get it to work is have FreeSWITCH and the web server run under the same user
  2263. # instead we made freeswitch user a member of the www-data group, and www-data user a member of the
  2264. # daemon group.
  2265. #added v3
  2266. #move the default extensions .noload
  2267. #The default FusionPBX install removes the default FreeSWITCH password, so anyone can register
  2268. #with these default FreeSWITCH extensions. They aren't 'in' FusionPBX anyhow, so we don't need
  2269. #them. We will leave them for reference.
  2270. /bin/echo "renaming default FreeSWITCH extensions .noload"
  2271. for i in /usr/local/freeswitch/conf/directory/default/1*.xml;do mv $i $i.noload ; done
  2272. if [ $DEBUG -eq 1 ]; then
  2273. /bin/echo
  2274. /bin/echo "Press Enter to continue (check for errors)"
  2275. read
  2276. fi
  2277. /bin/echo
  2278. /bin/echo "Finishing Up FusionPBX installation."
  2279. /bin/echo "Now for a database..."
  2280. /bin/echo
  2281. #-----------------
  2282. # MySQL
  2283. #-----------------
  2284. #Lets ask... sqlite or mysql -- for user option only
  2285. if [ $DEBUG -eq 1 ]; then
  2286. /bin/echo "New Option..."
  2287. /bin/echo " SQlite is already installed (and required)"
  2288. /bin/echo
  2289. read -p " Would you like to install MySQL, PostgreSQL, or stay with Sqlite (m/p/S)? " SQLITEMYSQL
  2290. case "$SQLITEMYSQL" in
  2291. [pP]*)
  2292. if [ $DISTRO = "wheezy" ]; then
  2293. echo "precise is PostgreSQL 9.4 by default"
  2294. POSTGRES9=9
  2295. elif [ $DISTRO = "jessie" ]; then
  2296. echo "jessie is PostgreSQL 9.4 by default"
  2297. POSTGRES9=9
  2298. else
  2299. /bin/echo
  2300. /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
  2301. /bin/echo " or verion 9 from PPA?"
  2302. /bin/echo
  2303. read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
  2304. fi
  2305. echo
  2306. ;;
  2307. esac
  2308. fi
  2309. case "$SQLITEMYSQL" in
  2310. [Mm]*)
  2311. #if [ $SQLITEMYSQL == "m" ]; then
  2312. /bin/echo "Installing MySQL"
  2313. /usr/bin/apt-get -y install mysql-server php5-mysql mysql-client
  2314. if [ -e /usr/sbin/nginx ]; then
  2315. #nginx is installed.
  2316. /etc/init.d/php5-fpm restart
  2317. /etc/init.d/nginx restart
  2318. elif [ -e /usr/sbin/apache2 ]; then
  2319. #apache2 is installed.
  2320. /etc/init.d/apache2 restart
  2321. fi
  2322. start_freeswitch
  2323. /bin/echo "Now you'll need to manually finish the install and come back"
  2324. /bin/echo " This way I can finish up the last bit of permissions issues"
  2325. /bin/echo " Just go to"
  2326. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2327. /bin/echo " MAKE SURE YOU CHOOSE MYSQL as your Database on the first page!!!"
  2328. /bin/echo " ON the Second Page:"
  2329. /bin/echo " Create Database Username: root"
  2330. /bin/echo " Create Database Password: the_pw_you_set_during_install"
  2331. /bin/echo " other options: whatever you like"
  2332. /bin/echo " I will wait here until you get done with that."
  2333. /bin/echo -ne " When MySQL is configured come back and press enter. "
  2334. read
  2335. ;;
  2336. [Pp]*)
  2337. #elif [ $SQLITEMYSQL == "p" ]; then
  2338. #/bin/echo -ne "Installing PostgeSQL"
  2339. #moving most of this to fs install
  2340. /bin/echo "Time to add a $GUI_NAME user for the database."
  2341. /bin/echo -ne " We will use $GUI_NAME as the username"
  2342. /bin/echo -ne " please set the password."
  2343. #add php postgres packages
  2344. if [ $POSTGRES9 == "9" ]; then
  2345. /bin/echo " version 9.3"
  2346. if [ $DISTRO = "squeeze" ]; then
  2347. #add squeeze repo
  2348. /bin/echo "Adding debian backports for postgres9.1"
  2349. /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
  2350. /usr/bin/apt-get update
  2351. /usr/bin/apt-get -y -t squeeze-backports install php5-pgsql
  2352. elif [ $DISTRO = "precise" ]; then
  2353. #already there...
  2354. /usr/bin/apt-get -y install php5-pgsql
  2355. elif [ $DISTRO = "wheezy" ]; then
  2356. POSTGRES9=9
  2357. #update repository for postgres 9.4 ...
  2358. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  2359. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
  2360. /usr/bin/apt-get update
  2361. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  2362. elif [ $DISTRO = "jessie" ]; then
  2363. POSTGRES9=9
  2364. /usr/bin/apt-get update
  2365. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  2366. else
  2367. #add the ppa
  2368. /usr/bin/apt-add-repository ppa:pitti/postgresql
  2369. /usr/bin/apt-get update
  2370. /usr/bin/apt-get -y install php5-pgsql
  2371. fi
  2372. else
  2373. /bin/echo " version 8.4"
  2374. /usr/bin/apt-get -y install postgresql libpq-dev
  2375. #The following NEW packages will be installed:
  2376. # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
  2377. # postgresql-client-common postgresql-common
  2378. fi
  2379. #Fix pg_hba.conf
  2380. cat > `find / -name pg_hba.conf` <<EOF
  2381. # TYPE DATABASE USER ADDRESS METHOD
  2382. # Database administrative login by Unix domain socket
  2383. local all postgres peer
  2384. local fusionpbx all md5
  2385. local freeswitch all md5
  2386. # "local" is for Unix domain socket connections only
  2387. local all all peer
  2388. # IPv4 local connections:
  2389. host all all 127.0.0.1/32 md5
  2390. # IPv6 local connections:
  2391. host all all ::1/128 md5
  2392. EOF
  2393. /etc/init.d/postgresql restart
  2394. /bin/su -l postgres -c "/usr/bin/createuser -s -e $GUI_NAME"
  2395. #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O $GUI_NAME $GUI_NAME"
  2396. /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O $GUI_NAME $GUI_NAME"
  2397. PGSQLPASSWORD="dummy"
  2398. PGSQLPASSWORD2="dummy2"
  2399. while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
  2400. /bin/echo
  2401. /bin/echo
  2402. /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
  2403. /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
  2404. /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
  2405. /bin/echo "psql. THE COMMAND USED IS:"
  2406. /bin/echo
  2407. /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER $GUI_NAME with PASSWORD \$PGSQLPASSWORD;' | psql $GUI_NAME\""
  2408. /bin/echo
  2409. /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
  2410. /bin/echo
  2411. /bin/echo "The pgsql username is $GUI_NAME"
  2412. /bin/echo "The pgsql database name is $GUI_NAME"
  2413. /bin/echo "Please provide a password for the $GUI_NAME user"
  2414. #/bin/stty -echo
  2415. read -s -p " Password: " PGSQLPASSWORD
  2416. /bin/echo
  2417. /bin/echo "Let's repeat that"
  2418. read -s -p " Password: " PGSQLPASSWORD2
  2419. /bin/echo
  2420. #/bin/stty echo
  2421. done
  2422. /bin/su -l postgres -c "/bin/echo \"ALTER USER $GUI_NAME with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql $GUI_NAME"
  2423. /bin/echo "overwriting pgsql password variable with random data"
  2424. PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
  2425. PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
  2426. if [ -e /usr/sbin/nginx ]; then
  2427. #nginx is installed.
  2428. /etc/init.d/php5-fpm restart
  2429. /etc/init.d/nginx restart
  2430. elif [ -e /usr/sbin/apache2 ]; then
  2431. #apache2 is installed.
  2432. /etc/init.d/apache2 restart
  2433. fi
  2434. #uncomment below to test the nativepgsql function. currently not working
  2435. # internal/external/callcenter profiles still going to sqlite.
  2436. #nativepgsql
  2437. start_freeswitch
  2438. /bin/echo "Now you'll need to manually finish the install and come back"
  2439. /bin/echo " This way I can finish up the last bit of permissions issues"
  2440. /bin/echo " Just go to"
  2441. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2442. /bin/echo " MAKE SURE YOU CHOOSE PostgreSQL as your Database on the first page!!!"
  2443. /bin/echo " ON the Second Page:"
  2444. /bin/echo " Database Name: $GUI_NAME"
  2445. /bin/echo " Database Username: $GUI_NAME"
  2446. /bin/echo " Database Password: whateveryouentered"
  2447. /bin/echo " Create Database Username: Leave_Blank"
  2448. /bin/echo " Create Database Password: Leave_Blank"
  2449. /bin/echo
  2450. /bin/echo " I will wait here until you get done with that."
  2451. /bin/echo -ne " When PostgreSQL is configured come back and press enter. "
  2452. read
  2453. ;;
  2454. *)
  2455. #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
  2456. /bin/echo "SQLITE is chosen. already done. nothing left to install..."
  2457. if [ -e /usr/sbin/nginx ]; then
  2458. #nginx is installed.
  2459. /etc/init.d/php5-fpm restart
  2460. /etc/init.d/nginx restart
  2461. elif [ -e /usr/sbin/apache2 ]; then
  2462. #apache2 is installed.
  2463. /etc/init.d/apache2 restart
  2464. fi
  2465. start_freeswitch
  2466. /bin/echo "FusionPBX install.php was done automatically"
  2467. /bin/echo " when sqlite was selected. "
  2468. /bin/echo " FreeSWITCH Directory: /usr/local/freeswitch"
  2469. /bin/echo " PHP Directory: $WWW_PATH/$GUI_NAME"
  2470. /bin/echo
  2471. /bin/echo " Database Filename: $GUI_NAME.db"
  2472. /bin/echo " Database Directory: $WWW_PATH/$GUI_NAME/secure"
  2473. /bin/echo
  2474. /bin/echo " Just go to"
  2475. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2476. /bin/echo
  2477. /bin/echo "Default login is (whatever you picked in the GUI install):"
  2478. /bin/echo " User: WhateverUsernameYouPicked"
  2479. /bin/echo " Passwd: YourPasswordYouPicked"
  2480. ;;
  2481. esac
  2482. #else
  2483. # /bin/echo "Didn't catch that. exiting"
  2484. # exit 1
  2485. #fi
  2486. finish_fpbx_install_permissions
  2487. #/bin/echo
  2488. #/bin/echo "The FusionPBX installation messed up permissions of /usr/local/freeswitch/storage"
  2489. #/bin/echo " Fixing..."
  2490. # read
  2491. #/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  2492. #/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  2493. #/bin/echo "Starting FreeSWITCH..."
  2494. #/etc/init.d/freeswitch start
  2495. /bin/echo "Setting up Fail2Ban for FusionPBX"
  2496. fusionfail2ban
  2497. if [ $DISTRO == "jessie" ]; then
  2498. sleep 5
  2499. /bin/systemctl restart fail2ban.service
  2500. else
  2501. /etc/init.d/fail2ban restart
  2502. fi
  2503. /bin/echo
  2504. /bin/echo
  2505. /bin/echo "Installation Completed. Now configure FreeSWITCH via the FusionPBX browser interface"
  2506. /bin/echo
  2507. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2508. /bin/echo "Default login is (whatever you picked in the GUI install):"
  2509. /bin/echo " User: WhateverUsernameYouPicked"
  2510. /bin/echo " Passwd: YourPasswordYouPicked"
  2511. fi
  2512. #------------------------------------
  2513. # DONE INSTALLING FUSIONPBX
  2514. #------------------------------------
  2515. #------------------------------------
  2516. # UPGRADE FREESWITCH
  2517. #------------------------------------
  2518. if [ $UPGFREESWITCH -eq 1 ]; then
  2519. #------------------------
  2520. # build modules.conf
  2521. #------------------------
  2522. /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
  2523. if [ $? -eq 0 ]; then
  2524. /bin/echo "Modules.conf Already edited"
  2525. else
  2526. #file exists and has been edited
  2527. build_modules
  2528. #check exit status
  2529. if [ $? -ne 0 ]; then
  2530. #previous had an error
  2531. /bin/echo "ERROR: Failed to enable build modules in modules.conf."
  2532. exit 1
  2533. else
  2534. /bin/echo "build_modules" >> /tmp/install_fusion_status
  2535. fi
  2536. fi
  2537. if [ $DEBUG -eq 1 ]; then
  2538. /bin/echo
  2539. /bin/echo "Press Enter to continue (check for errors)"
  2540. read
  2541. fi
  2542. #------------------------
  2543. # make current
  2544. #------------------------
  2545. /bin/grep 'made_current' /tmp/install_fusion_status > /dev/null
  2546. if [ $? -eq 0 ]; then
  2547. /bin/echo "Modules.conf Already edited"
  2548. else
  2549. /bin/echo
  2550. /bin/echo ' going to run make curent'
  2551. /bin/echo " Make current completely cleans the build environment and rebuilds FreeSWITCH™"
  2552. /bin/echo " so it runs a long time. However, it will not overwrite files in a pre-existing"
  2553. /bin/echo ' "conf" directory. Also, the clean targets leave the "modules.conf" file.'
  2554. /bin/echo " This handles the git pull, cleanup, and rebuild in one step"
  2555. /bin/echo ' src: http://wiki.freeswitch.org/wiki/Installation_Guide'
  2556. cd /usr/src/freeswitch
  2557. if [ $? -ne 0 ]; then
  2558. #previous had an error
  2559. /bin/echo "/usr/src/freeswitch does not exist"
  2560. /bin/echo "you probably installed from a FusionPBX ISO which deleted this"
  2561. /bin/echo "Directory to save space. rerun with install-freeswitch option"
  2562. exit 1
  2563. fi
  2564. cd /usr/src/freeswitch
  2565. #get on the 1.2.x release first...
  2566. echo
  2567. echo
  2568. echo "Checking to see which version of FreeSWITCH you are on"
  2569. git status |grep "1.2"
  2570. if [ $? -ne 0 ]; then
  2571. echo "It appears that you are currently on the FreeSWITCH Git Master branch, or no branch."
  2572. echo " We currently recommend that you switch to the 1.4.x branch,"
  2573. echo " since 1.5 [master]."
  2574. echo
  2575. read -p "Shall we change to the 1.4.x release branch [Y/n]? " YESNO
  2576. else
  2577. YESNO="no"
  2578. fi
  2579. case $YESNO in
  2580. [Nn]*)
  2581. echo "OK, staying on current...."
  2582. FSSTABLE=false
  2583. ;;
  2584. *)
  2585. echo "OK, switching to 1.4.x."
  2586. FSSTABLE=true
  2587. ;;
  2588. esac
  2589. if [ $FSSTABLE == true ]; then
  2590. echo "OK we'll now use the 1.4.x release branch"
  2591. cd /usr/src/freeswitch
  2592. #odd edge case, I think from a specific version checkout
  2593. # git status
  2594. # Not currently on any branch.
  2595. # Untracked files:
  2596. # (use "git add <file>..." to include in what will be committed)
  2597. #
  2598. # src/mod/applications/mod_httapi/Makefile
  2599. git status |grep -i "not currently"
  2600. if [ $? -eq 0 ]; then
  2601. echo "You are not on master branch. We have to fix that first"
  2602. /usr/bin/git checkout master
  2603. if [ $? -ne 0 ]; then
  2604. #git checkout had an error
  2605. /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2606. exit 1
  2607. fi
  2608. fi
  2609. #/usr/bin/git clone -b $FSStableVer git://stash.freeswitch.org/scm/fs/freeswitch.git
  2610. /usr/bin/git pull
  2611. if [ $? -ne 0 ]; then
  2612. #git checkout had an error
  2613. /bin/echo "GIT PULL to 1.2.x ERROR"
  2614. exit 1
  2615. fi
  2616. /usr/bin/git checkout $FSStableVer
  2617. if [ $? -ne 0 ]; then
  2618. #git checkout had an error
  2619. /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2620. exit 1
  2621. fi
  2622. #/usr/bin/git checkout master
  2623. #if [ $? -ne 0 ]; then
  2624. # #git checkout had an error
  2625. # /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2626. # exit 1
  2627. #fi
  2628. else
  2629. echo "Staying on dev branch."
  2630. fi
  2631. cd /usr/src/freeswitch
  2632. echo "reconfiguring mod_spandsp"
  2633. make spandsp-reconf
  2634. if [ $CORES > "1" ]; then
  2635. /bin/echo " multicore processor detected. Upgrading with -j $CORES"
  2636. /usr/bin/make -j $CORES current
  2637. else
  2638. /bin/echo " singlecore processor detected. Starting upgrade sans -j"
  2639. /usr/bin/make current
  2640. fi
  2641. #/usr/bin/make current
  2642. if [ $? -ne 0 ]; then
  2643. #previous had an error
  2644. /bin/echo "make current error"
  2645. exit 1
  2646. fi
  2647. if [ $DEBUG -eq 1 ]; then
  2648. /bin/echo
  2649. /bin/echo "I'm going to stop here and wait. FreeSWITCH has now been compiled and is ready to install"
  2650. /bin/echo "but in order to do this we need to stop FreeSWITCH [which will dump any active calls]."
  2651. /bin/echo "This should not take too long to finish, but we should try and time things correctly."
  2652. /bin/echo "The current status of your switch is:"
  2653. /bin/echo
  2654. /usr/local/freeswitch/bin/fs_cli -x status
  2655. /bin/echo
  2656. /bin/echo -n "Press Enter to continue the upgrade."
  2657. read
  2658. fi
  2659. /etc/init.d/freeswitch stop
  2660. if [ $? -ne 0 ]; then
  2661. #previous had an error
  2662. /bin/echo "Init ERROR, couldn't stop Freeswitch"
  2663. exit 1
  2664. fi
  2665. /usr/bin/make install
  2666. if [ $? -ne 0 ]; then
  2667. #previous had an error
  2668. /bin/echo "INSTALL ERROR!"
  2669. exit 1
  2670. else
  2671. /bin/echo "made_current" >> /tmp/install_fusion_status
  2672. fi
  2673. fi
  2674. #------------------------
  2675. # enable modules.conf.xml
  2676. #------------------------
  2677. /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
  2678. if [ $? -eq 0 ]; then
  2679. /bin/echo "Modules.conf.xml Already enabled"
  2680. else
  2681. #file exists and has been edited
  2682. enable_modules
  2683. #check exit status
  2684. if [ $? -ne 0 ]; then
  2685. #previous had an error
  2686. /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
  2687. exit 1
  2688. else
  2689. /bin/echo "enable_modules" >> /tmp/install_fusion_status
  2690. fi
  2691. fi
  2692. if [ $DEBUG -eq 1 ]; then
  2693. /bin/echo
  2694. /bin/echo "Press Enter to continue (check for errors)"
  2695. read
  2696. fi
  2697. #check for logrotate and change to cron.daily
  2698. if [ -a /etc/logrotate.d/freeswitch ]; then
  2699. /bin/echo "System configured for logrotate, changing"
  2700. /bin/echo " to new way."
  2701. /bin/rm /etc/logrotate.d/freeswitch
  2702. /etc/init.d/logrotate restart
  2703. freeswitch_logfiles
  2704. fi
  2705. if [ -e $WWW_PATH/$GUI_NAME ]; then
  2706. echo "I noticed that FusionPBX is installed too"
  2707. echo "now going to fix freeswitch permissions from upgrade to be safe"
  2708. www_permissions
  2709. else
  2710. echo "Standalone FreeSWITCH installation, no permissions to change"
  2711. fi
  2712. /etc/init.d/freeswitch start
  2713. fi
  2714. #------------------------------------
  2715. # DONE UPGRADING FREESWITCH
  2716. #------------------------------------
  2717. #------------------------------------
  2718. # UPGRADE FusionPBX
  2719. #------------------------------------
  2720. if [ $UPGFUSION -eq 1 ]; then
  2721. /bin/echo "Resetting FreeSWITCH permissions to www-data in case you did"
  2722. /bin/echo " a FreeSWITCH upgrade as well."
  2723. www_permissions
  2724. cd $WWW_PATH/$GUI_NAME
  2725. /bin/echo
  2726. /bin/echo "STOP! Make sure you are logged into fusionpbx as the superadmin (via browser)!"
  2727. read -p "Have you done this yet (y/n)? " YESNO
  2728. if [ $YESNO == "y" ]; then
  2729. /bin/echo "Be really sure you are logged in as superadmin."
  2730. /bin/echo " If nothing else, refresh the browser to make sure"
  2731. /bin/echo " the session isn't stale."
  2732. /bin/echo
  2733. /bin/echo "If you haven't done this you risk not being able to Upgrade->Schema"
  2734. /bin/echo " which will toast your database"
  2735. /bin/echo
  2736. FUSIONREV=$(svn info $WWW_PATH/$GUI_NAME |grep -i revision|sed -e s/Revision:\ //)
  2737. if [ $FUSIONREV -le 1877 ]; then
  2738. echo "The project is still working on an upgrade tool"
  2739. echo " for the latest svn version. It is recommended"
  2740. echo " that you stay with revision 1877. Your current"
  2741. echo " revision is $FUSIONREV"
  2742. echo
  2743. read -p "Do we want Revision 1877, or latest (1877/latest)? " YESNO2
  2744. else
  2745. read -p "Ready to upgrade (y/n)? " YESNO2
  2746. fi
  2747. case $YESNO2 in
  2748. [YylL]*)
  2749. #svn...
  2750. /usr/bin/svn update $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2751. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2752. #print message saying to hit advanced->upgrade schema
  2753. /bin/echo "Done upgrading Files"
  2754. /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
  2755. /bin/echo "and select Advanced -> Upgrade Schema"
  2756. ;;
  2757. [1]*)
  2758. /usr/bin/svn update -r r1877 $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2759. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2760. #print message saying to hit advanced->upgrade schema
  2761. /bin/echo "Done upgrading Files"
  2762. /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
  2763. /bin/echo "and select Advanced -> Upgrade Schema"
  2764. ;;
  2765. *)
  2766. echo "Bad option, exiting"
  2767. exit 1
  2768. ;;
  2769. esac
  2770. else
  2771. exit 1
  2772. fi
  2773. read -p "Do you want to try and run the auto-upgrade php script from CLI (y/n)? " YESNO
  2774. case $YESNO in
  2775. [yY]*)
  2776. echo "Starting... /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
  2777. /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php
  2778. echo "Done"
  2779. ;;
  2780. *)
  2781. echo "OK, don't forget to run it yourself via GUI or here with"
  2782. echo " /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
  2783. ;;
  2784. esac
  2785. fusionfail2ban
  2786. fi
  2787. #------------------------------------
  2788. # DONE UPGRADING FusionPBX
  2789. #------------------------------------
  2790. #success!!!
  2791. if [ -e /tmp/install_fusion_status ]; then
  2792. /bin/rm /tmp/install_fusion_status
  2793. fi
  2794. /bin/echo "Checking to see if FreeSWITCH is running!"
  2795. /usr/bin/pgrep freeswitch
  2796. if [ $? -ne 0 ]; then
  2797. /etc/init.d/freeswitch start
  2798. else
  2799. /bin/echo " DONE!"
  2800. fi
  2801. exit 0
  2802. ---------
  2803. #CHANGELOG
  2804. #---------
  2805. # vSVN, now using SVN.... November 2011
  2806. #v4.4.0pre 2011 April 12
  2807. #BUGS: FS CHANGED!!! 2011-05-12
  2808. # Add libssl-dev
  2809. # currently mod_cidlookup, mod_xml_curl mod_xml_cdr busted
  2810. #BUGS: FS isn't started at end of install-both auto
  2811. #BUGS: fix-https still throws usage help. check www-permissions too.
  2812. #BUGS: Apache heredoc isn't escaping the variables. documentroot and servername wrong.
  2813. #BUGS: dingaling still not compile right. let's change makefile and recompile module
  2814. #ADD: zip compression to nginx
  2815. #ADD: monit for freeswitch and nginx
  2816. #add libssl-dev for secure sip.
  2817. # ADD mod_spandsp for fax and g722
  2818. # apt-get install libtiff4-dev
  2819. # Add NTP, maybe run sudo ntpdate ntp.ubuntu.com to make suer date is correct.
  2820. # prevents make from dying (date in the future crap).
  2821. # BUGS: Had quotes around nginx config
  2822. # FS failed to start with script
  2823. # Fail2Ban FS-dos has freeswitch2 in jail.local
  2824. # Fail2ban not starting:
  2825. # freeswitch-dos ports wrong in jail.local.
  2826. # build again and run fail2ban-client -d to test.
  2827. # Add Option to download FreeSWITCH compiled source as tar.gz for iso
  2828. # Added Option --fix-permissions
  2829. # checks FreeSWITCH init script
  2830. # Added: upgrade-fusionpbx needs to fix permissions, since a FS upgrade kills them.
  2831. # FIXED Logrotate for nginx
  2832. # logfiles were: /var/log/fusionpbx_gui.*_log;
  2833. # logfiles now: /var/log/nginx/*.log
  2834. # Added: Fail2ban for FusionPBX failed login attempts
  2835. # Need information on attempts/rate/etc
  2836. # Added: Fail2ban for FusionPBX on failed provision attempts
  2837. # Need information on attempts/rate/etc
  2838. # Needs Testing!
  2839. # FIXED: RepeatedMsgReduction wasn't getting set correctly in rsyslog.conf
  2840. # Added Change Fail2ban on FreeSWITCH with attempts/rate/etc in config file (not default settings)
  2841. # Added: Option to download GIT from GitHub repository (It's faster), see DEFINES
  2842. # Make nginx/apache https by default
  2843. # iso needs to regenerate certificates post install, ideally with 10 year expirations.
  2844. # apt-get install ssl-cert
  2845. # ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
  2846. # ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
  2847. # ln -s /etc/ssl/certs/nginx.crt /var/www/fusionpbx/$HOSTNAME.crt
  2848. # /etc/init.d/nginx restart
  2849. # FIXED nginx config to not block html files... Don't do block ~ .ht
  2850. # Added FreeTDM, and Dahdi
  2851. #v4.3.3 2011 January 31
  2852. # Added: smp compile support. Script works, make -j doesn't. see jira FS-3005
  2853. # Fixed: NGinx file size error
  2854. # Added: Remove Nginx/php/apache properly
  2855. # FIXED removing nginx removes gnome/x.
  2856. # Added: Postgres (seems good)
  2857. # Fixed: Set up apache properly (fusionpbx file instead of default, use heredoc)
  2858. # TODO: look into setting up FS for mysql/pgsql
  2859. # Fixed: sqlite http request issue for nginx/apache
  2860. # Added: now doing ppa's the ubuntu way with apt-add-repository
  2861. # Added: set up auto install for nginx/apache, mysql/postgresql/sqlite, setnonat.
  2862. # Added: now prompts for rm -Rf /opt (or variable for auto-install).
  2863. # There's a bug in either ppa-purge or apt-add-repository (likely latter).
  2864. # if you install nginx, change your mind, install apache, change your mind again
  2865. # and re-install nginx, the repository for nginx/php5-fpm gets removed proerly
  2866. # [a '#' covers repo], but when re-enabling, the '#' gets replaced, and an 'n'
  2867. # is left on a newline afterward, preventing update/install from that repo.
  2868. # Fixed: Checking for nginx/apache2 binary instead of init scripts for if[x] restart
  2869. #v4.3.2.1 2011 January 1
  2870. # small problem when selecting nginx and sqlite. php5-fpm needed to restart
  2871. # so FusionPBX could see the FreeSWITCH directory.
  2872. #v4.3.2 2010 December 30
  2873. # logrotate was improperly setup. Needed to send sighup to fs_cli
  2874. # Caused FS to die the first time it tried to log after rotation.
  2875. # php5-cli is a dependancy. required for voicemail to email, and fax to email.
  2876. # added an nginx/php-fpm option. You can change a variable (for auto run)
  2877. # or it will prompt you when you install fusionpbx in user mode
  2878. # mysql added as an option.
  2879. # problem with the way ubuntu logs ssh failures [fail2ban]
  2880. # Failed password for root from 1.2.3.4 port 22 ssh2
  2881. # last message repeated 5 times
  2882. # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
  2883. # fail2ban: previous setup looked for freeswitch log in /var/log/freeswitch.log
  2884. # log is actually /usr/local/freeswitch/log/freeswitch.log
  2885. # Tries to see if you're on a static IP address. If you are, it wants to start
  2886. # FreeSWITCH with the -nonat option to save some time. Also a new variable
  2887. # TODO: Maybe probe cores and to the -b thing for quicker compile/bootstrap
  2888. # TODO: IPTABLES
  2889. #v4.3.1 2010 December 23
  2890. # look into make -j cores option
  2891. # made a state save file. so if there's an error, don't re-bootstrap, configure, etc.
  2892. # and remove it on a clean exit.
  2893. # requests for modules add/enable for ugrade-freeswitch. DONE
  2894. # mod dingaling needs libgnutls-dev libgnutls26 packages, and change:
  2895. # "--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
  2896. # in /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
  2897. # appears to be an ubuntu problem....
  2898. #v4.3 2010 December 22
  2899. # under case upgrade-freeswitch, variables were not set properly. It upgraded fusionpbx.. fixed.
  2900. # done: fail2ban error fixed. removed associated text
  2901. # done: have install check for /etc/fail2ban. reinstall (as in from iso) duplicates some txt
  2902. # done: remove or fix fusionpbx upgrade code. it either needs to log in
  2903. # and then update and run the schema upgrade. or get rid of it. Fixed by prompting the user
  2904. # to open a browser window, and warn.
  2905. # done: get logrotate working... let's not fill the disk.
  2906. # stop/start freeswitch for an upgrade, and an install...
  2907. #v4.2 2010 December 17
  2908. # made some changes so the text flows correctly now that we use curl
  2909. # to do install.php.
  2910. # sent curl output to dev null..
  2911. # added apt-get update before we install apache since remastersys removes apt data
  2912. # stopping FS before FusionPBX install, and starting afteward.
  2913. # changed license to WAF v1
  2914. #v4.1 2010 December 15
  2915. # changing cd sounds (48/32/16/8khz) down to hd sounds (16/8Kkhz)
  2916. #v4 2010 December 14
  2917. # now install-fusion|install-freeswitch|upgrade...
  2918. # also adding curl commands to finish fusionpbx install.
  2919. #v3 adding fail2ban et al.
  2920. #v2 2010 December 07
  2921. # adds arrays to process the modules. should make this much easier to edit.
  2922. # just make additions to modules_add
  2923. # This should work fine (even on a 2nd run).
  2924. #v1 2010 December 06
  2925. # was first cut