|
| 1 | +#!/usr/bin/env bash |
| 2 | +VERSION=$1 |
| 3 | + |
| 4 | +if [ -z "${VERSION}" ]; then |
| 5 | + echo "You must give a version to execute command on, for example 71 for PHP 7.1 container." |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +# directory of this script |
| 10 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 11 | + |
| 12 | +if [ -d ${DIR}/../vendor/solutiondrive/sd-test-environment-shopware ]; then |
| 13 | + PACKAGE_DIR="$( dirname "${DIR}" )"/vendor/solutiondrive/sd-test-environment-shopware |
| 14 | +elif [ -d ${DIR}/../solutiondrive/sd-test-environment-shopware ]; then |
| 15 | + PACKAGE_DIR="$( cd "$( dirname "${DIR}" )"/solutiondrive/sd-test-environment-shopware && pwd )" |
| 16 | +elif [ -d ${DIR}/../../../solutiondrive/sd-test-environment-shopware ]; then |
| 17 | + PACKAGE_DIR="$( dirname "${DIR}" )" |
| 18 | +fi |
| 19 | + |
| 20 | +if [ ! -d ${PACKAGE_DIR} ]; then |
| 21 | + echo "Could not find package directory of sd-test-environment-shopware. Did you move the bin directory?" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +PROJECT_DIR="$( dirname $( dirname $( dirname "${PACKAGE_DIR}") ) )" |
| 26 | +PROJECT_NAME="$( basename ${PROJECT_DIR} | tr '[:upper:]' '[:lower:]' )" |
| 27 | +# TODO: Think about a good solution for a different shopware version |
| 28 | +PHP_CONTAINER_NAME="${PROJECT_NAME}_shopware546_php${VERSION}_1" |
| 29 | +WORK_DIR="/var/www/shopware54_php${VERSION}" |
| 30 | + |
| 31 | +PLUGIN_NAME=$(find . -name '*.php' -maxdepth 1 |sed 's#.*/##' | sed 's/\.php$//1') |
| 32 | + |
| 33 | +PLUGIN_DIRECTORY="custom/plugins/$PLUGIN_NAME" |
| 34 | + |
| 35 | +function add_plugin { |
| 36 | + echo "Init plugin $PLUGIN_NAME" |
| 37 | + link_plugin |
| 38 | + install_plugin |
| 39 | + activate_plugin |
| 40 | +} |
| 41 | + |
| 42 | +function link_plugin { |
| 43 | + echo "Link plugin $PROJECT_NAME to $PLUGIN_DIRECTORY" |
| 44 | + execute_in_docker "ln -s /opt/host $PLUGIN_DIRECTORY" |
| 45 | +} |
| 46 | + |
| 47 | +function install_plugin { |
| 48 | + execute_in_docker "bin/console sw:plugin:refresh" |
| 49 | + execute_in_docker "bin/console sw:plugin:install $PLUGIN_NAME" |
| 50 | +} |
| 51 | + |
| 52 | +function activate_plugin { |
| 53 | + execute_in_docker "bin/console sw:plugin:activate $PLUGIN_NAME" |
| 54 | + execute_in_docker "bin/console sw:cache:clear" |
| 55 | +} |
| 56 | + |
| 57 | +function deactivate_plugin { |
| 58 | + execute_in_docker "bin/console sw:plugin:deactivate $PLUGIN_NAME" |
| 59 | + execute_in_docker "bin/console sw:cache:clear" |
| 60 | +} |
| 61 | + |
| 62 | +function remove_plugin { |
| 63 | + deactivate_plugin |
| 64 | + execute_in_docker "bin/console sw:plugin:uninstall $PLUGIN_NAME" |
| 65 | + execute_in_docker "rm $PLUGIN_DIRECTORY" |
| 66 | +} |
| 67 | + |
| 68 | +function execute_in_docker { |
| 69 | + docker exec --workdir ${WORK_DIR} -it ${PHP_CONTAINER_NAME} $1 |
| 70 | +} |
| 71 | + |
| 72 | +## start of the real program |
| 73 | + |
| 74 | +export PROJECT_DIR |
| 75 | +export PROJECT_NAME |
| 76 | + |
| 77 | +case "$2" in |
| 78 | + add) |
| 79 | + shift |
| 80 | + add_plugin $@ |
| 81 | + ;; |
| 82 | + remove) |
| 83 | + shift |
| 84 | + remove_plugin $@ |
| 85 | + ;; |
| 86 | + activate) |
| 87 | + shift |
| 88 | + activate_plugin $@ |
| 89 | + ;; |
| 90 | + deactivate) |
| 91 | + shift |
| 92 | + deactivate_plugin $@ |
| 93 | + ;; |
| 94 | + *) |
| 95 | + echo "usage: add/remove/activate/deactivate" |
| 96 | + ;; |
| 97 | +esac |
0 commit comments