-
-
Save yorkshire-pudding/ee6a2a3468be38bdeb3e3c7f092b90f8 to your computer and use it in GitHub Desktop.
Create a Backdrop instance using Lando.
This file contains 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
ISSUE=$1 | |
PR=$2 | |
PHP=$3 | |
INSTALL=$4 | |
if [[ $(basename $PWD) = "docroot" ]]; then | |
echo "You are already in a docroot!!! Moving up one level..." | |
cd .. | |
fi | |
if [[ -f ".lando.yml" ]]; then | |
echo ".lando.yml file found!!! Moving up one level..." | |
cd .. | |
fi | |
if [[ -z "${ISSUE}" ]]; then | |
read -e -p "GitHub issue # to work on?: " ISSUE | |
if [[ -z "${ISSUE}" ]]; then | |
ISSUE="$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)" | |
fi | |
fi | |
if [[ -d "$HOME/backdrop/${ISSUE}" ]]; then | |
echo "There seems to be an app in $HOME/backdrop/${ISSUE} already ;) Moving there..." | |
cd "$HOME/backdrop/${ISSUE}" | |
if [[ -f ".lando.yml" && -d "docroot" ]]; then | |
cd docroot | |
echo ".lando.yml file and docroot found ;) Starting app..." | |
lando start | |
return 1 | |
fi | |
if [[ -z "$(ls -A $HOME/backdrop/${ISSUE})" ]]; then | |
echo "Directory is empty. Moving on..." | |
else | |
echo "Directory is NOT empty. Aborting..." | |
return 1 | |
fi | |
else | |
echo "Creating $HOME/backdrop/${ISSUE} and moving there..." | |
mkdir $HOME/backdrop/${ISSUE} | |
cd $HOME/backdrop/${ISSUE} | |
fi | |
if [[ -z "${PR}" ]]; then | |
read -e -p "PR # to pull?: " PR | |
fi | |
if [[ -z "${PHP}" ]]; then | |
read -e -p "PHP version? (defaults to 7.4): " PHP | |
PHP=${PHP:-'7.4'} | |
echo "PHP version set to $PHP" | |
fi | |
if [[ -z "${INSTALL}" ]]; then | |
read -p "Install Backdrop? [y/n]: " -n 1 | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
INSTALL="install" | |
fi | |
fi | |
git clone https://github.com/backdrop/backdrop docroot | |
cd docroot | |
git remote add klonos https://github.com/klonos/backdrop | |
git push -u klonos 1.x:1.x --force | |
if [[ -z "${PR}" ]]; then | |
git checkout -b issue-${ISSUE} | |
else | |
git fetch origin pull/${PR}/head:issue-${ISSUE} | |
fi | |
git checkout issue-${ISSUE} | |
git stash | |
git merge origin/1.x -m "Merge 'origin/1.x' into klonos/issue-${ISSUE}" | |
git stash apply | |
cd .. | |
wget https://gist.githubusercontent.com/klonos/fe7b0b070697cf699646edd5c007db02/raw/124b258926098f00538679af0a2679976c82c45a/.lando.yml | |
sed -i '' -e "s/???/${ISSUE}/g" .lando.yml | |
sed -i '' -e "s/'?.?'/'${PHP}'/g" .lando.yml | |
# Drush 8.x requires PHP 5.4.5+. See https://docs.drush.org/en/7.x/install/#pick-a-version | |
if [[ $(version $PHP) -lt $(version 5.4.5) ]]; then | |
echo "Setting Drush version to 7.x (Drush 8.x requires PHP 5.4.5+)..." | |
# The following command does the job, but strips blank lines from the original | |
# file. No biggie, but follow https://github.com/mikefarah/yq/issues/515 for | |
# any solution in the future. | |
yq e -i '.config.drush = "7^"' .lando.yml | |
fi | |
# Used in order to get the latest stable version of backdrush - this was before | |
# hard-coding backdrush to 1.x-1.x (which always gets the latest HEAD). | |
# BACKDRUSH="$(curl -sL https://api.github.com/repos/backdrop-contrib/drush/releases/latest | jq -r '.tag_name')" | |
# sed -i '' -e "s/'?.?.?'/'${BACKDRUSH}'/g" .lando.yml | |
cd docroot | |
lando start | |
# lando composer require backdrop/coder | |
# lando phpcs --config-set installed_paths /app/docroot/vendor/backdrop/coder/coder_sniffer | |
if [[ "${INSTALL}" = "install" ]]; then | |
lando bee si --profile=standard --db=mysql://root:backdrop@localhost/backdrop --username=admin --password=password --site-name=${ISSUE} --auto | |
# Move settings into settings.local.php, so that they can be git-ignored. | |
echo | |
echo "Changes in settings.php:" | |
git diff -U0 --color settings.php | grep '^\e\[[^m]*m[-+]' | grep -Ev '(--- a/|\+\+\+ b/)' | |
echo "Moving settings from settings.php to settings.local.php..." | |
echo "<?php" >> settings.local.php | |
echo >> settings.local.php | |
awk '/^\$config_directories\['\''.*'\''\]/' settings.php >> settings.local.php | |
awk '/^\$settings\['\''hash_salt'\''\]/' settings.php >> settings.local.php | |
echo "Resetting settings.php..." | |
git restore settings.php | |
echo "Done!" | |
echo | |
echo "Contents of settings.local.php:" | |
cat settings.local.php | |
echo | |
# Currently "drush en" does not work if the module is not present; first use | |
# "drush dl", then follow "drush en", which works: | |
# lando drush dl devel | |
# Use git clone (via bclone), in order to get latest devel HEAD. bclone | |
# accepts PR numbers as additional parameters, and fetches these PRs if they | |
# are still open/unmerged (for testing on local). | |
bclone devel | |
lando bee en devel_generate | |
lando bee cset system.core preprocess_css 0 | |
lando bee cset system.core preprocess_js 0 | |
lando bee cset system.core error_level all | |
lando bee cset admin_bar.settings position_fixed 1 | |
# Remove the following if something like "lando vitals" gets implemented. | |
# See: https://github.com/lando/lando/issues/2506 | |
lando info --format json | jq '.. | objects | with_entries(select(.key | contains("urls"))) | select(. != {}) | .urls | select(. != [])' | jq -r .[] | sed 's/\/*$//g' | |
# cget/cset was not supported before Backdrop drush 1.2.0, so config values | |
# were set directly in .json files using jq. Uncomment the following set of | |
# commands to use that method again. | |
# cd docroot/files/config_*/active | |
# jq --indent 4 '.error_level = "all" | .preprocess_css = 0 | .preprocess_js = 0' system.core.json > system.tmp.$$.json | |
# mv system.tmp.$$.json system.core.json | |
# jq --indent 4 '.position_fixed = 1' admin_bar.settings.json > admin.tmp.$$.json | |
# mv admin.tmp.$$.json admin_bar.settings.json | |
# cd ../../../ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment