Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
6.5 KiB

  1. #!/bin/sh
  2. #move to script directory so all relative paths work
  3. cd "$(dirname "$0")"
  4. #includes
  5. . ./config.sh
  6. . ./colors.sh
  7. #database details
  8. database_username=fusionpbx
  9. if [ .$database_password = .'random' ]; then
  10. database_password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
  11. fi
  12. #allow the script to use the new password
  13. export PGPASSWORD=$database_password
  14. #update the database password
  15. #sudo -u postgres psql --host=$database_host --port=$database_port --username=$database_username -c "ALTER USER fusionpbx WITH PASSWORD '$database_password';"
  16. #sudo -u postgres psql --host=$database_host --port=$database_port --username=$database_username -c "ALTER USER freeswitch WITH PASSWORD '$database_password';"
  17. sudo -u postgres psql -c "ALTER USER fusionpbx WITH PASSWORD '$database_password';"
  18. sudo -u postgres psql -c "ALTER USER freeswitch WITH PASSWORD '$database_password';"
  19. #install the database backup
  20. cp backup/fusionpbx-backup /etc/cron.daily
  21. cp backup/fusionpbx-maintenance /etc/cron.daily
  22. chmod 755 /etc/cron.daily/fusionpbx-backup
  23. chmod 755 /etc/cron.daily/fusionpbx-maintenance
  24. sed -i "s/zzz/$database_password/g" /etc/cron.daily/fusionpbx-backup
  25. sed -i "s/zzz/$database_password/g" /etc/cron.daily/fusionpbx-maintenance
  26. #add the config.php
  27. mkdir -p /etc/fusionpbx
  28. chown -R www-data:www-data /etc/fusionpbx
  29. cp fusionpbx/config.php /etc/fusionpbx
  30. sed -i /etc/fusionpbx/config.php -e s:"{database_host}:$database_host:"
  31. sed -i /etc/fusionpbx/config.php -e s:'{database_username}:fusionpbx:'
  32. sed -i /etc/fusionpbx/config.php -e s:"{database_password}:$database_password:"
  33. #add the database schema
  34. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade_schema.php > /dev/null 2>&1
  35. #get the server hostname
  36. if [ .$domain_name = .'hostname' ]; then
  37. domain_name=$(hostname -f)
  38. fi
  39. #get the ip address
  40. if [ .$domain_name = .'ip_address' ]; then
  41. domain_name=$(hostname -I | cut -d ' ' -f1)
  42. fi
  43. #get the domain_uuid
  44. domain_uuid=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  45. #add the domain name
  46. psql --host=$database_host --port=$database_port --username=$database_username -c "insert into v_domains (domain_uuid, domain_name, domain_enabled) values('$domain_uuid', '$domain_name', 'true');"
  47. #app defaults
  48. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php
  49. #add the user
  50. user_uuid=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  51. user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  52. user_name=$system_username
  53. if [ .$system_password = .'random' ]; then
  54. user_password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
  55. else
  56. user_password=$system_password
  57. fi
  58. password_hash=$(php -r "echo md5('$user_salt$user_password');");
  59. psql --host=$database_host --port=$database_port --username=$database_username -t -c "insert into v_users (user_uuid, domain_uuid, username, password, salt, user_enabled) values('$user_uuid', '$domain_uuid', '$user_name', '$password_hash', '$user_salt', 'true');"
  60. #get the superadmin group_uuid
  61. #echo "psql --host=$database_host --port=$database_port --username=$database_username -qtAX -c \"select group_uuid from v_groups where group_name = 'superadmin';\""
  62. group_uuid=$(psql --host=$database_host --port=$database_port --username=$database_username -qtAX -c "select group_uuid from v_groups where group_name = 'superadmin';");
  63. #add the user to the group
  64. user_group_uuid=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  65. group_name=superadmin
  66. #echo "insert into v_user_groups (user_group_uuid, domain_uuid, group_name, group_uuid, user_uuid) values('$user_group_uuid', '$domain_uuid', '$group_name', '$group_uuid', '$user_uuid');"
  67. psql --host=$database_host --port=$database_port --username=$database_username -c "insert into v_user_groups (user_group_uuid, domain_uuid, group_name, group_uuid, user_uuid) values('$user_group_uuid', '$domain_uuid', '$group_name', '$group_uuid', '$user_uuid');"
  68. #update xml_cdr url, user and password
  69. xml_cdr_username=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
  70. xml_cdr_password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
  71. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_http_protocol}:http:"
  72. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{domain_name}:$database_host:"
  73. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_project_path}::"
  74. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_user}:$xml_cdr_username:"
  75. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_pass}:$xml_cdr_password:"
  76. #app defaults
  77. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade.php
  78. #restart freeswitch
  79. /bin/systemctl daemon-reload
  80. /bin/systemctl restart freeswitch
  81. #install the email_queue service
  82. cp /var/www/fusionpbx/app/email_queue/resources/service/debian.service /etc/systemd/system/email_queue.service
  83. systemctl enable email_queue
  84. systemctl start email_queue
  85. systemctl daemon-reload
  86. #install the event_guard service
  87. cp /var/www/fusionpbx/app/event_guard/resources/service/debian.service /etc/systemd/system/event_guard.service
  88. /bin/systemctl enable event_guard
  89. /bin/systemctl start event_guard
  90. /bin/systemctl daemon-reload
  91. #welcome message
  92. echo ""
  93. echo ""
  94. verbose "Installation Notes. "
  95. echo ""
  96. echo " Please save the this information and reboot this system to complete the install. "
  97. echo ""
  98. echo " Use a web browser to login."
  99. echo " domain name: https://$domain_name"
  100. echo " username: $user_name"
  101. echo " password: $user_password"
  102. echo ""
  103. echo " The domain name in the browser is used by default as part of the authentication."
  104. echo " If you need to login to a different domain then use username@domain."
  105. echo " username: $user_name@$domain_name";
  106. echo ""
  107. echo " Official FusionPBX Training"
  108. echo " Fastest way to learn FusionPBX. For more information https://www.fusionpbx.com."
  109. echo " Available online and in person. Includes documentation and recording."
  110. echo ""
  111. echo " Location: Online"
  112. echo " Admin Training: TBA"
  113. echo " Advanced Training: TBA"
  114. echo " Continuing Education: https://www.fusionpbx.com/training"
  115. echo " Timezone: https://www.timeanddate.com/weather/usa/idaho"
  116. echo ""
  117. echo " Additional information."
  118. echo " https://fusionpbx.com/members.php"
  119. echo " https://fusionpbx.com/training.php"
  120. echo " https://fusionpbx.com/support.php"
  121. echo " https://www.fusionpbx.com"
  122. echo " http://docs.fusionpbx.com"
  123. echo ""