Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
Last active April 10, 2018 13:58
Show Gist options
  • Save PieterScheffers/a474ed14ecb89d8ef513e38b4e154ac3 to your computer and use it in GitHub Desktop.
Save PieterScheffers/a474ed14ecb89d8ef513e38b4e154ac3 to your computer and use it in GitHub Desktop.
Install shopware with git script
#!/usr/bin/env bash
# exit script if a command exits with a non-zero
set -e
SHOPWARE_VERSION=5.2.26
SHOPWARE_DB_HOST=localhost
SHOPWARE_DB_PORT=3306
SHOPWARE_DB_NAME=mydatabase
SHOPWARE_DB_USER=myuser
SHOPWARE_DB_PASS=mypassword
SHOPWARE_APP_HOST=shop.example.com
SHOPWARE_APP_PATH=
# check ant is installed
command -v ant >/dev/null 2>&1 || { echo >&2 "ant is required but not installed. Aborting..."; exit 1; }
# check git is installed
command -v git >/dev/null 2>&1 || { echo >&2 "git is required but not installed. Aborting..."; exit 1; }
# check composer is installed
command -v composer >/dev/null 2>&1 || { echo >&2 "composer is required but not installed. Aborting..."; exit 1; }
# check php modules
php -m | grep -Fxq ctype >/dev/null 2>&1 || { echo >&2 "ctype php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq curl >/dev/null 2>&1 || { echo >&2 "curl php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq dom >/dev/null 2>&1 || { echo >&2 "dom php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq hash >/dev/null 2>&1 || { echo >&2 "hash php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq iconv >/dev/null 2>&1 || { echo >&2 "iconv php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq gd >/dev/null 2>&1 || { echo >&2 "gd php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq json >/dev/null 2>&1 || { echo >&2 "json php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq mbstring >/dev/null 2>&1 || { echo >&2 "mbstring php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq openssl >/dev/null 2>&1 || { echo >&2 "openssl php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq session >/dev/null 2>&1 || { echo >&2 "session php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq SimpleXML >/dev/null 2>&1 || { echo >&2 "SimpleXML php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq xml >/dev/null 2>&1 || { echo >&2 "xml php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq zip >/dev/null 2>&1 || { echo >&2 "zip php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq zlib >/dev/null 2>&1 || { echo >&2 "zlib php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq PDO >/dev/null 2>&1 || { echo >&2 "PDO php module is required but not installed. Aborting..."; exit 1; }
php -m | grep -Fxq pdo_mysql >/dev/null 2>&1 || { echo >&2 "pdo_mysql php module is required but not installed. Aborting..."; exit 1; }
##########################################################
## INSTALLATION of https://github.com/shopware/shopware ##
##########################################################
##### Clean database #####
# echo "Cleaning database..."
# TABLES=$(mysql -u $SHOPWARE_DB_USER -p$SHOPWARE_DB_PASS $SHOPWARE_DB_NAME -e 'show tables' | awk '{ print $1}' | grep -v '^Tables')
# if [ ! -z "$TABLES" ]; then
# for t in $TABLES
# do
# echo "Deleting $t table from $SHOPWARE_DB_NAME database..."
# $MYSQL -u $SHOPWARE_DB_USER -p$SHOPWARE_DB_PASS $SHOPWARE_DB_NAME -e "drop table $t"
# done
# fi
##### END Clean database #####
# Clone the git repository
# git clone https://github.com/shopware/shopware.git
# download Shopware
wget -O shopware.tar.gz "https://github.com/shopware/shopware/archive/v$SHOPWARE_VERSION.tar.gz"
# untar/gzip
tar -zxvf shopware.tar.gz
# remove tar
rm shopware.tar.gz
# move files from 'shopware' subdir to current dir
mv shopware-*/* .
mv shopware-*/.[!.]* .
# remove shopware subdir
rm -rf shopware-*/
# Set the correct directory permissions
chmod -R 755 var
chmod -R 755 web
chmod -R 755 files
chmod -R 755 media
chmod -R 755 engine/Shopware/Plugins/Community
# An Ant Buildfile is used to set up the configuration and database connection
cd build/
# ant configure
cat > build.properties <<- EOM
db.host=$SHOPWARE_DB_HOST
db.name=$SHOPWARE_DB_NAME
db.user=$SHOPWARE_DB_USER
db.password=$SHOPWARE_DB_PASS
db.port=$SHOPWARE_DB_PORT
app.path=$SHOPWARE_APP_PATH
app.host=$SHOPWARE_APP_HOST
EOM
chmod 644 build.properties
ant build-unit
cd ..
# Download the test images
wget -O test_images.zip http://releases.s3.shopware.com/test_images.zip
# extract test images
unzip test_images.zip
# remove images zip file
rm -rf test_images.zip
# Download international demo data
php bin/console sw:store:download SwagDemoDataEN
php bin/console sw:plugin:install SwagDemoDataEN
php bin/console sw:plugin:activate SwagDemoDataEN
# change language of shop to english
cat > install_shopware.php << EndOfPHP
<?php
try
{
// parse ant configuration file for database values
\$ini = parse_ini_file(__DIR__ . "/build/build.properties");
\$db = new PDO("mysql:host={\$ini['db.host']};port={\$ini['db.port']};dbname={\$ini['db.name']};charset=utf8mb4", \$ini['db.user'], \$ini['db.password']);
\$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Change locale of default shops to english
\$sql = "UPDATE s_core_shops SET locale_id = 2";
\$db->query(\$sql);
// change locale of default users to english
\$sql = "UPDATE s_core_auth SET localeID = 2";
\$db->query(\$sql);
}
catch(Exception \$ex)
{
echo "install_shopware.php: Exception: " . \$ex->getMessage() . "\n";
}
EndOfPHP
php install_shopware.php
rm -rf install_shopware.php
# Write version to Application.php file
cat > change_version.php << EndOfPHP
<?php
try
{
\$version = "$SHOPWARE_VERSION";
\$appFile = __DIR__ . "/engine/Shopware/Application.php";
\$contents = file_get_contents(\$appFile);
\$contents = str_replace("const VERSION = '___VERSION___';", "const VERSION = '" . \$version . "';", \$contents);
\$contents = str_replace("const VERSION_TEXT = '___VERSION_TEXT___';", "const VERSION_TEXT = '';", \$contents);
file_put_contents(\$appFile, \$contents);
}
catch(Exception \$ex)
{
echo "change_version.php: Exception: " . \$ex->getMessage() . "\n";
}
EndOfPHP
php change_version.php
rm -rf change_version.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment