(Re)Installing Magento 2 from shell

Sometimes, you accidentally bork your Magento 2 development database. Sometimes, you just want to reinstall as a sanity check. Luckily, you don’t have to re-extract the installer – you can simply un-install and re-install Magento 2 using the ./bin/magento CLI tool, see:

https://devdocs.magento.com/guides/v2.2/install-gde/install/cli/install-cli-install.html

However, the command needs a lot of arguments. I just dropped the following into a shell script at ./bin/reinstall.sh

[0s][/var/www/m2/bin]$ cat ./reinstall.sh
#!/bin/bash

./magento setup:install --admin-firstname Andy --admin-lastname Boyd \
--admin-email [email protected] --admin-user admin \
--admin-password Password1! --base-url http://m2.local --backend-frontname m2_admin \
--db-host localhost --db-name m2 --db-user root --db-password Password1!