install_fusionpbx.sh 104 KB

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