Fixes in install_mariadb

This commit is contained in:
absurdo 2023-05-12 01:02:45 +02:00
parent c56366923f
commit eb7e913469
4 changed files with 116 additions and 10 deletions

View file

@ -39,25 +39,74 @@ if linux_distro=='debian':
# /etc/mysql/mariadb.conf.d/50-server.cnf
# bind-address = 127.0.0.1
print('Setting the password...')
if subprocess.call("sudo mysqladmin -u root password "+args.password, shell=True) > 0:
print('Error, cannot set the MariaDB Root password')
sys.exit(1)
if args.ip:
if subprocess.call("sudo sed -i 's/bind-address = 127.0.0.1/bind-address = {}/g' /etc/mysql/mariadb.conf.d/50-server.cnf".format(args.ip), shell=True) > 0:
print('Error, cannot install MariaDB...')
sys.exit(1)
elif linux_distro=='arch':
if call("sudo pacman -S --noconfirm mariadb", shell=True) > 0:
if subprocess.call("sudo pacman -S --noconfirm mariadb", shell=True) > 0:
print('Error, cannot install MariaDB...')
exit(1)
print('Setting the password...')
elif linux_distro=='rocky' or linux_distro=='alma' or linux_distro=='fedora':
if subprocess.call("sudo dnf install -y mariadb-server expect", shell=True) > 0:
print('Error, cannot install MariaDB...')
exit(1)
if subprocess.call("sudo systemctl restart mariadb", shell=True) > 0:
print('Error, cannot start mariadb')
sys.exit(1)
if subprocess.call("sudo mysqladmin -u root password "+args.password, shell=True) > 0:
print('Error, cannot set the MariaDB Root password')
sys.exit(1)
else:
print('Mariadb installed successfully')
sys.exit(0)
print('Setting the password...')
sql_setup="""UPDATE mysql.user SET Password=PASSWORD('{}') WHERE User='root';
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test_\%';
FLUSH PRIVILEGES;""".format(args.password)
"""
with open('./sql_setup.sql', 'w') as f:
f.write(sql_setup)
if subprocess.call("sudo mysql --user=root < ./sql_setup.sql", shell=True) > 0:
print('Error, cannot set the password')
sys.exit(1)
else:
print('Mariadb installed successfully')
sys.exit(0)
"""
if subprocess.call("sudo MYSQL_PASS=%s ./modules/pastafari2/scripts/servers/databases/mariadb/mysql_secure.sh" % args.password, shell=True) > 0:
print('Error, cannot set the password')
sys.exit(1)
else:
print('Mariadb installed successfully')
sys.exit(0)
if args.ip:
if subprocess.call("sudo sed -i 's/pid-file=\/run\/mariadb\/mariadb.pid/pid-file=\/run\/mariadb\/mariadb.pid\nbind-address = {}/g' /etc/my.cnf.d/mariadb-server.cnf".format(args.ip), shell=True) > 0:
print('Error, cannot install MariaDB...')
sys.exit(1)
if subprocess.call("sudo systemctl enable mariadb", shell=True) > 0:
print('Error, cannot enable mariadb')
sys.exit(1)
if subprocess.call("sudo systemctl restart mariadb", shell=True) > 0:
print('Error, cannot restart mariadb')

View file

@ -0,0 +1,25 @@
#!/bin/bash
expect -f - <<-EOF
set timeout 10
spawn mysql_secure_installation
expect "Enter current password for root (enter for none):"
send -- "\r"
expect "Switch to unix_socket authentication"
send -- "n\r"
expect "Set root password?"
send -- "y\r"
expect "New password:"
send -- "${MYSQL_PASS}\r"
expect "Re-enter new password:"
send -- "${MYSQL_PASS}\r"
expect "Remove anonymous users?"
send -- "y\r"
expect "Disallow root login remotely?"
send -- "y\r"
expect "Remove test database and access to it?"
send -- "y\r"
expect "Reload privilege tables now?"
send -- "y\r"
expect eof
EOF