#!/bin/bash function getConfig() { if [[ ! -n ${PHP_VERSION} ]]; then while true; do read -p "Which PHP version is your project using? [0=No, 1=Yes] " PHP_VERSION case ${PHP_VERSION} in 7.0) break ;; 7.1) break ;; 7.2) break ;; 7.3) break ;; 7.4) break ;; 8.0) break ;; 8.1) break ;; *) echo "Version not supported." ;; esac done fi if [[ ! -n ${COMPOSER_DOWNGRADE} ]]; then while true; do read -p "Do you want to downgrade Composer to version 1? [0=No, 1=Yes] " COMPOSER_DOWNGRADE case ${COMPOSER_DOWNGRADE} in 0) break ;; 1) break ;; *) echo "Only 1 or 0 are valid responses." ;; esac done fi if [[ ! -n ${COMPOSE_PROJECT_NAME} ]]; then read -p "Name your project (used as subdomain): " COMPOSE_PROJECT_NAME fi } function exitContainer() { if [[ "$L3D_ALWAYS_CLEANUP" == "1" ]]; then /usr/local/bin/delete $COMPOSE_PROJECT_NAME fi } function startContainer() { if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then mode=REBUILD if [[ $COMPOSE_PROJECT_NAME == "." ]]; then mode=NONPRESISTENT else ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_l3d$) if [[ -n ${ID} ]]; then docker start ${COMPOSE_PROJECT_NAME}_l3d mode=REGULAR fi fi if [[ "$mode" != "REGULAR" ]]; then start_params=( --env L3DHOSTDIR=${WORKDIR} --env L3DVERSION=${L3DVERSION} --env L3DSHELL=${L3DSHELL} --env L3D_ALWAYS_CLEANUP=${L3D_ALWAYS_CLEANUP} --env HOME=/home/${USERNAME} --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} --env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} --env PHP_VERSION=${PHP_VERSION} --env SSH_AUTH_SOCK=${SSHAUTHSOCK} --volume ${L3DDOCKERHOST}:/var/run/docker.sock --volume ${WORKDIR}:/drupal --volume ${SSHAUTH}:${SSHAUTHSOCK} --volume ${HOMEDIR}:/home/${USERNAME} --workdir /drupal ) if [[ ${L3DHOSTOS} != Darwin ]]; then start_params+=( --user ${USERID}:${GROUPID} --group-add ${GROUPIDS// / --group-add } --volume /etc/group:/etc/group:ro --volume /etc/passwd:/etc/passwd:ro --volume /etc/shadow:/etc/shadow:ro --volume /etc/sudoers:/etc/sudoers:ro --volume /etc/sudoers.d:/etc/sudoers.d:ro ) # else # (see #62) Disabled for now. #start_params+=( # --volume ${HOMEDIR}/.passwd:/etc/passwd:ro #) fi if [[ "$mode" == "REBUILD" ]]; then start_params+=( --hostname ${COMPOSE_PROJECT_NAME}-l3d ) docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \ "${start_params[@]}" \ --restart unless-stopped \ registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION} else start_params+=( --hostname "L3D" --env HOMEDIR=${HOMEDIR} --env WORKDIR=${WORKDIR} --env SSHAUTH=${SSHAUTH} ) docker run -it --rm \ "${start_params[@]}" \ registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION} \ /usr/local/bin/.start exitContainer return fi fi docker exec -it \ --env HOMEDIR=${HOMEDIR} \ --env WORKDIR=${WORKDIR} \ --env SSHAUTH=${SSHAUTH} \ ${COMPOSE_PROJECT_NAME}_l3d \ /usr/local/bin/.start exitContainer fi } if [[ -n $1 ]]; then if [[ "$1" == "." ]]; then COMPOSE_PROJECT_NAME=. else ID=$(docker container ls --all -q -f name=^$1_l3d$) if [[ -n ${ID} ]]; then PHP_VERSION=unknown COMPOSE_PROJECT_NAME=$1 fi fi fi getConfig startContainer