Automatically populate FreePBX using self-written bash script, what options do I have?

Hi guys,

After the price increase at 3CX, I am switching to FreePBX. To setup our server(s) in the future, I’d like to automate a couple of things:

  • Install FreePBX with NGINX on a clean Ubuntu installation using a bash script (done)
  • Configure Gmail in postfix for sending e-mails (done)
  • Pre-populate FreePBX by automatically adding:
    *- Extensions
    *- Inbound rules
    *- Outbound rules
    *- SIP settings
    *- Modules (IVR, time conditions, user management)

I have done quite some research and I have found that:

  • Overwriting files (e.g. /etc/asterisk/sip_additional.conf) does get reverted after a reboot;
  • Bootstrap is an alternative, but classes and variables are hard to find (you’ll have to search for them manually in the source code);

Does anyone have an idea how to pre-populate our installation more easily; e.g. by writing database queries or so?


Curious. Why would you not use the official distro?

Good question. I use a set of best practices, combined with:

  • NGINX instead of Apache2
  • Installing certbot by default
  • UFW rules
  • Folders (eg. partitions, /var/www)
  • PHP settings (memory limit, bars, execution time)
  • Automatically restart PHP / DB if it crashes
  • Send an e-mail when one of the partitions is full

So I went ahead and created a bash script to do all of this. The next step is to create a script that automatically:

  • Add extensions
  • Setup Twilio inbound/outbound trunks
  • Install modules (IVR, etc…)

You could try the bulk handler, I think it has fwconsole commands for it, but I might be wrong.

1 Like

Unfortunately it doesn’t seem to have CLI-commands. The bulk handler handles the import/export of (wiki > display/FPG/Bulk+Handler+User+Guide):

  • Extensions
  • Users
  • Groups
  • Contacts (address book)

That’s about the same as I was able to achieve by using the bootstrap example (wiki > display/FOP/Bootstrap). If someone can explain me where to get more of these values, I can probably use bootstrap:

  • core_users_add($vars);
  • core_devices_add(255,‘sip’,’’,‘fixed’,255,‘Bobby’);

(because I am new here, I cannot place links to the wiki pages I’ve used)

Thanks! I think that’s the best solution for automating the server-process as much as possible.

Export current settings:
fwconsole setting --export /var/www/html/export.txt

Import settings:
fwconsole setting --import import_settings.txt

Install modules:
fwconsole ma downloadinstall backup
fwconsole ma enable backup

Apply config (if it haven’t done so)
fwconsole reload

Thing that’ll have to be done manually:

  • Adding extensions
  • Adding Inbound routes
  • Adding outbound routes

The best part has now been automated. I’ll document the last steps (especially the - extremely difficult Twilio integration) somewhere else (Evernote I guess :slight_smile: ).

Last but not least, for those who are wondering. Setting up your own VM with Ubuntu is pretty easy. Just follow this guide.

p.s. While it can, I do not recommend to use NGINX for FreePBX. While it is possible, you’ll have to made a lot of modifications to the server. CHECKREFERER has also to be disabled.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.