once-as-root.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. #== Import script args ==
  3. timezone=$(echo "$1")
  4. readonly IP=$2
  5. #== Bash helpers ==
  6. function info {
  7. echo " "
  8. echo "--> $1"
  9. echo " "
  10. }
  11. #== Provision script ==
  12. info "Provision-script user: `whoami`"
  13. export DEBIAN_FRONTEND=noninteractive
  14. info "Configure timezone"
  15. timedatectl set-timezone ${timezone} --no-ask-password
  16. info "Add the VM IP to the list of allowed IPs"
  17. awk -v ip=$IP -f /app/vagrant/provision/provision.awk /app/config/web.php
  18. info "Prepare root password for MySQL"
  19. debconf-set-selections <<< 'mariadb-server mysql-server/root_password password'
  20. debconf-set-selections <<< 'mariadb-server mysql-server/root_password_again password'
  21. echo "Done!"
  22. info "Update OS software"
  23. apt-get update
  24. apt-get upgrade -y
  25. info "Install additional software"
  26. apt-get install -y php7.2-curl php7.2-cli php7.2-intl php7.2-mysqlnd php7.2-gd php7.2-fpm php7.2-mbstring php7.2-xml unzip nginx mariadb-server-10.1 php.xdebug
  27. info "Configure MySQL"
  28. sed -i 's/.*bind-address.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
  29. mysql <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
  30. mysql <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
  31. mysql <<< "DROP USER 'root'@'localhost'"
  32. mysql <<< 'FLUSH PRIVILEGES'
  33. echo "Done!"
  34. info "Configure PHP-FPM"
  35. sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
  36. sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
  37. sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
  38. cat << EOF > /etc/php/7.2/mods-available/xdebug.ini
  39. zend_extension=xdebug.so
  40. xdebug.remote_enable=1
  41. xdebug.remote_connect_back=1
  42. xdebug.remote_port=9000
  43. xdebug.remote_autostart=1
  44. EOF
  45. echo "Done!"
  46. info "Configure NGINX"
  47. sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
  48. echo "Done!"
  49. info "Enabling site configuration"
  50. ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
  51. echo "Done!"
  52. info "Removing default site configuration"
  53. rm /etc/nginx/sites-enabled/default
  54. echo "Done!"
  55. info "Initialize databases for MySQL"
  56. mysql <<< 'CREATE DATABASE yii2basic'
  57. mysql <<< 'CREATE DATABASE yii2basic_test'
  58. echo "Done!"
  59. info "Install composer"
  60. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer