finish.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #set the current working directory
  8. cwd=$(pwd)
  9. if [ .$nginx_enabled = .'true' ]; then
  10. #database details
  11. database_username=fusionpbx
  12. if [ .$database_password = .'random' ]; then
  13. database_password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20)
  14. fi
  15. #allow the script to use the new password
  16. export PGPASSWORD=$database_password
  17. #install the dependencies
  18. pkg install --yes sudo
  19. #update the database password
  20. sudo -u postgres psql -c "ALTER USER fusionpbx WITH PASSWORD '$database_password';"
  21. sudo -u postgres psql -c "ALTER USER freeswitch WITH PASSWORD '$database_password';"
  22. #add the config.php
  23. mkdir -p /etc/fusionpbx
  24. chown -R www:www /etc/fusionpbx
  25. cp fusionpbx/config.php /etc/fusionpbx
  26. sed -i' ' -e s:"{database_host}:$database_host:" /etc/fusionpbx/config.php
  27. sed -i' ' -e s:'{database_username}:fusionpbx:' /etc/fusionpbx/config.php
  28. sed -i' ' -e s:"{database_password}:$database_password:" /etc/fusionpbx/config.php
  29. #add the database schema
  30. cd /usr/local/www/fusionpbx && /usr/local/bin/php /usr/local/www/fusionpbx/core/upgrade/upgrade_schema.php > /dev/null 2>&1
  31. #get the primary interface name
  32. if [ .$interface_name = .'auto' ]; then
  33. interface_name=$(ifconfig -l | awk '{print $1}')
  34. if [ .$interface_name = .'lo0' ]; then
  35. interface_name=$(ifconfig -l | awk '{print $2}')
  36. fi
  37. fi
  38. #get the ip address
  39. local_ip_v4=$(ifconfig $interface_name | grep 'inet ' | awk '{print $2}')
  40. #get the server hostname
  41. if [ .$domain_name = .'hostname' ]; then
  42. domain_name=$(hostname -f)
  43. fi
  44. #get the ip address
  45. if [ .$domain_name = .'ip_address' ]; then
  46. domain_name=$(ifconfig $interface_name | grep 'inet ' | awk '{print $2}')
  47. fi
  48. #get the domain uuid
  49. domain_uuid=$(uuidgen);
  50. #add the domain name
  51. 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');"
  52. #app defaults
  53. cd /usr/local/www/fusionpbx && /usr/local/bin/php /usr/local/www/fusionpbx/core/upgrade/upgrade_domains.php
  54. #add the user
  55. user_uuid=$(/usr/local/bin/php /usr/local/www/fusionpbx/resources/uuid.php);
  56. user_salt=$(/usr/local/bin/php /usr/local/www/fusionpbx/resources/uuid.php);
  57. user_name=$system_username
  58. if [ .$system_password = .'random' ]; then
  59. user_password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20)
  60. else
  61. user_password=$system_password
  62. fi
  63. password_hash=$(php -r "echo md5('$user_salt$user_password');");
  64. 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');"
  65. #get the superadmin group_uuid
  66. group_uuid=$(psql --host=$database_host --port=$database_port --username=$database_username -t -c "select group_uuid from v_groups where group_name = 'superadmin';");
  67. group_uuid=$(echo $group_uuid | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
  68. #add the user to the group
  69. user_group_uuid=$(/usr/local/bin/php /usr/local/www/fusionpbx/resources/uuid.php);
  70. group_name=superadmin
  71. 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');"
  72. #add the local_ip_v4 address
  73. psql --host=$database_host --port=$database_port --username=$database_username -t -c "insert into v_vars (var_uuid, var_name, var_value, var_category, var_order, var_enabled) values ('4507f7a9-2cbb-40a6-8799-f8f168082585', 'local_ip_v4', '$local_ip_v4', 'Defaults', '0', 'true');";
  74. #app defaults
  75. if [ .$nginx_enabled = .'true' ]; then
  76. cd /usr/local/www/fusionpbx && php /usr/local/www/fusionpbx/core/upgrade/upgrade_domains.php
  77. fi
  78. #reset the current working directory
  79. cd $cwd
  80. fi
  81. if [ .$switch_enabled = .'true' ]; then
  82. #update xml_cdr url, user and password
  83. xml_cdr_username=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20)
  84. xml_cdr_password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20)
  85. #set the conf directory
  86. if [ .$switch_source = ."package" ]; then
  87. conf_dir="/usr/local/etc/freeswitch";
  88. fi
  89. if [ .$switch_source = ."source" ]; then
  90. conf_dir="/usr/local/freeswitch/conf";
  91. fi
  92. #update the xml_cdr.conf.xml file
  93. sed -i' ' -e s:"{v_http_protocol}:http:" $conf_dir/autoload_configs/xml_cdr.conf.xml
  94. sed -i' ' -e s:"{domain_name}:127.0.0.1:" $conf_dir/autoload_configs/xml_cdr.conf.xml
  95. sed -i' ' -e s:"{v_project_path}::" $conf_dir/autoload_configs/xml_cdr.conf.xml
  96. sed -i' ' -e s:"{v_user}:$xml_cdr_username:" $conf_dir/autoload_configs/xml_cdr.conf.xml
  97. sed -i' ' -e s:"{v_pass}:$xml_cdr_password:" $conf_dir/autoload_configs/xml_cdr.conf.xml
  98. #restart freeswitch
  99. service freeswitch restart
  100. #install monit.sh
  101. if [ .$monit_enabled = .'true' ]; then
  102. . ./monit.sh
  103. fi
  104. fi
  105. #welcome message
  106. echo ""
  107. echo ""
  108. verbose "Installation has completed."
  109. echo ""
  110. if [ .$nginx_enabled = .'true' ]; then
  111. echo " Use a web browser to login."
  112. echo " domain name: http://$domain_name"
  113. echo " username: $user_name"
  114. echo " password: $user_password"
  115. echo ""
  116. echo " The domain name in the browser is used by default as part of the authentication."
  117. echo " If you need to login to a different domain then use username@domain."
  118. echo " username: $user_name@$domain_name";
  119. echo ""
  120. fi
  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 ""