Skip to content

Instantly share code, notes, and snippets.

@dale42
Created June 22, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dale42/be415d17404151d49baacb20a1400317 to your computer and use it in GitHub Desktop.
Save dale42/be415d17404151d49baacb20a1400317 to your computer and use it in GitHub Desktop.
A bash script to rebuild a Drupal site from scratch. Although most of the values are parameterized, it is not meant to be a fully generic script and will require site-by-site customization.
#!/bin/bash
# Reinstall a Drupal instance to reset it back to a know state.
# A file base and Drush alias must already be configured.
DRUSH8='/Users/dale/bin/drush8/vendor/bin/drush'
DRUPALDIR='/Users/dale/Sites/group428'
CONFIGDIR='sites/default/group42config/sync'
DRUSHID='@g428'
SITE_NAME='Group 428'
ACCOUNT='admin'
PASS='an-appropriate-password'
EMAIL='no-reply@group42.ca'
DB_URL='mysql://group428:group428@localhost/group428'
# Nuke the database
$DRUSH8 $DRUSHID sql-drop --yes
# Nuke the filebase
echo "Resetting files"
chmod -R u+w $DRUPALDIR/*
rm $DRUPALDIR/sites/default/settings.php
rm -r $DRUPALDIR/sites/default/files
rm -r $DRUPALDIR/$CONFIGDIR
# Fresh Drupal install
cd $DRUPALDIR
$DRUSH8 site-install standard --db-url=$DB_URL --site-name=$SITE_NAME --account-name=$ACCOUNT --account-pass=$PASS --account-mail=$EMAIL --yes
# Base configuration
$DRUSH8 $DRUSHID en admin_toolbar,admin_toolbar_tools --yes
# Allow upcoming changes to settings.php
chmod u+w $DRUPALDIR/sites/default
chmod u+w $DRUPALDIR/sites/default/settings.php
# Configuration Management
sed -i '' "/config\_directories\['sync'\]/d" $DRUPALDIR/sites/default/settings.php
echo "\$config_directories['sync'] = '$CONFIGDIR';" >> $DRUPALDIR/sites/default/settings.php
# Migrate
echo "\ninclude 'settings-migrate.php';" >> $DRUPALDIR/sites/default/settings.php
$DRUSH8 $DRUSHID en migrate,migrate_drupal,migrate_plus,migrate_tools,migrate_upgrade --yes
# Login
$DRUSH8 $DRUSHID uli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment