123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291 |
- #!/bin/bash
- # install_fusionpbx
- LICENSE=$( cat << DELIM
- #------------------------------------------------------------------------------
- #
- # "THE WAF LICENSE" (version 1)
- # This is the Wife Acceptance Factor (WAF) License.
- # jamesdotfsatstubbornrosesd0tcom wrote this file. As long as you retain this
- # notice you can do whatever you want with it. If you appreciate the work,
- # please consider purchasing something from my wife's wishlist. That pays
- # bigger dividends to this coder than anything else I can think of ;). It also
- # keeps her happy while she's being ignored; so I can work on this stuff.
- # James Rose
- #
- # latest wishlist: http://www.stubbornroses.com/waf.html
- #
- # Credit: Based off of the BEER-WARE LICENSE (REVISION 42) by Poul-Henning Kamp
- #
- # Contributor(s):
- # Gill Abada <[email protected]>
- # Mark J Crane <[email protected]>
- # Andrew Stanaitis <[email protected]>
- #------------------------------------------------------------------------------
- DELIM
- )
- #---------
- #VARIABLES
- #---------
- #Variables are for the auto installation option.
- #for apache set to a, for nginx/php-fpm set to n -> for an auto install, user mode will prompt
- APACHENGINX=n
- # for mysql set m. for sqlite set s. for postgresql set p
- SQLITEMYSQL=p
- # for postgresql v 9.0 (from ppa) set to 9
- # must set SQLITEMYSQL to p
- POSTGRES9=9
- # to start FreeSWITCH with -nonat option set SETNONAT to y
- SETNONAT=y
- # rm -Rf /opt? A default install doesn't have /opt so no worries
- # if you do, set to no, and it will link /usr/local/freeswitch to /opt/freeswitch
- #REMOVED OPTION
- #RMOPT=y
- # use freedtm/dahdi? y/n
- DO_DAHDI=n
- # default distro
- #DISTRO=precise
- #DISTRO=squeeze
- #DISTRO=precise
- #DISTRO=lucid
- #DISTRO=wheezy
- DISTRO=jessie
- #below is a list of modules we want to add to provide functionality for FusionPBX
- #don't worry about the applications/mod_ format. This script will find that in modules.conf
- #PAY ATTENTION TO THE SPACES POST AND PRE PARENTHESIS
- # mod_shout removed
- if [ $DO_DAHDI == "y" ]; then
- 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 )
- else
- 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 )
- fi
- #-------
- #DEFINES
- #-------
- VERSION="Version - using subversion, no longer keeping track. WAF License"
- FSGIT=https://freeswitch.org/stash/scm/fs/freeswitch.git
- FSSTABLE=true
- FSStablefile=freeswitch-1.6.6
- FSStableVer="v1.6"
- FSDB=p
- #right now, make -j not working. see: jira FS-3005
- CORES=$(/bin/grep processor -c /proc/cpuinfo)
- #CORES=1
- FQDN=$(hostname -f)
- #SRCPATH="/usr/src/freeswitch" #DEFAULT
- SRCPATH="/usr/src/freeswitch"
- #EN_PATH="/usr/local/freeswitch/conf/autoload_configs" #DEFAULT
- EN_PATH="/usr/local/freeswitch/conf/autoload_configs"
- WWW_PATH="/var/www"
- #used for Apache
- #WWW_PATH="/var/www/html"
- GUI_NAME=fusionpbx
- INST_FPBX=git
- #INST_FPBX=svn
- #INST_FPBX=tgz
- #full path required
- #TGZ_FILE="/home/coltpbx/fusionpbx-1.2.1.tar.gz"
- FUSIONPBX_GIT_SERVER=https://github.com
- FUSIONPBX_GIT_CONTRIBUTER=fusionpbx
- FUSIONPBX_GIT_PROJECT=fusionpbx
- FUSIONPBX_GIT_ASKBRANCH=0
- FSREV=false
- #IF FSCHECKOUTVER is true, FSSTABLE needs to be false
- FSCHECKOUTVER=false
- FPBXREV="1876"
- FBPXCHECKOUTVER=false
- #dev
- #URLSCRIPT="http://fusionpbx.googlecode.com/svn/branches/dev/scripts/install/ubuntu/install_fusionpbx.sh"
- #trunk
- #URLSCRIPT="https://fusionpbx.googlecode.com/svn/trunk/scripts/install/ubuntu/install_fusionpbx.sh"
- URLSCRIPT="https://raw.githubusercontent.com/fusionpbx/fusionpbx-scripts/master/install/debian/install_fusionpbx.sh"
- INSFUSION=0
- INSFREESWITCH=0
- UPGFUSION=0
- UPGFREESWITCH=0
- #---------
- # NOTES
- #---------
- # This Script installs or upgrades FreeSWITCH and FusionPBX on a fresh install of
- # Ubuntu 10.04 LTS [lucid]. It tries to edit all appropriate files, and
- # set the permissions correctly.
- #When you install ubuntu, you should select the "Manual package selection" option.
- #This way we can keep the install to the bare minimum. This script will install
- #everything you need (and nothing) - hopefully, you don't. Just quit tasksel
- #---------
- #FUNCTIONS
- #---------
- function nativepgsql {
- /bin/echo
- /bin/echo "By default, FreeSWITCH is using sqlite, until we tell it not to."
- /bin/echo "FreeSWITCH can be configured to use postgresql natively, but it is"
- /bin/echo "not always advantageous to do so."
- read -p " Use Postgres (p) or Sqlite (s) [p/S]? " FSDB
- case $FSDB in
- [pP])
- #tell FS about the postgresql database...
- echo " Please type in the password for the freeswitch database you configured below."
- read -p "Password: " FSDBPASS
-
- FPATH="/var/www/fusionpbx/resources/templates/conf"
- /bin/echo "setting switch.conf.xml"
- sed -i $FPATH/autoload_configs/switch.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/autoload_configs/switch.conf.xml <<EOF
- <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'" />
- </settings>
- </configuration>
- EOF
-
- /bin/echo "setting callcenter.conf.xml"
- sed -i $FPATH/autoload_configs/callcenter.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/autoload_configs/callcenter.conf.xml <<EOF
- <param name="odbc-dsn" value="\$\${dsn}"/>
- </settings>
- </configuration>
- EOF
- /bin/echo "setting fifo.conf.xml"
- sed -i $FPATH/autoload_configs/fifo.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/autoload_configs/fifo.conf.xml <<EOF
- <param name="odbc-dsn" value="\$\${dsn}"/>
- </settings>
- </configuration>
- EOF
- /bin/echo "setting internal.conf.xml"
- sed -i $FPATH/sip_profiles/internal.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/sip_profiles/internal.xml <<EOF
- <param name="odbc-dsn" value="\$\${dsn}"/>
- </settings>
- </configuration>
- EOF
- /bin/echo "setting external.conf.xml"
- sed -i $FPATH/sip_profiles/external.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/sip_profiles/external.xml <<EOF
- <param name="odbc-dsn" value="\$\${dsn}"/>
- </settings>
- </configuration>
- EOF
-
- /bin/echo "setting db.conf.xml"
- sed -i $FPATH/autoload_configs/db.conf.xml -e s,\<\/settings\>,,g -e s,\<\/configuration\>,,g
- cat >> $FPATH/autoload_configs/db.conf.xml <<EOF
- <param name="odbc-dsn" value="\$\${dsn}"/>
- </settings>
- </configuration>
- EOF
-
- ;;
-
- *)
- /bin/echo "Ok, using sqlite, nothing more to do here."
- ;;
- esac
- }
- function nginxconfig {
- apt-get install -y ssl-cert
- ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
- ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
- ln -s /etc/ssl/certs/nginx.crt $WWW_PATH/$GUI_NAME/$HOSTNAME.crt
- #don't forget to escape 'DELIM'. otherwise the $fastcgi part
- #gets escaped.
- #manually escaping now. needs variables....
- /bin/cat > /etc/nginx/sites-available/$GUI_NAME <<DELIM
- server {
- listen 127.0.0.1:80;
- server_name 127.0.0.1;
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log;
- client_max_body_size 10M;
- client_body_buffer_size 128k;
- location / {
- root $WWW_PATH/$GUI_NAME;
- index index.php;
- }
- location ~ \.php$ {
- fastcgi_pass unix:/var/run/php5-fpm.sock;
- #fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
- }
- # Disable viewing .htaccess & .htpassword & .db
- location ~ .htaccess {
- deny all;
- }
- location ~ .htpassword {
- deny all;
- }
- location ~^.+.(db)$ {
- deny all;
- }
- }
- server {
- listen 80;
- server_name $GUI_NAME;
- #grandstream
- rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=\$1;
- #aastra
- #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=\$1 last;
- #yealink common
- rewrite "^.*/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=\$1\$2;
- #yealink mac
- rewrite "^.*/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=\$1 last;
- #polycom
- rewrite "^.*/provision/000000000000.cfg$" "/app/provison/?mac=\$1&file=%7b%24mac%7d.cfg";
- #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
- rewrite "^.*/provision/features.cfg$" /app/provision/?mac=\$1&file=features.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=\$1&file=sip.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=\$1;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=\$1&file=%7b%24mac%7d-registration.cfg";
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-site.cfg$" /app/provision/?mac=\$1&file=site.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-web.cfg$" /app/provision/?mac=\$1&file=web.cfg;
- if (\$uri !~* ^.*provision.*$) {
- rewrite ^(.*) https://\$host\$1 permanent;
- break;
- }
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log;
- client_max_body_size 10M;
- client_body_buffer_size 128k;
- location / {
- root $WWW_PATH/$GUI_NAME;
- index index.php;
- }
- location ~ \.php$ {
- fastcgi_pass unix:/var/run/php5-fpm.sock;
- #fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
- }
- # Disable viewing .htaccess & .htpassword & .db
- location ~ .htaccess {
- deny all;
- }
- location ~ .htpassword {
- deny all;
- }
- location ~^.+.(db)$ {
- deny all;
- }
- }
- server {
- listen 443;
- server_name $GUI_NAME;
- ssl on;
- ssl_certificate /etc/ssl/certs/nginx.crt;
- ssl_certificate_key /etc/ssl/private/nginx.key;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_ciphers HIGH:!ADH:!MD5;
- #grandstream
- rewrite "^.*/provision/cfg([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/?mac=\$1;
- #aastra
- #rewrite "^.*/provision/([A-Fa-f0-9]{12})(\.(cfg))?$" /app/provision/?mac=\$1 last;
- #yealink common
- rewrite "^.*/(y[0-9]{12})(\.cfg)?$" /app/provision/index.php?file=\$1\$2;
- #yealink mac
- rewrite "^.*/([A-Fa-f0-9]{12})(\.(xml|cfg))?$" /app/provision/index.php?mac=\$1 last;
- #polycom
- rewrite "^.*/provision/000000000000.cfg$" "/app/provison/?mac=\$1&file=%7b%24mac%7d.cfg";
- #rewrite "^.*/provision/sip_330(\.(ld))$" /includes/firmware/sip_330.$2;
- rewrite "^.*/provision/features.cfg$" /app/provision/?mac=\$1&file=features.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-sip.cfg$" /app/provision/?mac=\$1&file=sip.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-phone.cfg$" /app/provision/?mac=\$1;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-registration.cfg$" "/app/provision/?mac=\$1&file=%7b%24mac%7d-registration.cfg";
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-site.cfg$" /app/provision/?mac=\$1&file=site.cfg;
- rewrite "^.*/provision/([A-Fa-f0-9]{12})-web.cfg$" /app/provision/?mac=\$1&file=web.cfg;
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error.log;
- client_max_body_size 10M;
- client_body_buffer_size 128k;
- location / {
- root $WWW_PATH/$GUI_NAME;
- index index.php;
- }
- location ~ \.php$ {
- fastcgi_pass unix:/var/run/php5-fpm.sock;
- #fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $WWW_PATH/$GUI_NAME\$fastcgi_script_name;
- }
- # Disable viewing .htaccess & .htpassword & .db
- location ~ .htaccess {
- deny all;
- }
- location ~ .htpassword {
- deny all;
- }
- location ~^.+.(db)$ {
- deny all;
- }
- }
- DELIM
- /bin/ln -s /etc/nginx/sites-available/$GUI_NAME /etc/nginx/sites-enabled/$GUI_NAME
- /bin/echo "document root for nginx is:"
- /bin/echo " $WWW_PATH/$GUI_NAME"
- /bin/echo " php has an upload file size limit of 10 MegaBytes"
- /bin/echo
- /bin/echo "now install FusionPBX. This should go fast."
- /bin/echo
- #nginx install doesn't create /var/www
- /bin/mkdir $WWW_PATH
- /bin/chown -R www-data:www-data $WWW_PATH
- /bin/chmod -R 775 $WWW_PATH
- /etc/init.d/php5-fpm
- /etc/init.d/nginx restart
- }
- function start_freeswitch {
- /usr/sbin/service freeswitch start
- echo Waiting for freeswitch to start ...;
- sleep 10;
- echo ... Continuing;
- }
- function fusionfail2ban {
- /bin/cat > /etc/fail2ban/filter.d/$GUI_NAME.conf <<'DELIM'
- # Fail2Ban configuration file
- #
- # Author: soapee01
- #
- [Definition]
- # Option: failregex
- # Notes.: regex to match the password failures messages in the logfile. The
- # host must be matched by a group named "host". The tag "<HOST>" can
- # be used for standard IP/hostname matching and is only an alias for
- # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
- # Values: TEXT
- #
- #failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
- #[hostname] variable doesn't seem to work in every case. Do this instead:
- failregex = .* FusionPBX: \[<HOST>\] authentication failed for
- = .* FusionPBX: \[<HOST>\] provision attempt bad password for
- # Option: ignoreregex
- # Notes.: regex to ignore. If this regex matches, the line is ignored.
- # Values: TEXT
- #
- ignoreregex =
- DELIM
- /bin/grep -i $GUI_NAME /etc/fail2ban/jail.local > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FusionPBX Jail already set"
- else
- /bin/cat >> /etc/fail2ban/jail.local <<DELIM
- [$GUI_NAME]
- enabled = true
- port = 80,443
- protocol = tcp
- filter = $GUI_NAME
- logpath = /var/log/auth.log
- action = iptables-allports[name=$GUI_NAME, protocol=all]
- # sendmail-whois[name=$GUI_NAME, dest=root, [email protected]] #no smtp server installed
- maxretry = 5
- findtime = 600
- bantime = 600
- DELIM
- fi
- }
- function www_permissions {
- #consider not stopping here... it's causing some significant delays, or just pause until it starts back up...
- #/etc/init.d/freeswitch stop
- /usr/sbin/adduser www-data audio
- /usr/sbin/adduser www-data dialout
- /bin/echo "setting FreeSWITCH owned by www-data.www-data"
- /bin/chown -R www-data.www-data /usr/local/freeswitch
- #remove 'other' permissions on freeswitch
- /bin/chmod -R o-rwx /usr/local/freeswitch/
- #set FreeSWITCH directories full permissions for user/group with group sticky
- /bin/echo "Setting group ID sticky for FreeSWITCH"
- /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
- #make sure FreeSWITCH directories have group write
- /bin/echo "Setting Group Write for FreeSWITCH files"
- /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
- #make sure FreeSWITCH files have group write
- /bin/echo "Setting Group Write for FreeSWITCH directories"
- /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
- /bin/echo "setting FusionPBX owned by www-data.www-data just in case"
- if [ -e /var/www/fusionpbx ]; then
- /bin/chown -R www-data.www-data /var/www/fusionpbx
- fi
- /bin/echo "Changing /etc/init.d/freeswitch to start with user www-data"
- /bin/sed -i -e s,'USER=freeswitch','USER=www-data', /etc/init.d/freeswitch
- #/etc/init.d/freeswitch start
- }
- function finish_fpbx_install_permissions {
- /bin/echo
- /bin/echo "The FusionPBX installation changed permissions of /usr/local/freeswitch/storage"
- /bin/echo " Waiting on you to finish installation (via browser), I'll clean up"
- /bin/echo -ne " the last bit of permissions when you finish."
- /bin/echo "Waiting on $WWW_PATH/$GUI_NAME/resources/config.php"
- while [ ! -e $WWW_PATH/$GUI_NAME/resources/config.php ]
- do
- /bin/echo -ne '.'
- sleep 1
- done
- /bin/echo
- /bin/echo "$WWW_PATH/$GUI_NAME/resources/config.php Found!"
- /bin/echo " Waiting 5 more seconds to be sure. "
- SLEEPTIME=0
- while [ "$SLEEPTIME" -lt 5 ]
- do
- /bin/echo -ne '.'
- sleep 1
- let "SLEEPTIME = $SLEEPTIME + 1"
- done
- /bin/echo " Fixing..."
- /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
- /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
- /bin/echo " FIXED"
- }
- function build_modules {
- #bandaid
- sed -i -e "s/applications\/mod_voicemail_ivr/#applications\/mod_voicemail_ivr/" $SRCPATH/modules.conf
- #------------
- # new way v2
- #------------
- #find the default modules - redundant really...
- modules_comp_default=( `/bin/grep -v ^$ /usr/src/freeswitch/modules.conf |/bin/grep -v ^# | /usr/bin/tr '\n' ' '` )
- #add the directory prefixes to the modules in array so the modules we wish to add will compile
- module_count=`echo ${#modules_add[@]}`
- index=0
- while [ "$index" -lt "$module_count" ]
- do
- modules_compile_add[$index]=`/bin/grep ${modules_add[$index]} $SRCPATH/modules.conf | sed -e "s/#//g"`
- let "index = $index + 1"
- done
- modules_compile=( ${modules_comp_default[*]} ${modules_compile_add[*]} )
- #BUILD MODULES.CONF for COMPILER
- echo
- echo
- echo "Now enabling modules for compile in $SRCPATH/modules.conf"
- index=0
- module_count=`echo ${#modules_compile[@]}`
- #get rid of funky spacing in modules.conf
- /bin/sed -i -e "s/ *//g" $SRCPATH/modules.conf
- while [ "$index" -lt "$module_count" ]
- do
- grep ${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
- if [ $? -eq 0 ]; then
- #module is present in file. see if we need to enable it
- grep '#'${modules_compile[$index]} $SRCPATH/modules.conf > /dev/null
- if [ $? -eq 0 ]; then
- /bin/sed -i -e s,'#'${modules_compile[$index]},${modules_compile[$index]}, $SRCPATH/modules.conf
- /bin/echo " [ENABLED] ${modules_compile[$index]}"
- else
- /bin/echo " ${modules_compile[$index]} ALREADY ENABLED!"
- fi
- else
- #module is not present. Add to end of file
- #/bin/echo "did not find ${modules_compile[$index]}"
- /bin/echo ${modules_compile[$index]} >> $SRCPATH/modules.conf
- /bin/echo " [ADDED] ${modules_compile[$index]}"
- fi
- let "index = $index + 1"
- done
- #--------------
- #end new way v2
- #--------------
- }
- function enable_modules {
- #------------
- # new way v2
- #------------
- #ENABLE MODULES for FreeSWITCH
- #
- echo
- echo
- echo "Now enabling modules for FreeSWITCH in $EN_PATH/modules.conf.xml"
- index=0
- module_count=`echo ${#modules_add[@]}`
- #get rid of any funky whitespace
- /bin/sed -i -e s,'<!-- *<','<!--<', -e s,'> *-->','>-->', $EN_PATH/modules.conf.xml
- while [ "$index" -lt "$module_count" ]
- do
- #more strangness to take care of, example:
- #Now enabling modules for FreeSWITCH in /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
- #[ADDED] ../../libs/freetdm/mod_freetdm
- modules_add[$index]=`/bin/echo ${modules_add[$index]} | /bin/sed -e 's/.*mod_/mod_/'`
- grep ${modules_add[$index]} $EN_PATH/modules.conf.xml > /dev/null
- if [ $? -eq 0 ]; then
- #module is present in file, see if we need to enable it.
- grep '<!--<load module="'${modules_add[$index]}'"/>-->' $EN_PATH/modules.conf.xml > /dev/null
- if [ $? -eq 0 ]; then
- #/bin/echo "found ${modules_compile[$index]}"
- /bin/sed -i -e s,'<!--<load module="'${modules_add[$index]}'"/>-->','<load module="'${modules_add[$index]}'"/>', \
- $EN_PATH/modules.conf.xml
- /bin/echo " [ENABLED] ${modules_add[$index]}"
- else
- /bin/echo " ${modules_add[$index]} ALREADY ENABLED!"
- fi
- else
- #not in file. we need to add, and will do so below <modules> tag at top of file
- /bin/sed -i -e s,'<modules>','&\n <load module="'${modules_add[$index]}'"/>', $EN_PATH/modules.conf.xml
- /bin/echo " [ADDED] ${modules_add[$index]}"
- fi
- let "index = $index + 1"
- done
- #--------------
- #end new way v2
- #--------------
- }
- function freeswitch_logfiles {
- /bin/echo
- /bin/echo "logrotate not happy with FS: see http://wiki.fusionpbx.com/index.php?title=RotateFSLogs doing differently now..."
- /bin/echo " SEE: /etc/cron.daily/freeswitch_log_rotation"
- /bin/cat > /etc/cron.daily/freeswitch_log_rotation <<'DELIM'
- #!/bin/bash
- # logrotate replacement script
- # put in /etc/cron.daily
- # don't forget to make it executable
- # you might consider changing /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml
- # <param name="rollover" value="0"/>
- #number of days of logs to keep
- NUMBERDAYS=30
- FSPATH="/usr/local/freeswitch"
- $FSPATH/bin/fs_cli -x "fsctl send_sighup" |grep '+OK' >/tmp/rotateFSlogs
- if [ $? -eq 0 ]; then
- #-cmin 2 could bite us (leave some files uncompressed, eg 11M auto-rotate). Maybe -1440 is better?
- find $FSPATH/log/ -name "freeswitch.log.*" -cmin -2 -exec gzip {} \;
- find $FSPATH/log/ -name "freeswitch.log.*.gz" -mtime +$NUMBERDAYS -exec /bin/rm {} \;
- chown www-data.www-data $FSPATH/log/freeswitch.log
- chmod 660 $FSPATH/log/freeswitch.log
- logger FreeSWITCH Logs rotated
- /bin/rm /tmp/rotateFSlogs
- else
- logger FreeSWITCH Log Rotation Script FAILED
- mail -s '$HOST FS Log Rotate Error' root < /tmp/rotateFSlogs
- /bin/rm /tmp/rotateFSlogs
- fi
- DELIM
- /bin/chmod 755 /etc/cron.daily/freeswitch_log_rotation
- /bin/echo "Now dropping 10MB limit from FreeSWITCH"
- /bin/echo " This is so the rotation/compression part of the cron script"
- /bin/echo " will work properly."
- /bin/echo " SEE: /usr/local/freeswitch/conf/autoload_configs/logfile.conf.xml"
- # <param name="rollover" value="10485760"/>
- /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
- }
- case $1 in
- fix-https)
- nginxconfig
- ;;
- fix-permissions)
- /etc/init.d/freeswitch stop
- www_permissions
- /etc/init.d/freeswitch start
- ;;
- install-freeswitch)
- INSFUSION=0
- INSFREESWITCH=1
- UPGFUSION=0
- UPGFREESWITCH=0
-
- ;;
- install-fusionpbx)
- INSFUSION=1
- INSFREESWITCH=0
- UPGFUSION=0
- UPGFREESWITCH=0
- ;;
- install-both)
- INSFUSION=1
- INSFREESWITCH=1
- UPGFUSION=0
- UPGFREESWITCH=0
- ;;
- upgrade-fusionpbx)
- INSFUSION=0
- INSFREESWITCH=0
- UPGFUSION=1
- UPGFREESWITCH=0
- ;;
- upgrade-freeswitch)
- INSFUSION=0
- INSFREESWITCH=0
- UPGFUSION=0
- UPGFREESWITCH=1
- ;;
- upgrade-both)
- INSFUSION=0
- INSFREESWITCH=0
- UPGFUSION=1
- UPGFREESWITCH=1
- ;;
- version)
- /bin/echo " "$VERSION
- /bin/echo
- /bin/echo "$LICENSE"
- exit 0
- ;;
- -v)
- /bin/echo " "$VERSION
- /bin/echo
- /bin/echo "$LICENSE"
- exit 0
- ;;
- --version)
- /bin/echo " "$VERSION
- /bin/echo
- /bin/echo "$LICENSE"
- exit 0
- ;;
- *)
- /bin/echo
- /bin/echo "This script should be called as:"
- /bin/echo " install_fusionpbx option1 option2"
- /bin/echo
- /bin/echo " option1:"
- /bin/echo " install-freeswitch"
- /bin/echo " install-fusionpbx"
- /bin/echo " install-both"
- /bin/echo " upgrade-freeswitch"
- /bin/echo " upgrade-fusionpbx"
- /bin/echo " fix-https"
- /bin/echo " fix-permissions"
- /bin/echo " version|--version|-v"
- /bin/echo
- /bin/echo " option2:"
- /bin/echo " user: option waits in certain places for the user to check for errors"
- /bin/echo " it is interactive and prompts you about what to install"
- /bin/echo " auto: tries an automatic install. Get a cup of coffee, this will"
- /bin/echo " take a while. FOR THE BRAVE!"
- /bin/echo
- /bin/echo " EXAMPLE"
- /bin/echo " install_fusionpbx install-both user"
- /bin/echo
- exit 0
- ;;
- esac
- case $2 in
- user)
- DEBUG=1
- ;;
- auto)
- DEBUG=0
- ;;
- *)
- /bin/echo
- /bin/echo "This script should be called as:"
- /bin/echo " install_fusionpbx option1 option2"
- /bin/echo
- /bin/echo " option1:"
- /bin/echo " install-freeswitch"
- /bin/echo " install-fusionpbx"
- /bin/echo " install-both"
- /bin/echo " upgrade-freeswitch"
- /bin/echo " upgrade-fusionpbx"
- /bin/echo " fix-https"
- /bin/echo " fix-permissions"
- /bin/echo " version|--version|-v"
- /bin/echo
- /bin/echo " option2:"
- /bin/echo " user: option waits in certain places for the user to check for errors"
- /bin/echo " it is interactive and prompts you about what to install"
- /bin/echo " auto: tries an automatic install. Get a cup of coffee, this will"
- /bin/echo " take a while. FOR THE BRAVE!"
- /bin/echo
- /bin/echo " EXAMPLE"
- /bin/echo " install_fusionpbx install-both user"
- /bin/echo
- exit 0
- ;;
- esac
- #---------------------
- # ENVIRONMENT CHECKS
- #---------------------
- #check for root
- if [ $EUID -ne 0 ]; then
- /bin/echo "This script must be run as root" 1>&2
- exit 1
- fi
- echo "Good, you are root."
- if [ ! -s /usr/bin/lsb_release ]; then
- /bin/echo "Tell your upstream distro to include lsb_release"
- /bin/echo
- apt-get upgrade && apt-get -y install lsb-release
- fi
- #check for internet connection
- /usr/bin/wget -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
- if [ ! -s /tmp/index.google ]; then
- echo "No Internet connection. Exiting."
- /bin/rm /tmp/index.google
- #exit 1
- else
- echo "Internet connection is working, continuing!"
- /bin/rm /tmp/index.google
- fi
- ##/bin/grep -i lucid /etc/lsb-release > /dev/null
- #lsb_release -c |grep -i lucid > /dev/null
- DISTRO_DETECT=$(lsb_release -c |sed -e s/Codename://g |sed -r 's/\s+//g')
- case $DISTRO_DETECT in
- lucid)
- #if [ $? -eq 0 ]; then
- DISTRO=lucid
- /bin/echo "Good, you're running Ubuntu 10.04 LTS codename Lucid"
- /bin/echo
- ;;
- #else
- # lsb_release -c |grep -i squeeze > /dev/null
- # if [ $? -eq 0 ]; then
- squeeze)
- DISTRO=squeeze
- /bin/echo "OK you're running Debian Squeeze. This script is known to work"
- /bin/echo " with apache/nginx and mysql|sqlite|postgres8 options"
- /bin/echo " Please consider providing feedback on repositories for nginx"
- /bin/echo " and php-fpm."
- /bin/echo
- CONTINUE=YES
- # fi
- ;;
- # lsb_release -c |grep -i wheezy > /dev/null
- # if [ $? -eq 0 ]; then
- wheezy)
- DISTRO=wheezy
- /bin/echo "OK you're running Debian Wheezy. This script is known to work"
- /bin/echo " with apache/nginx and sqlite|postgres9.4 options"
- /bin/echo " Please consider providing feedback on whether or not this works."
-
- /bin/echo
- CONTINUE=YES
- # fi
- ;;
-
- # lsb_release -c |grep -i precise > /dev/null
- # if [ $? -eq 0 ]; then
- precise)
- DISTRO=precise
- /bin/echo "OK you're running Ubuntu 12.04 LTS [precise]. This script is"
- /bin/echo " works fine."
- /bin/echo
- CONTINUE=YES
- ;;
- jessie)
- DISTRO=jessie
- /bin/echo "OK you're running Debian Jessie. This script is known to work"
- /bin/echo " with apache/nginx and sqlite|postgres9.4 options"
- /bin/echo " Please consider providing feedback on whether or not this works."
- /bin/echo
- CONTINUE=YES
- ;;
- # else
- *)
- /bin/echo "This script was written for Ubuntu 10.04 LTS codename Lucid, 12.04 LTS and Debian Squeeze"
- /bin/echo
- /bin/echo "Your OS appears to be:"
- lsb_release -a
- read -p "Do you want to continue [y|n]? " CONTINUE
- case "$CONTINUE" in
- [yY]*)
- /bin/echo "Ok, this doesn't always work..,"
- /bin/echo " but we'll give it a go."
- #set the default to try to install like precise instead of lucid. PPA's aren't required for wheezy or precise going forward...
- DISTRO=precise
- ;;
- *)
- /bin/echo "Quitting."
- exit 1
- ;;
- esac
- ;;
- # fi
- #fi
- esac
- #Check for new version
- WHEREAMI=$(echo "`pwd`/`basename $0`")
- wget $URLSCRIPT -O /tmp/install_fusionpbx.latest
- CURMD5=$(md5sum "$WHEREAMI" | sed -e "s/\ .*//")
- echo "The md5sum of the current script is: $CURMD5"
- NEWMD5=$(md5sum /tmp/install_fusionpbx.latest | sed -e "s/\ .*//")
- echo "The md5sum of the latest script is: $NEWMD5"
- if [[ "$CURMD5" == "$NEWMD5" ]]; then
- echo "files are the same, continuing"
- else
- echo "There is a new version of this script."
- echo " It is PROBABLY a good idea use the new version"
- echo " the new file is saved in /tmp/install_fusionpbx.latest"
- echo " to see the difference, run:"
- echo " diff -y /tmp/install_fusionpbx.latest $WHEREAMI"
- read -p "Continue with the current script [y/N]? " YESNO
- case $YESNO in
- [Yy]*)
- echo "OK, Continuing"
- echo " Deleting newest script in /tmp"
- rm /tmp/install_fusionpbx.latest
- ;;
- *)
- ;;
- esac
- fi
- #----------------------
- #END ENVIRONMENT CHECKS
- #----------------------
- #---------------------------------------
- # INSTALL FREESWITCH
- #---------------------------------------
- if [ $INSFREESWITCH -eq 1 ]; then
- /bin/echo "Upgrading the system, and adding the necessary dependencies for a FreeSWITCH compile"
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue..."
- fi
- /usr/bin/apt-get update
- /usr/bin/apt-get -y upgrade
- if [ $DISTRO == "precise" ]; then
- /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
- autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
- python-dev pkg-config libtiff4-dev php5-curl php5-imap php5-mcrypt lame \
- libperl-dev libgdbm-dev gettext libssl-dev \
- libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev \
- libsqlite3-dev libedit-dev libgdbm-dev libmemcached-dev \
- screen htop pkg-config bzip2 curl ntp memcached libldns-dev \
- time bison unixodbc libmyodbc unixodbc-dev libtiff-tools
- elif [ $DISTRO == "wheezy" ]; then
- /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
- autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
- python-dev pkg-config libtiff5-dev libldns-dev \
- libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
- libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libpq-dev \
- screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
- time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev
- elif [ $DISTRO == "jessie" ]; then
- /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
- autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev \
- python-dev pkg-config libtiff5-dev libldns-dev \
- libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
- libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libpq-dev \
- screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
- time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev libtool-bin\
- yasm nasm
- else
- /usr/bin/apt-get -y install ssh vim git-core libjpeg-dev subversion build-essential \
- python-dev pkg-config libtiff5-dev libldns-dev \
- libperl-dev libgdbm-dev libdb-dev gettext libcurl4-openssl-dev \
- libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev \
- autoconf automake devscripts gawk g++ git-core libtool make libncurses5-dev libjpeg62-dev \
- screen htop pkg-config bzip2 curl memcached ntp php5-curl php5-imap php5-mcrypt lame \
- time bison libssl-dev unixodbc libmyodbc unixodbc-dev libtiff-tools libmemcached-dev
- fi
- ##1.6 stuff
- echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
- wget -O - http://files.freeswitch.org/repo/deb/freeswitch-1.6/key.gpg |apt-key add -
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install --force-yes liblua5.2-0 liblua5.2-dev libopus-dev libcodec2-dev libyuv-dev libopus-dev libsndfile-dev libvpx-dev libvpx2-dev yasm
- #added libgnutls-dev libgnutls26 for dingaling...
- #gnutls no longer required for dingaling (git around oct 17 per mailing list..)
- # removed libgnutls-dev libgnutls26
- if [ $DO_DAHDI == "y" ]; then
- #add stuff for free_tdm/dahdi
- apt-get -y install linux-headers-`uname -r`
- #add the headers so dahdi can build the modules...
- apt-get -y install dahdi
- fi
- LDRUN=0
- /bin/echo -ne "Waiting on ldconfig to finish so bootstrap will work"
- while [ $LDRUN -eq 0 ]
- do
- echo -ne "."
- sleep 1
- /usr/bin/pgrep -f ldconfig > /dev/null
- LDRUN=$?
- done
- /bin/echo
- /bin/echo
- /bin/echo "ldconfig is finished"
- /bin/echo
- if [ ! -e /tmp/install_fusion_status ]; then
- touch /tmp/install_fusion_status
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue check for errors"
- fi
- #-----------------
- # Databases
- #-----------------
- #Lets ask... sqlite or postgresql -- for user option only
- if [ $DEBUG -eq 1 ]; then
- /bin/echo "New Option..."
- /bin/echo " FreeSWITCH now has native support for PostgreSQL (no more odbc in the core)"
- /bin/echo " also note that freeswitch is now compiled with zrtp support"
- /bin/echo
- read -p " Would you like to install PostgreSQL or stay with Sqlite (p/S)? " SQLITEMYSQL
- case "$SQLITEMYSQL" in
- [pP]*)
- if [ $DISTRO = "wheezy" ]; then
- echo "wheezy is PostgreSQL 9.4 by default"
- POSTGRES9=9
- elif [ $DISTRO = "jessie" ]; then
- echo "jessie is PostgreSQL 9.4 by default"
- POSTGRES9=9
- else
- /bin/echo
- /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
- /bin/echo " or verion 9 from PPA?"
- /bin/echo
- read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
- fi
- echo
- ;;
- esac
- fi
- case "$SQLITEMYSQL" in
- [Pp]*)
- /bin/echo -ne "Installing PostgeSQL"
- /bin/echo "DISTRO IS $DISTRO space"
- if [ $POSTGRES9 == "9" ]; then
- /bin/echo " version 9.x"
- if [ $DISTRO = "squeeze" ]; then
- #add squeeze repo
- /bin/echo "Adding debian backports for postgres9.1"
- /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
- /usr/bin/apt-get update
- /usr/bin/apt-get -y -t squeeze-backports install postgresql-9.1 libpq-dev
- elif [ $DISTRO = "precise" ]; then
- POSTGRES9=9
- #update repository for postgres 9.4 ...
- /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
- wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.4 libpq-dev
- elif [ $DISTRO = "wheezy" ]; then
- POSTGRES9=9
- #update repository for postgres 9.4 ...
- /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
- wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
- elif [ $DISTRO = "jessie" ]; then
- POSTGRES9=9
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
-
- service postgresql status |grep down
- if [ $? -eq 0 ]; then
- echo "The postgresql service is not running"
- echo "It may have not detected the locale correctly"
- echo "In another screen you should create a new cluster"
- echo " example:"
- echo " pg_createcluster --locale en_US.UTF-8 --start 9.3 main"
- echo " then see if it is running with 'service postgresql status'"
- read -p " this script will pause until this issue is resolved"
- fi
-
- else
- #add the ppa
- /usr/bin/apt-add-repository ppa:pitti/postgresql
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.3 libpq-dev
- fi
- else
- /bin/echo " version 8.4"
- /usr/bin/apt-get -y install postgresql libpq-dev
- #The following NEW packages will be installed:
- # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
- # postgresql-client-common postgresql-common
- fi
- #Fix pg_hba.conf
- cat > `find / -name pg_hba.conf` <<EOF
- # TYPE DATABASE USER ADDRESS METHOD
- # Database administrative login by Unix domain socket
- local all postgres peer
- local fusionpbx all md5
- local freeswitch all md5
- # "local" is for Unix domain socket connections only
- local all all peer
- # IPv4 local connections:
- host all all 127.0.0.1/32 md5
- # IPv6 local connections:
- host all all ::1/128 md5
- EOF
- /etc/init.d/postgresql restart
- /bin/su -l postgres -c "/usr/bin/createuser -s -e fusionpbx"
- #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O fusionpbx freeswitch"
- /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O fusionpbx freeswitch"
- PGSQLPASSWORD="dummy"
- PGSQLPASSWORD2="dummy2"
- while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
- /bin/echo
- /bin/echo
- /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
- /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
- /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
- /bin/echo "psql. THE COMMAND USED IS:"
- /bin/echo
- /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER fusionpbx with PASSWORD \$PGSQLPASSWORD;' | psql freeswitch\""
- /bin/echo
- /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
- /bin/echo
- /bin/echo "The pgsql username is fusionpbx"
- /bin/echo "The pgsql database name is freeswitch"
- /bin/echo "Please provide a password for the fusionpbx user"
- #/bin/stty -echo
- read -s -p " Password: " PGSQLPASSWORD
- /bin/echo
- /bin/echo "Let's repeat that"
- read -s -p " Password: " PGSQLPASSWORD2
- /bin/echo
- #/bin/stty echo
- done
- /bin/su -l postgres -c "/bin/echo \"ALTER USER fusionpbx with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql freeswitch"
- /bin/echo "overwriting pgsql password variable with random data"
- PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
- PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
- ;;
- *)
- #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
- /bin/echo "SQLITE is chosen. already done. nothing left to install..."
- ;;
- esac
- #------------------------
- # GIT FREESWITCH
- #------------------------
- /bin/grep 'git_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Git Already Done. Skipping"
- else
- cd /usr/src
- if [ "$FSSTABLE" == true ]; then
- echo "installing $FSStableVer of FreeSWITCH"
- /usr/bin/git clone $FSGIT
- cd /usr/src/freeswitch
- /usr/bin/git checkout $FSStableVer
- if [ $? -ne 0 ]; then
- #git had an error
- /bin/echo "GIT ERROR"
- exit 1
- fi
- elif [ "$FSSTABLE" == file ]; then
- echo "installing $FSStablefile of FreeSWITCH"
- wget http://files.freeswitch.org/freeswitch-releases/$FSStablefile.tar.gz
- tar -zxvf $FSStablefile.tar.gz
- mkdir freeswitch
- cp -R $FSStablefile/* /usr/src/freeswitch/
- cd /usr/src/freeswitch
- else
- echo "going dev branch."
- /usr/bin/git clone $FSGIT
- if [ $? -ne 0 ]; then
- #git had an error
- /bin/echo "GIT ERROR"
- exit 1
- fi
- if [ $FSCHECKOUTVER == true ]; then
- echo "OK we'll check out FreeSWITCH version $FSREV"
- cd /usr/src/freeswitch
- /usr/bin/git checkout $FSREV
- if [ $? -ne 0 ]; then
- #git checkout had an error
- /bin/echo "GIT CHECKOUT ERROR"
- exit 1
- fi
- fi
- /bin/echo "git_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ -e /usr/src/FreeSWITCH ]; then
- /bin/ln -s /usr/src/FreeSWITCH /usr/src/freeswitch
- elif [ -e /usr/src/freeswitch.git ]; then
- /bin/ln -s /usr/src/freeswitch.git /usr/src/freeswitch
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # BOOTSTRAP FREESWITCH
- #------------------------
- /bin/grep 'bootstrap_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Bootstrap already done. skipping"
-
- elif [ "$FSSTABLE" == file ]; then
- echo "bootstrap not required"
-
- else
- #Attempt to fix build on 1.6.6
- sed -i "40i m4_include(m4/memmove.m4)" /usr/src/freeswitch/libs/spandsp/configure.ac
- cat > /usr/src/freeswitch/libs/spandsp/m4/memmove.m4 <<EOF
- AC_DEFUN([AC_FUNC_MEMMOVE],
- [AC_CHECK_FUNCS(memmove)
- AC_MSG_CHECKING(for working memmove)
- AC_CACHE_VAL(ac_cv_have_working_memmove,
- [AC_TRY_RUN(
- [#include <stdio.h>
- int main(void)
- {
- char buf[10];
- strcpy (buf, "01234567");
- memmove (buf, buf + 2, 3);
- if (strcmp (buf, "23434567"))
- exit (1);
- strcpy (buf, "01234567");
- memmove (buf + 2, buf, 3);
- if (strcmp (buf, "01012567"))
- exit (1);
- exit (0);
- }], ac_cv_have_working_memmove=yes, ac_cv_have_working_memmove=no, ac_cv_have_working_memmove=cross)])
- AC_MSG_RESULT([$ac_cv_have_working_memmove])
- if test x$ac_cv_have_working_memmove != "xyes"; then
- AC_LIBOBJ(memmove)
- AC_MSG_WARN([Replacing missing/broken memmove.])
- AC_DEFINE(PREFER_PORTABLE_MEMMOVE, 1, "enable replacement memmove if system memmove is broken or missing")
- fi])
- EOF
- #might see about -j option to bootstrap.sh
- /etc/init.d/ssh start
- cd /usr/src/freeswitch
- /bin/echo
- /bin/echo "FreeSWITCH Downloaded"
- /bin/echo
- /bin/echo "Bootstrapping."
- /bin/echo
- #next line failed (couldn't find file) not sure why.
- #it did run fine a second time. Go figure (really).
- #ldconfig culprit?
- if [ $CORES -gt 1 ]; then
- /bin/echo " multicore processor detected. Starting Bootstrap with -j"
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- /usr/src/freeswitch/bootstrap.sh -j
- else
- /bin/echo " singlecore processor detected. Starting Bootstrap sans -j"
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- /usr/src/freeswitch/bootstrap.sh
- fi
- if [ $? -ne 0 ]; then
- #bootstrap had an error
- /bin/echo "BOOTSTRAP ERROR"
- exit 1
- else
- /bin/echo "bootstrap_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # build modules.conf
- #------------------------
- /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Modules.conf Already edited"
- else
- #file exists and has been edited
- build_modules
- #check exit status
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Failed to enable build modules in modules.conf."
- exit 1
- else
- /bin/echo "build_modules" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # CONFIGURE FREESWITCH
- #------------------------
- /bin/grep 'config_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FreeSWITCH already Configured! Skipping."
- else
- /bin/echo
- /bin/echo -ne "Configuring FreeSWITCH. This will take a while [~15 minutes]"
- /bin/sleep 1
- /bin/echo -ne " ."
- /bin/sleep 1
- /bin/echo -ne " ."
- /bin/sleep 1
- /bin/echo -ne " ."
- case "$FSDB" in
- [Pp]*)
- #/usr/src/freeswitch/configure --enable-core-pgsql-support --enable-zrtp
- #zrtp busted atm.
- /usr/src/freeswitch/configure --enable-core-pgsql-support
-
- ;;
- *)
- #/usr/src/freeswitch/configure --enable-zrtp
- #zrtp busted atm
- /usr/src/freeswitch/configure
- ;;
- esac
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: FreeSWITCH Configure ERROR."
- exit 1
- else
- /bin/echo "config_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- if [ -a /etc/init.d/freeswitch ]; then
- /bin/echo " In case of an install where FS exists (iso), stop FS"
- /etc/init.d/freeswitch stop
- fi
- #------------------------
- # COMPILE FREESWITCH
- #------------------------
- /bin/grep 'compile_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FreeSWITCH already Compiled! Skipping."
- else
- #might see about -j cores option to make...
- /bin/echo
- /bin/echo -ne "Compiling FreeSWITCH. This might take a while [~30 minutes]"
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo -ne "."
- #making sure pwd is correct
- cd /usr/src/freeswitch
- if [ $CORES -gt 1 ]; then
- /bin/echo " multicore processor detected. Compiling with -j $CORES"
- #per anthm compile the freeswitch core first, then the modules.
- /usr/bin/make -j $CORES core
- /usr/bin/make -j $CORES
- else
- /bin/echo " singlecore processor detected. Starting compile sans -j"
- /usr/bin/make
- fi
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: FreeSWITCH Build Failure."
- exit 1
- else
- /bin/echo "compile_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # INSTALL FREESWITCH
- #------------------------
- /bin/grep 'install_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FreeSWITCH already Installed! Skipping."
- else
- #dingaling/ubuntu has an issue. let's edit the file...
- #"--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
- #tls no longer required for dingaling, so this weird issue doesn't happen. now uses openssl.
- # /bin/grep 'lgnutls' /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la > /dev/null
- # if [ $? -eq 0 ]; then
- # /bin/echo "dingaling fix already applied."
- # else
- # /bin/sed -i -e s,'--mode=relink gcc','--mode=relink gcc -lgnutls', /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
- # fi
- cd /usr/src/freeswitch
- if [ $CORES -gt 1 ]; then
- /bin/echo " multicore processor detected. Installing with -j $CORES"
- /usr/bin/make -j $CORES install
- else
- /bin/echo " singlecore processor detected. Starting install sans -j"
- /usr/bin/make install
- fi
- #/usr/bin/make install
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: FreeSWITCH INSTALL Failure."
- exit 1
- else
- /bin/echo "install_done" >> /tmp/install_fusion_status
- fi
- fi
- #------------------------
- # FREESWITCH HD SOUNDS
- #------------------------
- /bin/grep 'sounds_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FreeSWITCH HD SOUNDS DONE! Skipping."
- else
- /bin/echo
- /bin/echo -ne "Installing FreeSWITCH HD sounds (16/8khz). This will take a while [~10 minutes]"
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo "."
- cd /usr/src/freeswitch
- if [ $CORES -gt 1 ]; then
- /bin/echo " multicore processor detected. Installing with -j $CORES"
- /usr/bin/make -j $CORES hd-sounds-install
- else
- /bin/echo " singlecore processor detected. Starting install sans -j"
- /usr/bin/make hd-sounds-install
- fi
- #/usr/bin/make hd-sounds-install
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: FreeSWITCH make cdsounds-install ERROR."
- exit 1
- else
- /bin/echo "sounds_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # FREESWITCH MOH
- #------------------------
- /bin/grep 'moh_done' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "FreeSWITCH MOH DONE! Skipping."
- else
- /bin/echo
- /bin/echo -ne "Installing FreeSWITCH HD Music On Hold sounds (16/8kHz). This will take a while [~10 minutes]"
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo -ne "."
- /bin/sleep 1
- /bin/echo "."
- cd /usr/src/freeswitch
- if [ $CORES -gt 1 ]; then
- /bin/echo " multicore processor detected. Installing with -j $CORES"
- /usr/bin/make -j $CORES hd-moh-install
- else
- /bin/echo " singlecore processor detected. Starting install sans -j"
- /usr/bin/make hd-moh-install
- fi
- #/usr/bin/make hd-moh-install
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: FreeSWITCH make cd-moh-install ERROR."
- exit 1
- else
- /bin/echo "moh_done" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #------------------------
- # FREESWITCH INIT
- #------------------------
- #no need for tmp file. already handled...
- /bin/echo
- /bin/echo "Configuring /etc/init.d/freeswitch"
- /bin/grep local /etc/init.d/freeswitch > /dev/null
- if [ $? -eq 0 ]; then
- #file exists and has been edited
- /bin/echo "/etc/init.d/freeswitch already edited, skipping"
- elif [ -e /usr/src/freeswitch/debian/freeswitch.init ]; then
- /bin/sed /usr/src/freeswitch/debian/freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
- else
- /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.init -e s,opt,usr/local, >/etc/init.d/freeswitch
- #DAEMON
- /bin/sed -i /etc/init.d/freeswitch -e s,^DAEMON=.*,DAEMON=/usr/local/freeswitch/bin/freeswitch,
- #DAEMON_ARGS
- /bin/sed -i /etc/init.d/freeswitch -e s,'^DAEMON_ARGS=.*','DAEMON_ARGS="-u www-data -g www-data -rp -nc -nonat"',
- #PIDFILE
- /bin/sed -i /etc/init.d/freeswitch -e s,^PIDFILE=.*,PIDFILE=/usr/local/freeswitch/run/\$NAME.pid,
- #WORKDIR
- /bin/sed -i /etc/init.d/freeswitch -e s,^WORKDIR=.*,WORKDIR=/usr/local/freeswitch/lib/,
- fi
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Couldn't edit FreeSWITCH init script."
- exit 1
- fi
- /bin/chmod 755 /etc/init.d/freeswitch
- /bin/echo "enabling FreeSWITCH to start at boot"
- /bin/mkdir /etc/freeswitch
- /bin/touch /etc/freeswitch/freeswitch.xml
- /bin/grep true /etc/default/freeswitch > /dev/null
- if [ $? -eq 0 ]; then
- #file exists and has been edited
- /bin/echo "/etc/default/freeswitch already edited, skipping"
- else
- if [ -e /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default ]; then
- /bin/sed /usr/src/freeswitch/debian/freeswitch-sysvinit.freeswitch.default -e s,false,true, > /etc/default/freeswitch
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Couldn't edit freeswitch RC script."
- exit 1
- fi
- else
- /bin/sed /usr/src/freeswitch/debian/freeswitch.default -e s,false,true, > /etc/default/freeswitch
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Couldn't edit freeswitch RC script."
- exit 1
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo "Checking for a public IP Address..."
- PUBLICIP=no
- #turn off the auto-nat when we start freeswitch.
- #nasty syntax. searches for 10.a.b.c or 192.168.x.y addresses in ifconfig.
- /sbin/ifconfig | \
- /bin/grep 'inet addr:' | \
- /usr/bin/cut -d: -f2 | \
- /usr/bin/awk '{ print $1}' | \
- while read IPADDR; do
- echo "$IPADDR" | \
- /bin/grep -e '^10\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
- -e '^192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' \
- -e '^127.0.0.1$'
- #-e '^172\.[16-31]\.[0-9]\{1,3\}\.[0-9]\{1,3\}' \
- if [ $? -ne 0 ]; then
- PUBLICIP=yes
- fi
- done
- case "$PUBLICIP" in
- [Yy]*)
- if [ $DEBUG -eq 1 ]; then
- /bin/echo "You appear to have a public IP address."
- /bin/echo " I can make sure FreeSWITCH starts with"
- /bin/echo " the -nonat option (starts quicker)."
- /bin/echo
- read -p "Would you like for me to do this (y/n)? " SETNONAT
- fi
-
- ;;
- *)
- /bin/echo "Dynamic IP. leaving FreeSWITCH for aggressive nat"
- SETNONAT=no
- ;;
- esac
- fi
- case "$SETNONAT" in
- [Yy]*)
- /bin/sed /etc/default/freeswitch -i -e s,'FREESWITCH_PARAMS="-nc"','FREESWITCH_PARAMS="-nc -nonat -reincarnate"',
- /bin/echo "init script set to start 'freeswitch -nc -nonat'"
- ;;
- *)
- /bin/echo "OK, not using -nonat option."
- ;;
- esac
- /bin/echo
- /usr/sbin/update-rc.d -f freeswitch defaults
- fi
- /bin/echo
- #don't do this. If freeswitch is a machine name, it really screws this test. It
- #won't hurt to adduser a second time anyhow.
- #/bin/grep freeswitch /etc/passwd > /dev/null
- #if [ $? -eq 0 ]; then
- #user already exists
- # /bin/echo "FreeSWITCH user already exists, skipping..."
- #else
- /bin/echo "adding freeswitch user"
- /usr/sbin/adduser --disabled-password --quiet --system \
- --home /usr/local/freeswitch \
- --gecos "FreeSWITCH Voice Platform" --ingroup daemon \
- freeswitch
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Failed adding freeswitch user."
- exit 1
- fi
- #fi
- /usr/sbin/adduser freeswitch audio
- /usr/sbin/groupadd freeswitch
- if [ $DO_DAHDI == "y" ]; then
- #dialout for dahdi
- /usr/sbin/adduser freeswitch dialout
- fi
- /bin/chown -R freeswitch:daemon /usr/local/freeswitch/
- /bin/echo "removing 'other' permissions on freeswitch"
- /bin/chmod -R o-rwx /usr/local/freeswitch/
- /bin/echo
- cd /usr/local/
- /bin/chown -R freeswitch:daemon /usr/local/freeswitch
- /bin/echo "FreeSWITCH directories now owned by freeswitch.daemon"
- /usr/bin/find freeswitch -type d -exec /bin/chmod u=rwx,g=srx,o= {} \;
- /bin/echo "FreeSWITCH directories now sticky group. This will cause any files created"
- /bin/echo " to default to the daemon group so FreeSWITCH can read them"
- /bin/echo
- #/bin/echo "removing /opt blindly (hope nothing is there) and linking it"
- #/bin/echo " to /usr/local so FusionPBX won't complain"
- #Opt might have been created due to a type in adduser freeswitch (home was /opt) check...
- #this looks to be the case.
- #the latest FusionBPX is correctly detecting /usr/local/freeswitch
- # probably always did.
- #let's try removing opt altogether...
- #/bin/echo
- /bin/ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
- #if [ $DEBUG -eq 1 ]; then
- # /bin/echo "FreeSWITCH was installed to /usr/local."
- # /bin/echo " normally we don't want to see /opt"
- # /bin/echo " since FusionPBX. tries to find it"
- # /bin/echo " and you end up with having to symlink"
- # /bin/echo " /usr/local/freeswitch to /opt/freeswitch"
- # /bin/echo
- # /bin/echo " It would be easier to blow /opt away; but"
- # /bin/echo " this may not be a fresh Ubuntu install."
- # /bin/echo
- # read -p "Can I 'rm -Rf /opt (Y/n)? " RMOPT
- #fi
- #case "$RMOPT" in
- #[Yy]*)
- # /bin/rm -Rf /opt
- #;;
- #*)
- #/bin/echo "OK, linking /usr/local/freeswitch to /opt/freeswitch"
- #/bin/ln -s /usr/local/freeswitch /opt/freeswitch
- #;;
- #esac
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- #------------------------
- # enable modules.conf.xml
- #------------------------
- /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Modules.conf.xml Already enabled"
- else
- #file exists and has been edited
- enable_modules
- #check exit status
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
- exit 1
- else
- /bin/echo "enable_modules" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- read -p "Press Enter to continue (check for errors)"
- fi
- #-----------------
- #Setup logrotate
- #-----------------
- # if [ -a /etc/logrotate.d/freeswitch ]; then
- if [ -a /etc/cron.daily/freeswitch_log_rotation ]; then
- /bin/echo "Logrotate for FreeSWITCH Already Done!"
- #call log script creation function
- freeswitch_logfiles
- fi
- #-----------------
- #harden FreeSWITCH
- #-----------------
- /bin/echo -ne "HARDENING"
- sleep 1
- /bin/echo -ne " ."
- sleep 1
- /bin/echo -ne " ."
- sleep 1
- /bin/echo -ne " ."
- /usr/bin/apt-get -y install fail2ban
- /bin/echo
- /bin/echo "Checking log-auth-failures"
- /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml > /dev/null
- if [ $? -eq 0 ]; then
- #see if it's uncommented
- /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml | /bin/grep '<!--' > /dev/null
- if [ $? -eq 1 ]; then
- #Check for true
- /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo " [ENABLED] log-auth-failures - Already Done!"
- else
- #it's false and uncommented, change it to true
- /bin/sed -i -e s,'<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
- /usr/local/freeswitch/conf/sip_profiles/internal.xml
- /bin/echo " [ENABLED] log-auth-failures - Was False!"
- fi
- else
- # It's commented
- # check for true
- /bin/grep log-auth-failures /usr/local/freeswitch/conf/sip_profiles/internal.xml |/bin/grep true > /dev/null
- if [ $? -eq 0 ]; then
- #it's commented and true
- /bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
- -e s,'<param name="log-auth-failures" value="true"/> *-->','<param name="log-auth-failures" value="true"/>', \
- -e s,'<!--<param name="log-auth-failures" value="true"/>','<param name="log-auth-failures" value="true"/>', \
- -e s,'<param name="log-auth-failures" value="true"/>-->','<param name="log-auth-failures" value="true"/>', \
- /usr/local/freeswitch/conf/sip_profiles/internal.xml
- /bin/echo " [ENABLED] log-auth-failures - Was Commented!"
- else
- #it's commented and false.
- /bin/sed -i -e s,'<!-- *<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
- -e s,'<param name="log-auth-failures" value="false"/> *-->','<param name="log-auth-failures" value="true"/>', \
- -e s,'<!--<param name="log-auth-failures" value="false"/>','<param name="log-auth-failures" value="true"/>', \
- -e s,'<param name="log-auth-failures" value="false"/>-->','<param name="log-auth-failures" value="true"/>', \
- /usr/local/freeswitch/conf/sip_profiles/internal.xml
- /bin/echo " [ENABLED] log-auth-failures - Was Commented and False!"
- fi
- fi
- else
- #It's not present...
- /bin/sed -i -e s,'<settings>','&\n <param name="log-auth-failures" value="true"/>', \
- /usr/local/freeswitch/conf/sip_profiles/internal.xml
- /bin/echo " [ENABLED] log-auth-failures - Wasn't there!"
- fi
- if [ -a /etc/fail2ban/filter.d/freeswitch.conf ]; then
- /bin/echo "fail2ban filter for freeswitch already done!"
- else
- /bin/cat > /etc/fail2ban/filter.d/freeswitch.conf <<"DELIM"
- # Fail2Ban configuration file
- #
- # Author: Rupa SChomaker
- #
- [Definition]
- # Option: failregex
- # Notes.: regex to match the password failures messages in the logfile. The
- # host must be matched by a group named "host". The tag "<HOST>" can
- # be used for standard IP/hostname matching and is only an alias for
- # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
- # Values: TEXT
- #
- failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
- \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
- # Option: ignoreregex
- # Notes.: regex to ignore. If this regex matches, the line is ignored.
- # Values: TEXT
- #
- ignoreregex =
- DELIM
- fi
-
- if [ -a /etc/fail2ban/filter.d/freeswitch-dos.conf ]; then
- /bin/echo "fail2ban filter for freeswitch-dos already done!"
- else
-
- /bin/cat > /etc/fail2ban/filter.d/freeswitch-dos.conf <<"DELIM"
- # Fail2Ban configuration file
- #
- # Author: soapee01
- #
- [Definition]
- # Option: failregex
- # Notes.: regex to match the password failures messages in the logfile. The
- # host must be matched by a group named "host". The tag "<HOST>" can
- # be used for standard IP/hostname matching and is only an alias for
- # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
- # Values: TEXT
- #
- failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'\w+\' for \[.*\] from ip <HOST>
- # Option: ignoreregex
- # Notes.: regex to ignore. If this regex matches, the line is ignored.
- # Values: TEXT
- #
- ignoreregex =
- DELIM
- fi
- #see if we've done this before (as in an ISO was made
- #with this script but the source wasn't included
- #so we have to reinstall...
- /bin/grep freeswitch /etc/fail2ban/jail.local > /dev/null
- if [ $? -ne 0 ]; then
- #add the following stanzas to the end of our file (don't overwrite)
- /bin/cat >> /etc/fail2ban/jail.local <<'DELIM'
- [freeswitch-tcp]
- enabled = true
- port = 5060,5061,5080,5081
- protocol = tcp
- filter = freeswitch
- logpath = /usr/local/freeswitch/log/freeswitch.log
- action = iptables-allports[name=freeswitch-tcp, protocol=all]
- maxretry = 5
- findtime = 600
- bantime = 600
- # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
- [freeswitch-udp]
- enabled = true
- port = 5060,5061,5080,5081
- protocol = udp
- filter = freeswitch
- logpath = /usr/local/freeswitch/log/freeswitch.log
- action = iptables-allports[name=freeswitch-udp, protocol=all]
- maxretry = 5
- findtime = 600
- bantime = 600
- # sendmail-whois[name=FreeSwitch, dest=root, [email protected]] #no smtp server installed
- [freeswitch-dos]
- enabled = true
- port = 5060,5061,5080,5081
- protocol = udp
- filter = freeswitch-dos
- logpath = /usr/local/freeswitch/log/freeswitch.log
- action = iptables-allports[name=freeswitch-dos, protocol=all]
- maxretry = 50
- findtime = 30
- bantime = 6000
- DELIM
- else
- /bin/echo"fail2ban jail.local for freeswitch already done!"
- fi
- #problem with the way ubuntu logs ssh failures [fail2ban]
- # Failed password for root from 1.2.3.4 port 22 ssh2
- # last message repeated 5 times
- # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
- /bin/echo "Turning off RepeatedMsgReduction in /etc/rsyslog.conf"
- #not sure what the deal is with the single quotes here. Fixed in v4.4.0
- #/bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
- /bin/sed -i 's/RepeatedMsgReduction\ on/RepeatedMsgReduction\ off/' /etc/rsyslog.conf
- /etc/init.d/rsyslog restart
- #bug in fail2ban. If you see this error
- #2011-02-27 14:11:42,326 fail2ban.actions.action: ERROR iptables -N fail2ban-freeswitch-tcp
- #http://www.fail2ban.org/wiki/index.php/Fail2ban_talk:Community_Portal#fail2ban.action.action_ERROR_on_startup.2Frestart
- /bin/grep -A 1 'time.sleep(0\.1)' /usr/bin/fail2ban-client |/bin/grep beautifier > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,beautifier\.setInputCmd\(c\),'time.sleep\(0\.1\)\n\t\t\tbeautifier.setInputCmd\(c\)', /usr/bin/fail2ban-client
- #this does slow the restart down quite a bit.
- else
- /bin/echo ' time.sleep(0.1) already added to /usr/bin/fail2ban-client'
- fi
- #still may have a problem with logrotate causing missing new FS log files.
- #should see log lines such as:
- #2011-02-13 06:37:59,889 fail2ban.filter : INFO Log rotation detected for /usr/local/freeswitch/log/freeswitch.log
- /etc/init.d/freeswitch start
-
- if [ $DISTRO == "jessie" ]; then
- sleep 5
- /bin/systemctl restart fail2ban.service
- else
- /etc/init.d/fail2ban restart
- fi
- /bin/echo " fail2ban for ssh enabled by default"
- /bin/echo " Default is 3 failures before your IP gets blocked for 600 seconds"
- /bin/echo " SEE http://wiki.freeswitch.org/wiki/Fail2ban"
- /bin/echo
- /bin/echo
- /bin/echo "FreeSWITCH Installation Completed. Have Fun!"
- /bin/echo
- fi
- #---------------------------------------
- # DONE INSTALLING FREESWITCH
- #---------------------------------------
-
- #---------------------------------------
- # INSTALL FUSIONPBX
- #---------------------------------------
- if [ $INSFUSION -eq 1 ]; then
- /bin/echo "FYI, we will need to change ownership of all FreeSWITCH"
- /bin/echo " Directories to www-data.www-data"
- /bin/echo " We will also need to change the init script to"
- /bin/echo " start FreeSWITCH as the www-data user."
- /bin/echo
- /bin/echo "This is a workaround to FreeSWITCH jira FS-3016"
- /bin/echo " The better way would be to have FreeSWITCH and FusionPBX"
- /bin/echo " share group permissions; unfortunately, FreeSWITCH writes"
- /bin/echo " log files, voicemail, etc with group permissions off."
- /bin/echo
- /bin/echo "This behavior is hard coded into FreeSWITCH."
- /bin/echo " For now, you need to be aware that if an"
- /bin/echo " exploit is found for apache2 or nginx"
- /bin/echo " The attacker would have access to the entire"
- /bin/echo " FreeSWITCH directory. This isn't quite as bad as it seems though."
- /bin/echo " since simply having access to configuration can do damage"
- /bin/echo "Watch your logfiles."
- #read -p " press enter to continue."
- /bin/echo
- /bin/echo "Stopping FreeSWITCH..."
- /etc/init.d/freeswitch stop
- www_permissions
- #Lets ask... nginx or apache -- for user option only
- if [ $DEBUG -eq 1 ]; then
- /bin/echo "New Option..."
- read -p "Would you prefer Apache or Ngnix [nginx and php-fpm from ppa repos] (a/N)? " APACHENGINX
- fi
- #remastersys iso ditches the apt data. have to update
- /usr/bin/apt-get update
- #get reqs for both
- /usr/bin/apt-get -y install git-core python-software-properties subversion ghostscript
- #provides apt-add-repository
- #installs python-software-properties unattended-upgrades
- #/usr/bin/apt-get -y install ppa-purge #in backports. don't want that repo
- if [ ! -e /usr/sbin/ppa-purge ]; then
- /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
- /usr/bin/dpkg -i /var/cache/apt/archives/ppa-purge_0+bzr46.1~lucid1_all.deb
- fi
- /usr/bin/apt-get -y install sqlite php5-cli php5-sqlite php5-odbc
- if [ $DISTRO = "precise" ]; then
- /usr/bin/apt-get -y install php-db
- fi
- if [ $DISTRO = "wheezy" ]; then
- /usr/bin/apt-get -y install php5-sqlite php-db
- fi
- if [ $DISTRO = "jessie" ]; then
- /usr/bin/apt-get -y install php5-sqlite php-db
- fi
- #-----------------
- # Apache
- #-----------------
- case "$APACHENGINX" in
- [Aa]*)
- #if [ $APACHENGINX == "a" ]; then
- if [ -e /usr/sbin/nginx ]; then
- #nginx is installed.
- /bin/echo
- /bin/echo "Nginx is installed, and you selected apache2."
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo " We need to remove nginx/php5-fpm. The packages"
- /bin/echo " are not purged, so configuration files will stay."
- /bin/echo
- read -p " Do you want to remove nginx/php5-fpm and install apache2 (y/n)? " YESNO
- else
- YESNO=y
- fi
- case "$YESNO" in
- [Yy]*)
- /bin/grep brianmercer /etc/apt/sources.list > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "php-fpm ppa already add the old way. Fixing"
- /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
- fi
- /bin/grep nginx /etc/apt/sources.list > /dev/null
- if [ $? -ne 0 ]; then
- /bin/echo "nginx ppa already add the old way. Fixing"
- /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
- fi
- #remove ppa's
- /usr/sbin/ppa-purge ppa:brianmercer/php
- /usr/sbin/ppa-purge ppa:nginx/stable
- #remove packages
- /usr/bin/apt-get -y remove nginx nginx-full libevent-1.4-2 libt1-5 \
- php-apc php-pear php5-fpm php5-gd php5-memcache
- #ttf-dejavu-core fontconfig-config libfontconfig1 libxpm4 #removes x/gnome
- #libxslt1.1 libxslt1.1 #removes midori
- #libgd2-xpm #removed by ppa-purge
- #libgd2-noxpm #removed by ppa-purge
- /usr/bin/apt-get clean
- /usr/bin/apt-get update
- #re-install removed packages
- /usr/bin/apt-get -y install libgd2-noxpm
- /bin/echo " NGINX/PHP5-FPM REMOVED!"
- ;;
- *)
- /bin/echo "OK. We'll stop. Exiting!"
- exit 1
- ;;
- esac
- fi
- /usr/bin/apt-get -y install apache2 libapache2-mod-php5
- #installs:
- #apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
- # /bin/grep fusionpbx /etc/apache2/sites-enabled/000-default > /dev/null
- # if [ $? -ne 0 ]; then
- if [ ! -e /etc/apache2/sites-enabled/$GUI_NAME ]; then
- #disable the default 000-default site
- /usr/sbin/a2dissite default
- #let's use a heredoc now, and do this the right way. #no 'quotes' with variables
- /bin/cat >> /etc/apache2/sites-available/$GUI_NAME <<DELIM
- <VirtualHost *:80>
- ServerAdmin webmaster@localhost
- ServerName $FQDN
- DocumentRoot $WWW_PATH/$GUI_NAME
- <Directory />
- Options FollowSymLinks
- AllowOverride None
- </Directory>
- <Directory $WWW_PATH/$GUI_NAME/>
- Options Indexes FollowSymLinks MultiViews
- AllowOverride None
- Order allow,deny
- allow from all
- </Directory>
- ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
- <Directory "/usr/lib/cgi-bin">
- AllowOverride None
- Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
- Order allow,deny
- Allow from all
- </Directory>
- ErrorLog /var/log/apache2/error.log
- # Possible values include: debug, info, notice, warn, error, crit,
- # alert, emerg.
- LogLevel warn
- CustomLog /var/log/apache2/access.log combined
- Alias /doc/ "/usr/share/doc/"
- <Directory "/usr/share/doc/">
- Options Indexes MultiViews FollowSymLinks
- AllowOverride None
- Order deny,allow
- Deny from all
- Allow from 127.0.0.0/255.0.0.0 ::1/128
- </Directory>
- </VirtualHost>
- DELIM
- /usr/sbin/a2ensite $GUI_NAME
- /bin/cat >> /etc/apache2/conf.d/securedb.conf <<'DELIM'
- #
- # The following lines prevent .db files from being
- # viewed by Web clients.
- #
- <Files ~ "^.*\.db">
- Order allow,deny
- Deny from all
- Satisfy all
- </Files>
- DELIM
- /etc/init.d/apache2 restart
- # /bin/sed -i -e s,"DocumentRoot /var/www","DocumentRoot /var/www/fusionpbx", \
- # -e s,"<Directory /var/www/>","<Directory /var/www/fusionpbx/>", \
- # /etc/apache2/sites-enabled/000-default
- if [ $? -ne 0 ]; then
- #previous had an error
- # /bin/echo "ERROR: Failed edit of /etc/apache2/sites-enabled/000-default"
- /bin/echo "ERROR: Failed addtion of /etc/apache2/sites-enabled/$GUI_NAME"
- exit 1
- else
- # /bin/echo "/etc/apache2/sites-enabled/000-default modified."
- /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME added."
- /bin/echo " Root www directory is now $WWW_PATH/$GUI_NAME"
- fi
- else
- /bin/echo
- #/bin/echo "/etc/apache2/sites-enabled/000-default already edited. Skipping..."
- /bin/echo "/etc/apache2/sites-enabled/$GUI_NAME already there. Skipping..."
- fi
- /bin/grep 10M /etc/php5/apache2/php.ini > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", /etc/php5/apache2/php.ini
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: failed edit of /etc/php5/apache2/php.ini upload_max_filesize = 10M."
- exit 1
- fi
- else
- /bin/echo
- /bin/echo "/etc/php5/apache2/php.ini already edited. Skipping..."
- fi
- /bin/echo "document root for apache2 is:"
- /bin/echo " $WWW_PATH/$GUI_NAME"
- /bin/echo " php has an upload file size limit of 10 MegaBytes"
- /bin/echo
- /bin/echo "now install FusionPBX. This should go fast."
- /bin/echo
- ;;
- #-----------------
- # Apache Done
- #-----------------
- #-----------------
- # NGINX
- #-----------------
- *)
- #elif [ $APACHENGINX == "n" ] || [ $APACHENGINX == "N" ] || [ $APACHENGINX == "" ]; then
- # ^ would be almost there. empty read isn't caught. switching to case. more flexible...
- if [ -e /usr/sbin/apache2 ]; then
- #apache2 is installed.
- /bin/echo
- /bin/echo "Apache2 is installed, and you selected nginx/php5-fpm."
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo " We need to remove apache2, and php5. The packages"
- /bin/echo " are not purged, so configuration files will stay."
- /bin/echo
- /bin/echo " Do you want to remove apache2/php5 and install "
- read -p " nginx/php5-fpm (y/n)? " YESNO
- else
- YESNO=y
- fi
- case "$YESNO" in
- [Yy]*)
- #remove packages
- /usr/bin/apt-get -y remove apache2 apache2-mpm-prefork apache2-utils apache2.2-bin \
- apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 \
- libaprutil1-ldap ssl-cert
-
- /bin/echo " APACHE2 REMOVED!"
- #removing libapr removes subversion!
- /usr/bin/apt-get -y install subversion
- ;;
- *)
- /bin/echo "OK. We'll stop. Exiting!"
- exit 1
- ;;
- esac
- fi
-
- if [ $DISTRO = "squeeze" ]; then
- #setup debian repos for nginx/php5-fpm
- /bin/echo "adding dotdeb repository for php5-fpm and nginx"
- /bin/echo "deb http://packages.dotdeb.org squeeze all" > /etc/apt/sources.list.d/squeeze-dotdeb.list
- /usr/bin/wget -O /tmp/dotdeb.gpg http://www.dotdeb.org/dotdeb.gpg
- /bin/cat /tmp/dotdeb.gpg | apt-key add -
- /bin/rm /tmp/dotdeb.gpg
- /usr/bin/apt-get update
- elif [ $DISTRO = "wheezy" ]; then
- #included in main repo we have nginx [nginx-full] and php5-fpm
- echo "already in Debian 7.x [wheezy], nothing to add."
- elif [ $DISTRO = "jessie" ]; then
- #included in main repo we have nginx [nginx-full] and php5-fpm
- echo "already in Debian 8.x [jessie], nothing to add."
- elif [ $DISTRO = "precise" ]; then
- #included in main repo we have nginx [nginx-full] and php5-fpm
- echo "already in 12.04 LTS [precise], nothing to add."
- else
- #add-apt-repository ppa:brianmercer/php // apt-get -y install python-software-properties
- #Add php5-fpm ppa to the list
- /bin/grep brianmercer /etc/apt/sources.list > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "php-fpm ppa already add the old way. Fixing"
- /bin/sed -i -e s,'deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main',, /etc/apt/sources.list
- /usr/bin/apt-add-repository ppa:brianmercer/php
- elif [ ! -e /etc/apt/sources.list.d./brianmercer-php-lucid.list ]; then
- /bin/echo "Adding PPA for php-fpm"
- #/bin/echo "deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucidmain" >> /etc/apt/sources.list
- #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D0DC64F
- /usr/bin/apt-add-repository ppa:brianmercer/php
- else
- /bin/echo "php-fpm ppa already added."
- fi
- #Add NGINX-ppa to src list.
- /bin/grep nginx /etc/apt/sources.list > /dev/null
- if [ $? -ne 0 ]; then
- /bin/echo "nginx ppa already add the old way. Fixing"
- /bin/sed -i -e s,'deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main',, /etc/apt/sources.list
- /usr/bin/apt-add-repository ppa:nginx/stable
- elif [ ! -e /etc/apt/sources.list.d./nginx-stable-lucid.list ]; then
- /bin/echo "Adding PPA for latest nginx"
- /usr/bin/apt-add-repository ppa:nginx/stable
- #/bin/echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
- #/usr/bin/apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
- else
- /bin/echo "nginx ppa already added"
- fi
- fi
- /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y
- /usr/bin/apt-get -y install nginx
- #installs libgd2-noxpm libxslt1.1 nginx nginx-full
- if [ $DISTRO = "squeeze" ]; then
- /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php5-apc php5-sqlite php5-json
- else
- #should work for precise
- /usr/bin/apt-get -y install php5-fpm php5-common php5-gd php-pear php5-memcache php-apc php5-json
- fi
- if [ $DISTRO = "squeeze" ]; then
- PHPINIFILE="/etc/php5/fpm/php.ini"
- PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
- elif [ $DISTRO = "precise" ]; then
- PHPINIFILE="/etc/php5/fpm/php.ini"
- #also exists, but www.conf used by default...
- #PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
- #max_children set in /etc/php5/fpm/pool.d/www.conf
- PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
- elif [ $DISTRO = "lucid" ]; then
- #lucid ppa conf files changed 1/20/2013
- PHPINIFILE="/etc/php5/fpm/php.ini"
- PHPCONFFILE="/etc/php5/fpm/pool.d/www.conf"
- elif [ $DISTRO = "wheezy" ]; then
- PHPINIFILE="/etc/php5/fpm/php.ini"
- PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
- elif [ $DISTRO = "jessie" ]; then
- PHPINIFILE="/etc/php5/fpm/php.ini"
- PHPCONFFILE="/etc/php5/fpm/php-fpm.conf"
- else
- PHPINIFILE="/etc/php5/fpm/php.ini"
- PHPCONFFILE="/etc/php5/fpm/php5-fpm.conf"
- fi
- /bin/grep 10M $PHPINIFILE > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,"upload_max_filesize = 2M","upload_max_filesize = 10M", $PHPINIFILE
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: failed edit of $PHPINIFILE upload_max_filesize = 10M."
- exit 1
- fi
- else
- /bin/echo
- /bin/echo "/etc/php5/fpm/php.ini already edited. Skipping..."
- fi
- #change to socket
- grep "listen = 127.0.0.1:9000" $PHPCONFFILE |grep \;
- if [ $? -ne 0 ]; then
- /bin/sed -i $PHPCONFFILE -e s,listen\ \=\ 127\.0\.0\.\1\:9000,listen\ \=\ \/var\/run\/php5-fpm.sock,
- fi
- #uncomment lines that are needed for unix socket
- /bin/sed -i -e s,";listen.owner","listen.owner", $PHPCONFFILE
- /bin/sed -i -e s,";listen.group","listen.group", $PHPCONFFILE
- /bin/sed -i -e s,";listen.mode","listen.mode", $PHPCONFFILE
- ##Applying fix for cgi.fix_pathinfo
- /bin/grep 'cgi\.fix_pathinfo=0' $PHPINIFILE > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,';cgi\.fix_pathinfo=1','cgi\.fix_pathinfo=0', $PHPINIFILE
- if [ $? -ne 0 ]; then
- /bin/echo "ERROR: failed edit of $PHPINIFILE cgi.fix_pathinfo=0"
- exit 1
- fi
- else
- /bin/echo
- /bin/echo "/etc/php5/fpm/php.ini already edited for cgi.fix_pathinfo. Skipping..."
- fi
- #We don't need so many php children. 1 per core should be fine FOR NOW.
- #/bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", /etc/php5/fpm/php5-fpm.conf
- /bin/grep "pm.max_children = 4" $PHPCONFFILE > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,"pm.max_children = 10","pm.max_children = 4", $PHPCONFFILE
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_children = 4"
- exit 1
- fi
- else
- /bin/echo
- /bin/echo "$PHPCONFFILE [children] already edited. Skipping..."
- fi
- #max_servers must be <= max_children
- /bin/grep "pm.max_spare_servers = 4" $PHPCONFFILE > /dev/null
- if [ $? -ne 0 ]; then
- /bin/sed -i -e s,"pm.max_spare_servers = 6","pm.max_spare_servers = 4", $PHPCONFFILE
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: failed edit of $PHPCONFFILE pm.max_spare_servers = 4"
- exit 1
- fi
- else
- /bin/echo
- /bin/echo "pm.max_spare_servers not changed"
- fi
- #update auto-starts ###PHP5-fpm and nginx are wrong??
- update-rc.d php5-fpm enable
- /etc/init.d/php5-fpm start
- ##setup niginx for fusionpbx & phpmyadmin!
- update-rc.d nginx enable
- /etc/init.d/nginx start
- #NGINX server config:
- rm /etc/nginx/sites-enabled/default
- /bin/grep '.db' /etc/nginx/sites-available/$GUI_NAME >> /dev/null
- if [ $? -ne 0 ]; then
- /bin/echo "Nginx insecure previous installation"
- /bin/echo " allows http access to FusionPBX database"
- /bin/echo " FIXING..."
- /bin/rm /etc/nginx/sites-available/$GUI_NAME
- fi
- if [ -a /etc/nginx/sites-available/$GUI_NAME ]; then
- /bin/echo "/etc/nginx/sites-available/$GUI_NAME already exists... skipping"
- else
- nginxconfig
- fi
- if [ $DISTRO = "lucid" ]; then
- /bin/grep fastcgi_param.*HTTPS.*\$https\; /etc/nginx/fastcgi_params
- if [ $? -eq 0 ]; then
- echo "Fixing a weird nginx fastcgi_parm issue"
- echo " you can also add the following stanzas to"
- echo " your /etc/nginx/sites-enabled/$GUI_NAME file"
- echo " set $https off; #for listen 80 and listen localhost"
- echo " set $https on; #for listen 443"
- /bin/sed -i /etc/nginx/fastcgi_params -e s/fastcgi_param.*HTTPS.*\$https\;/#fastcgi_param\ HTTPS\ \$https\;/
- fi
- fi
- ;;
- esac
- #-----------------
- # NGINX Done
- #-----------------
-
- #else
- # /bin/echo "Didn't catch that. exiting"
- # exit 1
- #fi
- cd $WWW_PATH
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- /bin/echo "Stopping FreeSWITCH..."
- /usr/sbin/service freeswitch stop
- if [[ "$INST_FPBX" == "svn" ]]; then
- if [ $FBPXCHECKOUTVER == true ]; then
- /bin/echo "Going to install FusionPBX SVN Rev $FPBXREV"
- /usr/bin/svn checkout -r r$FPBXREV $FPBXBRANCH $WWW_PATH/$GUI_NAME
- else
- /bin/echo "Going to install FusionPBX latest SVN!"
- #removed -r r1877 r1877 from new install
- /usr/bin/svn checkout $FPBXBRANCH $WWW_PATH/$GUI_NAME
- fi
- elif [ $INST_FPBX == tgz ]; then
- /bin/tar -C $WWW_PATH -xzvf $TGZ_FILE
- elif [ $INST_FPBX == git ]; then
- FUSIONPBX_GIT="$FUSIONPBX_GIT_SERVER/$FUSIONPBX_GIT_CONTRIBUTER/$FUSIONPBX_GIT_PROJECT";
- /usr/bin/git clone $FUSIONPBX_GIT
- cd $GUI_NAME;
- if [ $FUSIONPBX_GIT_ASKBRANCH == 1 ]
- then
- branches=()
- eval eval "$(/usr/bin/git for-each-ref --shell --format='branches+=(%(refname:short))' refs/remotes/ | perl -l -wpe "s{'\w+/}{'}")"
- for id in "${!branches[@]}";
- do
- branch=${branches[$id]};
- printf "[%s] %s" $id $branch;
- if [ $branch == 'master' ];
- then
- printf " *default";
- default_branch=$id;
- fi
- printf "\n";
-
- done
- while true;
- do
- read -p "Which branch would you like to use? " branch
- if [[ -z $branch ]];
- then branch=$default_branch;
- fi;
- if [[ -n "${branches[$branch]}" ]];
- then break;
- fi;
- echo "Please choose a existing branch.";
- done
- /usr/bin/git checkout "${branches[$branch]}"
- fi;
- fi
- if [ ! -e $WWW_PATH/$GUI_NAME ]; then
- /bin/mv $WWW_PATH/fusionpbx $WWW_PATH/$GUI_NAME
- fi
- /usr/sbin/adduser freeswitch www-data
- /usr/sbin/adduser www-data daemon
- /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
- /bin/echo "freeswitch is now a member of the www-data group"
- /bin/echo " www-data is now a member of the daemon group"
- /usr/bin/find $WWW_PATH/$GUI_NAME -type f -exec /bin/chmod 644 {} \;
- /usr/bin/find $WWW_PATH/$GUI_NAME -type d -exec /bin/chmod 755 {} \;
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- if [ $APACHENGINX == "a" ]; then
- /etc/init.d/apache2 restart
- elif [ $APACHENGINX == "n" ]; then
- /etc/init.d/nginx restart
- fi
- /bin/echo "FusionPBX install needs Write permissions on group to remove files"
- /bin/echo "The daemon group (of which www-data is a member) can now edit all files"
- /bin/echo " in your FreeSWITCH installation. This may or may not be desirable"
- /bin/echo
- /bin/echo "if you want to change this, run (as root)"
- /bin/echo " /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g-w {} \;"
- /bin/echo " /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g-w {} \;"
- /bin/echo " however; FusionPBX won't be able to make changes anymore"
- /usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
- /usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
- # /bin/echo "go to the web address in your browser to finish configuration"
- # /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
- # /bin/echo "don't forget to start FreeSWITCH after the install!"
- # /bin/echo "/etc/init.d/freeswitch start"
- #FreeSWITCH needs read access to scripts in /var/www/fusionpbx/secure
- #per mcrane on IRC
- #mcrane: the easiest way to get it to work is have FreeSWITCH and the web server run under the same user
- # instead we made freeswitch user a member of the www-data group, and www-data user a member of the
- # daemon group.
- #added v3
- #move the default extensions .noload
- #The default FusionPBX install removes the default FreeSWITCH password, so anyone can register
- #with these default FreeSWITCH extensions. They aren't 'in' FusionPBX anyhow, so we don't need
- #them. We will leave them for reference.
- /bin/echo "renaming default FreeSWITCH extensions .noload"
- for i in /usr/local/freeswitch/conf/directory/default/1*.xml;do mv $i $i.noload ; done
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- /bin/echo
- /bin/echo "Finishing Up FusionPBX installation."
- /bin/echo "Now for a database..."
- /bin/echo
- #-----------------
- # MySQL
- #-----------------
- #Lets ask... sqlite or mysql -- for user option only
- if [ $DEBUG -eq 1 ]; then
- /bin/echo "New Option..."
- /bin/echo " SQlite is already installed (and required)"
- /bin/echo
- read -p " Would you like to install MySQL, PostgreSQL, or stay with Sqlite (m/p/S)? " SQLITEMYSQL
- case "$SQLITEMYSQL" in
- [pP]*)
- if [ $DISTRO = "wheezy" ]; then
- echo "precise is PostgreSQL 9.4 by default"
- POSTGRES9=9
- elif [ $DISTRO = "jessie" ]; then
- echo "jessie is PostgreSQL 9.4 by default"
- POSTGRES9=9
- else
- /bin/echo
- /bin/echo "OK, PostgreSQL! Would you prefer the stock verion 8.4"
- /bin/echo " or verion 9 from PPA?"
- /bin/echo
- read -p "PostgreSQL 8.4 or 9 [8/9]? " POSTGRES9
- fi
- echo
- ;;
- esac
- fi
- case "$SQLITEMYSQL" in
- [Mm]*)
- #if [ $SQLITEMYSQL == "m" ]; then
- /bin/echo "Installing MySQL"
- /usr/bin/apt-get -y install mysql-server php5-mysql mysql-client
- if [ -e /usr/sbin/nginx ]; then
- #nginx is installed.
- /etc/init.d/php5-fpm restart
- /etc/init.d/nginx restart
- elif [ -e /usr/sbin/apache2 ]; then
- #apache2 is installed.
- /etc/init.d/apache2 restart
- fi
- start_freeswitch
- /bin/echo "Now you'll need to manually finish the install and come back"
- /bin/echo " This way I can finish up the last bit of permissions issues"
- /bin/echo " Just go to"
- /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
- /bin/echo " MAKE SURE YOU CHOOSE MYSQL as your Database on the first page!!!"
- /bin/echo " ON the Second Page:"
- /bin/echo " Create Database Username: root"
- /bin/echo " Create Database Password: the_pw_you_set_during_install"
- /bin/echo " other options: whatever you like"
- /bin/echo " I will wait here until you get done with that."
- /bin/echo -ne " When MySQL is configured come back and press enter. "
- read
- ;;
- [Pp]*)
- #elif [ $SQLITEMYSQL == "p" ]; then
- #/bin/echo -ne "Installing PostgeSQL"
- #moving most of this to fs install
- /bin/echo "Time to add a $GUI_NAME user for the database."
- /bin/echo -ne " We will use $GUI_NAME as the username"
- /bin/echo -ne " please set the password."
- #add php postgres packages
- if [ $POSTGRES9 == "9" ]; then
- /bin/echo " version 9.3"
- if [ $DISTRO = "squeeze" ]; then
- #add squeeze repo
- /bin/echo "Adding debian backports for postgres9.1"
- /bin/echo "deb http://backports.debian.org/debian-backports squeeze-backports main" > /etc/apt/sources.list.d/squeeze-backports.list
- /usr/bin/apt-get update
- /usr/bin/apt-get -y -t squeeze-backports install php5-pgsql
- elif [ $DISTRO = "precise" ]; then
- #already there...
- /usr/bin/apt-get -y install php5-pgsql
- elif [ $DISTRO = "wheezy" ]; then
- POSTGRES9=9
- #update repository for postgres 9.4 ...
- /bin/echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" > /etc/apt/sources.list.d/pgdg.list
- wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
- elif [ $DISTRO = "jessie" ]; then
- POSTGRES9=9
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install postgresql-9.4 libpq-dev php5-pgsql
- else
- #add the ppa
- /usr/bin/apt-add-repository ppa:pitti/postgresql
- /usr/bin/apt-get update
- /usr/bin/apt-get -y install php5-pgsql
- fi
- else
- /bin/echo " version 8.4"
- /usr/bin/apt-get -y install postgresql libpq-dev
- #The following NEW packages will be installed:
- # libpq5 php5-pgsql postgresql postgresql-8.4 postgresql-client-8.4
- # postgresql-client-common postgresql-common
- fi
- #Fix pg_hba.conf
- cat > `find / -name pg_hba.conf` <<EOF
- # TYPE DATABASE USER ADDRESS METHOD
- # Database administrative login by Unix domain socket
- local all postgres peer
- local fusionpbx all md5
- local freeswitch all md5
- # "local" is for Unix domain socket connections only
- local all all peer
- # IPv4 local connections:
- host all all 127.0.0.1/32 md5
- # IPv6 local connections:
- host all all ::1/128 md5
- EOF
- /etc/init.d/postgresql restart
- /bin/su -l postgres -c "/usr/bin/createuser -s -e $GUI_NAME"
- #/bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -O $GUI_NAME $GUI_NAME"
- /bin/su -l postgres -c "/usr/bin/createdb -E UTF8 -T template0 -O $GUI_NAME $GUI_NAME"
- PGSQLPASSWORD="dummy"
- PGSQLPASSWORD2="dummy2"
- while [ $PGSQLPASSWORD != $PGSQLPASSWORD2 ]; do
- /bin/echo
- /bin/echo
- /bin/echo "THIS PROBABLY ISN'T THE MOST SECURE THING TO DO."
- /bin/echo "IT IS; HOWEVER, AUTOMATED. WE ARE STORING THE PASSWORD"
- /bin/echo "AS A BASH VARIABLE, AND USING ECHO TO PIPE IT TO"
- /bin/echo "psql. THE COMMAND USED IS:"
- /bin/echo
- /bin/echo "/bin/su -l postgres -c \"/bin/echo 'ALTER USER $GUI_NAME with PASSWORD \$PGSQLPASSWORD;' | psql $GUI_NAME\""
- /bin/echo
- /bin/echo "AFTERWARDS WE OVERWRITE THE VARIABLE WITH RANDOM DATA"
- /bin/echo
- /bin/echo "The pgsql username is $GUI_NAME"
- /bin/echo "The pgsql database name is $GUI_NAME"
- /bin/echo "Please provide a password for the $GUI_NAME user"
- #/bin/stty -echo
- read -s -p " Password: " PGSQLPASSWORD
- /bin/echo
- /bin/echo "Let's repeat that"
- read -s -p " Password: " PGSQLPASSWORD2
- /bin/echo
- #/bin/stty echo
- done
- /bin/su -l postgres -c "/bin/echo \"ALTER USER $GUI_NAME with PASSWORD '$PGSQLPASSWORD';\" | /usr/bin/psql $GUI_NAME"
- /bin/echo "overwriting pgsql password variable with random data"
- PGSQLPASSWORD=$(/usr/bin/head -c 512 /dev/urandom)
- PGSQLPASSWORD2=$(/usr/bin/head -c 512 /dev/urandom)
- if [ -e /usr/sbin/nginx ]; then
- #nginx is installed.
- /etc/init.d/php5-fpm restart
- /etc/init.d/nginx restart
- elif [ -e /usr/sbin/apache2 ]; then
- #apache2 is installed.
- /etc/init.d/apache2 restart
- fi
-
- #uncomment below to test the nativepgsql function. currently not working
- # internal/external/callcenter profiles still going to sqlite.
- #nativepgsql
-
-
- start_freeswitch
- /bin/echo "Now you'll need to manually finish the install and come back"
- /bin/echo " This way I can finish up the last bit of permissions issues"
- /bin/echo " Just go to"
- /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
- /bin/echo " MAKE SURE YOU CHOOSE PostgreSQL as your Database on the first page!!!"
- /bin/echo " ON the Second Page:"
- /bin/echo " Database Name: $GUI_NAME"
- /bin/echo " Database Username: $GUI_NAME"
- /bin/echo " Database Password: whateveryouentered"
- /bin/echo " Create Database Username: Leave_Blank"
- /bin/echo " Create Database Password: Leave_Blank"
- /bin/echo
- /bin/echo " I will wait here until you get done with that."
- /bin/echo -ne " When PostgreSQL is configured come back and press enter. "
- read
- ;;
- *)
- #elif [ $SQLITEMYSQL == "s" || $SQLITEMYSQL == "S" || $SQLITEMYSQL == "" ]; then
- /bin/echo "SQLITE is chosen. already done. nothing left to install..."
- if [ -e /usr/sbin/nginx ]; then
- #nginx is installed.
- /etc/init.d/php5-fpm restart
- /etc/init.d/nginx restart
- elif [ -e /usr/sbin/apache2 ]; then
- #apache2 is installed.
- /etc/init.d/apache2 restart
- fi
- start_freeswitch
- /bin/echo "FusionPBX install.php was done automatically"
- /bin/echo " when sqlite was selected. "
- /bin/echo " FreeSWITCH Directory: /usr/local/freeswitch"
- /bin/echo " PHP Directory: $WWW_PATH/$GUI_NAME"
- /bin/echo
- /bin/echo " Database Filename: $GUI_NAME.db"
- /bin/echo " Database Directory: $WWW_PATH/$GUI_NAME/secure"
- /bin/echo
- /bin/echo " Just go to"
- /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
- /bin/echo
- /bin/echo "Default login is (whatever you picked in the GUI install):"
- /bin/echo " User: WhateverUsernameYouPicked"
- /bin/echo " Passwd: YourPasswordYouPicked"
- ;;
- esac
- #else
- # /bin/echo "Didn't catch that. exiting"
- # exit 1
- #fi
- finish_fpbx_install_permissions
- #/bin/echo
- #/bin/echo "The FusionPBX installation messed up permissions of /usr/local/freeswitch/storage"
- #/bin/echo " Fixing..."
- # read
- #/usr/bin/find /usr/local/freeswitch -type f -exec /bin/chmod g+w {} \;
- #/usr/bin/find /usr/local/freeswitch -type d -exec /bin/chmod g+w {} \;
- #/bin/echo "Starting FreeSWITCH..."
- #/etc/init.d/freeswitch start
- /bin/echo "Setting up Fail2Ban for FusionPBX"
- fusionfail2ban
-
- if [ $DISTRO == "jessie" ]; then
- sleep 5
- /bin/systemctl restart fail2ban.service
- else
- /etc/init.d/fail2ban restart
- fi
- /bin/echo
- /bin/echo
- /bin/echo "Installation Completed. Now configure FreeSWITCH via the FusionPBX browser interface"
- /bin/echo
- /bin/echo ' http://'`/sbin/ifconfig eth0 | /bin/grep 'inet addr:' | /usr/bin/cut -d: -f2 | /usr/bin/awk '{ print $1}'`
- /bin/echo "Default login is (whatever you picked in the GUI install):"
- /bin/echo " User: WhateverUsernameYouPicked"
- /bin/echo " Passwd: YourPasswordYouPicked"
- fi
- #------------------------------------
- # DONE INSTALLING FUSIONPBX
- #------------------------------------
- #------------------------------------
- # UPGRADE FREESWITCH
- #------------------------------------
- if [ $UPGFREESWITCH -eq 1 ]; then
- #------------------------
- # build modules.conf
- #------------------------
- /bin/grep 'build_modules' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Modules.conf Already edited"
- else
- #file exists and has been edited
- build_modules
- #check exit status
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Failed to enable build modules in modules.conf."
- exit 1
- else
- /bin/echo "build_modules" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- #------------------------
- # make current
- #------------------------
- /bin/grep 'made_current' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Modules.conf Already edited"
- else
- /bin/echo
- /bin/echo ' going to run make curent'
- /bin/echo " Make current completely cleans the build environment and rebuilds FreeSWITCH™"
- /bin/echo " so it runs a long time. However, it will not overwrite files in a pre-existing"
- /bin/echo ' "conf" directory. Also, the clean targets leave the "modules.conf" file.'
- /bin/echo " This handles the git pull, cleanup, and rebuild in one step"
- /bin/echo ' src: http://wiki.freeswitch.org/wiki/Installation_Guide'
- cd /usr/src/freeswitch
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "/usr/src/freeswitch does not exist"
- /bin/echo "you probably installed from a FusionPBX ISO which deleted this"
- /bin/echo "Directory to save space. rerun with install-freeswitch option"
- exit 1
- fi
- cd /usr/src/freeswitch
- #get on the 1.2.x release first...
- echo
- echo
- echo "Checking to see which version of FreeSWITCH you are on"
- git status |grep "1.2"
- if [ $? -ne 0 ]; then
- echo "It appears that you are currently on the FreeSWITCH Git Master branch, or no branch."
- echo " We currently recommend that you switch to the 1.4.x branch,"
- echo " since 1.5 [master]."
- echo
- read -p "Shall we change to the 1.4.x release branch [Y/n]? " YESNO
- else
- YESNO="no"
- fi
- case $YESNO in
- [Nn]*)
- echo "OK, staying on current...."
- FSSTABLE=false
- ;;
- *)
- echo "OK, switching to 1.4.x."
- FSSTABLE=true
- ;;
- esac
- if [ $FSSTABLE == true ]; then
- echo "OK we'll now use the 1.4.x release branch"
- cd /usr/src/freeswitch
-
- #odd edge case, I think from a specific version checkout
- # git status
- # Not currently on any branch.
- # Untracked files:
- # (use "git add <file>..." to include in what will be committed)
- #
- # src/mod/applications/mod_httapi/Makefile
- git status |grep -i "not currently"
- if [ $? -eq 0 ]; then
- echo "You are not on master branch. We have to fix that first"
- /usr/bin/git checkout master
- if [ $? -ne 0 ]; then
- #git checkout had an error
- /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
- exit 1
- fi
- fi
- #/usr/bin/git clone -b $FSStableVer git://stash.freeswitch.org/scm/fs/freeswitch.git
- /usr/bin/git pull
- if [ $? -ne 0 ]; then
- #git checkout had an error
- /bin/echo "GIT PULL to 1.2.x ERROR"
- exit 1
- fi
- /usr/bin/git checkout $FSStableVer
- if [ $? -ne 0 ]; then
- #git checkout had an error
- /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
- exit 1
- fi
- #/usr/bin/git checkout master
- #if [ $? -ne 0 ]; then
- # #git checkout had an error
- # /bin/echo "GIT CHECKOUT to 1.2.x ERROR"
- # exit 1
- #fi
- else
- echo "Staying on dev branch."
- fi
- cd /usr/src/freeswitch
- echo "reconfiguring mod_spandsp"
- make spandsp-reconf
- if [ $CORES > "1" ]; then
- /bin/echo " multicore processor detected. Upgrading with -j $CORES"
- /usr/bin/make -j $CORES current
- else
- /bin/echo " singlecore processor detected. Starting upgrade sans -j"
- /usr/bin/make current
- fi
- #/usr/bin/make current
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "make current error"
- exit 1
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "I'm going to stop here and wait. FreeSWITCH has now been compiled and is ready to install"
- /bin/echo "but in order to do this we need to stop FreeSWITCH [which will dump any active calls]."
- /bin/echo "This should not take too long to finish, but we should try and time things correctly."
- /bin/echo "The current status of your switch is:"
- /bin/echo
- /usr/local/freeswitch/bin/fs_cli -x status
- /bin/echo
- /bin/echo -n "Press Enter to continue the upgrade."
- read
- fi
- /etc/init.d/freeswitch stop
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "Init ERROR, couldn't stop Freeswitch"
- exit 1
- fi
- /usr/bin/make install
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "INSTALL ERROR!"
- exit 1
- else
- /bin/echo "made_current" >> /tmp/install_fusion_status
- fi
- fi
- #------------------------
- # enable modules.conf.xml
- #------------------------
- /bin/grep 'enable_modules' /tmp/install_fusion_status > /dev/null
- if [ $? -eq 0 ]; then
- /bin/echo "Modules.conf.xml Already enabled"
- else
- #file exists and has been edited
- enable_modules
- #check exit status
- if [ $? -ne 0 ]; then
- #previous had an error
- /bin/echo "ERROR: Failed to enable modules in modules.conf.xml."
- exit 1
- else
- /bin/echo "enable_modules" >> /tmp/install_fusion_status
- fi
- fi
- if [ $DEBUG -eq 1 ]; then
- /bin/echo
- /bin/echo "Press Enter to continue (check for errors)"
- read
- fi
- #check for logrotate and change to cron.daily
- if [ -a /etc/logrotate.d/freeswitch ]; then
- /bin/echo "System configured for logrotate, changing"
- /bin/echo " to new way."
- /bin/rm /etc/logrotate.d/freeswitch
- /etc/init.d/logrotate restart
- freeswitch_logfiles
- fi
- if [ -e $WWW_PATH/$GUI_NAME ]; then
- echo "I noticed that FusionPBX is installed too"
- echo "now going to fix freeswitch permissions from upgrade to be safe"
- www_permissions
- else
- echo "Standalone FreeSWITCH installation, no permissions to change"
- fi
- /etc/init.d/freeswitch start
- fi
- #------------------------------------
- # DONE UPGRADING FREESWITCH
- #------------------------------------
- #------------------------------------
- # UPGRADE FusionPBX
- #------------------------------------
- if [ $UPGFUSION -eq 1 ]; then
- /bin/echo "Resetting FreeSWITCH permissions to www-data in case you did"
- /bin/echo " a FreeSWITCH upgrade as well."
- www_permissions
- cd $WWW_PATH/$GUI_NAME
- /bin/echo
- /bin/echo "STOP! Make sure you are logged into fusionpbx as the superadmin (via browser)!"
- read -p "Have you done this yet (y/n)? " YESNO
- if [ $YESNO == "y" ]; then
- /bin/echo "Be really sure you are logged in as superadmin."
- /bin/echo " If nothing else, refresh the browser to make sure"
- /bin/echo " the session isn't stale."
- /bin/echo
- /bin/echo "If you haven't done this you risk not being able to Upgrade->Schema"
- /bin/echo " which will toast your database"
- /bin/echo
- FUSIONREV=$(svn info $WWW_PATH/$GUI_NAME |grep -i revision|sed -e s/Revision:\ //)
- if [ $FUSIONREV -le 1877 ]; then
- echo "The project is still working on an upgrade tool"
- echo " for the latest svn version. It is recommended"
- echo " that you stay with revision 1877. Your current"
- echo " revision is $FUSIONREV"
- echo
- read -p "Do we want Revision 1877, or latest (1877/latest)? " YESNO2
- else
- read -p "Ready to upgrade (y/n)? " YESNO2
- fi
- case $YESNO2 in
- [YylL]*)
- #svn...
- /usr/bin/svn update $FPBXBRANCH $WWW_PATH/$GUI_NAME
- /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
- #print message saying to hit advanced->upgrade schema
- /bin/echo "Done upgrading Files"
- /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
- /bin/echo "and select Advanced -> Upgrade Schema"
- ;;
- [1]*)
- /usr/bin/svn update -r r1877 $FPBXBRANCH $WWW_PATH/$GUI_NAME
- /bin/chown -R www-data:www-data $WWW_PATH/$GUI_NAME
- #print message saying to hit advanced->upgrade schema
- /bin/echo "Done upgrading Files"
- /bin/echo "For the Upgrade to finish you MUST login to FusionPBX as superadmin"
- /bin/echo "and select Advanced -> Upgrade Schema"
- ;;
- *)
- echo "Bad option, exiting"
- exit 1
- ;;
- esac
- else
- exit 1
- fi
- read -p "Do you want to try and run the auto-upgrade php script from CLI (y/n)? " YESNO
- case $YESNO in
- [yY]*)
- echo "Starting... /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
- /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php
- echo "Done"
- ;;
- *)
- echo "OK, don't forget to run it yourself via GUI or here with"
- echo " /usr/bin/php $WWW_PATH/$GUI_NAME/core/upgrade/upgrade.php"
- ;;
- esac
- fusionfail2ban
- fi
- #------------------------------------
- # DONE UPGRADING FusionPBX
- #------------------------------------
- #success!!!
- if [ -e /tmp/install_fusion_status ]; then
- /bin/rm /tmp/install_fusion_status
- fi
- /bin/echo "Checking to see if FreeSWITCH is running!"
- /usr/bin/pgrep freeswitch
- if [ $? -ne 0 ]; then
- /etc/init.d/freeswitch start
- else
- /bin/echo " DONE!"
- fi
- exit 0
- ---------
- #CHANGELOG
- #---------
- # vSVN, now using SVN.... November 2011
- #v4.4.0pre 2011 April 12
- #BUGS: FS CHANGED!!! 2011-05-12
- # Add libssl-dev
- # currently mod_cidlookup, mod_xml_curl mod_xml_cdr busted
- #BUGS: FS isn't started at end of install-both auto
- #BUGS: fix-https still throws usage help. check www-permissions too.
- #BUGS: Apache heredoc isn't escaping the variables. documentroot and servername wrong.
- #BUGS: dingaling still not compile right. let's change makefile and recompile module
- #ADD: zip compression to nginx
- #ADD: monit for freeswitch and nginx
- #add libssl-dev for secure sip.
- # ADD mod_spandsp for fax and g722
- # apt-get install libtiff4-dev
- # Add NTP, maybe run sudo ntpdate ntp.ubuntu.com to make suer date is correct.
- # prevents make from dying (date in the future crap).
- # BUGS: Had quotes around nginx config
- # FS failed to start with script
- # Fail2Ban FS-dos has freeswitch2 in jail.local
- # Fail2ban not starting:
- # freeswitch-dos ports wrong in jail.local.
- # build again and run fail2ban-client -d to test.
- # Add Option to download FreeSWITCH compiled source as tar.gz for iso
- # Added Option --fix-permissions
- # checks FreeSWITCH init script
- # Added: upgrade-fusionpbx needs to fix permissions, since a FS upgrade kills them.
- # FIXED Logrotate for nginx
- # logfiles were: /var/log/fusionpbx_gui.*_log;
- # logfiles now: /var/log/nginx/*.log
- # Added: Fail2ban for FusionPBX failed login attempts
- # Need information on attempts/rate/etc
- # Added: Fail2ban for FusionPBX on failed provision attempts
- # Need information on attempts/rate/etc
- # Needs Testing!
- # FIXED: RepeatedMsgReduction wasn't getting set correctly in rsyslog.conf
- # Added Change Fail2ban on FreeSWITCH with attempts/rate/etc in config file (not default settings)
- # Added: Option to download GIT from GitHub repository (It's faster), see DEFINES
- # Make nginx/apache https by default
- # iso needs to regenerate certificates post install, ideally with 10 year expirations.
- # apt-get install ssl-cert
- # ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/nginx.key
- # ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/nginx.crt
- # ln -s /etc/ssl/certs/nginx.crt /var/www/fusionpbx/$HOSTNAME.crt
- # /etc/init.d/nginx restart
-
- # FIXED nginx config to not block html files... Don't do block ~ .ht
- # Added FreeTDM, and Dahdi
- #v4.3.3 2011 January 31
- # Added: smp compile support. Script works, make -j doesn't. see jira FS-3005
- # Fixed: NGinx file size error
- # Added: Remove Nginx/php/apache properly
- # FIXED removing nginx removes gnome/x.
- # Added: Postgres (seems good)
- # Fixed: Set up apache properly (fusionpbx file instead of default, use heredoc)
- # TODO: look into setting up FS for mysql/pgsql
- # Fixed: sqlite http request issue for nginx/apache
- # Added: now doing ppa's the ubuntu way with apt-add-repository
- # Added: set up auto install for nginx/apache, mysql/postgresql/sqlite, setnonat.
- # Added: now prompts for rm -Rf /opt (or variable for auto-install).
- # There's a bug in either ppa-purge or apt-add-repository (likely latter).
- # if you install nginx, change your mind, install apache, change your mind again
- # and re-install nginx, the repository for nginx/php5-fpm gets removed proerly
- # [a '#' covers repo], but when re-enabling, the '#' gets replaced, and an 'n'
- # is left on a newline afterward, preventing update/install from that repo.
- # Fixed: Checking for nginx/apache2 binary instead of init scripts for if[x] restart
- #v4.3.2.1 2011 January 1
- # small problem when selecting nginx and sqlite. php5-fpm needed to restart
- # so FusionPBX could see the FreeSWITCH directory.
- #v4.3.2 2010 December 30
- # logrotate was improperly setup. Needed to send sighup to fs_cli
- # Caused FS to die the first time it tried to log after rotation.
- # php5-cli is a dependancy. required for voicemail to email, and fax to email.
- # added an nginx/php-fpm option. You can change a variable (for auto run)
- # or it will prompt you when you install fusionpbx in user mode
- # mysql added as an option.
- # problem with the way ubuntu logs ssh failures [fail2ban]
- # Failed password for root from 1.2.3.4 port 22 ssh2
- # last message repeated 5 times
- # SOLUTION: Turn off RepeatedMsgReduction in rsyslog.
- # fail2ban: previous setup looked for freeswitch log in /var/log/freeswitch.log
- # log is actually /usr/local/freeswitch/log/freeswitch.log
- # Tries to see if you're on a static IP address. If you are, it wants to start
- # FreeSWITCH with the -nonat option to save some time. Also a new variable
- # TODO: Maybe probe cores and to the -b thing for quicker compile/bootstrap
- # TODO: IPTABLES
- #v4.3.1 2010 December 23
- # look into make -j cores option
- # made a state save file. so if there's an error, don't re-bootstrap, configure, etc.
- # and remove it on a clean exit.
- # requests for modules add/enable for ugrade-freeswitch. DONE
- # mod dingaling needs libgnutls-dev libgnutls26 packages, and change:
- # "--mode=relink gcc" --> "--mode=relink gcc -lgnutls"
- # in /usr/src/freeswitch/src/mod/endpoints/mod_dingaling/mod_dingaling.la
- # appears to be an ubuntu problem....
- #v4.3 2010 December 22
- # under case upgrade-freeswitch, variables were not set properly. It upgraded fusionpbx.. fixed.
- # done: fail2ban error fixed. removed associated text
- # done: have install check for /etc/fail2ban. reinstall (as in from iso) duplicates some txt
- # done: remove or fix fusionpbx upgrade code. it either needs to log in
- # and then update and run the schema upgrade. or get rid of it. Fixed by prompting the user
- # to open a browser window, and warn.
- # done: get logrotate working... let's not fill the disk.
- # stop/start freeswitch for an upgrade, and an install...
- #v4.2 2010 December 17
- # made some changes so the text flows correctly now that we use curl
- # to do install.php.
- # sent curl output to dev null..
- # added apt-get update before we install apache since remastersys removes apt data
- # stopping FS before FusionPBX install, and starting afteward.
- # changed license to WAF v1
- #v4.1 2010 December 15
- # changing cd sounds (48/32/16/8khz) down to hd sounds (16/8Kkhz)
- #v4 2010 December 14
- # now install-fusion|install-freeswitch|upgrade...
- # also adding curl commands to finish fusionpbx install.
- #v3 adding fail2ban et al.
- #v2 2010 December 07
- # adds arrays to process the modules. should make this much easier to edit.
- # just make additions to modules_add
- # This should work fine (even on a 2nd run).
- #v1 2010 December 06
- # was first cut
|