once-as-root.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. source /app/vagrant/provision/common.sh
  3. #== Import script args ==
  4. timezone=$(echo "$1")
  5. readonly IP=$2
  6. #== Provision script ==
  7. info "Provision-script user: `whoami`"
  8. export DEBIAN_FRONTEND=noninteractive
  9. info "Configure timezone"
  10. timedatectl set-timezone ${timezone} --no-ask-password
  11. info "AWK initial replacement work"
  12. awk -v ip=$IP -f /app/vagrant/provision/provision.awk /app/environments/dev/*end/config/main-local.php
  13. info "Prepare root password for MySQL"
  14. debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password \"''\""
  15. debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password \"''\""
  16. echo "Done!"
  17. info "Update OS software"
  18. apt-get update
  19. apt-get upgrade -y
  20. info "Add ppa:ondrej/php"
  21. apt-get install -y python-software-properties
  22. apt-get update && apt-get upgrade -y
  23. add-apt-repository -y ppa:ondrej/php
  24. info "Install additional software"
  25. apt-get install -y php7.4-curl php7.4-cli php7.4-intl php7.4-mysqlnd php7.4-gd php7.4-fpm php7.4-mbstring php7.4-xml unzip nginx mysql-server-5.7 php7.4-xdebug
  26. info "Configure MySQL"
  27. sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
  28. mysql -uroot <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
  29. mysql -uroot <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
  30. mysql -uroot <<< "DROP USER 'root'@'localhost'"
  31. mysql -uroot <<< "FLUSH PRIVILEGES"
  32. echo "Done!"
  33. info "Configure PHP-FPM"
  34. sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
  35. sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
  36. sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.4/fpm/pool.d/www.conf
  37. cat << EOF > /etc/php/7.4/mods-available/xdebug.ini
  38. zend_extension=xdebug.so
  39. xdebug.remote_enable=1
  40. xdebug.remote_connect_back=1
  41. xdebug.remote_port=9000
  42. xdebug.remote_autostart=1
  43. EOF
  44. echo "Done!"
  45. info "Configure NGINX"
  46. sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
  47. echo "Done!"
  48. info "Enabling site configuration"
  49. ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
  50. echo "Done!"
  51. info "Initailize databases for MySQL"
  52. mysql -uroot <<< "CREATE DATABASE yii2advanced"
  53. mysql -uroot <<< "CREATE DATABASE yii2advanced_test"
  54. echo "Done!"
  55. info "Install composer"
  56. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer