finish.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.conf
  27. mkdir -p /etc/fusionpbx
  28. cp fusionpbx/config.conf /etc/fusionpbx
  29. sed -i /etc/fusionpbx/config.conf -e s:"{database_host}:$database_host:"
  30. sed -i /etc/fusionpbx/config.conf -e s:"{database_name}:$database_name:"
  31. sed -i /etc/fusionpbx/config.conf -e s:"{database_username}:$database_username:"
  32. sed -i /etc/fusionpbx/config.conf -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 && /usr/bin/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=$(/usr/bin/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 && /usr/bin/php /var/www/fusionpbx/core/upgrade/upgrade.php
  78. #restart freeswitch
  79. /bin/systemctl daemon-reload
  80. /bin/systemctl restart freeswitch
  81. #make the /var/run directory and set the ownership
  82. mkdir /var/run/fusionpbx
  83. chown -R www-data:www-data /var/run/fusionpbx
  84. #install the email_queue service
  85. cp /var/www/fusionpbx/app/email_queue/resources/service/debian.service /etc/systemd/system/email_queue.service
  86. systemctl enable email_queue
  87. systemctl start email_queue
  88. systemctl daemon-reload
  89. #install the event_guard service
  90. cp /var/www/fusionpbx/app/event_guard/resources/service/debian.service /etc/systemd/system/event_guard.service
  91. /bin/systemctl enable event_guard
  92. /bin/systemctl start event_guard
  93. /bin/systemctl daemon-reload
  94. #install the websockets service
  95. cp /var/www/fusionpbx/core/websockets/resources/service/debian-websockets.service /etc/systemd/system/websockets.service
  96. systemctl daemon-reload
  97. systemctl enable --now websockets
  98. #install the active_calls service
  99. cp /var/www/fusionpbx/app/active_calls/resources/service/debian-active_calls.service /etc/systemd/system/active_calls.service
  100. systemctl daemon-reload
  101. systemctl enable --now active_calls
  102. #add xml cdr import to crontab
  103. apt install cron
  104. (crontab -l; echo "* * * * * $(which php) /var/www/fusionpbx/app/xml_cdr/xml_cdr_import.php 300") | crontab
  105. #welcome message
  106. echo ""
  107. echo ""
  108. verbose "Installation Notes. "
  109. echo ""
  110. echo " Please save this information and reboot this system to complete the install. "
  111. echo ""
  112. echo " Use a web browser to login."
  113. echo " domain name: https://$domain_name"
  114. echo " username: $user_name"
  115. echo " password: $user_password"
  116. echo ""
  117. echo " The domain name in the browser is used by default as part of the authentication."
  118. echo " If you need to login to a different domain then use username@domain."
  119. echo " username: $user_name@$domain_name";
  120. echo ""
  121. echo " Official FusionPBX Training"
  122. echo " Fastest way to learn FusionPBX. For more information https://www.fusionpbx.com."
  123. echo " Available online and in person. Includes documentation and recording."
  124. echo ""
  125. echo " Location: Online"
  126. echo " Admin Training: TBA"
  127. echo " Advanced Training: TBA"
  128. echo " Continuing Education: https://www.fusionpbx.com/training"
  129. echo " Timezone: https://www.timeanddate.com/weather/usa/idaho"
  130. echo ""
  131. echo " Additional information."
  132. echo " https://fusionpbx.com/members.php"
  133. echo " https://fusionpbx.com/training.php"
  134. echo " https://fusionpbx.com/support.php"
  135. echo " https://www.fusionpbx.com"
  136. echo " http://docs.fusionpbx.com"
  137. echo ""
  138. # pgpassword security and conflict avoidance
  139. unset PGPASSWORD