Skip to content

Instantly share code, notes, and snippets.

@andrewhenke
Last active July 3, 2021 20:35
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 andrewhenke/cb87e6e1f91909cf9f6e7ddba0334fc7 to your computer and use it in GitHub Desktop.
Save andrewhenke/cb87e6e1f91909cf9f6e7ddba0334fc7 to your computer and use it in GitHub Desktop.
Mattermost MySQL database & user interactive setup tool.
#!/bin/bash
set -euo pipefail
clear
echo "Thank you for using the automatic database & user initialization tool"
echo "This script is developed by Andrew Henke - https://andrewhenke.com"
clear
sudo apt-get install mysql-server &>/dev/null
#Install Screen
interval=1
long_interval=30
{
trap "exit" SIGUSR1
sleep $interval; sleep $interval
while true
do
echo -n '.' # Use dots.
sleep $interval
done; } & # Start a progress bar as a background process.
pid=$!
trap "echo !; kill -USR1 $pid; wait $pid" EXIT # To handle ^C.
echo -n 'Installing MySQL Server - Please wait '
sleep $long_interval
clear
kill -USR1 $pid
wait $pid # Stop the progress bar.
trap EXIT
#End Install Screen
clear
read -r -s -p $'Success! Press enter to initialize the Mattermost database...'
clear
read -p "Enter the name for the Mattermost database: " database
clear
read -p "Enter the name of the Mattermost database user: " dbuser
clear
read -sp "Enter the password for the Mattermost database user: " dbpass
sudo mysql -u "root" -Bse "CREATE DATABASE $database;
CREATE USER '$dbuser'@'%' IDENTIFIED BY '$dbpass';
GRANT ALL PRIVILEGES ON mattermost.* TO '$dbuser'@'%';"
clear
echo "Database $database successfully initialized - User $dbuser created with password $dbpass"
read -r -s -p $'Press enter to continue...\n'
echo "Execution completed - exiting"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment