Last active
April 25, 2025 10:13
-
-
Save anavarre/6339b8af92a08dca4ac8c2b27fc839a6 to your computer and use it in GitHub Desktop.
Install latest XB from xb-demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Invoke the script from anywhere (e.g .bashrc alias) | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
check_dependencies() { | |
for cmd in ddev git composer curl jq; do | |
if ! command -v "$cmd" &> /dev/null; then | |
echo "❌ '$cmd' is not installed. Install it and try again." | |
exit 1 | |
fi | |
done | |
} | |
check_xb_demo() { | |
if [[ -f composer.json ]]; then | |
if grep -qw "phenaproxima/xb-demo" composer.json; then | |
return | |
fi | |
fi | |
echo "❌ You must run this script from within the xb-demo repo." | |
echo "" | |
echo "Pull it from [email protected]:phenaproxima/xb-demo.git" | |
} | |
decide_xb_stability() { | |
read -p "Do you want to pull the (l)atest XB tag or would you like to chase (d)ev instead? " answer | |
echo "" | |
if [[ "$answer" =~ ^([lL])$ ]]; then | |
ref="^$(curl -s "https://git.drupalcode.org/api/v4/projects/project%2Fexperience_builder/repository/tags" | jq -r '.[0].name')@alpha" | |
export ref | |
elif [[ "$answer" =~ ^([dd])$ ]]; then | |
ref="0.x-dev" | |
export ref | |
else | |
exit 1 | |
fi | |
} | |
cleanup_repo() { | |
if [[ -d ".ddev" ]]; then | |
ddev stop > /dev/null 2>&1 | |
echo "✅ DDEV environment stopped." | |
ddev delete --omit-snapshot -y > /dev/null 2>&1 | |
echo "✅ DDEV environment deleted." | |
fi | |
git clean -fdx > /dev/null 2>&1 | |
git reset --hard > /dev/null 2>&1 | |
echo "✅ Git repository cleaned." | |
} | |
update_repo() { | |
git fetch origin > /dev/null 2>&1 | |
git checkout main > /dev/null 2>&1 | |
git pull origin main > /dev/null 2>&1 | |
echo "✅ Git repository updated." | |
} | |
prepare_app() { | |
composer require "drupal/experience_builder:${ref}" > /dev/null 2>&1 | |
echo "✅ Using XB ref ${ref}" | |
ddev config --project-type=drupal11 --docroot=web > /dev/null 2>&1 | |
echo "✅ DDEV environment created." | |
ddev composer install > /dev/null 2>&1 | |
echo "✅ Composer dependencies pulled in." | |
} | |
install_drupal() { | |
ddev drush si --db-url=mysql://db:db@db/db --account-pass=admin --yes > /dev/null 2>&1 | |
echo "✅ Drupal install completed (user/pass: admin)." | |
echo "" | |
read -p "Do you want to (v)iew the site or get a (l)ogin link? (v/l) " answer | |
if [[ "$answer" =~ ^([vV])$ ]]; then | |
ddev launch | |
elif [[ "$answer" =~ ^([lL])$ ]]; then | |
ddev drush uli | |
else | |
exit 1 | |
fi | |
} | |
check_dependencies | |
check_xb_demo | |
decide_xb_stability | |
cleanup_repo | |
update_repo | |
prepare_app | |
install_drupal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment