Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created June 19, 2013 11:59
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 deekayen/5813738 to your computer and use it in GitHub Desktop.
Save deekayen/5813738 to your computer and use it in GitHub Desktop.
D8 reinstallation script by patrickd http://dropbucket.org/node/657. Resets settings.php, removes config and php cache, deletes all tables of a database.
#!/bin/bash
# Put this into your drupal root as uninstall.sh
# Make it executable with $ chmod +x uninstall.sh
# Add it to your .gitignore $ echo uninstall.sh >> .gitignore
# To disable sudo to demand a password for executing this script:
# execute $ visudo
# and add the following lines with the correct paths and your own username:
# Cmnd_Alias D8_UNINSTALL_SCRIPT = /var/www/drupal/uninstall.sh
# patrickd ALL=(ALL) NOPASSWD: D8_UNINSTALL_SCRIPT
# MySQL username
MUSER="root"
# MySQL password
MPASS="root"
# Database to delete all tables from
MDB="drupal"
echo "Removing files..."
sudo rm -rf sites/default/files/*
echo "Resetting settings.php..."
rm sites/default/settings.php
cp sites/default/default.settings.php sites/default/settings.php
chmod 777 sites/default/settings.php
MYSQL=$(which mysql)
AWK=$(which awk)
GREP=$(which grep)
TABLES=$($MYSQL -u $MUSER -p$MPASS $MDB -e 'show tables' | $AWK '{ print $1}' | $GREP -v '^Tables' )
for t in $TABLES
do
echo "Deleting $t table from $MDB database..."
$MYSQL -u $MUSER -p$MPASS $MDB -e "drop table $t"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment