Last active
July 3, 2021 20:35
-
-
Save andrewhenke/cb87e6e1f91909cf9f6e7ddba0334fc7 to your computer and use it in GitHub Desktop.
Mattermost MySQL database & user interactive setup tool.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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