Skip to content

Commit

Permalink
Automatic setup of online production variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kassambara committed Feb 22, 2020
1 parent fbd0be8 commit 7c435db
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ mysql/*
!mysql/.keep
logs/nginx/*
!logs/nginx/.keep
_trash
69 changes: 69 additions & 0 deletions setup-onlinehost.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Description -----------------------------------------------
#
# Automatically set online production environment variables
# You just need to specify some custom settings then execute:
# chmod +x setup-onlinehost.sh && ./setup-onlinehost.sh
#
#----------------------------------------------------------

# Change these settings as you want %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
project_name="wordpress"
user_name="wordpress"
pass_word="wordpress"
email="[email protected]"
website_title="My Blog"
website_url="https://www.example.com"
phmyadmin_url="sql.example.com"
env_file=".env"
compose_file="docker-compose.yml"
# STOP here and execute: chmod +x setup.sh && ./setup.sh %%%%%%%%%


echo ---SETTING PRODUCTION ENVIRONMENT VARIABLES----
echo $env_file and $compose_file backups \(before update\) are available in _trash folder

# Backup configuration files before updating
# ---------------------------------------------------------
mkdir -p _trash
cp $env_file _trash/$env_file
cp $compose_file _trash/$compose_file
# Download initial version
rm -rf $compose_file $env_file
curl -s https://raw.githubusercontent.com/kassambara/wordpress-docker-compose/master/docker-compose-onlinehost.yml > $compose_file
curl -s https://raw.githubusercontent.com/kassambara/wordpress-docker-compose/master/.env > $env_file


# Update automatically .env file
# --------------------------------------------------------------------------
sed -i -e "/COMPOSE_PROJECT_NAME/s/wordpress/$project_name/" $env_file

# Update User password and name
sed -i -e "/DATABASE_PASSWORD/s/password/$pass_word/" $env_file
sed -i -e "/DATABASE_USER/s/root/$user_name/" $env_file
sed -i -e "/WORDPRESS_ADMIN_PASSWORD/s/wordpress/$pass_word/" $env_file
sed -i -e "/WORDPRESS_ADMIN_USER/s/wordpress/$user_name/" $env_file
sed -i -e "s/[email protected]/$email/" $env_file

# Update website info
url=$website_url
url=$(echo $url | sed 's/http:/https:/g') # Replace htpp by https

url_without_http=${url/https:\/\//} # Replace https
url_without_www=${url_without_http/www./}
url=$(echo $url | sed 's;/;\\/;g') # Escape / in url
sed -i -e "s/sql.example.com/$phmyadmin_url/" $env_file
sed -i -e "s/My Blog/$website_title/" $env_file
sed -i -e "s/http:\/\/localhost/$url/" $env_file
sed -i -e "s/localhost/$url_without_http/" $env_file
sed -i -e "s/example.com/$url_without_www/" $env_file

# Update automatically docker-compose.yml file
# --------------------------------------------------------------------------
sed -i -e "s/https:\/\/www.change-me-with-your-domain.com/$url/" $compose_file

echo -----------------DONE-----------------
echo Inspect now the $env_file and the $compose_file files to check if settings are OK


0 comments on commit 7c435db

Please sign in to comment.