finish.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_host=127.0.0.1
  9. database_port=5432
  10. database_username=fusionpbx
  11. if [ .$database_password = .'random' ]; then
  12. database_password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64 | sed 's/[=\+//]//g')
  13. fi
  14. #allow the script to use the new password
  15. export PGPASSWORD=$database_password
  16. #update the database password
  17. sudo -u postgres /usr/bin/psql -c "ALTER USER fusionpbx WITH PASSWORD '$database_password';"
  18. sudo -u postgres /usr/bin/psql -c "ALTER USER freeswitch WITH PASSWORD '$database_password';"
  19. #add the config.conf
  20. mkdir -p /etc/fusionpbx/
  21. cp fusionpbx/config.conf /etc/fusionpbx/
  22. sed -i /etc/fusionpbx/config.conf -e s:"{database_host}:$database_host:"
  23. sed -i /etc/fusionpbx/config.conf -e s:"{database_name}:$database_name:"
  24. sed -i /etc/fusionpbx/config.conf -e s:"{database_username}:$database_username:"
  25. sed -i /etc/fusionpbx/config.conf -e s:"{database_password}:$database_password:"
  26. #add the database schema
  27. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade_schema.php > /dev/null 2>&1
  28. #get the server hostname
  29. #domain_name=$(hostname -f)
  30. #get the ip address
  31. domain_name=$(hostname -I | cut -d ' ' -f1)
  32. #get a domain_uuid
  33. domain_uuid=$(php /var/www/fusionpbx/resources/uuid.php);
  34. #add the domain name
  35. 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');"
  36. #app defaults
  37. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php
  38. #add the user
  39. user_uuid=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  40. user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  41. user_name=$system_username
  42. if [ .$system_password = .'random' ]; then
  43. user_password=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g')
  44. else
  45. user_password=$system_password
  46. fi
  47. password_hash=$(php -r "echo md5('$user_salt$user_password');");
  48. 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');"
  49. #get the superadmin group_uuid
  50. group_uuid=$(psql --host=$database_host --port=$database_port --username=$database_username -t -c "select group_uuid from v_groups where group_name = 'superadmin';");
  51. group_uuid=$(echo $group_uuid | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
  52. #add the user to the group
  53. user_group_uuid=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php);
  54. group_name=superadmin
  55. 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');"
  56. #update the php configuration
  57. sed -i 's/user nginx/user freeswitch daemon/g' /etc/nginx/nginx.conf
  58. chown -Rf freeswitch:daemon /var/lib/nginx
  59. sed -ie 's/user = apache/user = freeswitch/g' /etc/php-fpm.d/www.conf
  60. #update permissions
  61. chown -R freeswitch:daemon /var/lib/php/session
  62. #update the permissions
  63. chown -R freeswitch.daemon /etc/freeswitch /var/lib/freeswitch /var/log/freeswitch /usr/share/freeswitch /var/www/fusionpbx
  64. find /etc/freeswitch -type d -exec chmod 770 {} \;
  65. find /var/lib/freeswitch -type d -exec chmod 770 {} \;
  66. find /var/log/freeswitch -type d -exec chmod 770 {} \;
  67. find /usr/share/freeswitch -type d -exec chmod 770 {} \;
  68. find /etc/freeswitch -type f -exec chmod 664 {} \;
  69. find /var/lib/freeswitch -type f -exec chmod 664 {} \;
  70. find /var/log/freeswitch -type f -exec chmod 664 {} \;
  71. find /usr/share/freeswitch -type f -exec chmod 664 {} \;
  72. #update xml_cdr url, user and password
  73. xml_cdr_username=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g')
  74. xml_cdr_password=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g')
  75. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_http_protocol}:http:"
  76. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{domain_name}:127.0.0.1:"
  77. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_project_path}::"
  78. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_user}:$xml_cdr_username:"
  79. sed -i /etc/freeswitch/autoload_configs/xml_cdr.conf.xml -e s:"{v_pass}:$xml_cdr_password:"
  80. #app defaults
  81. cd /var/www/fusionpbx && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php
  82. #restart services
  83. systemctl daemon-reload
  84. systemctl mask wpa_supplicant.service
  85. systemctl stop wpa_supplicant.service
  86. systemctl enable fail2ban
  87. systemctl enable ntpd
  88. systemctl enable php-fpm
  89. systemctl enable nginx
  90. systemctl enable freeswitch
  91. systemctl enable memcached
  92. systemctl enable postgresql-14
  93. systemctl daemon-reload
  94. systemctl restart php-fpm
  95. systemctl restart nginx
  96. systemctl restart freeswitch
  97. #welcome message
  98. echo ""
  99. verbose "Installation has completed."
  100. echo ""
  101. echo " Use a web browser to login."
  102. echo " domain name: https://$domain_name"
  103. echo " username: $user_name"
  104. echo " password: $user_password"
  105. echo ""
  106. echo " The domain name in the browser is used by default as part of the authentication."
  107. echo " If you need to login to a different domain then use username@domain."
  108. echo " username: $user_name@$domain_name";
  109. echo ""
  110. echo " Official FusionPBX Training"
  111. echo " Fastest way to learn FusionPBX. For more information https://www.fusionpbx.com."
  112. echo " Available online and in person. Includes documentation and recording."
  113. echo ""
  114. echo " Location: Online"
  115. echo " Admin Training: TBA"
  116. echo " Advanced Training: TBA"
  117. echo " Continuing Education: https://www.fusionpbx.com/training"
  118. echo " Timezone: https://www.timeanddate.com/weather/usa/idaho"
  119. echo ""
  120. echo " Additional information."
  121. echo " https://fusionpbx.com/members.php"
  122. echo " https://fusionpbx.com/training.php"
  123. echo " https://fusionpbx.com/support.php"
  124. echo " https://www.fusionpbx.com"
  125. echo " http://docs.fusionpbx.com"
  126. echo ""
  127. warning "*------------------------------------------*"
  128. warning "* NOTE: Please save the above information. *"
  129. warning "* REBOOT YOUR SERVER TO COMPLETE INSTALL. *"
  130. warning "*------------------------------------------*"
  131. echo ""