Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active October 18, 2018 14:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kyletaylored/9ad838940180b8efb0b3aecfa6f54827 to your computer and use it in GitHub Desktop.
Save kyletaylored/9ad838940180b8efb0b3aecfa6f54827 to your computer and use it in GitHub Desktop.
A shell script to help set up a standard DrupalVM project
#!/bin/bash
# Get project directory and git url
echo "Project code (used for project directory name):"
read project_code
echo "Project repo git url (can be blank):"
read project_git_url
# Clone DrupalVM
git clone git@github.com:geerlingguy/drupal-vm.git $project_code
cd $project_code
# Copy default.config.yml to start altering values
cp default.config.yml config.yml
# Replace config file values.
sed -in "s/^vagrant_hostname.*/vagrant_hostname: ${project_code}.dave/1" config.yml
sed -in "s/^vagrant_machine_name.*/vagrant_machine_name: ${project_code}/1" config.yml
sed -in "s/^vagrant_ip.*/vagrant_ip: 0.0.0.0/1" config.yml
# Assumed most projects aren't Composer based.
sed -in "s/^drupal_build_composer_project.*/drupal_build_composer_project: false/1" config.yml
# Don't run a fresh Drupal build
sed -in "s/^drupal_install_site.*/drupal_install_site: false/1" config.yml
read -r -p "Is this an Acquia project? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]];
then
sed -in "s%^drupal_core_path.*%drupal_core_path: \"{{ drupal_composer_install_dir }}/web/docroot\"%1" config.yml
fi
read -r -p "Is this a Drupal 7 project? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]];
then
# Downgrade Solr version (at least for D7), incompatible with Search API.
# https://www.drupal.org/node/1999310
sed -in "s/^solr_version.*/solr_version: \"5.4.1\"/1" config.yml
# Downgrade PHP to 5.6
sed -in "s/^php_version.*/php_version: \"5.6\"/1" config.yml
fi
# Create the source directory and clone if available.
if [ -z "$project_git_url" ]
then
echo "No repo supplied, skipping..."
else
mkdir -p drupal
cd drupal
git clone $project_git_url web
cd ../
fi
# Install Vagrant plugins
vagrant plugin install vagrant-auto_network
# The following are no longer needed, now autoinstalled by DrupalVM.
#vagrant plugin install vagrant-hostsupdater
#vagrant plugin install vagrant-vbguest
# Set up vagrant server.
vagrant up --provision
vagrant ssh
@kyletaylored
Copy link
Author

Changed delimiter on Acquia line as to not trigger a regex (or whatever was breaking)

@kyletaylored
Copy link
Author

kyletaylored commented Jul 19, 2017

I've been having an issue with characters being added to the config.yml file using sed. In order to edit the single file without a copy, we use the -i or --in-place flag to edit the stream. The problem is, the core sed program on OSX expects a secondary parameter to add a suffix to the file (which causes n or -n to be added).

I updated this to work with the GNU version of sed, so if you're using this on a Mac, you need to install gnu-sed using Homebrew and alias that to sed.

brew install gnu-sed
echo 'alias sed=gsed' >> ~/.bash_profile

More info on Stackoverflow: sed command with -i option failing on Mac

@kyletaylored
Copy link
Author

Had to change .dev to .dave because Chrome forces all .dev domains to use HTTPS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment