Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DDEV command to install OM (incl. sample data) #3248

Merged
merged 14 commits into from
Jul 3, 2023
138 changes: 138 additions & 0 deletions .ddev/commands/web/openmage-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/bash

## Description: Install OpenMage
## Usage: openmage-install
sreichel marked this conversation as resolved.
Show resolved Hide resolved
## Example: ddev openmage-install -d -s -k -q

ROOT="${PWD}"

QUIET_INSTALL_FLAG=''
SAMPLE_DATA_FLAG=''
SAMPLE_DATA_KEEP_FLAG=''
USE_DEFAULT_FLAG=''

while getopts 'dskq' flag; do
case "${flag}" in
d) USE_DEFAULT_FLAG='true' ;;
s) SAMPLE_DATA_FLAG='true' ;;
k) SAMPLE_DATA_KEEP_FLAG='true' ;;
q) QUIET_INSTALL_FLAG='true' ;;
esac
done


#quiet install
if [[ "${QUIET_INSTALL_FLAG}" ]]; then
USE_DEFAULT_FLAG='true'
SAMPLE_DATA_FLAG='true'
fi

LOCALXML="${ROOT}/app/etc/local.xml"
if [ -f "${LOCALXML}" ]; then
if [[ "${QUIET_INSTALL_FLAG}" ]]; then
DELETE='y'
else
read -r -p "OpenMage is already installed. Delete local.xml and drop database [y/N]: " DELETE
DELETE=${DELETE,,} # to lower
sreichel marked this conversation as resolved.
Show resolved Hide resolved
fi

if [[ "${DELETE}" =~ ^(yes|y) ]]; then
mysql -u db -h db -e "DROP SCHEMA IF EXISTS db; CREATE SCHEMA db;";
rm "${LOCALXML}"
else
exit 1
fi
fi

# install sample data
if [[ "${SAMPLE_DATA_FLAG}" ]]; then
INSTALL_SAMPLE_DATA='y'
else
read -r -p "Install sample data? [y/N]: " INSTALL_SAMPLE_DATA
sreichel marked this conversation as resolved.
Show resolved Hide resolved
INSTALL_SAMPLE_DATA=${INSTALL_SAMPLE_DATA,,} # to lower
fi

if [[ $INSTALL_SAMPLE_DATA =~ ^(yes|y) ]]; then
SAMPLE_DATA_URL=https://github.com/Vinai/compressed-magento-sample-data/raw/master/compressed-magento-sample-data-1.9.2.4.tgz
SAMPLE_DATA_DIRECTORY="${ROOT}/.sampleData"
SAMPLE_DATA_FILE=sample_data.tgz

if [[ ! -d "${SAMPLE_DATA_DIRECTORY}" ]]; then
echo "Creating backup directory"
sreichel marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p "${SAMPLE_DATA_DIRECTORY}"
fi

cd "${SAMPLE_DATA_DIRECTORY}" || exit
if [[ ! -f "${SAMPLE_DATA_DIRECTORY}/${SAMPLE_DATA_FILE}" ]]; then
echo "Downloading sample data"
sreichel marked this conversation as resolved.
Show resolved Hide resolved
wget "${SAMPLE_DATA_URL}" -O "${SAMPLE_DATA_FILE}"
fi

echo "Uncompress sample data"
sreichel marked this conversation as resolved.
Show resolved Hide resolved
tar xf "${SAMPLE_DATA_FILE}"

echo "Copy sample data"
sreichel marked this conversation as resolved.
Show resolved Hide resolved
cp -r magento-sample-data-1.9.2.4/* "${PWD}/"
addison74 marked this conversation as resolved.
Show resolved Hide resolved

echo "Import sample data"
sreichel marked this conversation as resolved.
Show resolved Hide resolved
mysql -u db -h db db < "${SAMPLE_DATA_DIRECTORY}/magento-sample-data-1.9.2.4/magento_sample_data_for_1.9.2.4.sql"

# remove sample data
if [[ "${SAMPLE_DATA_KEEP_FLAG}" ]]; then
rm -rf $(
find . -maxdepth 1 -type f -name "*" ! -name "${SAMPLE_DATA_FILE}")
else
cd "${ROOT}" || exit
rm -rf "${SAMPLE_DATA_DIRECTORY}"
fi
fi

cd "${ROOT}" || exit

if [[ "${USE_DEFAULT_FLAG}" ]]; then
ADMIN_USER='admin'
ADMIN_FIRSTNAME='OpenMage'
ADMIN_LASTNAME='Administrator'
ADMIN_EMAIL='[email protected]'
ADMIN_PASSWORD='veryl0ngpassw0rd'
TABLE_PREFIX=''
else
read -r -p "Admin user [admin]: " ADMIN_USER
ADMIN_USER=${ADMIN_USER:-admin}
read -r -p "Admin firstname [OpenMage]: " ADMIN_FIRSTNAME
ADMIN_FIRSTNAME=${ADMIN_FIRSTNAME:-OpenMage}
read -r -p "Admin lastname [Administrator]: " ADMIN_LASTNAME
ADMIN_LASTNAME=${ADMIN_LASTNAME:-Administrator}
read -r -p "Admin email [[email protected]]: " ADMIN_EMAIL
ADMIN_EMAIL=${ADMIN_EMAIL:[email protected]}
read -r -p "Admin password [veryl0ngpassw0rd]: " ADMIN_PASSWORD
ADMIN_PASSWORD=${ADMIN_PASSWORD:-veryl0ngpassw0rd}
read -r -p "Table prefix []: " TABLE_PREFIX
TABLE_PREFIX=${TABLE_PREFIX:-}
fi

php -f install.php -- \
--license_agreement_accepted 'yes' \
--locale 'en_US' \
--timezone 'America/New_York' \
--db_host 'db' \
--db_name 'db' \
--db_user 'db' \
--db_pass 'db' \
--db_prefix "${TABLE_PREFIX}" \
--url "${DDEV_PRIMARY_URL}" \
--use_rewrites 'yes' \
--use_secure 'yes' \
--secure_base_url "${DDEV_PRIMARY_URL}" \
--use_secure_admin 'yes' \
--admin_username "${ADMIN_USER}" \
--admin_lastname "${ADMIN_LASTNAME}" \
--admin_firstname "${ADMIN_FIRSTNAME}" \
--admin_email "${ADMIN_EMAIL}" \
--admin_password "${ADMIN_PASSWORD}" \
--session_save 'files' \
--admin_frontname 'admin' \
--backend_frontname 'admin' \
--default_currency 'USD' \
--enable_charts 'yes' \
--skip_url_validation 'yes'