Skip to content

Commit

Permalink
Setup script refactor, and fix for short commands -s and -t
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjol committed Aug 30, 2024
1 parent 65770e7 commit 2a68007
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 36 deletions.
37 changes: 37 additions & 0 deletions commands/host/includes/aljibe_includes
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#ddev-generated

## Check if a project is running. If it is not, start it.
star_project() {
if [ "${DDEV_PROJECT_STATUS}" != "running" ] && [ -z "$no_recursion" ]; then
echo "Project ${DDEV_PROJECT} is not running, starting it"
ddev start
fi
}

## Helps checking if there are arguments in the command
has_argument() {
[[ ("$1" == *=* && -n ${1#*=}) || ( -n "$2" && "$2" != -*) ]];
}

## Extracts the argument from the command
extract_argument() {
if [[ $1 == *=* ]]; then
echo "${1#*=}"
else
echo "$2"
fi
}

run_commands() {
local CMDS=("$@")
if [ ${#CMDS[@]} -gt 0 ]; then
echo
echo -e "\033[32mRunning commands: \033[0m\n"
for cmd in "${CMDS[@]}"; do
echo "- running $cmd ... "
eval "$cmd"
done
echo -e "\033[32m\nCommands finished\n"
fi
}
50 changes: 15 additions & 35 deletions commands/host/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
## Usage: setup [flags]
## Example: ddev setup --no-install

# Include the ddev_checks script
source "$(dirname "$0")/includes/aljibe_includes"

# Initialize our own variables
NO_INSTALL=0
NO_THEMES=0

## Project must be running to run this command
ddev start || exit 1
star_project

CONFIG_DEFAULT_SITE=$(ddev aljibe-config default_site)
if [ "$CONFIG_DEFAULT_SITE" == 'null' ]; then
Expand Down Expand Up @@ -42,18 +45,6 @@ echo "Usage: ddev setup [options]"
exit 0
}

has_argument() {
[[ ("$1" == *=* && -n ${1#*=}) || ( -n "$2" && "$2" != -*) ]];
}

extract_argument() {
if [[ $1 == *=* ]]; then
echo "${1#*=}"
else
echo "$2"
fi
}

handle_options() {
while [ $# -gt 0 ]; do
case $1 in
Expand All @@ -72,7 +63,7 @@ handle_options() {
NO_THEMES=1
shift
;;
-s | --sites*)
-s* | --sites*)
if [[ $1 == *=* ]]; then
IFS=',' read -a SITES <<< "$(extract_argument "$1")"
shift
Expand All @@ -85,7 +76,7 @@ handle_options() {
shift 2
fi
;;
-t | --themes*)
-t* | --themes*)
if [[ $1 == *=* ]]; then
IFS=',' read -ar THEMES <<< "$(extract_argument "$1")"
shift
Expand All @@ -110,17 +101,12 @@ handle_options() {
handle_options "$@"

# Launch pre setup hooks
readarray -t PRE_SETUP_CMDS < <(ddev aljibe-config hooks.pre_setup)
if [ ${#PRE_SETUP_CMDS[@]} -gt 0 ]; then
echo
echo -e "\033[32mRunning PRE SETUP commands (defined in .ddev/aljibe.yml): \033[0m\n"
for cmd in "${PRE_SETUP_CMDS[@]}"; do
echo "- running $cmd ... "
eval "$cmd"
done
echo -e "\033[32m\nPRE SETUP commands finished\n"
fi
echo -e "\033[32mRunning PRE SETUP commands (defined in .ddev/aljibe.yml): \033[0m\n"
readarray -t CMDS < <(ddev aljibe-config hooks.pre_setup)
run_commands "${CMDS[@]}"
echo -e "\033[32m\nPRE SETUP commands finished\n"

# Prepare Drupal and dev environment
ddev composer install || exit 1
ddev exec vendor/bin/grumphp git:init

Expand Down Expand Up @@ -153,13 +139,7 @@ if [ "$NO_INSTALL" -eq 0 ]; then
fi

# Launch post setup hooks
readarray -t POST_SETUP_CMDS < <(ddev aljibe-config hooks.post_setup)
if [ ${#POST_SETUP_CMDS[@]} -gt 0 ]; then
echo
echo -e "\033[32mRunning POST SETUP commands (defined in .ddev/aljibe.yml): \033[0m\n"
for cmd in "${POST_SETUP_CMDS[@]}"; do
echo "- running $cmd ... "
eval "$cmd"
done
echo -e "\033[32m\nPOST SETUP commands finished\n"
fi
echo -e "\033[32mRunning POST SETUP commands (defined in .ddev/aljibe.yml): \033[0m\n"
readarray -t CMDS < <(ddev aljibe-config hooks.post_setup)
run_commands "${CMDS[@]}"
echo -e "\033[32m\nPOST SETUP commands finished\n"
8 changes: 7 additions & 1 deletion commands/host/site-install
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## Description: Install given drupal site
## Usage: site-install
## Example: ddev site-install default

# Include the ddev_checks script
source "$(dirname "$0")/includes/aljibe_includes"

## Project must be running to run this command
star_project

SITE_PROFILES_FILE=".ddev/site-profiles"
SITE=${1:-'self'}
ENV=${2:-'local'}
Expand Down Expand Up @@ -59,7 +66,6 @@ else
fi
fi


cp ${DDEV_DOCROOT}/${SITE_PATH}/example.settings.local.php ${DDEV_DOCROOT}/${SITE_PATH}/settings.local.php
cp ${DDEV_DOCROOT}/${SITE_PATH}/example.local.drush.yml ${DDEV_DOCROOT}/${SITE_PATH}/local.drush.yml

Expand Down

0 comments on commit 2a68007

Please sign in to comment.