diff --git a/commands/host/all-sites-drush b/commands/host/all-sites-drush new file mode 100755 index 0000000..4650b52 --- /dev/null +++ b/commands/host/all-sites-drush @@ -0,0 +1,26 @@ +#!/bin/bash +#ddev-generated +## Description: Launches a drush command on all of the sites +## Usage: all-sites-drush [drush command] + +source "$(dirname "$0")/includes/aljibe_includes" + +ENV='local' +COMMAND='' +SITES=() + +COMMAND=$@; +if [ -z "$COMMAND" ]; then + echo "Please provide a drush command" + exit +fi + +## Get all sites from the drush/sites folder. +set_sites_variable + +## Run the command in all sites. +for SITE in "${SITES[@]}"; do + SITE_ALIAS=$SITE.$ENV + echo "Running drush $COMMAND in $SITE" + ddev drush @${SITE_ALIAS} $COMMAND +done diff --git a/commands/host/includes/aljibe_includes b/commands/host/includes/aljibe_includes index 2ff472f..6f2099d 100644 --- a/commands/host/includes/aljibe_includes +++ b/commands/host/includes/aljibe_includes @@ -43,4 +43,9 @@ run_hooks() { echo -e "\033[32mRunning $1 commands: \033[0m\n" readarray -t CMDS < <(ddev aljibe-config hooks.$1) run_commands "${CMDS[@]}" -} \ No newline at end of file +} + +## Get all sites list from the drush/sites folder. +set_sites_variable() { + mapfile -t SITES < <(find drush/sites -name '*.site.yml' -exec basename {} \; | cut -d'.' -f1) +} diff --git a/commands/host/setup b/commands/host/setup index dc794b4..1b3fd58 100755 --- a/commands/host/setup +++ b/commands/host/setup @@ -139,4 +139,4 @@ if [ "$NO_INSTALL" -eq 0 ]; then fi # Launch post setup hooks -run_hooks "post_setup" \ No newline at end of file +run_hooks "post_setup"