updated creatmysqlscript

This commit is contained in:
2021-10-29 16:02:10 -03:00
parent 20bd5cfa3e
commit 170f5381fe
3 changed files with 118 additions and 74 deletions
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
sudo mv /var/lib/mysql /var/lib/mysql_old
sudo mv /etc/mysql /etc/mysql_backup
mv ~/.librography ~/.librography_backup
sudo apt remove mariadb
sudo apt remove mariadb-server
sudo apt remove mariadb-client
sudo apt remove openjdk-8-jdk
+102 -67
View File
@@ -1,89 +1,124 @@
#!/bin/bash #!/bin/bash
echo "Now we will need update your system and install dependencies, do you want to proceed? "
PS3='Choose a option '
options=("proceed" "Quit")
select opt in "${options[@]}"
do
case $opt in
"proceed")
# ask type of instalation: 1- server / 2- client
########################## temporario #################### ########################## temporario ####################
#sudo apt update #sudo apt update
#sudo apt upgrade #sudo apt upgrade
#sudo apt install openjdk-8-jdk # mariadb-server mariadb-client #sudo apt install openjdk-8-jdk
mkdir ~/.librography
rm ~/.librography/DBUser echo "What is the current configuration for this machine?"
touch ~/.librography/DBUser PS3='Choose a option '
echo "Entre com o nome para o usuario do banco de dados: " options=("server" "client" "Quit")
read dbuser select opt in "${options[@]}"
echo $dbuser >> ~/.librography/DBUser do
case $opt in
"server")
echo "proceed to install server"
rm ~/.librography/DBPass if [ -d /var/lib/mysql/mysql ] ; then
touch ~/.librography/DBPass echo "mysql already installed, skipping!"
echo "Entre com a senha para o usuario do banco de dados: " else
read dbpass sudo apt install mariadb-server
echo $dbpass >> ~/.librography/DBPass echo "now we will proceed with the secure installation and configuration of the database"
#echo "first you will choose the password for Mysql server"
echo "Next you can answer in order: n - y - y - y - y "
read -p "Press enter to continue"
sudo mysql_secure_installation
fi
rm ~/.librography/ipserver if [ -d /var/lib/mysql/gowl ] ; then
touch ~/.librography/ipserver echo " database gowl exist! skipping "
else
rm ~/.librography/IPSERVER
touch ~/.librography/IPSERVER
touch ~/.librography/DefaultPrinter
touch ~/.Librography/DefaultPrinter mkdir ~/.librography
rm ~/.librography/DBUSER
touch ~/.librography/DBUSER
DBUSER=gowl
echo $DBUSER >> ~/.librography/DBUSER
PS3='What is the current configuration for this machine? ' rm ~/.librography/DBPASS
options=("server" "client" "Quit") touch ~/.librography/DBPASS
select opt in "${options[@]}" echo "Entre com a senha para o usuario do banco de dados: "
do read DBPASS
case $opt in echo $DBPASS >> ~/.librography/DBPASS
"server")
echo "proceed to install server"
sudo apt install mariadb-server
echo "now we will proceed with the secure instalaltion and configuration of the database"
echo "you can answer in order: n - y - y - y - y."
read -p "Press enter to continue"
sudo mysql_secure_installation
echo localhost >> ~/.librography/ipserver
sudo mysql <<MYSQL_SCRIPT sudo mysql <<MYSQL_SCRIPT
CREATE DATABASE $dbuser; CREATE DATABASE $DBUSER;
CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpass'; CREATE USER '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASS';
GRANT ALL PRIVILEGES ON $dbuser.* TO '$dbuser'@'localhost'; GRANT ALL PRIVILEGES ON $DBUSER.* TO '$DBUSER'@'localhost';
FLUSH PRIVILEGES; source script.sql
FLUSH PRIVILEGES;
MYSQL_SCRIPT MYSQL_SCRIPT
echo "MySQL user created."
echo "Username: $DBUSER"
echo "Password: $DBPASS"
fi
echo "MySQL user created." IPSERVER=localhost
echo "Username: $dbuser" echo $IPSERVER >> ~/.librography/IPSERVER
echo "Password: $dbpass"
break echo "-------- Installation finished! ------------"
;; echo " DataBase Url/ip: $IPSERVER"
"client") echo " DataBase Username : $DBUSER"
echo "proceed to install a cliente" echo " DataBase Password : $DBPASS"
sudo apt install mariadb-client
echo "Entre com o ip do servidor com o banco de dados: " break
read ipserver ;;
echo $ipserver >> ~/.librography/ipserver "client")
echo "proceed to install a cliente"
sudo apt install mariadb-client
mkdir ~/.librography
rm ~/.librography/IPSERVER
touch ~/.librography/IPSERVER
touch ~/.librography/DefaultPrinter
echo "Enter the database server ip: "
read IPSERVER
echo $IPSERVER >> ~/.librography/IPSERVER
break rm ~/.librography/DBUSER
;; touch ~/.librography/DBUSER
"Quit") DBUSER=gowl
break echo $DBUSER >> ~/.librography/DBUSER
;;
*) echo "invalid option $REPLY";; rm ~/.librography/DBPASS
touch ~/.librography/DBPASS
echo "Entre com a senha do usuario do banco de dados: "
read DBPASS
echo $DBPASS >> ~/.librography/DBPASS
echo "-------- Installation finished! ------------"
echo " DataBase Url/ip: $IPSERVER"
echo " DataBase Username : $DBUSER"
echo " DataBase Password : $DBPASS"
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
break
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac esac
done done
# create shortcut on desktop
# is the mysql already configured?
# proceed with secure install:
#echo "Enter the user name for database: "
#read password
#echo "The Current User Name is $first_name"
#echo
#echo "Enter other users'names: "
#read name1 name2 name3
#$echo "$name1, $name2, $name3 are the other users."
#PASS=`pwgen -s 40 1`
#PASS= dbpass
View File