Published: July 5, 2024
A bash script to install different Drupal profiles the easy way
Over the past few weeks I've been sharing handy ways to set up Drupal for easier Drupal core development. Here's a bash script for installing Drupal and allowing you to choose what profile you want.
When contributing to Drupal core, or any distribution of Drupal like LocalGov Drupal, or doing anything that needs you to install and reinstall Drupal a lot, it gets frustrating having to go through the same steps.
I often hit the up arrow to use my last command in my terminal which might look something like this:
ddev drush si standard -y && drush cex -y && git add config/sync && git commit -m "config" && ddev drush uli
What does that do?
- Installs Drupal using the standard profile
- Exports the default config to the
config/sync
directory - Adds this config to a dummy git repo that goes no where - this is so if I need to do something that changes config, I can re-export the config and do a
git diff
to see what changes I need to add back in to my module/installation profile - Gets me a login link
However, I often need to install the Umami profile, since I am a Drupal core maintainer for that. And I often need to install the LocalGov Drupal profile, since I am the frontend lead for that project. And sometimes I need to install the demo_content
module with LocalGov Drupal.
With all that in mind, I decided to create a bash script that would install any of these profiles and allow me to choose which one when I run it. Here's the script:
#!/bin/bash
set -x
#!/bin/bash
echo "What profile do you want to install?"
options=("Standard" "Umami" "LocalGov" "LocalGov (with Demo Content)" "LocalGov Microsites" "LocalGov (with Elections)")
# Check if a command-line argument was provided
if [ $# -gt 0 ]; then
# Use the command-line argument as the profile selection
profile_selection=$1
else
# No argument provided, fall back to interactive selection
select profile_selection in "${options[@]}"
do
break
done
fi
case $profile_selection in
"Standard" | 1)
ddev drush si standard -y
;;
"Umami" | 2)
ddev drush si demo_umami -y
;;
"LocalGov" | 3)
ddev drush si localgov -y
;;
"LocalGov (with Demo Content)" | 4)
ddev drush si localgov -y
ddev drush en localgov_demo -y
;;
"LocalGov Microsites" | 5)
ddev drush si localgov_microsites -y
;;
"LocalGov (with Elections)" | 6)
ddev drush si localgov -y
ddev drush en localgov_elections_demo_content -y
;;
*)
echo "Invalid option. Please run the script again with a valid option."
exit 1
;;
esac
ddev drush cex -y
ddev drush cr
# wait 3 seconds, so the config has fully exported
sleep 3
git add config
git commit -m "config"
ddev drush uli
This script gives me six options:
- Standard - the standard installation of Drupal
- Umami - the Demo Umami profile
- LocalGov - the default LocalGov Drupal installation profile
- LocalGov (with Demo Content) - installs the demo content module after installing LocalGov Drupal
- LocalGov Microsites - the LGD microsites platform profile
- LocalGov (with Elections) - enables the elections suite of modules, I needed that lots over the past few weeks
Now, when I want to re-install Drupal, I can run bash _install-drupal.sh
(it has the underscore so it stays at the top of the directory I have it saved in). That will then ask me to enter 1-6 for what profile I want to enable, or I can run bash _install-drupal.sh 2
to install profile 2, which is Demo Umami.
This came in very handy today when working on a hook_install()
to set various created dates for the demo content in the Umami profile. I had to reinstall the site to test it about 20 times, so this was a real time-saver.
After the profiles install, I then export the config. After that I wait 3 seconds, if not the git add config
often doesn't get all the config and the directory may not have finished getting cleared out and restocked.
I hope that help you. If you have any improvements, I'd love to hear them.