Skip to content

Instantly share code, notes, and snippets.

@sidharrell
Last active March 21, 2016 10:29
Show Gist options
  • Save sidharrell/f66b7010794cbe887106 to your computer and use it in GitHub Desktop.
Save sidharrell/f66b7010794cbe887106 to your computer and use it in GitHub Desktop.
setupd8.ubuntu
#!/bin/bash
# edits if using:
# current hostname: localhost
# this only affects the message output with the link to the new site, not any functionality
# current local git clone of Drupal 8: /home/$user/Development/drupal
# you will need to locally clone drupal 8. It's a lot more efficient on whatever hosts drupal's git repo.
# current OS: Ubuntu
# requires pwgen, drush, sed, awk, git
# requires the template at https://gist.github.com/sidharrell/47767f2bb468ec65a84d in /etc/apache2/sites-available/template
# requires a "127.0.0.1 *.localhost" in /etc/hosts to fix firefox problem
if [ $# -eq 2 ] && [ `whoami` == root ]; then
echo "Usage: setupd8 <domain> <user>"
user=$2
usertrunc=$(echo $2 | cut -c1-3)
domain=$(echo $usertrunc"_"$1 | tr '-' '_' | cut -c1-16);
echo "This will set up a Drupal 8 installation from the current state of your repository in /home/$user/Development/drupal."
echo "The new site will be reachable in the browser at"
printf "\nhttp://$domain.localhost\n"
echo "At the end of this script Drush will give you the new password for the admin user to login."
echo "/var/www/$domain and it's database will be reset."
else
echo "Incorrect usage";
echo "Usage: setupd8 <domain> <user>"
echo "You must be running as sudo for this to work."
exit 1;
fi
while true; do
read -p "OK? (y/n): " ok;
case $ok in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n.";;
esac
done
root="/var/www/$domain/htdocs"
a2dissite $domain
rm -rf /etc/apache2/sites-available/$domain.conf /var/www/$domain
sed "s/XXXXXX/$domain/g" /etc/apache2/sites-available/template > /etc/apache2/sites-available/$domain.conf
a2ensite $domain
git clone /home/$user/Development/drupal $root
systemctl restart apache2
chown -R $user.www-data $root
find $root -type f -exec chmod 644 {} \;
find $root -type d -exec chmod 2755 {} \;
pw=$(pwgen 13 1)
mysql -e "drop database $domain; drop user '$domain'@'localhost';"
mysql -e "create database $domain; create user '$domain'@'localhost' identified by '$pw';"
mysql -e "grant all on $domain.* to '$domain'@'localhost';"
printf "\n\n"
drush --root=$root si --db-url=mysql://$domain:$pw@localhost:3306/$domain -y
printf "\n\n"
# Enable the development settings (disable CSS/JS aggregation, render caches, etc.)
cp $root/sites/example.settings.local.php $root/sites/default/settings.local.php
echo "include __DIR__ . '/settings.local.php';" | sudo tee -a $root/sites/default/settings.php > /dev/null
# Enable simpletest.module
drush --root=$root en simpletest -y
chown -R $user.www-data $root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment