first commit
This commit is contained in:
18
vagrant/provision/always-as-root.sh
Normal file
18
vagrant/provision/always-as-root.sh
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#== Bash helpers ==
|
||||
|
||||
function info {
|
||||
echo " "
|
||||
echo "--> $1"
|
||||
echo " "
|
||||
}
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
info "Restart web-stack"
|
||||
service php7.2-fpm restart
|
||||
service nginx restart
|
||||
service mysql restart
|
||||
79
vagrant/provision/once-as-root.sh
Normal file
79
vagrant/provision/once-as-root.sh
Normal file
@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#== Import script args ==
|
||||
|
||||
timezone=$(echo "$1")
|
||||
readonly IP=$2
|
||||
|
||||
#== Bash helpers ==
|
||||
|
||||
function info {
|
||||
echo " "
|
||||
echo "--> $1"
|
||||
echo " "
|
||||
}
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
info "Configure timezone"
|
||||
timedatectl set-timezone ${timezone} --no-ask-password
|
||||
|
||||
info "Add the VM IP to the list of allowed IPs"
|
||||
awk -v ip=$IP -f /app/vagrant/provision/provision.awk /app/config/web.php
|
||||
|
||||
info "Prepare root password for MySQL"
|
||||
debconf-set-selections <<< 'mariadb-server mysql-server/root_password password'
|
||||
debconf-set-selections <<< 'mariadb-server mysql-server/root_password_again password'
|
||||
echo "Done!"
|
||||
|
||||
info "Update OS software"
|
||||
apt-get update
|
||||
apt-get upgrade -y
|
||||
|
||||
info "Install additional software"
|
||||
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
|
||||
|
||||
info "Configure MySQL"
|
||||
sed -i 's/.*bind-address.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||
mysql <<< "CREATE USER 'root'@'%' IDENTIFIED BY ''"
|
||||
mysql <<< "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"
|
||||
mysql <<< "DROP USER 'root'@'localhost'"
|
||||
mysql <<< 'FLUSH PRIVILEGES'
|
||||
echo "Done!"
|
||||
|
||||
info "Configure PHP-FPM"
|
||||
sed -i 's/user = www-data/user = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
|
||||
sed -i 's/group = www-data/group = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
|
||||
sed -i 's/owner = www-data/owner = vagrant/g' /etc/php/7.2/fpm/pool.d/www.conf
|
||||
cat << EOF > /etc/php/7.2/mods-available/xdebug.ini
|
||||
zend_extension=xdebug.so
|
||||
xdebug.remote_enable=1
|
||||
xdebug.remote_connect_back=1
|
||||
xdebug.remote_port=9000
|
||||
xdebug.remote_autostart=1
|
||||
EOF
|
||||
echo "Done!"
|
||||
|
||||
info "Configure NGINX"
|
||||
sed -i 's/user www-data/user vagrant/g' /etc/nginx/nginx.conf
|
||||
echo "Done!"
|
||||
|
||||
info "Enabling site configuration"
|
||||
ln -s /app/vagrant/nginx/app.conf /etc/nginx/sites-enabled/app.conf
|
||||
echo "Done!"
|
||||
|
||||
info "Removing default site configuration"
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
echo "Done!"
|
||||
|
||||
info "Initialize databases for MySQL"
|
||||
mysql <<< 'CREATE DATABASE yii2basic'
|
||||
mysql <<< 'CREATE DATABASE yii2basic_test'
|
||||
echo "Done!"
|
||||
|
||||
info "Install composer"
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
31
vagrant/provision/once-as-vagrant.sh
Normal file
31
vagrant/provision/once-as-vagrant.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#== Import script args ==
|
||||
|
||||
github_token=$(echo "$1")
|
||||
|
||||
#== Bash helpers ==
|
||||
|
||||
function info {
|
||||
echo " "
|
||||
echo "--> $1"
|
||||
echo " "
|
||||
}
|
||||
|
||||
#== Provision script ==
|
||||
|
||||
info "Provision-script user: `whoami`"
|
||||
|
||||
info "Configure composer"
|
||||
composer config --global github-oauth.github.com ${github_token}
|
||||
echo "Done!"
|
||||
|
||||
info "Install project dependencies"
|
||||
cd /app
|
||||
composer --no-progress --prefer-dist install
|
||||
|
||||
info "Create bash-alias 'app' for vagrant user"
|
||||
echo 'alias app="cd /app"' | tee /home/vagrant/.bash_aliases
|
||||
|
||||
info "Enabling colorized prompt for guest console"
|
||||
sed -i "s/#force_color_prompt=yes/force_color_prompt=yes/" /home/vagrant/.bashrc
|
||||
50
vagrant/provision/provision.awk
Normal file
50
vagrant/provision/provision.awk
Normal file
@ -0,0 +1,50 @@
|
||||
###
|
||||
# Modifying Yii2's files for Vagrant VM
|
||||
#
|
||||
# @author HA3IK <golubha3ik@gmail.com>
|
||||
# @version 1.0.0
|
||||
|
||||
BEGIN {
|
||||
print "AWK BEGINs its work:"
|
||||
IGNORECASE = 1
|
||||
|
||||
# Correct IP - wildcard last octet
|
||||
match(ip, /(([0-9]+\.)+)/, arr)
|
||||
ip = arr[1] "*"
|
||||
}
|
||||
# BODY
|
||||
{
|
||||
# Check if it's the same file
|
||||
if (FILENAME != isFile["same"]){
|
||||
msg = "- Work with: " FILENAME
|
||||
# Close a previous file
|
||||
close(isFile["same"])
|
||||
# Delete previous data
|
||||
delete isFile
|
||||
# Save current file
|
||||
isFile["same"] = FILENAME
|
||||
# Define array index for the file
|
||||
switch (FILENAME){
|
||||
case /config\/web\.php$/:
|
||||
isFile["IsConfWeb"] = 1
|
||||
msg = msg " - add allowed IP: " ip
|
||||
break
|
||||
}
|
||||
# Print the concatenated message for the file
|
||||
print msg
|
||||
}
|
||||
|
||||
# IF config/web.php
|
||||
if (isFile["IsConfWeb"]){
|
||||
# IF line has "allowedIPs" and doesn't has our IP
|
||||
if (match($0, "allowedIPs") && !match($0, ip)){
|
||||
match($0, /([^\]]+)(.+)/, arr)
|
||||
$0 = sprintf("%s, '%s'%s", arr[1], ip, arr[2])
|
||||
}
|
||||
# Rewrite the file
|
||||
print $0 > FILENAME
|
||||
}
|
||||
}
|
||||
END {
|
||||
print "AWK ENDs its work."
|
||||
}
|
||||
Reference in New Issue
Block a user