Support for MySQL 8.0.
This commit is contained in:
Cristhian Martínez Ochoa 2022-10-29 12:38:29 -06:00
parent 32a0f58c24
commit cdd3ffd701
6 changed files with 118 additions and 57 deletions

View file

@ -580,8 +580,8 @@ check_exported_conf() {
tar -C / -xf $file $HOME/.aws/credentials --absolute-names
fi
if [[ $(conf_read mysql) == "true" ]]; then
if tar -tvf $file --absolute-names | grep -oq "/etc/mysql/mariadb.conf.d/90-webinoly.cnf"; then
tar -C / -xf $file /etc/mysql/mariadb.conf.d/90-webinoly.cnf --absolute-names
if tar -tvf $file --absolute-names | grep -oq "$MYSQL_CONF_PATH/90-webinoly.cnf"; then
tar -C / -xf $file $MYSQL_CONF_PATH/90-webinoly.cnf --absolute-names
sudo systemctl restart mysql
fi
fi
@ -639,7 +639,7 @@ export_server() {
[[ -f /opt/webinoly/templates/source/custom_header_http_webinoly.data ]] && local include="$include /opt/webinoly/templates/source/custom_header_http_webinoly.data"
[[ -f /opt/webinoly/templates/source/custom_header_https_webinoly.data ]] && local include="$include /opt/webinoly/templates/source/custom_header_https_webinoly.data"
[[ -f /opt/webinoly/templates/source/custom_header_html_webinoly.data ]] && local include="$include /opt/webinoly/templates/source/custom_header_html_webinoly.data"
[[ -f /etc/mysql/mariadb.conf.d/90-webinoly.cnf ]] && local include="$include /etc/mysql/mariadb.conf.d/90-webinoly.cnf"
[[ -f $MYSQL_CONF_PATH/90-webinoly.cnf ]] && local include="$include /etc/mysql/mariadb.conf.d/90-webinoly.cnf"
[[ -d /etc/nginx/certs ]] && local include="$include /etc/nginx/certs"
sudo tar $exclude -Pcf $destination/$filename $include

View file

@ -9,8 +9,10 @@ readonly svr_version="1.8"
readonly os_ubuntu_supported=(bionic focal jammy) # https://ubuntu.com/about/release-cycle
readonly php_supported=(7.4 8.0 8.1 8.2) # https://www.php.net/supported-versions.php
readonly php_default="8.1"
readonly mysql_supported=(10.4 10.5 10.6) # https://mariadb.com/kb/en/mariadb-server-release-dates/
readonly mysql_default="10.6"
readonly mariadb_supported=(10.4 10.5 10.6) # https://mariadb.com/kb/en/mariadb-server-release-dates/
readonly mariadb_default="10.6"
readonly mysql_supported=(8.0)
readonly mysql_default="8.0"
readonly datadog_agent_ver="7"
readonly tools_port_default="22222"
@ -71,6 +73,9 @@ conf_write() {
ADMIN_PASS=$( echo $(conf_read mysql-admin) | openssl enc -d -a -salt )
[[ -z $ADMIN_PASS ]] && readonly ADMIN_PASS="dUmb" || readonly ADMIN_PASS=$ADMIN_PASS # Never empty, prevent asking password!
# MySQL folder
[[ $(conf_read db-engine) == "mysql" ]] && readonly MYSQL_CONF_PATH="/etc/mysql/mysql.conf.d" || readonly MYSQL_CONF_PATH="/etc/mysql/mariadb.conf.d"
# Current original user HOME even with sudo (root) - This script always run with sudo, so $HOME is always /root
# https://askubuntu.com/questions/1186999/how-does-sudo-handle-home-differently-since-19-10
readonly CURRENT_HOME=$(eval echo ~${SUDO_USER:-${USER}})
@ -120,10 +125,19 @@ check_php_version() {
}
check_mysql_version() {
local check="false"
for val in "${mysql_supported[@]}"
do
[[ $val == $1 ]] && check="true"
done
# It works for both MySQL and MariaDB!
if [[ $(conf_read db-engine) == "mysql" ]]; then
for val in "${mysql_supported[@]}"
do
[[ $val == $1 ]] && check="true"
done
else
for val in "${mariadb_supported[@]}"
do
[[ $val == $1 ]] && check="true"
done
fi
echo $check
}
@ -1238,28 +1252,28 @@ dbword_check() {
cnf_delete() {
#Example: cnf_delete error_log
[[ -f /etc/mysql/mariadb.conf.d/90-webinoly.cnf ]] && sudo sed -i "/^$1 /d" /etc/mysql/mariadb.conf.d/90-webinoly.cnf
[[ -f $MYSQL_CONF_PATH/90-webinoly.cnf ]] && sudo sed -i "/^$1 /d" $MYSQL_CONF_PATH/90-webinoly.cnf
}
cnf_write() {
#Example: cnf_write error_log /var/log/mysql/error.log
cnf_delete $1
[[ -n $2 ]] && local value="= $2"
echo "$1 $value" >> /etc/mysql/mariadb.conf.d/90-webinoly.cnf
echo "$1 $value" >> $MYSQL_CONF_PATH/90-webinoly.cnf
}
cnf_read() {
#Example: cnf_read error_log
echo $( grep -P "^$1 = " /etc/mysql/mariadb.conf.d/90-webinoly.cnf | cut -f 2 -d "=" -s | sed 's/ //g' )
echo $( grep -P "^$1 = " $MYSQL_CONF_PATH/90-webinoly.cnf | cut -f 2 -d "=" -s | sed 's/ //g' )
}
mysql_default_cnf() {
# Creates the default Webinoly Configuration File (.cnf) for mysql if not exists.
if [[ ! -f /etc/mysql/mariadb.conf.d/90-webinoly.cnf ]]; then
sudo touch /etc/mysql/mariadb.conf.d/90-webinoly.cnf
sudo chmod 644 /etc/mysql/mariadb.conf.d/90-webinoly.cnf
sudo chown -R root:root /etc/mysql/mariadb.conf.d/90-webinoly.cnf
if [[ ! -f $MYSQL_CONF_PATH/90-webinoly.cnf ]]; then
sudo touch $MYSQL_CONF_PATH/90-webinoly.cnf
sudo chmod 644 $MYSQL_CONF_PATH/90-webinoly.cnf
sudo chown -R root:root $MYSQL_CONF_PATH/90-webinoly.cnf
echo "# Webinoly MySQL Configuration File
[mysqld]
log_error = /var/log/mysql/error.log" >> /etc/mysql/mariadb.conf.d/90-webinoly.cnf
log_error = /var/log/mysql/error.log" >> $MYSQL_CONF_PATH/90-webinoly.cnf
fi
}

View file

@ -215,11 +215,18 @@ mysql_install() {
local reinstall="true"
fi
# MariaDB Installation
local ver=$(conf_read mysql-ver)
echo "mariadb-server-${ver} mysql-server/root_password password $AUTOGENPASS_ROOT" | debconf-set-selections
echo "mariadb-server-${ver} mysql-server/root_password_again password $AUTOGENPASS_ROOT" | debconf-set-selections
sudo apt -y install apt-transport-https dirmngr mariadb-server
# MySQL Installation
if [[ $(conf_read db-engine) == "mysql" ]]; then
echo "mysql-community-server mysql-community-server/root-pass password $AUTOGENPASS_ROOT" | debconf-set-selections
echo "mysql-community-server mysql-community-server/re-root-pass password $AUTOGENPASS_ROOT" | debconf-set-selections
echo "mysql-community-server mysql-server/default-auth-override select Use Strong Password Encryption (RECOMMENDED)" | debconf-set-selections
sudo apt -y install mysql-server
else
local ver=$(conf_read mysql-ver)
echo "mariadb-server-${ver} mysql-server/root_password password $AUTOGENPASS_ROOT" | debconf-set-selections
echo "mariadb-server-${ver} mysql-server/root_password_again password $AUTOGENPASS_ROOT" | debconf-set-selections
sudo apt -y install apt-transport-https dirmngr mariadb-server
fi
conf_write mysql true
@ -250,7 +257,7 @@ _EOF_
mysql_client_install() {
api-events_update im2
sudo apt -y install mariadb-client
[[ $(conf_read db-engine) != "mysql" ]] && sudo apt -y install mariadb-client || sudo apt -y install mysql-client
conf_write mysql-client true
api-events_update im3
echo "${gre}MySQL Client has been successfully installed!${end}"
@ -887,16 +894,26 @@ stack_builder() {
fi
if [[ $3 =~ ^(mysql|mysql-client)$ && $(conf_read mysql-client) != "true" ]]; then
[[ -n $(conf_read mysql-ver) && $(check_mysql_version $(conf_read mysql-ver)) == "true" ]] || conf_write mysql-ver $mysql_default
if [[ -n $(conf_read mysql-ver) && $(check_mysql_version $(conf_read mysql-ver)) == "true" ]]; then
echo "${blu}Retrieving a saved MySQL/MariaDB version configured before...${dim}${end}"
else
echo "${blu}Setting the default MySQL/MariaDB version...${dim}${end}"
[[ $(conf_read db-engine) == "mysql" ]] && conf_write mysql-ver $mysql_default || conf_write mysql-ver $mariadb_default
fi
# REMOVE: when a new LTS is released and jammy supports more than one version.
if [[ $(conf_read mysql-ver) != "10.6" && $(lsb_release -c | cut -d':' -f 2 | xargs) == "jammy" ]]; then
if [[ $(conf_read db-engine) != "mysql" && $(conf_read mysql-ver) != "10.6" && $(lsb_release -c | cut -d':' -f 2 | xargs) == "jammy" ]]; then
conf_write mysql-ver 10.6
echo "${gre}Force MariaDB 10.6 because is the only LTS version supported in Ubuntu 22.04!${end}"
fi
if [[ $(conf_read db-engine) == "mysql" ]]; then
[[ ! -s /usr/share/keyrings/mysql-archive-keyring.gpg ]] && sudo rm -rf /usr/share/keyrings/mysql-archive-keyring.gpg # Prevent issues!
[[ ! -f /usr/share/keyrings/mysql-archive-keyring.gpg ]] && wget -nv -O- 'https://repo.mysql.com/RPM-GPG-KEY-mysql-2022' | sudo gpg --dearmor -o /usr/share/keyrings/mysql-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/mysql-archive-keyring.gpg] http://repo.mysql.com/apt/ubuntu $(lsb_release -cs) mysql-8.0" | sudo tee /etc/apt/sources.list.d/mysql.list
# https://mariadb.org/download/?t=repo-config
if [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
elif [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
echo | sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://mirrors.syringanetworks.net/mariadb/repo/$(conf_read mysql-ver)/ubuntu $(check_osname) main"
else

View file

@ -594,15 +594,28 @@ local ver_four_war="0"
# MySQL
if [[ $(conf_read mysql) == "true" ]]; then
# To check supported versions: https://mariadb.com/kb/en/mariadb-server/
local ver_mysql_ver=$(sudo mysql --version | sed 's/.*Distrib \([^\-]*\).*/\1/' | cut -f 1-2 -d'.')
if [[ $(conf_read db-engine) == "mysql" ]]; then
local ver_mysql_ver=$(sudo mysql --version | grep -Eo "Ver [0-9\.]+" | cut -f 2 -d' ' | cut -f 1-2 -d'.')
else
# To check supported versions: https://mariadb.com/kb/en/mariadb-server/
local ver_mysql_ver=$(sudo mysql --version | sed 's/.*Distrib \([^\-]*\).*/\1/' | cut -f 1-2 -d'.')
fi
if [[ ! -d /etc/mysql ]]; then
echo "- [ERROR] Folder: /etc/mysql not found!"
local ver_four_err="1"
fi
if [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
if [[ $(conf_read db-engine) == "mysql" ]]; then
if [[ ! -f /usr/share/keyrings/mysql-archive-keyring.gpg || ! -s /usr/share/keyrings/mysql-archive-keyring.gpg ]]; then
echo "- [ERROR] MySQL Apt Key not found!"
local ver_four_err="1"
fi
if [[ ! -f /etc/apt/sources.list.d/mysql.list || ! -s /etc/apt/sources.list.d/mysql.list ]]; then
echo "- [ERROR] MySQL PPA not found in sources list!"
local ver_four_err="1"
fi
elif [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
if [[ ! -f /etc/apt/trusted.gpg || -z $(grep -Foia "mariadb signing key" /etc/apt/trusted.gpg) ]]; then
echo "- [ERROR] MariaDB Apt Key not found!"
local ver_four_err="1"
@ -649,8 +662,9 @@ if [[ -z $critical_mode ]]; then
local ver_four_war="1"
fi
if ! [[ $ver_mysql_ver =~ ^(10.0|10.1|10.2|10.3|10.4|10.5|10.6)$ ]]; then
echo "${dim}- [WARNING] Unknown MariaDB (MySQL) version!${end}${red}"
# MySQL and MariaDB can be mixed, don't worry!
if ! [[ $ver_mysql_ver =~ ^(8.0|10.0|10.1|10.2|10.3|10.4|10.5|10.6)$ ]]; then
echo "${dim}- [WARNING] Unknown MySQL/MariaDB version!${end}${red}"
local ver_four_war="1"
elif [[ $ver_mysql_ver =~ ^(10.0|10.1)$ ]]; then
echo "${dim}- [WARNING] You have an obsolete MariaDB version (${ver_mysql_ver}) installed that not even receive security updates!${end}${red}"

View file

@ -396,14 +396,24 @@
###########################
##### MySQL #####
###########################
#####################################
##### MySQL / MariaDB #####
#####################################
# MariaDB Version
# Database Engine
# Values: mariadb | mysql
# Default: mariadb
# Note: (set before installing, server-reset not needed)
# Note: NEVER change this value here when MySQL/MariaDB package is already installed.
###########################
#db-engine:mariadb
# MySQL/MariaDB Version
# Values: https://mariadb.com/kb/en/mariadb-server-release-dates/ (at least latest three stable)
# Default: <latest-stable>
# Note: (set before installing, server-reset not needed)
# Note: In case of MySQL, 8.0 is the only supported version.
# Note: NEVER change this value here when MySQL (MariaDB) package is already installed, use the proper command instead.
# Same as: sudo stack -mysql-ver=10.6 (<-This is the proper command to change the MarianDB version even when is already installed)
###########################
@ -431,7 +441,7 @@
#dbrole:full
# MySQL General Log
# MySQL/MariaDB General Log
# Values: boolean (true/false)
# Default: false
# Note: When enabled, you can see this log in real-time using 'sudo log -mysql=general'
@ -439,7 +449,7 @@
#mysql-log-general:false
# MySQL Binary Log
# MySQL/MariaDB Binary Log
# Values: boolean (true/false)
# Default: false
# Note: When enabled, you can see this log in real-time using 'sudo log -mysql=binary'
@ -447,7 +457,7 @@
#mysql-log-binary:false
# MySQL Slow Query Log
# MySQL/MariaDB Slow Query Log
# Values: boolean (true/false)
# Default: false
# Note: When enabled, you can see this log in real-time using 'sudo log -mysql=slow'
@ -455,7 +465,7 @@
#mysql-log-slow:false
# MySQL Long Query Time
# MySQL/MariaDB Long Query Time
# Values: number int (seconds)
# Default: 10
# Note: If a query takes longer than this many seconds to execute, the query is logged to the slow query log.
@ -463,7 +473,7 @@
#mysql-long-query-time:3
# MySQL Public/External Access
# MySQL/MariaDB Public/External Access
# Values: boolean (true/false)
# Default: false
# Same as: sudo webinoly -mysql-public-access=on

View file

@ -22,10 +22,14 @@ if [[ ${purge,,} == "force" || ${purge_server_all,,} == "force" || ${php,,} == "
fi
purge_mysql_client() {
sudo apt -y purge mariadb-client
[[ $(conf_read db-engine) == "mysql" ]] && sudo apt -y purge mysql-client || sudo apt -y purge mariadb-client
if [[ $(conf_read db-engine) == "mysql" ]]; then
sudo rm -rf /etc/apt/trusted.gpg.d/mysql_release_signing_key.asc
sudo rm -rf /etc/apt/sources.list.d/mysql.list
# APT-KEY deprecated in 22.04
if [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
elif [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
echo | sudo add-apt-repository --remove "http://mirrors.syringanetworks.net/mariadb/repo/$(conf_read mysql-ver)/ubuntu"
sudo apt-key del 0xF1656F24C74CD1D8
else
@ -234,26 +238,28 @@ elif [[ -n $purge && -n $mysql ]]; then
[[ $(conf_read mysql-tool-pma) == "true" ]] && stack -pma -purge=force
mysqlver=$(conf_read mysql-ver)
sudo systemctl stop mysql
if [[ $mysql == "keep-data" ]]; then
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean false" | debconf-set-selections
else
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean true" | debconf-set-selections
fi
sudo rm -rf /etc/mysql/*.conf.d/* # Prevent warnings when purging packages
# Purge is better, instead of remove even when keep-data is enabled, it prevents warnings during reinstallation.
sudo apt -y purge mariadb-server mariadb-common mysql-common
purge_mysql_client
purge_autoremove="true"
# APT-KEY deprecated in 22.04
if [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
echo | sudo add-apt-repository --remove "http://mirrors.syringanetworks.net/mariadb/repo/${mysqlver}/ubuntu"
if [[ $(conf_read db-engine) == "mysql" ]]; then
if [[ $mysql == "keep-data" ]]; then
echo "mysql-community-server mysql-community-server/remove-data-dir boolean false" | debconf-set-selections
else
echo "mysql-community-server mysql-community-server/remove-data-dir boolean true" | debconf-set-selections
fi
sudo apt -y purge mysql-server mysql-common mysql-common
else
sudo rm -rf /usr/share/keyrings/mariadb-archive-keyring.gpg
sudo rm -rf /etc/apt/sources.list.d/mariadb.list
if [[ $mysql == "keep-data" ]]; then
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean false" | debconf-set-selections
else
echo "mariadb-server-${mysqlver} mariadb-server-${mysqlver}/postrm_remove_databases boolean true" | debconf-set-selections
fi
sudo apt -y purge mariadb-server mariadb-common mysql-common
fi
purge_mysql_client
purge_autoremove="true"
if [[ $mysql != "keep-data" ]]; then
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql