Browse Source

init

master
Sven Ullmann 2 years ago
parent
commit
3016ccb87d
  1. 44
      .etc/config.sh
  2. 1
      .gitignore
  3. 40
      README.md
  4. 20
      bin/commands/clone_repo.sh
  5. 57
      bin/commands/create_local_env.sh
  6. 11
      bin/commands/import_db.sh
  7. 50
      bin/commands/import_gdpr_data.sh
  8. 21
      bin/commands/import_media.sh
  9. 97
      bin/commands/install_shopware.sh
  10. 2
      bin/commands/make_local_database.sh
  11. 33
      bin/commands/switch_system.sh
  12. 20
      bin/includes/includes.sh
  13. 48
      bin/manager
  14. 0
      shared/.keep

44
.etc/config.sh

@ -9,23 +9,18 @@ app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)
project_name='www.domain.de'
shopware_version='6'
### STAGE
stage_use_git='y' # if the stage system is deployed using git
stage_ssh_user='your-user'
stage_ssh_domain='your-domain'
stage_ssh_has_key_file='y'
stage_ssh_key_file='/path/to/.ssh/key'
stage_httpdocs_path='/var/www/vhosts/domain.de/httpdocs'
stage_httpdocs_slug='/shopware' # optional slug if you install the software not directly in httpdocs
stage_database_has_socket='n'
stage_database_socket=''
stage_database_host='localhost'
stage_database_port='3306'
@ -41,17 +36,13 @@ stage_database_admin_password=''
### LIVE
live_use_git='y'
live_ssh_user='user'
live_ssh_domain='domain.de'
live_ssh_has_key_file='n'
live_ssh_key_file=''
live_httpdocs_path='/var/www/vhosts/domain.de/httpdocs'
live_httpdocs_slug=''
live_database_has_socket='n'
live_database_socket=''
live_database_host='localhost'
live_database_port='3306'
@ -67,10 +58,9 @@ live_database_admin_password=''
### LOCAL STAGE
local_stage_use_git='y' # if you don't work with the git working copy / you can sync local htdocs/. with git repo
local_stage_host='localhost'
local_stage_slug='/shopware'
local_stage_database_has_socket='n'
local_stage_database_socket=''
local_stage_database_host='localhost'
local_stage_database_port='3306'
@ -86,7 +76,7 @@ local_stage_database_admin_password=''
### LOCAL LIVE
local_live_use_git='y'
local_live_host='localhost'
local_live_slug='/shopware'
local_live_database_has_socket='n'
@ -102,7 +92,7 @@ local_live_database_admin_user=''
local_live_database_admin_password=''
### SHOPWARE USER
### SHOPWARE
local_shopware_user='user'
@ -110,13 +100,27 @@ local_shopware_email='email'
local_shopware_firstname='Name'
local_shopware_lastname='Lastname'
install_shopware_name="Project"
install_shopware_email="$local_shopware_email"
install_shopware_locale='de_DE'
install_shopware_currency='EUR'
install_shopware_storefront_name="Storefront"
install_shopware_storefront_url='https://localhost/domain.de/www.domain.de'
### MAILER
local_mailer_url='smtp://localhost:1025'
### GIT
git_has_ssh_key_file='n'
git_ssh_key_file=''
git_url=''
git_shopware_path=''
# you can update stage with data from live
live_to_stage_live_urls=("https://www.domain.de")
@ -128,12 +132,12 @@ stage_to_local_local_urls=("https://localhost/domain.de/stage.domain.de")
# here more complete, copy the live system to local
live_to_local_live_urls=(
"http://www.domain.de"
"https://www.domain.de"
"http://www.domain.de"
)
live_to_local_local_urls=(
"http://localhost/martins-domain.de/www.domain.de"
"https://localhost/domain.de/www.domain.de"
"http://localhost/domain.de/www.domain.de"
)
@ -190,6 +194,14 @@ gdpr_tables=(
)
### Media Files
import_media_files=(
"/files"
"/public/media"
)
### POST SCRIPT

1
.gitignore

@ -3,5 +3,6 @@
backup
bin/postscripts
etc
shared
var
!.keep

40
README.md

@ -20,17 +20,47 @@ Replace {script-name} with the name of the script wich is located in bin/command
## Commands
Chronologicaly!
### Clone Repo
bin/commands/clone_repo.sh
# Usage: clone_repo.sh
### Install/Update Shopware
bin/commands/install_shopware.sh
# Usage: install_shopware.sh
### Create local .env
bin/commands/create_local_env.sh
# Usage: create_local_env.sh [local_live|local_stage]
### Import Database
Usage: import_db.sh [live|stage]
bin/commands/import_db.sh
# Usage: import_db.sh [live|stage]
### Make local Database changes
bin/commands/make_local_database.sh
# Usage: make_local_database.sh [live|stage]
### Make changes to the new local database (URL's and Admin-User)
Usage: make_local_database.sh [live|stage]
bin/commands/make_local_database.sh
# Usage: make_local_database.sh [live|stage]
### Import media files
Usage: import_media.sh [live|stage] /path/to/files
bin/commands/import_media.sh
# Usage: import_media.sh [live|stage] /path/to/files
# Example:
# import_media.sh stage /files
# import_media.sh stage /public/media
### Switch the System
import_media.sh stage /files
import_media.sh stage /public/media
bin/commands/switch_system.sh
# Usage: switch_system [live|stage]

20
bin/commands/clone_repo.sh

@ -0,0 +1,20 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
echo
echoMainTitle "Cloning Repository"
repo_path="$app_dir/git/$project_name"
if [ ! -d "$repo_path" ] && [ "$git_url" != "" ]
then
addSSHKey "git"
git clone "$git_url" "$repo_path"
fi
postScript "$app_dir/bin/postscript/clone_repo.sh"

57
bin/commands/create_local_env.sh

@ -0,0 +1,57 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
env=$(getArgument "1" "Usage: create_local_env.sh [local_live|local_stage]" "local_live local_stage" | sed -e 's/local_//')
echo
echoMainTitle "Create local .env file"
echo
local_database_socket=$(eval "echo \"\$local_${env}_database_socket\"")
local_database_host=$(eval "echo \"\$local_${env}_database_host\"")
local_database_port=$(eval "echo \"\$local_${env}_database_port\"")
local_database_name=$(eval "echo \"\$local_${env}_database_name\"")
local_database_user=$(eval "echo \"\$local_${env}_database_user\"")
local_database_password=$(eval "echo \"\$local_${env}_database_password\"")
if [ "$local_database_socket" != "" ]
then
db_connection="mysql://$local_database_host?unix_socket=$local_database_socket&dbname=$local_database_name&user=$local_database_user&password=$local_database_password"
else
db_connection="mysql://$local_database_user:$local_database_password@$local_database_host:$local_database_port/$local_database_name"
fi
app_url=$(eval "echo \"\$${env}_to_local_local_urls[0]\"")
ssh_user=$(eval "echo \"\$${env}_ssh_user\"")
ssh_domain=$(eval "echo \"\$${env}_ssh_domain\"")
ssh_httpdocs_path=$(eval "echo \"\$${env}_ssh_httpdocs_path\"")
ssh_httpdocs_slug=$(eval "echo \"\$${env}_ssh_httpdocs_slug\"")
addSSHKey "$env"
app_secret=$(ssh "$ssh_user"@"$ssh_domain" "cat \"$ssh_httpdocs_path$ssh_httpdocs_slug/.env\"" | sed -i -r 's/^APP_SECRET=\(.*\)\$/\\1/')
instance_id=$(ssh "$ssh_user"@"$ssh_domain" "cat \"$ssh_httpdocs_path$ssh_httpdocs_slug/.env\"" | sed -i -r 's/^INSTANCE_ID=\(.*\)\$/\\1/')
host=$(eval "echo \"\$local_${env}_host}\"")
path="$app_dir/git/$project_name"
cat <<- EOF > "$path/.env"
APP_ENV=dev
APP_SECRET=$app_secret
APP_URL=$app_url
TRUSTED_HOSTS=$host
MAILER_URL=$local_mailer_url
INSTANCE_ID=$instance_id
DATABASE_URL=$db_connection
COMPOSER_HOME=vendor
BLUE_GREEN_DEPLOYMENT=1
SHOPWARE_HTTP_CACHE_ENABLED=0
SHOPWARE_HTTP_DEFAULT_TTL=0
EOF
postScript "$app_dir/bin/postscripts/create_local_env.sh"

11
bin/commands/import_db.sh

@ -1,11 +1,16 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
usage="Usage: import_db.sh [live|stage]"
env=$(getArgument $1 "$usage" "live stage")
env=$(getArgument "$1" "Usage: import_db.sh [live|stage]" "live stage")
echo
echoMainTitle "Import Database from $env to local ($env)"
currentDate=$(date '+%Y-%m-%d_%H:%M:%S')
addSSHKey "$env"
@ -69,6 +74,7 @@ echo "Post Scripts ..."
postScript "$app_dir/bin/postscripts/import_db.sh"
"$app_dir/bin/commands/make_local_database.sh" "$env"
"$app_dir/bin/commands/create_local_env.sh" "local_$env"
echo "Cleanup ..."
@ -76,4 +82,3 @@ rm "$app_dir/var/tmp/drop_local_$env.sql"
rm "$app_dir/var/tmp/${env}_structure.sql"
rm "$app_dir/var/tmp/${env}_data.sql"
echo

50
bin/commands/import_gdpr_data.sh

@ -0,0 +1,50 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
env=$(getArgument "1" "Usage: import_gdpr_data.sh [live|stage]" "live stage")
echo
echoMainTitle "Fetch GDPR Data from $env"
currentDate=$(date '+%Y-%m-%d_%H:%M:%S')
addSSHKey "$env"
ssh_user="$(eval "echo \$${env}_ssh_user")"
ssh_domain="$(eval "echo \$${env}_ssh_domain")"
includedTables=$(buildIncludedTables "${gdprTables[@]}"
database_name=$(eval "echo \$${env}_database_name")
local_database_name=$(eval "echo \$local_${env}_database_name")
echo "Fetching Data ..."
scp "$app_dir/etc/${env}.my.cnf" "$ssh_user"@"$ssh_domain":"~/${env}.my.cnf"
ssh "$ssh_user"@"$ssh_domain" "mysqldump --defaults-extra-file=~/${env}.my.cnf --no-tablespaces --no-create-info --skip-triggers \
"$database_name" "${includedTables[@]}" | LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip -9 > \
~/${env}_gdpr_data.sql.gz"
scp "$ssh_user"@"$ssh_domain":"~/${env}_gdpr_data.sql.gz" "$app_dir/var/tmp/${env}_gdpr_data.sql.gz"
ssh "$ssh_user"@"$ssh_domain" "unlink ~/${env}_gdpr_data.sql.gz"
ssh "$ssh_user"@"$ssh_domain" "unlink ~/${env}.my.cnf"
echo "Backup Data ..."
cp "$app_dir/var/tmp/${env}_gdpr_data.sql.gz" "$app_dir/backup/database/${env}/${currentDate}_${env}_gdpr_data.sql.gz"
echo "Uncompress Data ..."
gzip -d "$app_dir/var/tmp/${env}_gdpr_data.sql.gz"
echo "Import Data ..."
mysql --defaults-extra-file="$app_dir/etc/local.my.cnf" -D "$local_database_name" < "$app_dir/var/tmp/${env}_gdpr_data.sql"
echo "Post Scripts ..."
postScript "$app_dir/bin/postscripts/import_gdpr_data.sh" ]
echo "Cleanup ..."
rm "$app_dir/var/tmp/${env}_gdpr_data.sql"

21
bin/commands/import_media.sh

@ -1,26 +1,37 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
env=$(getArgument "$1" "Usage: import_media.sh [live|stage] /path/to/files" "live stage")
filepath=$(getArgument "$2" "Usage: import_media.sh [live|stage] /path/to/files" "/files /public/media")
filepath=$(getArgument "$2" "Usage: import_media.sh [live|stage] /path/to/files" true)
echo
echoMainTitle "Fetching $filepath files from $env"
addSSHKey "$env"
ssh_user="$(eval "echo \$${env}_ssh_user")"
ssh_domain="$(eval "echo \$${env}_ssh_domain")"
slug="$(eval "echo \"\$local_${env}_slug\"")"
source="$(eval "echo \"\$${env}_httpdocs_path\$${env}_httpdocs_slug\$filepath/.\"")"
target="$app_dir/git/${project_name}${slug}${filepath}/."
echo
echoMainTitle "Fetching $filepath files from $env"
target="$app_dir/shared/$project_name/$env$filepath"
link="$app_dir/git/${project_name}${slug}${filepath}/."
echo
echo "Fetch Files ..."
rsync -auvzqLK --delete "$ssh_user"@"$ssh_domain":"$source" "$target"
if [ -f "$link" ]
then
rm -rf "$link"
fi
ln -s "$target" "$link"
postScript "$app_dir/bin/postscripts/import_media.sh"
echo

97
bin/commands/install_shopware.sh

@ -0,0 +1,97 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
updatemode=0
echo
echoMainTitle "Shopware installer/updater"
path="$app_dir/git/$project_name$git_shopware_path"
if [ -f "$path/install.lock" ]
then
updatemode=1
echo "Update mode"
else
echo "Install mode"
fi
if [ "$updatemode" == "0" ]
then
echo
echoSequenzeTitle "Wich database to use?"
echo
echoSelect "[live] " "Local live database"
echoSelect "[stage]" "Local stage database"
echo
env=$(readConsole "Select: " "Invalid selection" "live stage")
fi
### Fetch sources
echo
echo "Fetch sources ..."
wget -q --show-progress -O "$app_dir/var/tmp/sdp.html" "https://www.shopware.com/de/download/"
if [ "$updatemode" == "0" ]
then
download_url=$(grep -Po '(?<=href=")https://releases.shopware.com/sw6/install_[^"]*' "$app_dir/var/tmp/sdp.html")
filename="shopware_install.zip"
else
download_url=$(grep -Po '(?<=href=")https://releases.shopware.com/sw6/update_[^"]*' "$app_dir/var/tmp/sdp.html")
filename="shopware_update.zip"
fi
wget -q --show-progress -O "$app_dir/var/tmp/$filename" "$download_url"
echo "Install files ..."
unzip -oqq "$app_dir/var/tmp/$filename" -d "$path"
local_database_socket=$(eval "echo \"\$local_${env}_database_socket\"")
local_database_host=$(eval "echo \"\$local_${env}_database_host\"")
local_database_port=$(eval "echo \"\$local_${env}_database_port\"")
local_database_name=$(eval "echo \"\$local_${env}_database_name\"")
local_database_user=$(eval "echo \"\$local_${env}_database_user\"")
local_database_password=$(eval "echo \"\$local_${env}_database_password\"")
if [ "$local_database_socket" != "" ]
then
database_url="mysql:unix_socket=$local_database_socket;dbname=$local_database_name;user=$local_database_user;password=$local_database_password"
else
database_url="mysql://$local_database_user:$local_database_password@$local_database_host:$local_database_port/$local_database_name"
fi
export DATABASE_URL="$database_url"
cwd=$(pwd)
cd "$path"
if [ "$updatemode" == "0" ]
then
echo "Setup Shopware ..."
cp "$app_dir/etc/.env.local" "$path/.env"
bin/console system:install --shop-name="$install_shopware_name" --shop-email="$install_shopware_email" \
--shop-locale="$install_shopware_locale" --shop-currency="$install_shopware_currency" --no-interaction --env="dev"
bin/console sales-channel:create:storefront --name="$install_shopware_storefront_name" --url="$install_install_shopware_storefront_url" --no-interaction --quiet
bin/console user:create -a --firstName="$local_shopware_user" --lastName="$local_shopware_firstname" --email="$local_shopware_email" "$local_shopware_user"
else
echo "Prepare Shopware setup ..."
bin/console --quiet --no-interaction --env="dev" system:update:prepare
"$path/public/recovery/update/index.php"
fi
cd "$cwd"
postScript "$app_dir/bin/postscripts/install_shopware.sh"
rm "$app_dir/var/tmp/sdp.html"
rm "$app_dir/var/tmp/$filename"

2
bin/commands/make_local_database.sh

@ -1,5 +1,7 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"

33
bin/commands/switch_system.sh

@ -0,0 +1,33 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(dirname "${BASH_SOURCE[0]}")/../includes/includes.sh"
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
source "$app_dir/etc/config.sh"
env=$(getArgument "$1" "Usage: switch_system.sh [live|stage] [true|false: UpdateDatabase]" "live stage")
update_database_flag=$(getArgument "$2" "Usage: switch_system.sh [live|stage] [true|false: UpdateDatabase]" "true false")
echoMainTitle "Switch to local_$env System"
shopware_check_install="$app_dir/git/$project_name$git_shopware_path/src"
if [ ! -d "$shopware_check_install" ]
then
echo
echoError "No Shopware installed, try bin/commands/install_shopware.sh"
exit
fi
if [ "$update_database_flag" == true ]
then
"$app_dir/bin/commands/import_db.sh" "$env"
"$app_dir/bin/commands/create_local_env.sh" "local_$env"
"$app_dir/bin/commands/make_local_database.sh" "$env"
fi
for path in "${import_media_files[@]}"
do
"$app_dir/bin/commands/import_media.sh" "$env" "$path"
done

20
bin/includes/includes.sh

@ -23,9 +23,9 @@ then
}
function getArgument {
local var=$1
local errmsg=$2
local allow=${3:-false}
local var=$1
if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
then
@ -68,8 +68,15 @@ then
local message="$1"
local errmsg="$2"
local allow=${3:-false}
local default=${4:-""}
if [ "$default" != "" ]
then
message="$message [d:$default]"
fi
read -p "$message" var
var=${var:-$default}
if [ "$(isAllowed "$var" "$allow")" == false ]
then
@ -82,21 +89,19 @@ then
function addSSHKey {
local env=$(getArgument "$1" "Usage: addSSHKey [live|stage|git]" "live stage git")
local ssh_key_file="$app_dir/.ssh/$env"
local has_ssh_key_file=$(eval "echo \"\$${env}_has_ssh_key_file\"")
local ssh_key_file=$(eval "echo \"\$${env}_has_ssh_key_file\"")
if [ "$has_ssh_key_file" == "y" ]
if [ "$ssh_key_file" != "" ]
then
copySSHKeys "$env"
else
installSSHKey "$env"
fi
ssh-add "$ssh_key_file"
ssh-add "$app_dir/.ssh/$env"
}
function copySSHKeys {
local env=$(getArgument "$1" "Usage: copySSHKeys [live|stage|git]" "live stage git")
local has=$(eval "echo \$${env}_has_ssk_key_file")
local source=$(eval "echo \$${env}_ssh_key_file")
local target="$app_dir/.ssh/$env"
@ -120,12 +125,11 @@ then
function installSSHKey {
local env=$(getArgument "$1" "Usage: installSSHKey [live|stage|git]" "live stage git")
local has=$(eval "echo \"\$${env}_has_ssh_key_file\"")
local file=$(eval "echo \"\$${env}_ssh_key_file\"")
local user=$(eval "echo \"\$${env}_ssh_user\"")
local domain=$(eval "echo \"\$${env}_ssh_domain\"")
if [ "$has" == "n" ] && [ ! -f "$app_dir/.ssh/$env"]
if [ "$file" == "" ] && [ ! -f "$app_dir/.ssh/$env" ]
then
ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$env" -q -N ""
chmod 0600 "$app_dir/.ssh/$env"

48
bin/manager

@ -12,13 +12,11 @@ echoMainTitle "What do you want to do today?"
echo
echoSelect "[1]" "Databaseupdate"
echoSelect "[2]" "Fetching Files"
echoSelect "[3]" "Fetching Public Media"
echo
main_selection=$(readConsole "Select: " "Invalid selection" "1 2 3")
main_selection=$(readConsole "Select: " "Invalid selection" "1 2")
words=(
'databaseupdate'
'files'
'media'
)
for i in "${!words[@]}"
@ -64,41 +62,39 @@ then
echo
echoSelect "[live] " "Live"
echoSelect "[stage] " "Stage"
echo
env=$(readConsole "Select: " "Invalid selection" "live stage")
echoSubTitle "Select a directory:"
echo
confirm=$(readConsole "You want to copy the /files from $env to local ($env)? [y,n]: " "Invalid selection" "y n")
if [ "$confirm" == "y" ]
echoSelect "[1] " "/files"
echoSelect "[2] " "/public/media"
echoSelect "[3] " ".. custom .."
files_selection=$(readConsole "Select: " "Invalid selection" "1 2 3")
values=(
"/files"
"/public/media"
)
if [ "$files_selection" -gt "${#values[@]}" ]
then
source "$app_dir/bin/commands/import_media.sh" "$env" "/files"
files_selection=$(readConsole "Please give a subpath to the shopware root on $env: ", "Invalid selection", true)
else
echo "Aborted"
for i in "${!values[@]}"
do
((cur=i+1))
if [ "$cur" == "$files_selection" ]
then
files_selection="${values[$i]}"
fi
done
fi
fi
if [ "$main_selection" == "media" ]
then
echo
echoSubTitle "Fetching public Media"
echo
echo "From Environment:"
echo
echoSelect "[live] " "Live"
echoSelect "[stage] " "Stage"
echo
env=$(readConsole "Select: " "Invalid selection" "live stage")
echo
confirm=$(readConsole "You want to copy the /public/media from $env to local ($env? [y,n]: " "Invalid selection" "y n")
confirm=$(readConsole "You want to copy the /files from $env to local ($env)? [y,n]: " "Invalid selection" "y n")
if [ "$confirm" == "y" ]
then
source "$app_dir/bin/commands/import_media.sh" "$env" "/public/media"
source "$app_dir/bin/commands/import_media.sh" "$env" "$files_selection"
else
echo "Aborted"
fi
fi
echo

0
shared/.keep

Loading…
Cancel
Save