install_fusionpbx.sh 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291
  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. yasm nasm
  848. else
  849. /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
  850. python-dev pkg-config libtiff5-dev libldns-dev \
  851. libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
  852. libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev \
  853. autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev libjpeg62-dev \
  854. screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
  855. time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev
  856. fi
  857. ##1.6 stuff
  858. echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
  859. wget -O - http://files.freeswitch.org/repo/deb/freeswitch-1.6/key.gpg |apt-key add -
  860. /usr/bin/apt-get update
  861. /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
  862. #added libgnutls-dev libgnutls26 for dingaling...
  863. #gnutls no longer required for dingaling (git around oct 17 per mailing list..)
  864. # removed libgnutls-dev libgnutls26
  865. if [ $DO_DAHDI == "y" ]; then
  866. #add stuff for free_tdm/dahdi
  867. apt-get -y install linux-headers-`uname -r`
  868. #add the headers so dahdi can build the modules...
  869. apt-get -y install dahdi
  870. fi
  871. LDRUN=0
  872. /bin/echo -ne "Waiting on ldconfig to finish so bootstrap will work"
  873. while [ $LDRUN -eq 0 ]
  874. do
  875. echo -ne "."
  876. sleep 1
  877. /usr/bin/pgrep -f ldconfig > /dev/null
  878. LDRUN=$?
  879. done
  880. /bin/echo
  881. /bin/echo
  882. /bin/echo "ldconfig is finished"
  883. /bin/echo
  884. if [ ! -e /tmp/install_fusion_status ]; then
  885. touch /tmp/install_fusion_status
  886. fi
  887. if [ $DEBUG -eq 1 ]; then
  888. /bin/echo
  889. read -p "Press Enter to continue check for errors"
  890. fi
  891. #-----------------
  892. # Databases
  893. #-----------------
  894. #Lets ask... sqlite or postgresql -- for user option only
  895. if [ $DEBUG -eq 1 ]; then
  896. /bin/echo "New Option..."
  897. /bin/echo " FreeSWITCH now has native support for PostgreSQL (no more odbc in the core)"
  898. /bin/echo " also note that freeswitch is now compiled with zrtp support"
  899. /bin/echo
  900. read -p " Would you like to install PostgreSQL or stay with Sqlite (p/S)? " SQLITEMYSQL
  901. case "$SQLITEMYSQL" in
  902. [pP]*)
  903. if [ $DISTRO = "wheezy" ]; then
  904. echo "wheezy is PostgreSQL 9.4 by default"
  905. POSTGRES9=9
  906. elif [ $DISTRO = "jessie" ]; then
  907. echo "jessie is PostgreSQL 9.4 by default"
  908. POSTGRES9=9
  909. else
  910. /bin/echo
  911. /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
  912. /bin/echo " or verion 9 from PPA?"
  913. /bin/echo
  914. read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
  915. fi
  916. echo
  917. ;;
  918. esac
  919. fi
  920. case "$SQLITEMYSQL" in
  921. [Pp]*)
  922. /bin/echo -ne "Installing PostgeSQL"
  923. /bin/echo "DISTRO IS $DISTRO space"
  924. if [ $POSTGRES9 == "9" ]; then
  925. /bin/echo " version 9.x"
  926. if [ $DISTRO = "squeeze" ]; then
  927. #add squeeze repo
  928. /bin/echo "Adding debian backports for postgres9.1"
  929. /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
  930. /usr/bin/apt-get update
  931. /usr/bin/apt-get -y -t squeeze-backports install postgresql-9.1 libpq-dev
  932. elif [ $DISTRO = "precise" ]; then
  933. POSTGRES9=9
  934. #update repository for postgres 9.4 ...
  935. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  936. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
  937. /usr/bin/apt-get update
  938. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev
  939. elif [ $DISTRO = "wheezy" ]; then
  940. POSTGRES9=9
  941. #update repository for postgres 9.4 ...
  942. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  943. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
  944. /usr/bin/apt-get update
  945. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  946. elif [ $DISTRO = "jessie" ]; then
  947. POSTGRES9=9
  948. /usr/bin/apt-get update
  949. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  950. service postgresql status |grep down
  951. if [ $? -eq 0 ]; then
  952. echo "The postgresql service is not running"
  953. echo "It may have not detected the locale correctly"
  954. echo "In another screen you should create a new cluster"
  955. echo " example:"
  956. echo " pg_createcluster --locale en_US.UTF-8 --start 9.3 main"
  957. echo " then see if it is running with 'service postgresql status'"
  958. read -p " this script will pause until this issue is resolved"
  959. fi
  960. else
  961. #add the ppa
  962. /usr/bin/apt-add-repository ppa:pitti/postgresql
  963. /usr/bin/apt-get update
  964. /usr/bin/apt-get -y install postgresql-9.3 libpq-dev
  965. fi
  966. else
  967. /bin/echo " version 8.4"
  968. /usr/bin/apt-get -y install postgresql libpq-dev
  969. #The following NEW packages will be installed:
  970. # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
  971. # postgresql-client-common postgresql-common
  972. fi
  973. #Fix pg_hba.conf
  974. cat > `find / -name pg_hba.conf` <<EOF
  975. # TYPE DATABASE USER ADDRESS METHOD
  976. # Database administrative login by Unix domain socket
  977. local all postgres peer
  978. local fusionpbx all md5
  979. local freeswitch all md5
  980. # "local" is for Unix domain socket connections only
  981. local all all peer
  982. # IPv4 local connections:
  983. host all all 127.0.0.1/32 md5
  984. # IPv6 local connections:
  985. host all all ::1/128 md5
  986. EOF
  987. /etc/init.d/postgresql restart
  988. /bin/su -l postgres -c "/usr/bin/createuser -s -e fusionpbx"
  989. #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O fusionpbx freeswitch"
  990. /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O fusionpbx freeswitch"
  991. PGSQLPASSWORD="dummy"
  992. PGSQLPASSWORD2="dummy2"
  993. while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
  994. /bin/echo
  995. /bin/echo
  996. /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
  997. /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
  998. /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
  999. /bin/echo "psql. THE COMMAND USED IS:"
  1000. /bin/echo
  1001. /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER fusionpbx with PASSWORD \$PGSQLPASSWORD;' | psql freeswitch\""
  1002. /bin/echo
  1003. /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
  1004. /bin/echo
  1005. /bin/echo "The pgsql username is fusionpbx"
  1006. /bin/echo "The pgsql database name is freeswitch"
  1007. /bin/echo "Please provide a password for the fusionpbx user"
  1008. #/bin/stty -echo
  1009. read -s -p " Password: " PGSQLPASSWORD
  1010. /bin/echo
  1011. /bin/echo "Let's repeat that"
  1012. read -s -p " Password: " PGSQLPASSWORD2
  1013. /bin/echo
  1014. #/bin/stty echo
  1015. done
  1016. /bin/su -l postgres -c "/bin/echo \"ALTER USER fusionpbx with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql freeswitch"
  1017. /bin/echo "overwriting pgsql password variable with random data"
  1018. PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
  1019. PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
  1020. ;;
  1021. *)
  1022. #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
  1023. /bin/echo "SQLITE is chosen. already done. nothing left to install..."
  1024. ;;
  1025. esac
  1026. #------------------------
  1027. # GIT FREESWITCH
  1028. #------------------------
  1029. /bin/grep 'git_done' /tmp/install_fusion_status > /dev/null
  1030. if [ $? -eq 0 ]; then
  1031. /bin/echo "Git Already Done. Skipping"
  1032. else
  1033. cd /usr/src
  1034. if [ "$FSSTABLE" == true ]; then
  1035. echo "installing $FSStableVer of FreeSWITCH"
  1036. /usr/bin/git clone $FSGIT
  1037. cd /usr/src/freeswitch
  1038. /usr/bin/git checkout $FSStableVer
  1039. if [ $? -ne 0 ]; then
  1040. #git had an error
  1041. /bin/echo "GIT ERROR"
  1042. exit 1
  1043. fi
  1044. elif [ "$FSSTABLE" == file ]; then
  1045. echo "installing $FSStablefile of FreeSWITCH"
  1046. wget http://files.freeswitch.org/freeswitch-releases/$FSStablefile.tar.gz
  1047. tar -zxvf $FSStablefile.tar.gz
  1048. mkdir freeswitch
  1049. cp -R $FSStablefile/* /usr/src/freeswitch/
  1050. cd /usr/src/freeswitch
  1051. else
  1052. echo "going dev branch."
  1053. /usr/bin/git clone $FSGIT
  1054. if [ $? -ne 0 ]; then
  1055. #git had an error
  1056. /bin/echo "GIT ERROR"
  1057. exit 1
  1058. fi
  1059. if [ $FSCHECKOUTVER == true ]; then
  1060. echo "OK we'll check out FreeSWITCH version $FSREV"
  1061. cd /usr/src/freeswitch
  1062. /usr/bin/git checkout $FSREV
  1063. if [ $? -ne 0 ]; then
  1064. #git checkout had an error
  1065. /bin/echo "GIT CHECKOUT ERROR"
  1066. exit 1
  1067. fi
  1068. fi
  1069. /bin/echo "git_done" >> /tmp/install_fusion_status
  1070. fi
  1071. fi
  1072. if [ -e /usr/src/FreeSWITCH ]; then
  1073. /bin/ln -s /usr/src/FreeSWITCH /usr/src/freeswitch
  1074. elif [ -e /usr/src/freeswitch.git ]; then
  1075. /bin/ln -s /usr/src/freeswitch.git /usr/src/freeswitch
  1076. fi
  1077. if [ $DEBUG -eq 1 ]; then
  1078. /bin/echo
  1079. read -p "Press Enter to continue (check for errors)"
  1080. fi
  1081. #------------------------
  1082. # BOOTSTRAP FREESWITCH
  1083. #------------------------
  1084. /bin/grep 'bootstrap_done' /tmp/install_fusion_status > /dev/null
  1085. if [ $? -eq 0 ]; then
  1086. /bin/echo "Bootstrap already done. skipping"
  1087. elif [ "$FSSTABLE" == file ]; then
  1088. echo "bootstrap not required"
  1089. else
  1090. #Attempt to fix build on 1.6.6
  1091. sed -i "40i m4_include(m4/memmove.m4)" /usr/src/freeswitch/libs/spandsp/configure.ac
  1092. cat > /usr/src/freeswitch/libs/spandsp/m4/memmove.m4 <<EOF
  1093. AC_DEFUN([AC_FUNC_MEMMOVE],
  1094. [AC_CHECK_FUNCS(memmove)
  1095. AC_MSG_CHECKING(for working memmove)
  1096. AC_CACHE_VAL(ac_cv_have_working_memmove,
  1097. [AC_TRY_RUN(
  1098. [#include <stdio.h>
  1099. int main(void)
  1100. {
  1101. char buf[10];
  1102. strcpy (buf, "01234567");
  1103. memmove (buf, buf + 2, 3);
  1104. if (strcmp (buf, "23434567"))
  1105. exit (1);
  1106. strcpy (buf, "01234567");
  1107. memmove (buf + 2, buf, 3);
  1108. if (strcmp (buf, "01012567"))
  1109. exit (1);
  1110. exit (0);
  1111. }], ac_cv_have_working_memmove=yes, ac_cv_have_working_memmove=no, ac_cv_have_working_memmove=cross)])
  1112. AC_MSG_RESULT([$ac_cv_have_working_memmove])
  1113. if test x$ac_cv_have_working_memmove != "xyes"; then
  1114. AC_LIBOBJ(memmove)
  1115. AC_MSG_WARN([Replacing missing/broken memmove.])
  1116. AC_DEFINE(PREFER_PORTABLE_MEMMOVE, 1, "enable replacement memmove if system memmove is broken or missing")
  1117. fi])
  1118. EOF
  1119. #might see about -j option to bootstrap.sh
  1120. /etc/init.d/ssh start
  1121. cd /usr/src/freeswitch
  1122. /bin/echo
  1123. /bin/echo "FreeSWITCH Downloaded"
  1124. /bin/echo
  1125. /bin/echo "Bootstrapping."
  1126. /bin/echo
  1127. #next line failed (couldn't find file) not sure why.
  1128. #it did run fine a second time. Go figure (really).
  1129. #ldconfig culprit?
  1130. if [ $CORES -gt 1 ]; then
  1131. /bin/echo " multicore processor detected. Starting Bootstrap with -j"
  1132. if [ $DEBUG -eq 1 ]; then
  1133. /bin/echo
  1134. read -p "Press Enter to continue (check for errors)"
  1135. fi
  1136. /usr/src/freeswitch/bootstrap.sh -j
  1137. else
  1138. /bin/echo " singlecore processor detected. Starting Bootstrap sans -j"
  1139. if [ $DEBUG -eq 1 ]; then
  1140. /bin/echo
  1141. read -p "Press Enter to continue (check for errors)"
  1142. fi
  1143. /usr/src/freeswitch/bootstrap.sh
  1144. fi
  1145. if [ $? -ne 0 ]; then
  1146. #bootstrap had an error
  1147. /bin/echo "BOOTSTRAP ERROR"
  1148. exit 1
  1149. else
  1150. /bin/echo "bootstrap_done" >> /tmp/install_fusion_status
  1151. fi
  1152. fi
  1153. if [ $DEBUG -eq 1 ]; then
  1154. /bin/echo
  1155. read -p "Press Enter to continue (check for errors)"
  1156. fi
  1157. #------------------------
  1158. # build modules.conf
  1159. #------------------------
  1160. /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
  1161. if [ $? -eq 0 ]; then
  1162. /bin/echo "Modules.conf Already edited"
  1163. else
  1164. #file exists and has been edited
  1165. build_modules
  1166. #check exit status
  1167. if [ $? -ne 0 ]; then
  1168. #previous had an error
  1169. /bin/echo "ERROR: Failed to enable build modules in modules.conf."
  1170. exit 1
  1171. else
  1172. /bin/echo "build_modules" >> /tmp/install_fusion_status
  1173. fi
  1174. fi
  1175. if [ $DEBUG -eq 1 ]; then
  1176. /bin/echo
  1177. read -p "Press Enter to continue (check for errors)"
  1178. fi
  1179. #------------------------
  1180. # CONFIGURE FREESWITCH
  1181. #------------------------
  1182. /bin/grep 'config_done' /tmp/install_fusion_status > /dev/null
  1183. if [ $? -eq 0 ]; then
  1184. /bin/echo "FreeSWITCH already Configured! Skipping."
  1185. else
  1186. /bin/echo
  1187. /bin/echo -ne "Configuring FreeSWITCH. This will take a while [~15 minutes]"
  1188. /bin/sleep 1
  1189. /bin/echo -ne " ."
  1190. /bin/sleep 1
  1191. /bin/echo -ne " ."
  1192. /bin/sleep 1
  1193. /bin/echo -ne " ."
  1194. case "$FSDB" in
  1195. [Pp]*)
  1196. #/usr/src/freeswitch/configure --enable-core-pgsql-support --enable-zrtp
  1197. #zrtp busted atm.
  1198. /usr/src/freeswitch/configure --enable-core-pgsql-support
  1199. ;;
  1200. *)
  1201. #/usr/src/freeswitch/configure --enable-zrtp
  1202. #zrtp busted atm
  1203. /usr/src/freeswitch/configure
  1204. ;;
  1205. esac
  1206. if [ $? -ne 0 ]; then
  1207. #previous had an error
  1208. /bin/echo "ERROR: FreeSWITCH Configure ERROR."
  1209. exit 1
  1210. else
  1211. /bin/echo "config_done" >> /tmp/install_fusion_status
  1212. fi
  1213. fi
  1214. if [ $DEBUG -eq 1 ]; then
  1215. /bin/echo
  1216. read -p "Press Enter to continue (check for errors)"
  1217. fi
  1218. if [ -a /etc/init.d/freeswitch ]; then
  1219. /bin/echo " In case of an install where FS exists (iso), stop FS"
  1220. /etc/init.d/freeswitch stop
  1221. fi
  1222. #------------------------
  1223. # COMPILE FREESWITCH
  1224. #------------------------
  1225. /bin/grep 'compile_done' /tmp/install_fusion_status > /dev/null
  1226. if [ $? -eq 0 ]; then
  1227. /bin/echo "FreeSWITCH already Compiled! Skipping."
  1228. else
  1229. #might see about -j cores option to make...
  1230. /bin/echo
  1231. /bin/echo -ne "Compiling FreeSWITCH. This might take a while [~30 minutes]"
  1232. /bin/sleep 1
  1233. /bin/echo -ne "."
  1234. /bin/sleep 1
  1235. /bin/echo -ne "."
  1236. /bin/sleep 1
  1237. /bin/echo -ne "."
  1238. #making sure pwd is correct
  1239. cd /usr/src/freeswitch
  1240. if [ $CORES -gt 1 ]; then
  1241. /bin/echo " multicore processor detected. Compiling with -j $CORES"
  1242. #per anthm compile the freeswitch core first, then the modules.
  1243. /usr/bin/make -j $CORES core
  1244. /usr/bin/make -j $CORES
  1245. else
  1246. /bin/echo " singlecore processor detected. Starting compile sans -j"
  1247. /usr/bin/make
  1248. fi
  1249. if [ $? -ne 0 ]; then
  1250. #previous had an error
  1251. /bin/echo "ERROR: FreeSWITCH Build Failure."
  1252. exit 1
  1253. else
  1254. /bin/echo "compile_done" >> /tmp/install_fusion_status
  1255. fi
  1256. fi
  1257. if [ $DEBUG -eq 1 ]; then
  1258. /bin/echo
  1259. read -p "Press Enter to continue (check for errors)"
  1260. fi
  1261. #------------------------
  1262. # INSTALL FREESWITCH
  1263. #------------------------
  1264. /bin/grep 'install_done' /tmp/install_fusion_status > /dev/null
  1265. if [ $? -eq 0 ]; then
  1266. /bin/echo "FreeSWITCH already Installed! Skipping."
  1267. else
  1268. #dingaling/ubuntu has an issue. let's edit the file...
  1269. #"--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
  1270. #tls no longer required for dingaling, so this weird issue doesn't happen. now uses openssl.
  1271. # /bin/grep 'lgnutls' /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la > /dev/null
  1272. # if [ $? -eq 0 ]; then
  1273. # /bin/echo "dingaling fix already applied."
  1274. # else
  1275. # /bin/sed -i -e s,'--mode=relink gcc','--mode=relink gcc -lgnutls', /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
  1276. # fi
  1277. cd /usr/src/freeswitch
  1278. if [ $CORES -gt 1 ]; then
  1279. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1280. /usr/bin/make -j $CORES install
  1281. else
  1282. /bin/echo " singlecore processor detected. Starting install sans -j"
  1283. /usr/bin/make install
  1284. fi
  1285. #/usr/bin/make install
  1286. if [ $? -ne 0 ]; then
  1287. #previous had an error
  1288. /bin/echo "ERROR: FreeSWITCH INSTALL Failure."
  1289. exit 1
  1290. else
  1291. /bin/echo "install_done" >> /tmp/install_fusion_status
  1292. fi
  1293. fi
  1294. #------------------------
  1295. # FREESWITCH HD SOUNDS
  1296. #------------------------
  1297. /bin/grep 'sounds_done' /tmp/install_fusion_status > /dev/null
  1298. if [ $? -eq 0 ]; then
  1299. /bin/echo "FreeSWITCH HD SOUNDS DONE! Skipping."
  1300. else
  1301. /bin/echo
  1302. /bin/echo -ne "Installing FreeSWITCH HD sounds (16/8khz). This will take a while [~10 minutes]"
  1303. /bin/sleep 1
  1304. /bin/echo -ne "."
  1305. /bin/sleep 1
  1306. /bin/echo -ne "."
  1307. /bin/sleep 1
  1308. /bin/echo "."
  1309. cd /usr/src/freeswitch
  1310. if [ $CORES -gt 1 ]; then
  1311. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1312. /usr/bin/make -j $CORES hd-sounds-install
  1313. else
  1314. /bin/echo " singlecore processor detected. Starting install sans -j"
  1315. /usr/bin/make hd-sounds-install
  1316. fi
  1317. #/usr/bin/make hd-sounds-install
  1318. if [ $? -ne 0 ]; then
  1319. #previous had an error
  1320. /bin/echo "ERROR: FreeSWITCH make cdsounds-install ERROR."
  1321. exit 1
  1322. else
  1323. /bin/echo "sounds_done" >> /tmp/install_fusion_status
  1324. fi
  1325. fi
  1326. if [ $DEBUG -eq 1 ]; then
  1327. /bin/echo
  1328. read -p "Press Enter to continue (check for errors)"
  1329. fi
  1330. #------------------------
  1331. # FREESWITCH MOH
  1332. #------------------------
  1333. /bin/grep 'moh_done' /tmp/install_fusion_status > /dev/null
  1334. if [ $? -eq 0 ]; then
  1335. /bin/echo "FreeSWITCH MOH DONE! Skipping."
  1336. else
  1337. /bin/echo
  1338. /bin/echo -ne "Installing FreeSWITCH HD Music On Hold sounds (16/8kHz). This will take a while [~10 minutes]"
  1339. /bin/sleep 1
  1340. /bin/echo -ne "."
  1341. /bin/sleep 1
  1342. /bin/echo -ne "."
  1343. /bin/sleep 1
  1344. /bin/echo "."
  1345. cd /usr/src/freeswitch
  1346. if [ $CORES -gt 1 ]; then
  1347. /bin/echo " multicore processor detected. Installing with -j $CORES"
  1348. /usr/bin/make -j $CORES hd-moh-install
  1349. else
  1350. /bin/echo " singlecore processor detected. Starting install sans -j"
  1351. /usr/bin/make hd-moh-install
  1352. fi
  1353. #/usr/bin/make hd-moh-install
  1354. if [ $? -ne 0 ]; then
  1355. #previous had an error
  1356. /bin/echo "ERROR: FreeSWITCH make cd-moh-install ERROR."
  1357. exit 1
  1358. else
  1359. /bin/echo "moh_done" >> /tmp/install_fusion_status
  1360. fi
  1361. fi
  1362. if [ $DEBUG -eq 1 ]; then
  1363. /bin/echo
  1364. read -p "Press Enter to continue (check for errors)"
  1365. fi
  1366. #------------------------
  1367. # FREESWITCH INIT
  1368. #------------------------
  1369. #no need for tmp file. already handled...
  1370. /bin/echo
  1371. /bin/echo "Configuring /etc/init.d/freeswitch"
  1372. /bin/grep local /etc/init.d/freeswitch > /dev/null
  1373. if [ $? -eq 0 ]; then
  1374. #file exists and has been edited
  1375. /bin/echo "/etc/init.d/freeswitch already edited, skipping"
  1376. elif [ -e /usr/src/freeswitch/debian/freeswitch.init ]; then
  1377. /bin/sed /usr/src/freeswitch/debian/freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
  1378. else
  1379. /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
  1380. #DAEMON
  1381. /bin/sed -i /etc/init.d/freeswitch -e s,^DAEMON=.*,DAEMON=/usr/local/freeswitch/bin/freeswitch,
  1382. #DAEMON_ARGS
  1383. /bin/sed -i /etc/init.d/freeswitch -e s,'^DAEMON_ARGS=.*','DAEMON_ARGS="-u www-data -g www-data -rp -nc -nonat"',
  1384. #PIDFILE
  1385. /bin/sed -i /etc/init.d/freeswitch -e s,^PIDFILE=.*,PIDFILE=/usr/local/freeswitch/run/\$NAME.pid,
  1386. #WORKDIR
  1387. /bin/sed -i /etc/init.d/freeswitch -e s,^WORKDIR=.*,WORKDIR=/usr/local/freeswitch/lib/,
  1388. fi
  1389. if [ $? -ne 0 ]; then
  1390. #previous had an error
  1391. /bin/echo "ERROR: Couldn't edit FreeSWITCH init script."
  1392. exit 1
  1393. fi
  1394. /bin/chmod 755 /etc/init.d/freeswitch
  1395. /bin/echo "enabling FreeSWITCH to start at boot"
  1396. /bin/mkdir /etc/freeswitch
  1397. /bin/touch /etc/freeswitch/freeswitch.xml
  1398. /bin/grep true /etc/default/freeswitch > /dev/null
  1399. if [ $? -eq 0 ]; then
  1400. #file exists and has been edited
  1401. /bin/echo "/etc/default/freeswitch already edited, skipping"
  1402. else
  1403. if [ -e /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default ]; then
  1404. /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default -e s,false,true, > /etc/default/freeswitch
  1405. if [ $? -ne 0 ]; then
  1406. #previous had an error
  1407. /bin/echo "ERROR: Couldn't edit freeswitch RC script."
  1408. exit 1
  1409. fi
  1410. else
  1411. /bin/sed /usr/src/freeswitch/debian/freeswitch.default -e s,false,true, > /etc/default/freeswitch
  1412. if [ $? -ne 0 ]; then
  1413. #previous had an error
  1414. /bin/echo "ERROR: Couldn't edit freeswitch RC script."
  1415. exit 1
  1416. fi
  1417. fi
  1418. if [ $DEBUG -eq 1 ]; then
  1419. /bin/echo "Checking for a public IP Address..."
  1420. PUBLICIP=no
  1421. #turn off the auto-nat when we start freeswitch.
  1422. #nasty syntax. searches for 10.a.b.c or 192.168.x.y addresses in ifconfig.
  1423. /sbin/ifconfig | \
  1424. /bin/grep 'inet addr:' | \
  1425. /usr/bin/cut -d: -f2 | \
  1426. /usr/bin/awk '{ print $1}' | \
  1427. while read IPADDR; do
  1428. echo "$IPADDR" | \
  1429. /bin/grep -e '^10\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
  1430. -e '^192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
  1431. -e '^127.0.0.1$'
  1432. #-e '^172\.[16-31]\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
  1433. if [ $? -ne 0 ]; then
  1434. PUBLICIP=yes
  1435. fi
  1436. done
  1437. case "$PUBLICIP" in
  1438. [Yy]*)
  1439. if [ $DEBUG -eq 1 ]; then
  1440. /bin/echo "You appear to have a public IP address."
  1441. /bin/echo " I can make sure FreeSWITCH starts with"
  1442. /bin/echo " the -nonat option (starts quicker)."
  1443. /bin/echo
  1444. read -p "Would you like for me to do this (y/n)? " SETNONAT
  1445. fi
  1446. ;;
  1447. *)
  1448. /bin/echo "Dynamic IP. leaving FreeSWITCH for aggressive nat"
  1449. SETNONAT=no
  1450. ;;
  1451. esac
  1452. fi
  1453. case "$SETNONAT" in
  1454. [Yy]*)
  1455. /bin/sed /etc/default/freeswitch -i -e s,'FREESWITCH_PARAMS="-nc"','FREESWITCH_PARAMS="-nc -nonat -reincarnate"',
  1456. /bin/echo "init script set to start 'freeswitch -nc -nonat'"
  1457. ;;
  1458. *)
  1459. /bin/echo "OK, not using -nonat option."
  1460. ;;
  1461. esac
  1462. /bin/echo
  1463. /usr/sbin/update-rc.d -f freeswitch defaults
  1464. fi
  1465. /bin/echo
  1466. #don't do this. If freeswitch is a machine name, it really screws this test. It
  1467. #won't hurt to adduser a second time anyhow.
  1468. #/bin/grep freeswitch /etc/passwd > /dev/null
  1469. #if [ $? -eq 0 ]; then
  1470. #user already exists
  1471. # /bin/echo "FreeSWITCH user already exists, skipping..."
  1472. #else
  1473. /bin/echo "adding freeswitch user"
  1474. /usr/sbin/adduser --disabled-password --quiet --system \
  1475. --home /usr/local/freeswitch \
  1476. --gecos "FreeSWITCH Voice Platform" --ingroup daemon \
  1477. freeswitch
  1478. if [ $? -ne 0 ]; then
  1479. #previous had an error
  1480. /bin/echo "ERROR: Failed adding freeswitch user."
  1481. exit 1
  1482. fi
  1483. #fi
  1484. /usr/sbin/adduser freeswitch audio
  1485. /usr/sbin/groupadd freeswitch
  1486. if [ $DO_DAHDI == "y" ]; then
  1487. #dialout for dahdi
  1488. /usr/sbin/adduser freeswitch dialout
  1489. fi
  1490. /bin/chown -R freeswitch:daemon /usr/local/freeswitch/
  1491. /bin/echo "removing 'other' permissions on freeswitch"
  1492. /bin/chmod -R o-rwx /usr/local/freeswitch/
  1493. /bin/echo
  1494. cd /usr/local/
  1495. /bin/chown -R freeswitch:daemon /usr/local/freeswitch
  1496. /bin/echo "FreeSWITCH directories now owned by freeswitch.daemon"
  1497. /usr/bin/find freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
  1498. /bin/echo "FreeSWITCH directories now sticky group. This will cause any files created"
  1499. /bin/echo " to default to the daemon group so FreeSWITCH can read them"
  1500. /bin/echo
  1501. #/bin/echo "removing /opt blindly (hope nothing is there) and linking it"
  1502. #/bin/echo " to /usr/local so FusionPBX won't complain"
  1503. #Opt might have been created due to a type in adduser freeswitch (home was /opt) check...
  1504. #this looks to be the case.
  1505. #the latest FusionBPX is correctly detecting /usr/local/freeswitch
  1506. # probably always did.
  1507. #let's try removing opt altogether...
  1508. #/bin/echo
  1509. /bin/ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
  1510. #if [ $DEBUG -eq 1 ]; then
  1511. # /bin/echo "FreeSWITCH was installed to /usr/local."
  1512. # /bin/echo " normally we don't want to see /opt"
  1513. # /bin/echo " since FusionPBX. tries to find it"
  1514. # /bin/echo " and you end up with having to symlink"
  1515. # /bin/echo " /usr/local/freeswitch to /opt/freeswitch"
  1516. # /bin/echo
  1517. # /bin/echo " It would be easier to blow /opt away; but"
  1518. # /bin/echo " this may not be a fresh Ubuntu install."
  1519. # /bin/echo
  1520. # read -p "Can I 'rm -Rf /opt (Y/n)? " RMOPT
  1521. #fi
  1522. #case "$RMOPT" in
  1523. #[Yy]*)
  1524. # /bin/rm -Rf /opt
  1525. #;;
  1526. #*)
  1527. #/bin/echo "OK, linking /usr/local/freeswitch to /opt/freeswitch"
  1528. #/bin/ln -s /usr/local/freeswitch /opt/freeswitch
  1529. #;;
  1530. #esac
  1531. if [ $DEBUG -eq 1 ]; then
  1532. /bin/echo
  1533. /bin/echo "Press Enter to continue (check for errors)"
  1534. read
  1535. fi
  1536. #------------------------
  1537. # enable modules.conf.xml
  1538. #------------------------
  1539. /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
  1540. if [ $? -eq 0 ]; then
  1541. /bin/echo "Modules.conf.xml Already enabled"
  1542. else
  1543. #file exists and has been edited
  1544. enable_modules
  1545. #check exit status
  1546. if [ $? -ne 0 ]; then
  1547. #previous had an error
  1548. /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
  1549. exit 1
  1550. else
  1551. /bin/echo "enable_modules" >> /tmp/install_fusion_status
  1552. fi
  1553. fi
  1554. if [ $DEBUG -eq 1 ]; then
  1555. /bin/echo
  1556. read -p "Press Enter to continue (check for errors)"
  1557. fi
  1558. #-----------------
  1559. #Setup logrotate
  1560. #-----------------
  1561. # if [ -a /etc/logrotate.d/freeswitch ]; then
  1562. if [ -a /etc/cron.daily/freeswitch_log_rotation ]; then
  1563. /bin/echo "Logrotate for FreeSWITCH Already Done!"
  1564. #call log script creation function
  1565. freeswitch_logfiles
  1566. fi
  1567. #-----------------
  1568. #harden FreeSWITCH
  1569. #-----------------
  1570. /bin/echo -ne "HARDENING"
  1571. sleep 1
  1572. /bin/echo -ne " ."
  1573. sleep 1
  1574. /bin/echo -ne " ."
  1575. sleep 1
  1576. /bin/echo -ne " ."
  1577. /usr/bin/apt-get -y install fail2ban
  1578. /bin/echo
  1579. /bin/echo "Checking log-auth-failures"
  1580. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml > /dev/null
  1581. if [ $? -eq 0 ]; then
  1582. #see if it's uncommented
  1583. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml | /bin/grep '<!--' > /dev/null
  1584. if [ $? -eq 1 ]; then
  1585. #Check for true
  1586. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
  1587. if [ $? -eq 0 ]; then
  1588. /bin/echo " [ENABLED] log-auth-failures - Already Done!"
  1589. else
  1590. #it's false and uncommented, change it to true
  1591. /bin/sed -i -e s,'<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
  1592. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1593. /bin/echo " [ENABLED] log-auth-failures - Was False!"
  1594. fi
  1595. else
  1596. # It's commented
  1597. # check for true
  1598. /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
  1599. if [ $? -eq 0 ]; then
  1600. #it's commented and true
  1601. /bin/sed -i -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. -e s,'<param name="log-auth-failures" value="true"/>-->','<param name="log-auth-failures" value="true"/>', \
  1605. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1606. /bin/echo " [ENABLED] log-auth-failures - Was Commented!"
  1607. else
  1608. #it's commented and false.
  1609. /bin/sed -i -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. -e s,'<param name="log-auth-failures" value="false"/>-->','<param name="log-auth-failures" value="true"/>', \
  1613. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1614. /bin/echo " [ENABLED] log-auth-failures - Was Commented and False!"
  1615. fi
  1616. fi
  1617. else
  1618. #It's not present...
  1619. /bin/sed -i -e s,'<settings>','&\n <param name="log-auth-failures" value="true"/>', \
  1620. /usr/local/freeswitch/conf/sip_profiles/internal.xml
  1621. /bin/echo " [ENABLED] log-auth-failures - Wasn't there!"
  1622. fi
  1623. if [ -a /etc/fail2ban/filter.d/freeswitch.conf ]; then
  1624. /bin/echo "fail2ban filter for freeswitch already done!"
  1625. else
  1626. /bin/cat > /etc/fail2ban/filter.d/freeswitch.conf <<"DELIM"
  1627. # Fail2Ban configuration file
  1628. #
  1629. # Author: Rupa SChomaker
  1630. #
  1631. [Definition]
  1632. # Option: failregex
  1633. # Notes.: regex to match the password failures messages in the logfile. The
  1634. # host must be matched by a group named "host". The tag "<HOST>" can
  1635. # be used for standard IP/hostname matching and is only an alias for
  1636. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  1637. # Values: TEXT
  1638. #
  1639. failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1640. \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1641. # Option: ignoreregex
  1642. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  1643. # Values: TEXT
  1644. #
  1645. ignoreregex =
  1646. DELIM
  1647. fi
  1648. if [ -a /etc/fail2ban/filter.d/freeswitch-dos.conf ]; then
  1649. /bin/echo "fail2ban filter for freeswitch-dos already done!"
  1650. else
  1651. /bin/cat > /etc/fail2ban/filter.d/freeswitch-dos.conf <<"DELIM"
  1652. # Fail2Ban configuration file
  1653. #
  1654. # Author: soapee01
  1655. #
  1656. [Definition]
  1657. # Option: failregex
  1658. # Notes.: regex to match the password failures messages in the logfile. The
  1659. # host must be matched by a group named "host". The tag "<HOST>" can
  1660. # be used for standard IP/hostname matching and is only an alias for
  1661. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  1662. # Values: TEXT
  1663. #
  1664. failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
  1665. # Option: ignoreregex
  1666. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  1667. # Values: TEXT
  1668. #
  1669. ignoreregex =
  1670. DELIM
  1671. fi
  1672. #see if we've done this before (as in an ISO was made
  1673. #with this script but the source wasn't included
  1674. #so we have to reinstall...
  1675. /bin/grep freeswitch /etc/fail2ban/jail.local > /dev/null
  1676. if [ $? -ne 0 ]; then
  1677. #add the following stanzas to the end of our file (don't overwrite)
  1678. /bin/cat >> /etc/fail2ban/jail.local <<'DELIM'
  1679. [freeswitch-tcp]
  1680. enabled = true
  1681. port = 5060,5061,5080,5081
  1682. protocol = tcp
  1683. filter = freeswitch
  1684. logpath = /usr/local/freeswitch/log/freeswitch.log
  1685. action = iptables-allports[name=freeswitch-tcp, protocol=all]
  1686. maxretry = 5
  1687. findtime = 600
  1688. bantime = 600
  1689. # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
  1690. [freeswitch-udp]
  1691. enabled = true
  1692. port = 5060,5061,5080,5081
  1693. protocol = udp
  1694. filter = freeswitch
  1695. logpath = /usr/local/freeswitch/log/freeswitch.log
  1696. action = iptables-allports[name=freeswitch-udp, protocol=all]
  1697. maxretry = 5
  1698. findtime = 600
  1699. bantime = 600
  1700. # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
  1701. [freeswitch-dos]
  1702. enabled = true
  1703. port = 5060,5061,5080,5081
  1704. protocol = udp
  1705. filter = freeswitch-dos
  1706. logpath = /usr/local/freeswitch/log/freeswitch.log
  1707. action = iptables-allports[name=freeswitch-dos, protocol=all]
  1708. maxretry = 50
  1709. findtime = 30
  1710. bantime = 6000
  1711. DELIM
  1712. else
  1713. /bin/echo"fail2ban jail.local for freeswitch already done!"
  1714. fi
  1715. #problem with the way ubuntu logs ssh failures [fail2ban]
  1716. # Failed password for root from 1.2.3.4 port 22 ssh2
  1717. # last message repeated 5 times
  1718. # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
  1719. /bin/echo "Turning off RepeatedMsgReduction in /etc/rsyslog.conf"
  1720. #not sure what the deal is with the single quotes here. Fixed in v4.4.0
  1721. #/bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
  1722. /bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
  1723. /etc/init.d/rsyslog restart
  1724. #bug in fail2ban. If you see this error
  1725. #2011-02-27 14:11:42,326 fail2ban.actions.action: ERROR iptables -N fail2ban-freeswitch-tcp
  1726. #http://www.fail2ban.org/wiki/index.php/Fail2ban_talk:Community_Portal#fail2ban.action.action_ERROR_on_startup.2Frestart
  1727. /bin/grep -A 1 'time.sleep(0\.1)' /usr/bin/fail2ban-client |/bin/grep beautifier > /dev/null
  1728. if [ $? -ne 0 ]; then
  1729. /bin/sed -i -e s,beautifier\.setInputCmd\(c\),'time.sleep\(0\.1\)\n\t\t\tbeautifier.setInputCmd\(c\)', /usr/bin/fail2ban-client
  1730. #this does slow the restart down quite a bit.
  1731. else
  1732. /bin/echo ' time.sleep(0.1) already added to /usr/bin/fail2ban-client'
  1733. fi
  1734. #still may have a problem with logrotate causing missing new FS log files.
  1735. #should see log lines such as:
  1736. #2011-02-13 06:37:59,889 fail2ban.filter : INFO Log rotation detected for /usr/local/freeswitch/log/freeswitch.log
  1737. /etc/init.d/freeswitch start
  1738. if [ $DISTRO == "jessie" ]; then
  1739. sleep 5
  1740. /bin/systemctl restart fail2ban.service
  1741. else
  1742. /etc/init.d/fail2ban restart
  1743. fi
  1744. /bin/echo " fail2ban for ssh enabled by default"
  1745. /bin/echo " Default is 3 failures before your IP gets blocked for 600 seconds"
  1746. /bin/echo " SEE http://wiki.freeswitch.org/wiki/Fail2ban"
  1747. /bin/echo
  1748. /bin/echo
  1749. /bin/echo "FreeSWITCH Installation Completed. Have Fun!"
  1750. /bin/echo
  1751. fi
  1752. #---------------------------------------
  1753. # DONE INSTALLING FREESWITCH
  1754. #---------------------------------------
  1755. #---------------------------------------
  1756. # INSTALL FUSIONPBX
  1757. #---------------------------------------
  1758. if [ $INSFUSION -eq 1 ]; then
  1759. /bin/echo "FYI, we will need to change ownership of all FreeSWITCH"
  1760. /bin/echo " Directories to www-data.www-data"
  1761. /bin/echo " We will also need to change the init script to"
  1762. /bin/echo " start FreeSWITCH as the www-data user."
  1763. /bin/echo
  1764. /bin/echo "This is a workaround to FreeSWITCH jira FS-3016"
  1765. /bin/echo " The better way would be to have FreeSWITCH and FusionPBX"
  1766. /bin/echo " share group permissions; unfortunately, FreeSWITCH writes"
  1767. /bin/echo " log files, voicemail, etc with group permissions off."
  1768. /bin/echo
  1769. /bin/echo "This behavior is hard coded into FreeSWITCH."
  1770. /bin/echo " For now, you need to be aware that if an"
  1771. /bin/echo " exploit is found for apache2 or nginx"
  1772. /bin/echo " The attacker would have access to the entire"
  1773. /bin/echo " FreeSWITCH directory. This isn't quite as bad as it seems though."
  1774. /bin/echo " since simply having access to configuration can do damage"
  1775. /bin/echo "Watch your logfiles."
  1776. #read -p " press enter to continue."
  1777. /bin/echo
  1778. /bin/echo "Stopping FreeSWITCH..."
  1779. /etc/init.d/freeswitch stop
  1780. www_permissions
  1781. #Lets ask... nginx or apache -- for user option only
  1782. if [ $DEBUG -eq 1 ]; then
  1783. /bin/echo "New Option..."
  1784. read -p "Would you prefer Apache or Ngnix [nginx and php-fpm from ppa repos] (a/N)? " APACHENGINX
  1785. fi
  1786. #remastersys iso ditches the apt data. have to update
  1787. /usr/bin/apt-get update
  1788. #get reqs for both
  1789. /usr/bin/apt-get -y install git-core python-software-properties subversion ghostscript
  1790. #provides apt-add-repository
  1791. #installs python-software-properties unattended-upgrades
  1792. #/usr/bin/apt-get -y install ppa-purge #in backports. don't want that repo
  1793. if [ ! -e /usr/sbin/ppa-purge ]; then
  1794. /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
  1795. /usr/bin/dpkg -i /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
  1796. fi
  1797. /usr/bin/apt-get -y install sqlite php5-cli php5-sqlite php5-odbc
  1798. if [ $DISTRO = "precise" ]; then
  1799. /usr/bin/apt-get -y install php-db
  1800. fi
  1801. if [ $DISTRO = "wheezy" ]; then
  1802. /usr/bin/apt-get -y install php5-sqlite php-db
  1803. fi
  1804. if [ $DISTRO = "jessie" ]; then
  1805. /usr/bin/apt-get -y install php5-sqlite php-db
  1806. fi
  1807. #-----------------
  1808. # Apache
  1809. #-----------------
  1810. case "$APACHENGINX" in
  1811. [Aa]*)
  1812. #if [ $APACHENGINX == "a" ]; then
  1813. if [ -e /usr/sbin/nginx ]; then
  1814. #nginx is installed.
  1815. /bin/echo
  1816. /bin/echo "Nginx is installed, and you selected apache2."
  1817. if [ $DEBUG -eq 1 ]; then
  1818. /bin/echo
  1819. /bin/echo " We need to remove nginx/php5-fpm. The packages"
  1820. /bin/echo " are not purged, so configuration files will stay."
  1821. /bin/echo
  1822. read -p " Do you want to remove nginx/php5-fpm and install apache2 (y/n)? " YESNO
  1823. else
  1824. YESNO=y
  1825. fi
  1826. case "$YESNO" in
  1827. [Yy]*)
  1828. /bin/grep brianmercer /etc/apt/sources.list > /dev/null
  1829. if [ $? -eq 0 ]; then
  1830. /bin/echo "php-fpm ppa already add the old way. Fixing"
  1831. /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
  1832. fi
  1833. /bin/grep nginx /etc/apt/sources.list > /dev/null
  1834. if [ $? -ne 0 ]; then
  1835. /bin/echo "nginx ppa already add the old way. Fixing"
  1836. /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
  1837. fi
  1838. #remove ppa's
  1839. /usr/sbin/ppa-purge ppa:brianmercer/php
  1840. /usr/sbin/ppa-purge ppa:nginx/stable
  1841. #remove packages
  1842. /usr/bin/apt-get -y remove nginx nginx-full libevent-1.4-2 libt1-5 \
  1843. php-apc php-pear php5-fpm php5-gd php5-memcache
  1844. #ttf-dejavu-core fontconfig-config libfontconfig1 libxpm4 #removes x/gnome
  1845. #libxslt1.1 libxslt1.1 #removes midori
  1846. #libgd2-xpm #removed by ppa-purge
  1847. #libgd2-noxpm #removed by ppa-purge
  1848. /usr/bin/apt-get clean
  1849. /usr/bin/apt-get update
  1850. #re-install removed packages
  1851. /usr/bin/apt-get -y install libgd2-noxpm
  1852. /bin/echo " NGINX/PHP5-FPM REMOVED!"
  1853. ;;
  1854. *)
  1855. /bin/echo "OK. We'll stop. Exiting!"
  1856. exit 1
  1857. ;;
  1858. esac
  1859. fi
  1860. /usr/bin/apt-get -y install apache2 libapache2-mod-php5
  1861. #installs:
  1862. #apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
  1863. # /bin/grep fusionpbx /etc/apache2/sites-enabled/000-default > /dev/null
  1864. # if [ $? -ne 0 ]; then
  1865. if [ ! -e /etc/apache2/sites-enabled/$GUI_NAME ]; then
  1866. #disable the default 000-default site
  1867. /usr/sbin/a2dissite default
  1868. #let's use a heredoc now, and do this the right way. #no 'quotes' with variables
  1869. /bin/cat >> /etc/apache2/sites-available/$GUI_NAME <<DELIM
  1870. <VirtualHost *:80>
  1871. ServerAdmin webmaster@localhost
  1872. ServerName $FQDN
  1873. DocumentRoot $WWW_PATH/$GUI_NAME
  1874. <Directory />
  1875. Options FollowSymLinks
  1876. AllowOverride None
  1877. </Directory>
  1878. <Directory $WWW_PATH/$GUI_NAME/>
  1879. Options Indexes FollowSymLinks MultiViews
  1880. AllowOverride None
  1881. Order allow,deny
  1882. allow from all
  1883. </Directory>
  1884. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1885. <Directory "/usr/lib/cgi-bin">
  1886. AllowOverride None
  1887. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1888. Order allow,deny
  1889. Allow from all
  1890. </Directory>
  1891. ErrorLog /var/log/apache2/error.log
  1892. # Possible values include: debug, info, notice, warn, error, crit,
  1893. # alert, emerg.
  1894. LogLevel warn
  1895. CustomLog /var/log/apache2/access.log combined
  1896. Alias /doc/ "/usr/share/doc/"
  1897. <Directory "/usr/share/doc/">
  1898. Options Indexes MultiViews FollowSymLinks
  1899. AllowOverride None
  1900. Order deny,allow
  1901. Deny from all
  1902. Allow from 127.0.0.0/255.0.0.0 ::1/128
  1903. </Directory>
  1904. </VirtualHost>
  1905. DELIM
  1906. /usr/sbin/a2ensite $GUI_NAME
  1907. /bin/cat >> /etc/apache2/conf.d/securedb.conf <<'DELIM'
  1908. #
  1909. # The following lines prevent .db files from being
  1910. # viewed by Web clients.
  1911. #
  1912. <Files ~ "^.*\.db">
  1913. Order allow,deny
  1914. Deny from all
  1915. Satisfy all
  1916. </Files>
  1917. DELIM
  1918. /etc/init.d/apache2 restart
  1919. # /bin/sed -i -e s,"DocumentRoot /var/www","DocumentRoot /var/www/fusionpbx", \
  1920. # -e s,"<Directory /var/www/>","<Directory /var/www/fusionpbx/>", \
  1921. # /etc/apache2/sites-enabled/000-default
  1922. if [ $? -ne 0 ]; then
  1923. #previous had an error
  1924. # /bin/echo "ERROR: Failed edit of /etc/apache2/sites-enabled/000-default"
  1925. /bin/echo "ERROR: Failed addtion of /etc/apache2/sites-enabled/$GUI_NAME"
  1926. exit 1
  1927. else
  1928. # /bin/echo "/etc/apache2/sites-enabled/000-default modified."
  1929. /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME added."
  1930. /bin/echo " Root www directory is now $WWW_PATH/$GUI_NAME"
  1931. fi
  1932. else
  1933. /bin/echo
  1934. #/bin/echo "/etc/apache2/sites-enabled/000-default already edited. Skipping..."
  1935. /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME already there. Skipping..."
  1936. fi
  1937. /bin/grep 10M /etc/php5/apache2/php.ini > /dev/null
  1938. if [ $? -ne 0 ]; then
  1939. /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", /etc/php5/apache2/php.ini
  1940. if [ $? -ne 0 ]; then
  1941. #previous had an error
  1942. /bin/echo "ERROR: failed edit of /etc/php5/apache2/php.ini upload_max_filesize = 10M."
  1943. exit 1
  1944. fi
  1945. else
  1946. /bin/echo
  1947. /bin/echo "/etc/php5/apache2/php.ini already edited. Skipping..."
  1948. fi
  1949. /bin/echo "document root for apache2 is:"
  1950. /bin/echo " $WWW_PATH/$GUI_NAME"
  1951. /bin/echo " php has an upload file size limit of 10 MegaBytes"
  1952. /bin/echo
  1953. /bin/echo "now install FusionPBX. This should go fast."
  1954. /bin/echo
  1955. ;;
  1956. #-----------------
  1957. # Apache Done
  1958. #-----------------
  1959. #-----------------
  1960. # NGINX
  1961. #-----------------
  1962. *)
  1963. #elif [ $APACHENGINX == "n" ] || [ $APACHENGINX == "N" ] || [ $APACHENGINX == "" ]; then
  1964. # ^ would be almost there. empty read isn't caught. switching to case. more flexible...
  1965. if [ -e /usr/sbin/apache2 ]; then
  1966. #apache2 is installed.
  1967. /bin/echo
  1968. /bin/echo "Apache2 is installed, and you selected nginx/php5-fpm."
  1969. if [ $DEBUG -eq 1 ]; then
  1970. /bin/echo
  1971. /bin/echo " We need to remove apache2, and php5. The packages"
  1972. /bin/echo " are not purged, so configuration files will stay."
  1973. /bin/echo
  1974. /bin/echo " Do you want to remove apache2/php5 and install "
  1975. read -p " nginx/php5-fpm (y/n)? " YESNO
  1976. else
  1977. YESNO=y
  1978. fi
  1979. case "$YESNO" in
  1980. [Yy]*)
  1981. #remove packages
  1982. /usr/bin/apt-get -y remove apache2 apache2-mpm-prefork apache2-utils apache2.2-bin \
  1983. apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 \
  1984. libaprutil1-ldap ssl-cert
  1985. /bin/echo " APACHE2 REMOVED!"
  1986. #removing libapr removes subversion!
  1987. /usr/bin/apt-get -y install subversion
  1988. ;;
  1989. *)
  1990. /bin/echo "OK. We'll stop. Exiting!"
  1991. exit 1
  1992. ;;
  1993. esac
  1994. fi
  1995. if [ $DISTRO = "squeeze" ]; then
  1996. #setup debian repos for nginx/php5-fpm
  1997. /bin/echo "adding dotdeb repository for php5-fpm and nginx"
  1998. /bin/echo "deb http://packages.dotdeb.org squeeze all" > /etc/apt/sources.list.d/squeeze-dotdeb.list
  1999. /usr/bin/wget -O /tmp/dotdeb.gpg http://www.dotdeb.org/dotdeb.gpg
  2000. /bin/cat /tmp/dotdeb.gpg | apt-key add -
  2001. /bin/rm /tmp/dotdeb.gpg
  2002. /usr/bin/apt-get update
  2003. elif [ $DISTRO = "wheezy" ]; then
  2004. #included in main repo we have nginx [nginx-full] and php5-fpm
  2005. echo "already in Debian 7.x [wheezy], nothing to add."
  2006. elif [ $DISTRO = "jessie" ]; then
  2007. #included in main repo we have nginx [nginx-full] and php5-fpm
  2008. echo "already in Debian 8.x [jessie], nothing to add."
  2009. elif [ $DISTRO = "precise" ]; then
  2010. #included in main repo we have nginx [nginx-full] and php5-fpm
  2011. echo "already in 12.04 LTS [precise], nothing to add."
  2012. else
  2013. #add-apt-repository ppa:brianmercer/php // apt-get -y install python-software-properties
  2014. #Add php5-fpm ppa to the list
  2015. /bin/grep brianmercer /etc/apt/sources.list > /dev/null
  2016. if [ $? -eq 0 ]; then
  2017. /bin/echo "php-fpm ppa already add the old way. Fixing"
  2018. /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
  2019. /usr/bin/apt-add-repository ppa:brianmercer/php
  2020. elif [ ! -e /etc/apt/sources.list.d./brianmercer-php-lucid.list ]; then
  2021. /bin/echo "Adding PPA for php-fpm"
  2022. #/bin/echo "deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucidmain" >> /etc/apt/sources.list
  2023. #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F
  2024. /usr/bin/apt-add-repository ppa:brianmercer/php
  2025. else
  2026. /bin/echo "php-fpm ppa already added."
  2027. fi
  2028. #Add NGINX-ppa to src list.
  2029. /bin/grep nginx /etc/apt/sources.list > /dev/null
  2030. if [ $? -ne 0 ]; then
  2031. /bin/echo "nginx ppa already add the old way. Fixing"
  2032. /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
  2033. /usr/bin/apt-add-repository ppa:nginx/stable
  2034. elif [ ! -e /etc/apt/sources.list.d./nginx-stable-lucid.list ]; then
  2035. /bin/echo "Adding PPA for latest nginx"
  2036. /usr/bin/apt-add-repository ppa:nginx/stable
  2037. #/bin/echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
  2038. #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
  2039. else
  2040. /bin/echo "nginx ppa already added"
  2041. fi
  2042. fi
  2043. /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y
  2044. /usr/bin/apt-get -y install nginx
  2045. #installs libgd2-noxpm libxslt1.1 nginx nginx-full
  2046. if [ $DISTRO = "squeeze" ]; then
  2047. /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php5-apc php5-sqlite php5-json
  2048. else
  2049. #should work for precise
  2050. /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php-apc php5-json
  2051. fi
  2052. if [ $DISTRO = "squeeze" ]; then
  2053. PHPINIFILE="/etc/php5/fpm/php.ini"
  2054. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2055. elif [ $DISTRO = "precise" ]; then
  2056. PHPINIFILE="/etc/php5/fpm/php.ini"
  2057. #also exists, but www.conf used by default...
  2058. #PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2059. #max_children set in /etc/php5/fpm/pool.d/www.conf
  2060. PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
  2061. elif [ $DISTRO = "lucid" ]; then
  2062. #lucid ppa conf files changed 1/20/2013
  2063. PHPINIFILE="/etc/php5/fpm/php.ini"
  2064. PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
  2065. elif [ $DISTRO = "wheezy" ]; then
  2066. PHPINIFILE="/etc/php5/fpm/php.ini"
  2067. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2068. elif [ $DISTRO = "jessie" ]; then
  2069. PHPINIFILE="/etc/php5/fpm/php.ini"
  2070. PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
  2071. else
  2072. PHPINIFILE="/etc/php5/fpm/php.ini"
  2073. PHPCONFFILE="/etc/php5/fpm/php5-fpm.conf"
  2074. fi
  2075. /bin/grep 10M $PHPINIFILE > /dev/null
  2076. if [ $? -ne 0 ]; then
  2077. /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", $PHPINIFILE
  2078. if [ $? -ne 0 ]; then
  2079. #previous had an error
  2080. /bin/echo "ERROR: failed edit of $PHPINIFILE upload_max_filesize = 10M."
  2081. exit 1
  2082. fi
  2083. else
  2084. /bin/echo
  2085. /bin/echo "/etc/php5/fpm/php.ini already edited. Skipping..."
  2086. fi
  2087. #change to socket
  2088. grep "listen = 127.0.0.1:9000" $PHPCONFFILE |grep \;
  2089. if [ $? -ne 0 ]; then
  2090. /bin/sed -i $PHPCONFFILE -e s,listen\ \=\ 127\.0\.0\.\1\:9000,listen\ \=\ \/var\/run\/php5-fpm.sock,
  2091. fi
  2092. #uncomment lines that are needed for unix socket
  2093. /bin/sed -i -e s,";listen.owner","listen.owner", $PHPCONFFILE
  2094. /bin/sed -i -e s,";listen.group","listen.group", $PHPCONFFILE
  2095. /bin/sed -i -e s,";listen.mode","listen.mode", $PHPCONFFILE
  2096. ##Applying fix for cgi.fix_pathinfo
  2097. /bin/grep 'cgi\.fix_pathinfo=0' $PHPINIFILE > /dev/null
  2098. if [ $? -ne 0 ]; then
  2099. /bin/sed -i -e s,';cgi\.fix_pathinfo=1','cgi\.fix_pathinfo=0', $PHPINIFILE
  2100. if [ $? -ne 0 ]; then
  2101. /bin/echo "ERROR: failed edit of $PHPINIFILE cgi.fix_pathinfo=0"
  2102. exit 1
  2103. fi
  2104. else
  2105. /bin/echo
  2106. /bin/echo "/etc/php5/fpm/php.ini already edited for cgi.fix_pathinfo. Skipping..."
  2107. fi
  2108. #We don't need so many php children. 1 per core should be fine FOR NOW.
  2109. #/bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", /etc/php5/fpm/php5-fpm.conf
  2110. /bin/grep "pm.max_children = 4" $PHPCONFFILE > /dev/null
  2111. if [ $? -ne 0 ]; then
  2112. /bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", $PHPCONFFILE
  2113. if [ $? -ne 0 ]; then
  2114. #previous had an error
  2115. /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_children = 4"
  2116. exit 1
  2117. fi
  2118. else
  2119. /bin/echo
  2120. /bin/echo "$PHPCONFFILE [children] already edited. Skipping..."
  2121. fi
  2122. #max_servers must be <= max_children
  2123. /bin/grep "pm.max_spare_servers = 4" $PHPCONFFILE > /dev/null
  2124. if [ $? -ne 0 ]; then
  2125. /bin/sed -i -e s,"pm.max_spare_servers = 6","pm.max_spare_servers = 4", $PHPCONFFILE
  2126. if [ $? -ne 0 ]; then
  2127. #previous had an error
  2128. /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_spare_servers = 4"
  2129. exit 1
  2130. fi
  2131. else
  2132. /bin/echo
  2133. /bin/echo "pm.max_spare_servers not changed"
  2134. fi
  2135. #update auto-starts ###PHP5-fpm and nginx are wrong??
  2136. update-rc.d php5-fpm enable
  2137. /etc/init.d/php5-fpm start
  2138. ##setup niginx for fusionpbx & phpmyadmin!
  2139. update-rc.d nginx enable
  2140. /etc/init.d/nginx start
  2141. #NGINX server config:
  2142. rm /etc/nginx/sites-enabled/default
  2143. /bin/grep '.db' /etc/nginx/sites-available/$GUI_NAME >> /dev/null
  2144. if [ $? -ne 0 ]; then
  2145. /bin/echo "Nginx insecure previous installation"
  2146. /bin/echo " allows http access to FusionPBX database"
  2147. /bin/echo " FIXING..."
  2148. /bin/rm /etc/nginx/sites-available/$GUI_NAME
  2149. fi
  2150. if [ -a /etc/nginx/sites-available/$GUI_NAME ]; then
  2151. /bin/echo "/etc/nginx/sites-available/$GUI_NAME already exists... skipping"
  2152. else
  2153. nginxconfig
  2154. fi
  2155. if [ $DISTRO = "lucid" ]; then
  2156. /bin/grep fastcgi_param.*HTTPS.*\$https\; /etc/nginx/fastcgi_params
  2157. if [ $? -eq 0 ]; then
  2158. echo "Fixing a weird nginx fastcgi_parm issue"
  2159. echo " you can also add the following stanzas to"
  2160. echo " your /etc/nginx/sites-enabled/$GUI_NAME file"
  2161. echo " set $https off; #for listen 80 and listen localhost"
  2162. echo " set $https on; #for listen 443"
  2163. /bin/sed -i /etc/nginx/fastcgi_params -e s/fastcgi_param.*HTTPS.*\$https\;/#fastcgi_param\ HTTPS\ \$https\;/
  2164. fi
  2165. fi
  2166. ;;
  2167. esac
  2168. #-----------------
  2169. # NGINX Done
  2170. #-----------------
  2171. #else
  2172. # /bin/echo "Didn't catch that. exiting"
  2173. # exit 1
  2174. #fi
  2175. cd $WWW_PATH
  2176. if [ $DEBUG -eq 1 ]; then
  2177. /bin/echo
  2178. /bin/echo "Press Enter to continue (check for errors)"
  2179. read
  2180. fi
  2181. /bin/echo "Stopping FreeSWITCH..."
  2182. /usr/sbin/service freeswitch stop
  2183. if [[ "$INST_FPBX" == "svn" ]]; then
  2184. if [ $FBPXCHECKOUTVER == true ]; then
  2185. /bin/echo "Going to install FusionPBX SVN Rev $FPBXREV"
  2186. /usr/bin/svn checkout -r r$FPBXREV $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2187. else
  2188. /bin/echo "Going to install FusionPBX latest SVN!"
  2189. #removed -r r1877 r1877 from new install
  2190. /usr/bin/svn checkout $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2191. fi
  2192. elif [ $INST_FPBX == tgz ]; then
  2193. /bin/tar -C $WWW_PATH -xzvf $TGZ_FILE
  2194. elif [ $INST_FPBX == git ]; then
  2195. FUSIONPBX_GIT="$FUSIONPBX_GIT_SERVER/$FUSIONPBX_GIT_CONTRIBUTER/$FUSIONPBX_GIT_PROJECT";
  2196. /usr/bin/git clone $FUSIONPBX_GIT
  2197. cd $GUI_NAME;
  2198. if [ $FUSIONPBX_GIT_ASKBRANCH == 1 ]
  2199. then
  2200. branches=()
  2201. eval eval "$(/usr/bin/git for-each-ref --shell --format='branches+=(%(refname:short))' refs/remotes/ | perl -l -wpe "s{'\w+/}{'}")"
  2202. for id in "${!branches[@]}";
  2203. do
  2204. branch=${branches[$id]};
  2205. printf "[%s] %s" $id $branch;
  2206. if [ $branch == 'master' ];
  2207. then
  2208. printf " *default";
  2209. default_branch=$id;
  2210. fi
  2211. printf "\n";
  2212. done
  2213. while true;
  2214. do
  2215. read -p "Which branch would you like to use? " branch
  2216. if [[ -z $branch ]];
  2217. then branch=$default_branch;
  2218. fi;
  2219. if [[ -n "${branches[$branch]}" ]];
  2220. then break;
  2221. fi;
  2222. echo "Please choose a existing branch.";
  2223. done
  2224. /usr/bin/git checkout "${branches[$branch]}"
  2225. fi;
  2226. fi
  2227. if [ ! -e $WWW_PATH/$GUI_NAME ]; then
  2228. /bin/mv $WWW_PATH/fusionpbx $WWW_PATH/$GUI_NAME
  2229. fi
  2230. /usr/sbin/adduser freeswitch www-data
  2231. /usr/sbin/adduser www-data daemon
  2232. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2233. /bin/echo "freeswitch is now a member of the www-data group"
  2234. /bin/echo " www-data is now a member of the daemon group"
  2235. /usr/bin/find $WWW_PATH/$GUI_NAME -type f -exec /bin/chmod 644 {} \;
  2236. /usr/bin/find $WWW_PATH/$GUI_NAME -type d -exec /bin/chmod 755 {} \;
  2237. if [ $DEBUG -eq 1 ]; then
  2238. /bin/echo
  2239. /bin/echo "Press Enter to continue (check for errors)"
  2240. read
  2241. fi
  2242. if [ $APACHENGINX == "a" ]; then
  2243. /etc/init.d/apache2 restart
  2244. elif [ $APACHENGINX == "n" ]; then
  2245. /etc/init.d/nginx restart
  2246. fi
  2247. /bin/echo "FusionPBX install needs Write permissions on group to remove files"
  2248. /bin/echo "The daemon group (of which www-data is a member) can now edit all files"
  2249. /bin/echo " in your FreeSWITCH installation. This may or may not be desirable"
  2250. /bin/echo
  2251. /bin/echo "if you want to change this, run (as root)"
  2252. /bin/echo " /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g-w {} \;"
  2253. /bin/echo " /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g-w {} \;"
  2254. /bin/echo " however; FusionPBX won't be able to make changes anymore"
  2255. /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  2256. /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  2257. # /bin/echo "go to the web address in your browser to finish configuration"
  2258. # /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2259. # /bin/echo "don't forget to start FreeSWITCH after the install!"
  2260. # /bin/echo "/etc/init.d/freeswitch start"
  2261. #FreeSWITCH needs read access to scripts in /var/www/fusionpbx/secure
  2262. #per mcrane on IRC
  2263. #mcrane: the easiest way to get it to work is have FreeSWITCH and the web server run under the same user
  2264. # instead we made freeswitch user a member of the www-data group, and www-data user a member of the
  2265. # daemon group.
  2266. #added v3
  2267. #move the default extensions .noload
  2268. #The default FusionPBX install removes the default FreeSWITCH password, so anyone can register
  2269. #with these default FreeSWITCH extensions. They aren't 'in' FusionPBX anyhow, so we don't need
  2270. #them. We will leave them for reference.
  2271. /bin/echo "renaming default FreeSWITCH extensions .noload"
  2272. for i in /usr/local/freeswitch/conf/directory/default/1*.xml;do mv $i $i.noload ; done
  2273. if [ $DEBUG -eq 1 ]; then
  2274. /bin/echo
  2275. /bin/echo "Press Enter to continue (check for errors)"
  2276. read
  2277. fi
  2278. /bin/echo
  2279. /bin/echo "Finishing Up FusionPBX installation."
  2280. /bin/echo "Now for a database..."
  2281. /bin/echo
  2282. #-----------------
  2283. # MySQL
  2284. #-----------------
  2285. #Lets ask... sqlite or mysql -- for user option only
  2286. if [ $DEBUG -eq 1 ]; then
  2287. /bin/echo "New Option..."
  2288. /bin/echo " SQlite is already installed (and required)"
  2289. /bin/echo
  2290. read -p " Would you like to install MySQL, PostgreSQL, or stay with Sqlite (m/p/S)? " SQLITEMYSQL
  2291. case "$SQLITEMYSQL" in
  2292. [pP]*)
  2293. if [ $DISTRO = "wheezy" ]; then
  2294. echo "precise is PostgreSQL 9.4 by default"
  2295. POSTGRES9=9
  2296. elif [ $DISTRO = "jessie" ]; then
  2297. echo "jessie is PostgreSQL 9.4 by default"
  2298. POSTGRES9=9
  2299. else
  2300. /bin/echo
  2301. /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
  2302. /bin/echo " or verion 9 from PPA?"
  2303. /bin/echo
  2304. read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
  2305. fi
  2306. echo
  2307. ;;
  2308. esac
  2309. fi
  2310. case "$SQLITEMYSQL" in
  2311. [Mm]*)
  2312. #if [ $SQLITEMYSQL == "m" ]; then
  2313. /bin/echo "Installing MySQL"
  2314. /usr/bin/apt-get -y install mysql-server php5-mysql mysql-client
  2315. if [ -e /usr/sbin/nginx ]; then
  2316. #nginx is installed.
  2317. /etc/init.d/php5-fpm restart
  2318. /etc/init.d/nginx restart
  2319. elif [ -e /usr/sbin/apache2 ]; then
  2320. #apache2 is installed.
  2321. /etc/init.d/apache2 restart
  2322. fi
  2323. start_freeswitch
  2324. /bin/echo "Now you'll need to manually finish the install and come back"
  2325. /bin/echo " This way I can finish up the last bit of permissions issues"
  2326. /bin/echo " Just go to"
  2327. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2328. /bin/echo " MAKE SURE YOU CHOOSE MYSQL as your Database on the first page!!!"
  2329. /bin/echo " ON the Second Page:"
  2330. /bin/echo " Create Database Username: root"
  2331. /bin/echo " Create Database Password: the_pw_you_set_during_install"
  2332. /bin/echo " other options: whatever you like"
  2333. /bin/echo " I will wait here until you get done with that."
  2334. /bin/echo -ne " When MySQL is configured come back and press enter. "
  2335. read
  2336. ;;
  2337. [Pp]*)
  2338. #elif [ $SQLITEMYSQL == "p" ]; then
  2339. #/bin/echo -ne "Installing PostgeSQL"
  2340. #moving most of this to fs install
  2341. /bin/echo "Time to add a $GUI_NAME user for the database."
  2342. /bin/echo -ne " We will use $GUI_NAME as the username"
  2343. /bin/echo -ne " please set the password."
  2344. #add php postgres packages
  2345. if [ $POSTGRES9 == "9" ]; then
  2346. /bin/echo " version 9.3"
  2347. if [ $DISTRO = "squeeze" ]; then
  2348. #add squeeze repo
  2349. /bin/echo "Adding debian backports for postgres9.1"
  2350. /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
  2351. /usr/bin/apt-get update
  2352. /usr/bin/apt-get -y -t squeeze-backports install php5-pgsql
  2353. elif [ $DISTRO = "precise" ]; then
  2354. #already there...
  2355. /usr/bin/apt-get -y install php5-pgsql
  2356. elif [ $DISTRO = "wheezy" ]; then
  2357. POSTGRES9=9
  2358. #update repository for postgres 9.4 ...
  2359. /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
  2360. wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
  2361. /usr/bin/apt-get update
  2362. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  2363. elif [ $DISTRO = "jessie" ]; then
  2364. POSTGRES9=9
  2365. /usr/bin/apt-get update
  2366. /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
  2367. else
  2368. #add the ppa
  2369. /usr/bin/apt-add-repository ppa:pitti/postgresql
  2370. /usr/bin/apt-get update
  2371. /usr/bin/apt-get -y install php5-pgsql
  2372. fi
  2373. else
  2374. /bin/echo " version 8.4"
  2375. /usr/bin/apt-get -y install postgresql libpq-dev
  2376. #The following NEW packages will be installed:
  2377. # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
  2378. # postgresql-client-common postgresql-common
  2379. fi
  2380. #Fix pg_hba.conf
  2381. cat > `find / -name pg_hba.conf` <<EOF
  2382. # TYPE DATABASE USER ADDRESS METHOD
  2383. # Database administrative login by Unix domain socket
  2384. local all postgres peer
  2385. local fusionpbx all md5
  2386. local freeswitch all md5
  2387. # "local" is for Unix domain socket connections only
  2388. local all all peer
  2389. # IPv4 local connections:
  2390. host all all 127.0.0.1/32 md5
  2391. # IPv6 local connections:
  2392. host all all ::1/128 md5
  2393. EOF
  2394. /etc/init.d/postgresql restart
  2395. /bin/su -l postgres -c "/usr/bin/createuser -s -e $GUI_NAME"
  2396. #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O $GUI_NAME $GUI_NAME"
  2397. /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O $GUI_NAME $GUI_NAME"
  2398. PGSQLPASSWORD="dummy"
  2399. PGSQLPASSWORD2="dummy2"
  2400. while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
  2401. /bin/echo
  2402. /bin/echo
  2403. /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
  2404. /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
  2405. /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
  2406. /bin/echo "psql. THE COMMAND USED IS:"
  2407. /bin/echo
  2408. /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER $GUI_NAME with PASSWORD \$PGSQLPASSWORD;' | psql $GUI_NAME\""
  2409. /bin/echo
  2410. /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
  2411. /bin/echo
  2412. /bin/echo "The pgsql username is $GUI_NAME"
  2413. /bin/echo "The pgsql database name is $GUI_NAME"
  2414. /bin/echo "Please provide a password for the $GUI_NAME user"
  2415. #/bin/stty -echo
  2416. read -s -p " Password: " PGSQLPASSWORD
  2417. /bin/echo
  2418. /bin/echo "Let's repeat that"
  2419. read -s -p " Password: " PGSQLPASSWORD2
  2420. /bin/echo
  2421. #/bin/stty echo
  2422. done
  2423. /bin/su -l postgres -c "/bin/echo \"ALTER USER $GUI_NAME with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql $GUI_NAME"
  2424. /bin/echo "overwriting pgsql password variable with random data"
  2425. PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
  2426. PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
  2427. if [ -e /usr/sbin/nginx ]; then
  2428. #nginx is installed.
  2429. /etc/init.d/php5-fpm restart
  2430. /etc/init.d/nginx restart
  2431. elif [ -e /usr/sbin/apache2 ]; then
  2432. #apache2 is installed.
  2433. /etc/init.d/apache2 restart
  2434. fi
  2435. #uncomment below to test the nativepgsql function. currently not working
  2436. # internal/external/callcenter profiles still going to sqlite.
  2437. #nativepgsql
  2438. start_freeswitch
  2439. /bin/echo "Now you'll need to manually finish the install and come back"
  2440. /bin/echo " This way I can finish up the last bit of permissions issues"
  2441. /bin/echo " Just go to"
  2442. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2443. /bin/echo " MAKE SURE YOU CHOOSE PostgreSQL as your Database on the first page!!!"
  2444. /bin/echo " ON the Second Page:"
  2445. /bin/echo " Database Name: $GUI_NAME"
  2446. /bin/echo " Database Username: $GUI_NAME"
  2447. /bin/echo " Database Password: whateveryouentered"
  2448. /bin/echo " Create Database Username: Leave_Blank"
  2449. /bin/echo " Create Database Password: Leave_Blank"
  2450. /bin/echo
  2451. /bin/echo " I will wait here until you get done with that."
  2452. /bin/echo -ne " When PostgreSQL is configured come back and press enter. "
  2453. read
  2454. ;;
  2455. *)
  2456. #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
  2457. /bin/echo "SQLITE is chosen. already done. nothing left to install..."
  2458. if [ -e /usr/sbin/nginx ]; then
  2459. #nginx is installed.
  2460. /etc/init.d/php5-fpm restart
  2461. /etc/init.d/nginx restart
  2462. elif [ -e /usr/sbin/apache2 ]; then
  2463. #apache2 is installed.
  2464. /etc/init.d/apache2 restart
  2465. fi
  2466. start_freeswitch
  2467. /bin/echo "FusionPBX install.php was done automatically"
  2468. /bin/echo " when sqlite was selected. "
  2469. /bin/echo " FreeSWITCH Directory: /usr/local/freeswitch"
  2470. /bin/echo " PHP Directory: $WWW_PATH/$GUI_NAME"
  2471. /bin/echo
  2472. /bin/echo " Database Filename: $GUI_NAME.db"
  2473. /bin/echo " Database Directory: $WWW_PATH/$GUI_NAME/secure"
  2474. /bin/echo
  2475. /bin/echo " Just go to"
  2476. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2477. /bin/echo
  2478. /bin/echo "Default login is (whatever you picked in the GUI install):"
  2479. /bin/echo " User: WhateverUsernameYouPicked"
  2480. /bin/echo " Passwd: YourPasswordYouPicked"
  2481. ;;
  2482. esac
  2483. #else
  2484. # /bin/echo "Didn't catch that. exiting"
  2485. # exit 1
  2486. #fi
  2487. finish_fpbx_install_permissions
  2488. #/bin/echo
  2489. #/bin/echo "The FusionPBX installation messed up permissions of /usr/local/freeswitch/storage"
  2490. #/bin/echo " Fixing..."
  2491. # read
  2492. #/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
  2493. #/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
  2494. #/bin/echo "Starting FreeSWITCH..."
  2495. #/etc/init.d/freeswitch start
  2496. /bin/echo "Setting up Fail2Ban for FusionPBX"
  2497. fusionfail2ban
  2498. if [ $DISTRO == "jessie" ]; then
  2499. sleep 5
  2500. /bin/systemctl restart fail2ban.service
  2501. else
  2502. /etc/init.d/fail2ban restart
  2503. fi
  2504. /bin/echo
  2505. /bin/echo
  2506. /bin/echo "Installation Completed. Now configure FreeSWITCH via the FusionPBX browser interface"
  2507. /bin/echo
  2508. /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
  2509. /bin/echo "Default login is (whatever you picked in the GUI install):"
  2510. /bin/echo " User: WhateverUsernameYouPicked"
  2511. /bin/echo " Passwd: YourPasswordYouPicked"
  2512. fi
  2513. #------------------------------------
  2514. # DONE INSTALLING FUSIONPBX
  2515. #------------------------------------
  2516. #------------------------------------
  2517. # UPGRADE FREESWITCH
  2518. #------------------------------------
  2519. if [ $UPGFREESWITCH -eq 1 ]; then
  2520. #------------------------
  2521. # build modules.conf
  2522. #------------------------
  2523. /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
  2524. if [ $? -eq 0 ]; then
  2525. /bin/echo "Modules.conf Already edited"
  2526. else
  2527. #file exists and has been edited
  2528. build_modules
  2529. #check exit status
  2530. if [ $? -ne 0 ]; then
  2531. #previous had an error
  2532. /bin/echo "ERROR: Failed to enable build modules in modules.conf."
  2533. exit 1
  2534. else
  2535. /bin/echo "build_modules" >> /tmp/install_fusion_status
  2536. fi
  2537. fi
  2538. if [ $DEBUG -eq 1 ]; then
  2539. /bin/echo
  2540. /bin/echo "Press Enter to continue (check for errors)"
  2541. read
  2542. fi
  2543. #------------------------
  2544. # make current
  2545. #------------------------
  2546. /bin/grep 'made_current' /tmp/install_fusion_status > /dev/null
  2547. if [ $? -eq 0 ]; then
  2548. /bin/echo "Modules.conf Already edited"
  2549. else
  2550. /bin/echo
  2551. /bin/echo ' going to run make curent'
  2552. /bin/echo " Make current completely cleans the build environment and rebuilds FreeSWITCH™"
  2553. /bin/echo " so it runs a long time. However, it will not overwrite files in a pre-existing"
  2554. /bin/echo ' "conf" directory. Also, the clean targets leave the "modules.conf" file.'
  2555. /bin/echo " This handles the git pull, cleanup, and rebuild in one step"
  2556. /bin/echo ' src: http://wiki.freeswitch.org/wiki/Installation_Guide'
  2557. cd /usr/src/freeswitch
  2558. if [ $? -ne 0 ]; then
  2559. #previous had an error
  2560. /bin/echo "/usr/src/freeswitch does not exist"
  2561. /bin/echo "you probably installed from a FusionPBX ISO which deleted this"
  2562. /bin/echo "Directory to save space. rerun with install-freeswitch option"
  2563. exit 1
  2564. fi
  2565. cd /usr/src/freeswitch
  2566. #get on the 1.2.x release first...
  2567. echo
  2568. echo
  2569. echo "Checking to see which version of FreeSWITCH you are on"
  2570. git status |grep "1.2"
  2571. if [ $? -ne 0 ]; then
  2572. echo "It appears that you are currently on the FreeSWITCH Git Master branch, or no branch."
  2573. echo " We currently recommend that you switch to the 1.4.x branch,"
  2574. echo " since 1.5 [master]."
  2575. echo
  2576. read -p "Shall we change to the 1.4.x release branch [Y/n]? " YESNO
  2577. else
  2578. YESNO="no"
  2579. fi
  2580. case $YESNO in
  2581. [Nn]*)
  2582. echo "OK, staying on current...."
  2583. FSSTABLE=false
  2584. ;;
  2585. *)
  2586. echo "OK, switching to 1.4.x."
  2587. FSSTABLE=true
  2588. ;;
  2589. esac
  2590. if [ $FSSTABLE == true ]; then
  2591. echo "OK we'll now use the 1.4.x release branch"
  2592. cd /usr/src/freeswitch
  2593. #odd edge case, I think from a specific version checkout
  2594. # git status
  2595. # Not currently on any branch.
  2596. # Untracked files:
  2597. # (use "git add <file>..." to include in what will be committed)
  2598. #
  2599. # src/mod/applications/mod_httapi/Makefile
  2600. git status |grep -i "not currently"
  2601. if [ $? -eq 0 ]; then
  2602. echo "You are not on master branch. We have to fix that first"
  2603. /usr/bin/git checkout master
  2604. if [ $? -ne 0 ]; then
  2605. #git checkout had an error
  2606. /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2607. exit 1
  2608. fi
  2609. fi
  2610. #/usr/bin/git clone -b $FSStableVer git://stash.freeswitch.org/scm/fs/freeswitch.git
  2611. /usr/bin/git pull
  2612. if [ $? -ne 0 ]; then
  2613. #git checkout had an error
  2614. /bin/echo "GIT PULL to 1.2.x ERROR"
  2615. exit 1
  2616. fi
  2617. /usr/bin/git checkout $FSStableVer
  2618. if [ $? -ne 0 ]; then
  2619. #git checkout had an error
  2620. /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2621. exit 1
  2622. fi
  2623. #/usr/bin/git checkout master
  2624. #if [ $? -ne 0 ]; then
  2625. # #git checkout had an error
  2626. # /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
  2627. # exit 1
  2628. #fi
  2629. else
  2630. echo "Staying on dev branch."
  2631. fi
  2632. cd /usr/src/freeswitch
  2633. echo "reconfiguring mod_spandsp"
  2634. make spandsp-reconf
  2635. if [ $CORES > "1" ]; then
  2636. /bin/echo " multicore processor detected. Upgrading with -j $CORES"
  2637. /usr/bin/make -j $CORES current
  2638. else
  2639. /bin/echo " singlecore processor detected. Starting upgrade sans -j"
  2640. /usr/bin/make current
  2641. fi
  2642. #/usr/bin/make current
  2643. if [ $? -ne 0 ]; then
  2644. #previous had an error
  2645. /bin/echo "make current error"
  2646. exit 1
  2647. fi
  2648. if [ $DEBUG -eq 1 ]; then
  2649. /bin/echo
  2650. /bin/echo "I'm going to stop here and wait. FreeSWITCH has now been compiled and is ready to install"
  2651. /bin/echo "but in order to do this we need to stop FreeSWITCH [which will dump any active calls]."
  2652. /bin/echo "This should not take too long to finish, but we should try and time things correctly."
  2653. /bin/echo "The current status of your switch is:"
  2654. /bin/echo
  2655. /usr/local/freeswitch/bin/fs_cli -x status
  2656. /bin/echo
  2657. /bin/echo -n "Press Enter to continue the upgrade."
  2658. read
  2659. fi
  2660. /etc/init.d/freeswitch stop
  2661. if [ $? -ne 0 ]; then
  2662. #previous had an error
  2663. /bin/echo "Init ERROR, couldn't stop Freeswitch"
  2664. exit 1
  2665. fi
  2666. /usr/bin/make install
  2667. if [ $? -ne 0 ]; then
  2668. #previous had an error
  2669. /bin/echo "INSTALL ERROR!"
  2670. exit 1
  2671. else
  2672. /bin/echo "made_current" >> /tmp/install_fusion_status
  2673. fi
  2674. fi
  2675. #------------------------
  2676. # enable modules.conf.xml
  2677. #------------------------
  2678. /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
  2679. if [ $? -eq 0 ]; then
  2680. /bin/echo "Modules.conf.xml Already enabled"
  2681. else
  2682. #file exists and has been edited
  2683. enable_modules
  2684. #check exit status
  2685. if [ $? -ne 0 ]; then
  2686. #previous had an error
  2687. /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
  2688. exit 1
  2689. else
  2690. /bin/echo "enable_modules" >> /tmp/install_fusion_status
  2691. fi
  2692. fi
  2693. if [ $DEBUG -eq 1 ]; then
  2694. /bin/echo
  2695. /bin/echo "Press Enter to continue (check for errors)"
  2696. read
  2697. fi
  2698. #check for logrotate and change to cron.daily
  2699. if [ -a /etc/logrotate.d/freeswitch ]; then
  2700. /bin/echo "System configured for logrotate, changing"
  2701. /bin/echo " to new way."
  2702. /bin/rm /etc/logrotate.d/freeswitch
  2703. /etc/init.d/logrotate restart
  2704. freeswitch_logfiles
  2705. fi
  2706. if [ -e $WWW_PATH/$GUI_NAME ]; then
  2707. echo "I noticed that FusionPBX is installed too"
  2708. echo "now going to fix freeswitch permissions from upgrade to be safe"
  2709. www_permissions
  2710. else
  2711. echo "Standalone FreeSWITCH installation, no permissions to change"
  2712. fi
  2713. /etc/init.d/freeswitch start
  2714. fi
  2715. #------------------------------------
  2716. # DONE UPGRADING FREESWITCH
  2717. #------------------------------------
  2718. #------------------------------------
  2719. # UPGRADE FusionPBX
  2720. #------------------------------------
  2721. if [ $UPGFUSION -eq 1 ]; then
  2722. /bin/echo "Resetting FreeSWITCH permissions to www-data in case you did"
  2723. /bin/echo " a FreeSWITCH upgrade as well."
  2724. www_permissions
  2725. cd $WWW_PATH/$GUI_NAME
  2726. /bin/echo
  2727. /bin/echo "STOP! Make sure you are logged into fusionpbx as the superadmin (via browser)!"
  2728. read -p "Have you done this yet (y/n)? " YESNO
  2729. if [ $YESNO == "y" ]; then
  2730. /bin/echo "Be really sure you are logged in as superadmin."
  2731. /bin/echo " If nothing else, refresh the browser to make sure"
  2732. /bin/echo " the session isn't stale."
  2733. /bin/echo
  2734. /bin/echo "If you haven't done this you risk not being able to Upgrade->Schema"
  2735. /bin/echo " which will toast your database"
  2736. /bin/echo
  2737. FUSIONREV=$(svn info $WWW_PATH/$GUI_NAME |grep -i revision|sed -e s/Revision:\ //)
  2738. if [ $FUSIONREV -le 1877 ]; then
  2739. echo "The project is still working on an upgrade tool"
  2740. echo " for the latest svn version. It is recommended"
  2741. echo " that you stay with revision 1877. Your current"
  2742. echo " revision is $FUSIONREV"
  2743. echo
  2744. read -p "Do we want Revision 1877, or latest (1877/latest)? " YESNO2
  2745. else
  2746. read -p "Ready to upgrade (y/n)? " YESNO2
  2747. fi
  2748. case $YESNO2 in
  2749. [YylL]*)
  2750. #svn...
  2751. /usr/bin/svn update $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2752. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2753. #print message saying to hit advanced->upgrade schema
  2754. /bin/echo "Done upgrading Files"
  2755. /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
  2756. /bin/echo "and select Advanced -> Upgrade Schema"
  2757. ;;
  2758. [1]*)
  2759. /usr/bin/svn update -r r1877 $FPBXBRANCH $WWW_PATH/$GUI_NAME
  2760. /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
  2761. #print message saying to hit advanced->upgrade schema
  2762. /bin/echo "Done upgrading Files"
  2763. /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
  2764. /bin/echo "and select Advanced -> Upgrade Schema"
  2765. ;;
  2766. *)
  2767. echo "Bad option, exiting"
  2768. exit 1
  2769. ;;
  2770. esac
  2771. else
  2772. exit 1
  2773. fi
  2774. read -p "Do you want to try and run the auto-upgrade php script from CLI (y/n)? " YESNO
  2775. case $YESNO in
  2776. [yY]*)
  2777. echo "Starting... /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
  2778. /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php
  2779. echo "Done"
  2780. ;;
  2781. *)
  2782. echo "OK, don't forget to run it yourself via GUI or here with"
  2783. echo " /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
  2784. ;;
  2785. esac
  2786. fusionfail2ban
  2787. fi
  2788. #------------------------------------
  2789. # DONE UPGRADING FusionPBX
  2790. #------------------------------------
  2791. #success!!!
  2792. if [ -e /tmp/install_fusion_status ]; then
  2793. /bin/rm /tmp/install_fusion_status
  2794. fi
  2795. /bin/echo "Checking to see if FreeSWITCH is running!"
  2796. /usr/bin/pgrep freeswitch
  2797. if [ $? -ne 0 ]; then
  2798. /etc/init.d/freeswitch start
  2799. else
  2800. /bin/echo " DONE!"
  2801. fi
  2802. exit 0
  2803. ---------
  2804. #CHANGELOG
  2805. #---------
  2806. # vSVN, now using SVN.... November 2011
  2807. #v4.4.0pre 2011 April 12
  2808. #BUGS: FS CHANGED!!! 2011-05-12
  2809. # Add libssl-dev
  2810. # currently mod_cidlookup, mod_xml_curl mod_xml_cdr busted
  2811. #BUGS: FS isn't started at end of install-both auto
  2812. #BUGS: fix-https still throws usage help. check www-permissions too.
  2813. #BUGS: Apache heredoc isn't escaping the variables. documentroot and servername wrong.
  2814. #BUGS: dingaling still not compile right. let's change makefile and recompile module
  2815. #ADD: zip compression to nginx
  2816. #ADD: monit for freeswitch and nginx
  2817. #add libssl-dev for secure sip.
  2818. # ADD mod_spandsp for fax and g722
  2819. # apt-get install libtiff4-dev
  2820. # Add NTP, maybe run sudo ntpdate ntp.ubuntu.com to make suer date is correct.
  2821. # prevents make from dying (date in the future crap).
  2822. # BUGS: Had quotes around nginx config
  2823. # FS failed to start with script
  2824. # Fail2Ban FS-dos has freeswitch2 in jail.local
  2825. # Fail2ban not starting:
  2826. # freeswitch-dos ports wrong in jail.local.
  2827. # build again and run fail2ban-client -d to test.
  2828. # Add Option to download FreeSWITCH compiled source as tar.gz for iso
  2829. # Added Option --fix-permissions
  2830. # checks FreeSWITCH init script
  2831. # Added: upgrade-fusionpbx needs to fix permissions, since a FS upgrade kills them.
  2832. # FIXED Logrotate for nginx
  2833. # logfiles were: /var/log/fusionpbx_gui.*_log;
  2834. # logfiles now: /var/log/nginx/*.log
  2835. # Added: Fail2ban for FusionPBX failed login attempts
  2836. # Need information on attempts/rate/etc
  2837. # Added: Fail2ban for FusionPBX on failed provision attempts
  2838. # Need information on attempts/rate/etc
  2839. # Needs Testing!
  2840. # FIXED: RepeatedMsgReduction wasn't getting set correctly in rsyslog.conf
  2841. # Added Change Fail2ban on FreeSWITCH with attempts/rate/etc in config file (not default settings)
  2842. # Added: Option to download GIT from GitHub repository (It's faster), see DEFINES
  2843. # Make nginx/apache https by default
  2844. # iso needs to regenerate certificates post install, ideally with 10 year expirations.
  2845. # apt-get install ssl-cert
  2846. # ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
  2847. # ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
  2848. # ln -s /etc/ssl/certs/nginx.crt /var/www/fusionpbx/$HOSTNAME.crt
  2849. # /etc/init.d/nginx restart
  2850. # FIXED nginx config to not block html files... Don't do block ~ .ht
  2851. # Added FreeTDM, and Dahdi
  2852. #v4.3.3 2011 January 31
  2853. # Added: smp compile support. Script works, make -j doesn't. see jira FS-3005
  2854. # Fixed: NGinx file size error
  2855. # Added: Remove Nginx/php/apache properly
  2856. # FIXED removing nginx removes gnome/x.
  2857. # Added: Postgres (seems good)
  2858. # Fixed: Set up apache properly (fusionpbx file instead of default, use heredoc)
  2859. # TODO: look into setting up FS for mysql/pgsql
  2860. # Fixed: sqlite http request issue for nginx/apache
  2861. # Added: now doing ppa's the ubuntu way with apt-add-repository
  2862. # Added: set up auto install for nginx/apache, mysql/postgresql/sqlite, setnonat.
  2863. # Added: now prompts for rm -Rf /opt (or variable for auto-install).
  2864. # There's a bug in either ppa-purge or apt-add-repository (likely latter).
  2865. # if you install nginx, change your mind, install apache, change your mind again
  2866. # and re-install nginx, the repository for nginx/php5-fpm gets removed proerly
  2867. # [a '#' covers repo], but when re-enabling, the '#' gets replaced, and an 'n'
  2868. # is left on a newline afterward, preventing update/install from that repo.
  2869. # Fixed: Checking for nginx/apache2 binary instead of init scripts for if[x] restart
  2870. #v4.3.2.1 2011 January 1
  2871. # small problem when selecting nginx and sqlite. php5-fpm needed to restart
  2872. # so FusionPBX could see the FreeSWITCH directory.
  2873. #v4.3.2 2010 December 30
  2874. # logrotate was improperly setup. Needed to send sighup to fs_cli
  2875. # Caused FS to die the first time it tried to log after rotation.
  2876. # php5-cli is a dependancy. required for voicemail to email, and fax to email.
  2877. # added an nginx/php-fpm option. You can change a variable (for auto run)
  2878. # or it will prompt you when you install fusionpbx in user mode
  2879. # mysql added as an option.
  2880. # problem with the way ubuntu logs ssh failures [fail2ban]
  2881. # Failed password for root from 1.2.3.4 port 22 ssh2
  2882. # last message repeated 5 times
  2883. # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
  2884. # fail2ban: previous setup looked for freeswitch log in /var/log/freeswitch.log
  2885. # log is actually /usr/local/freeswitch/log/freeswitch.log
  2886. # Tries to see if you're on a static IP address. If you are, it wants to start
  2887. # FreeSWITCH with the -nonat option to save some time. Also a new variable
  2888. # TODO: Maybe probe cores and to the -b thing for quicker compile/bootstrap
  2889. # TODO: IPTABLES
  2890. #v4.3.1 2010 December 23
  2891. # look into make -j cores option
  2892. # made a state save file. so if there's an error, don't re-bootstrap, configure, etc.
  2893. # and remove it on a clean exit.
  2894. # requests for modules add/enable for ugrade-freeswitch. DONE
  2895. # mod dingaling needs libgnutls-dev libgnutls26 packages, and change:
  2896. # "--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
  2897. # in /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
  2898. # appears to be an ubuntu problem....
  2899. #v4.3 2010 December 22
  2900. # under case upgrade-freeswitch, variables were not set properly. It upgraded fusionpbx.. fixed.
  2901. # done: fail2ban error fixed. removed associated text
  2902. # done: have install check for /etc/fail2ban. reinstall (as in from iso) duplicates some txt
  2903. # done: remove or fix fusionpbx upgrade code. it either needs to log in
  2904. # and then update and run the schema upgrade. or get rid of it. Fixed by prompting the user
  2905. # to open a browser window, and warn.
  2906. # done: get logrotate working... let's not fill the disk.
  2907. # stop/start freeswitch for an upgrade, and an install...
  2908. #v4.2 2010 December 17
  2909. # made some changes so the text flows correctly now that we use curl
  2910. # to do install.php.
  2911. # sent curl output to dev null..
  2912. # added apt-get update before we install apache since remastersys removes apt data
  2913. # stopping FS before FusionPBX install, and starting afteward.
  2914. # changed license to WAF v1
  2915. #v4.1 2010 December 15
  2916. # changing cd sounds (48/32/16/8khz) down to hd sounds (16/8Kkhz)
  2917. #v4 2010 December 14
  2918. # now install-fusion|install-freeswitch|upgrade...
  2919. # also adding curl commands to finish fusionpbx install.
  2920. #v3 adding fail2ban et al.
  2921. #v2 2010 December 07
  2922. # adds arrays to process the modules. should make this much easier to edit.
  2923. # just make additions to modules_add
  2924. # This should work fine (even on a 2nd run).
  2925. #v1 2010 December 06
  2926. # was first cut