Skip to content

Commit 671e99c

Browse files
niktestNikita Alekseevjaapmarcus
authored
Added ability to install MySQL 8 (hestiacp#3064)
* Added ability to install classic MySQL * Implemented avoiding installation conflicts when the user chose to install MariaDB and MySQL together * Added support of Print identified with as hex feature, in case of usage MySQL 8 * Add mysql8 repo Fix issue with key become readonly - Mute output gpg --keyserver Don't mute output Check why it fails Check this Clean up code * Fix for rebuild_mysql_database() to make it works along with Print identified with as hex feature, in case of usage MySQL 8 Co-authored-by: Nikita Alekseev <niktest@mail.ru> Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 899e5f9 commit 671e99c

File tree

9 files changed

+187
-74
lines changed

9 files changed

+187
-74
lines changed

.github/ISSUE_TEMPLATE/BUG-REPORT.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ body:
4040
- Control Panel Installation or Upgrade
4141
- Control Panel Web Interface
4242
- (Backend) Web Server (Nginx, Apache2)
43-
- Database (MariaDB, PostgreSQL)
43+
- Database (MariaDB, MySQL, PostgreSQL)
4444
- Let's Encrypt SSL
4545
- Mail (Exim, Dovecot)
4646
- Mail Security (Antivirus, Antispam)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Features and Services
2525
* Multiple PHP versions (5.6 - 8.1, 8.0 as default)
2626
* DNS Server (Bind) with clustering capabilities
2727
* POP/IMAP/SMTP mail services with Anti-Virus, Anti-Spam, and Webmail (ClamAV, SpamAssassin, Sieve, Roundcube)
28-
* MariaDB and/or PostgreSQL databases
28+
* MariaDB/MySQL and/or PostgreSQL databases
2929
* Let's Encrypt SSL support with wildcard certificates
3030
* Firewall with brute-force attack detection and IP lists (iptables, fail2ban, and ipset).
3131

bin/v-add-sys-roundcube

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
source /etc/hestiacp/hestia.conf
1414
# shellcheck source=/usr/local/hestia/func/main.sh
1515
source $HESTIA/func/main.sh
16+
source $HESTIA/func/db.sh
1617
# load config file
1718
source_conf "$HESTIA/conf/hestia.conf"
1819
# upgrade config file
@@ -135,16 +136,21 @@ if [ "$UPDATE" == "no" ]; then
135136
chown www-data:www-data $RC_LOG
136137
chmod 751 $RC_LOG
137138

138-
if [ ! -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
139-
mysql -e "DROP DATABASE IF EXISTS roundcube"
140-
mysql -e "DROP USER IF EXISTS roundcube@localhost"
141-
mysql -e "CREATE DATABASE roundcube"
142-
# Mysql available on system
143-
r=$(generate_password)
144-
mysql -e "GRANT ALL ON roundcube.*
145-
TO roundcube@localhost IDENTIFIED BY '$r'"
146-
sed -i "s/%password%/$r/g" $RC_CONFIG_DIR/config.inc.php
147-
mysql roundcube < /var/lib/roundcube/SQL/mysql.initial.sql
139+
if [ ! -z "$(echo "$DB_SYSTEM" | grep -E 'mysql|pgsql')" ]; then
140+
host='localhost'
141+
database='roundcube'
142+
dbuser="$database"
143+
dbpass=$(generate_password)
144+
charset='UTF8'
145+
sed -i "s/%password%/$dbpass/g" $RC_CONFIG_DIR/config.inc.php
146+
147+
if [ ! -z "$(echo "$DB_SYSTEM" | grep -w 'mysql')" ]; then
148+
add_mysql_database
149+
mysql_query "USE $database; $(< /var/lib/roundcube/SQL/mysql.initial.sql)"
150+
else
151+
add_pgsql_database
152+
psql_query "USE $database; $(< /var/lib/roundcube/SQL/postgres.initial.sql)"
153+
fi
148154
fi
149155

150156
# TODO: Add support for PostgreSQL

bin/v-list-sys-services

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ if [ -n "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'remote' ]; then
239239
mariadb_string="MariaDB"
240240
if [[ ! $mysql_version =~ $mariadb_string ]]; then
241241
# MySQL
242-
service='mysqld'
242+
service='mysql'
243243
proc_name='mysqld'
244244
else
245245
# MariaDB

func/db.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,16 @@ add_mysql_database() {
291291
if [ "$mysql_ver_sub" -ge 8 ] || { [ "$mysql_ver_sub" -eq 5 ] && [ "$mysql_ver_sub_sub" -ge 7 ]; } then
292292
if [ "$mysql_ver_sub" -ge 8 ]; then
293293
# mysql >= 8
294-
md5=$(mysql_query "SHOW CREATE USER \`$dbuser\`" 2>/dev/null)
294+
295+
# This query will be proceeding with the usage of Print identified with as hex feature
296+
md5=$(mysql_query "SET print_identified_with_as_hex=ON; SHOW CREATE USER \`$dbuser\`" 2>/dev/null)
297+
295298
# echo $md5
296-
md5=$(echo "$md5" |grep password |cut -f4 -d \')
299+
if [[ "$md5" =~ 0x([^ ]+) ]]; then
300+
md5=$(echo "$md5" |grep password |grep -E -o '0x([^ ]+)')
301+
else
302+
md5=$(echo "$md5" |grep password |cut -f4 -d \')
303+
fi
297304
# echo $md5
298305
else
299306
# mysql < 8
@@ -410,9 +417,16 @@ change_mysql_password() {
410417
if [ "$mysql_ver_sub" -ge 8 ] || { [ "$mysql_ver_sub" -eq 5 ] && [ "$mysql_ver_sub_sub" -ge 7 ]; } then
411418
if [ "$mysql_ver_sub" -ge 8 ]; then
412419
# mysql >= 8
413-
md5=$(mysql_query "SHOW CREATE USER \`$DBUSER\`" 2>/dev/null)
420+
421+
# This query will be proceeding with the usage of Print identified with as hex feature
422+
md5=$(mysql_query "SET print_identified_with_as_hex=ON; SHOW CREATE USER \`$DBUSER\`" 2>/dev/null)
423+
414424
# echo $md5
415-
md5=$(echo "$md5" |grep password |cut -f4 -d \')
425+
if [[ "$md5" =~ 0x([^ ]+) ]]; then
426+
md5=$(echo "$md5" |grep password |grep -E -o '0x([^ ]+)')
427+
else
428+
md5=$(echo "$md5" |grep password |cut -f4 -d \')
429+
fi
416430
# echo $md5
417431
else
418432
# mysql < 8

func/rebuild.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,12 @@ rebuild_mysql_database() {
790790
# mysql >= 5.7
791791
mysql_query "CREATE USER IF NOT EXISTS \`$DBUSER\`" > /dev/null
792792
mysql_query "CREATE USER IF NOT EXISTS \`$DBUSER\`@localhost" > /dev/null
793-
query="UPDATE mysql.user SET authentication_string='$MD5'"
793+
# mysql >= 8, with enabled Print identified with as hex feature
794+
if [[ "$mysql_ver_sub" -ge 8 && "$MD5" =~ ^0x.* ]]; then
795+
query="UPDATE mysql.user SET authentication_string=UNHEX('${MD5:2}')"
796+
else
797+
query="UPDATE mysql.user SET authentication_string='$MD5'"
798+
fi
794799
query="$query WHERE User='$DBUSER'"
795800
else
796801
# mysql < 5.7

install/hst-install-debian.sh

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ software="nginx apache2 apache2-utils apache2-suexec-custom
4747
php$fpm_v-opcache php$fpm_v-pspell php$fpm_v-readline php$fpm_v-xml
4848
awstats vsftpd proftpd-basic bind9 exim4 exim4-daemon-heavy
4949
clamav-daemon spamassassin dovecot-imapd dovecot-pop3d dovecot-sieve dovecot-managesieved
50-
net-tools mariadb-client mariadb-common mariadb-server postgresql
50+
net-tools mariadb-client mariadb-common mariadb-server mysql-client mysql-common mysql-server postgresql
5151
postgresql-contrib phppgadmin mc flex whois git idn2 unzip zip sudo bc ftp lsof
5252
rrdtool quota e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban
5353
dnsutils bsdmainutils cron hestia=${HESTIA_INSTALL_VER} hestia-nginx
@@ -68,6 +68,7 @@ help() {
6868
-j, --proftpd Install ProFTPD [yes|no] default: no
6969
-k, --named Install Bind [yes|no] default: yes
7070
-m, --mysql Install MariaDB [yes|no] default: yes
71+
-M, --mysql-classic Install MySQL [yes|no] default: no
7172
-g, --postgresql Install PostgreSQL [yes|no] default: no
7273
-x, --exim Install Exim [yes|no] default: yes
7374
-z, --dovecot Install Dovecot [yes|no] default: yes
@@ -207,6 +208,7 @@ for arg; do
207208
--proftpd) args="${args}-j " ;;
208209
--named) args="${args}-k " ;;
209210
--mysql) args="${args}-m " ;;
211+
--mysql-classic) args="${args}-M " ;;
210212
--postgresql) args="${args}-g " ;;
211213
--exim) args="${args}-x " ;;
212214
--dovecot) args="${args}-z " ;;
@@ -234,7 +236,7 @@ done
234236
eval set -- "$args"
235237

236238
# Parsing arguments
237-
while getopts "a:w:v:j:k:m:g:d:x:z:Z:c:t:i:b:r:o:q:l:y:s:e:p:D:fh" Option; do
239+
while getopts "a:w:v:j:k:m:M:g:d:x:z:Z:c:t:i:b:r:o:q:l:y:s:e:p:D:fh" Option; do
238240
case $Option in
239241
a) apache=$OPTARG ;; # Apache
240242
w) phpfpm=$OPTARG ;; # PHP-FPM
@@ -243,6 +245,7 @@ while getopts "a:w:v:j:k:m:g:d:x:z:Z:c:t:i:b:r:o:q:l:y:s:e:p:D:fh" Option; do
243245
j) proftpd=$OPTARG ;; # Proftpd
244246
k) named=$OPTARG ;; # Named
245247
m) mysql=$OPTARG ;; # MariaDB
248+
M) mysqlclassic=$OPTARG ;; # MySQL
246249
g) postgresql=$OPTARG ;; # PostgreSQL
247250
x) exim=$OPTARG ;; # Exim
248251
z) dovecot=$OPTARG ;; # Dovecot
@@ -275,6 +278,7 @@ set_default_value 'vsftpd' 'yes'
275278
set_default_value 'proftpd' 'no'
276279
set_default_value 'named' 'yes'
277280
set_default_value 'mysql' 'yes'
281+
set_default_value 'mysqlclassic' 'no'
278282
set_default_value 'postgresql' 'no'
279283
set_default_value 'exim' 'yes'
280284
set_default_value 'dovecot' 'yes'
@@ -315,6 +319,9 @@ fi
315319
if [ "$apache" = "no" ]; then
316320
phpfpm='yes'
317321
fi
322+
if [ "$mysql" = 'yes' ] && [ "$mysqlclassic" = 'yes' ]; then
323+
mysql='no'
324+
fi
318325

319326
# Checking root permissions
320327
if [ "x$(id -u)" != 'x0' ]; then
@@ -555,6 +562,9 @@ echo
555562
if [ "$mysql" = 'yes' ]; then
556563
echo ' - MariaDB Database Server'
557564
fi
565+
if [ "$mysqlclassic" = 'yes' ]; then
566+
echo ' - MySQL Database Server'
567+
fi
558568
if [ "$postgresql" = 'yes' ]; then
559569
echo ' - PostgreSQL Database Server'
560570
fi
@@ -715,6 +725,24 @@ if [ "$mysql" = 'yes' ]; then
715725
curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg >/dev/null 2>&1
716726
fi
717727

728+
# Installing Mysql8 repo
729+
if [ "$mysqlclassic" = 'yes' ]; then
730+
echo "[ * ] Mysql 8"
731+
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-apt-config" >> /etc/apt/sources.list.d/mysql.list
732+
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-8.0" >> /etc/apt/sources.list.d/mysql.list
733+
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-tools" >> /etc/apt/sources.list.d/mysql.list
734+
echo "#deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-tools-preview" >> /etc/apt/sources.list.d/mysql.list
735+
echo "deb-src [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-8.0" >> /etc/apt/sources.list.d/mysql.list
736+
737+
GNUPGHOME="$(mktemp -d)"
738+
export GNUPGHOME
739+
for keyserver in $(shuf -e ha.pool.sks-keyservers.net hkp://p80.pool.sks-keyservers.net:80 keyserver.ubuntu.com hkp://keyserver.ubuntu.com:80)
740+
do
741+
gpg --no-default-keyring --keyring /usr/share/keyrings/mysql-keyring.gpg --keyserver "${keyserver}" --recv-keys "467B942D3A79BD29" >/dev/null 2>&1 && break
742+
done
743+
fi
744+
745+
718746
# Installing HestiaCP repo
719747
echo "[ * ] Hestia Control Panel"
720748
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/hestia-keyring.gpg] https://$RHOST/ $codename main" > $apt/hestia.list
@@ -886,6 +914,13 @@ if [ "$mysql" = 'no' ]; then
886914
software=$(echo "$software" | sed -e "s/mariadb-server//")
887915
software=$(echo "$software" | sed -e "s/mariadb-client//")
888916
software=$(echo "$software" | sed -e "s/mariadb-common//")
917+
fi
918+
if [ "$mysqlclassic" = 'no' ]; then
919+
software=$(echo "$software" | sed -e "s/mysql-server//")
920+
software=$(echo "$software" | sed -e "s/mysql-client//")
921+
software=$(echo "$software" | sed -e "s/mysql-common//")
922+
fi
923+
if [ "$mysql" = 'no' ] && [ "$mysqlclassic" = 'no' ]; then
889924
software=$(echo "$software" | sed -e "s/php$fpm_v-mysql//")
890925
fi
891926
if [ "$postgresql" = 'no' ]; then
@@ -1113,7 +1148,7 @@ if [ "$phpfpm" = 'yes' ]; then
11131148
fi
11141149

11151150
# Database stack
1116-
if [ "$mysql" = 'yes' ]; then
1151+
if [ "$mysql" = 'yes' ] || [ "$mysqlclassic" = 'yes' ]; then
11171152
installed_db_types='mysql'
11181153
fi
11191154

@@ -1466,11 +1501,12 @@ fi
14661501

14671502

14681503
#----------------------------------------------------------#
1469-
# Configure MariaDB #
1504+
# Configure MariaDB / MySQL #
14701505
#----------------------------------------------------------#
14711506

1472-
if [ "$mysql" = 'yes' ]; then
1473-
echo "[ * ] Configuring MariaDB database server..."
1507+
if [ "$mysql" = 'yes' ] || [ "$mysqlclassic" = 'yes' ]; then
1508+
[ "$mysql" = 'yes' ] && mysql_type="MariaDB" || mysql_type="MySQL"
1509+
echo "[ * ] Configuring $mysql_type database server..."
14741510
mycnf="my-small.cnf"
14751511
if [ $memory -gt 1200000 ]; then
14761512
mycnf="my-medium.cnf"
@@ -1479,28 +1515,43 @@ if [ "$mysql" = 'yes' ]; then
14791515
mycnf="my-large.cnf"
14801516
fi
14811517

1482-
# Run mysql_install_db
1483-
mysql_install_db >> $LOG
1518+
if [ "$mysql_type" = 'MariaDB' ]; then
1519+
# Run mysql_install_db
1520+
mysql_install_db >> $LOG
1521+
fi
1522+
14841523
# Remove symbolic link
14851524
rm -f /etc/mysql/my.cnf
14861525
# Configuring MariaDB
14871526
cp -f $HESTIA_INSTALL_DIR/mysql/$mycnf /etc/mysql/my.cnf
14881527

1528+
# Switch MariaDB inclusions to the MySQL
1529+
if [ "$mysql_type" = 'MySQL' ]; then
1530+
sed -i '/query_cache_size/d' /etc/mysql/my.cnf
1531+
sed -i 's|mariadb.conf.d|mysql.conf.d|g' /etc/mysql/my.cnf
1532+
fi
1533+
14891534
update-rc.d mysql defaults > /dev/null 2>&1
14901535
systemctl start mysql >> $LOG
1491-
check_result $? "mariadb start failed"
1536+
check_result $? "${mysql_type,,} start failed"
14921537

1493-
# Securing MariaDB installation
1538+
# Securing MariaDB/MySQL installation
14941539
mpass=$(gen_pass)
14951540
echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
14961541
chmod 600 /root/.my.cnf
14971542

1498-
# Ater root password
1543+
# Alter root password
14991544
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$mpass'; FLUSH PRIVILEGES;"
1500-
# Allow mysql access via socket for startup
1501-
mysql -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root';"
1502-
# Disable anonymous users
1503-
mysql -e "DELETE FROM mysql.global_priv WHERE User='';"
1545+
if [ "$mysql_type" = 'MariaDB' ]; then
1546+
# Allow mysql access via socket for startup
1547+
mysql -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root';"
1548+
# Disable anonymous users
1549+
mysql -e "DELETE FROM mysql.global_priv WHERE User='';"
1550+
else
1551+
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '$mpass';"
1552+
mysql -e "DELETE FROM mysql.user WHERE User='';"
1553+
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
1554+
fi
15041555
# Drop test database
15051556
mysql -e "DROP DATABASE IF EXISTS test"
15061557
mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
@@ -1517,7 +1568,7 @@ fi
15171568
# shellcheck source=/usr/local/hestia/install/upgrade/upgrade.conf
15181569
source $HESTIA/install/upgrade/upgrade.conf
15191570

1520-
if [ "$mysql" = 'yes' ]; then
1571+
if [ "$mysql" = 'yes' ] || [ "$mysqlclassic" = 'yes' ]; then
15211572
# Display upgrade information
15221573
echo "[ * ] Installing phpMyAdmin version v$pma_v..."
15231574

@@ -1793,11 +1844,21 @@ if [ "$fail2ban" = 'yes' ]; then
17931844
check_result $? "fail2ban start failed"
17941845
fi
17951846

1847+
# Configuring MariaDB/MySQL host
1848+
if [ "$mysql" = 'yes' ] || [ "$mysqlclassic" = 'yes' ]; then
1849+
$HESTIA/bin/v-add-database-host mysql localhost root $mpass
1850+
fi
1851+
1852+
# Configuring PostgreSQL host
1853+
if [ "$postgresql" = 'yes' ]; then
1854+
$HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
1855+
fi
1856+
17961857
#----------------------------------------------------------#
17971858
# Install Roundcube #
17981859
#----------------------------------------------------------#
17991860
# Min requirements Dovecot + Exim + Mysql
1800-
if [ "$mysql" == 'yes' ] && [ "$dovecot" == "yes" ]; then
1861+
if ([ "$mysql" == 'yes' ] || [ "$mysqlclassic" == 'yes' ]) && [ "$dovecot" == "yes" ]; then
18011862
echo "[ * ] Install Roundcube..."
18021863
$HESTIA/bin/v-add-sys-roundcube
18031864
write_config_value "WEBMAIL_ALIAS" "webmail"
@@ -1932,18 +1993,6 @@ if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
19321993
systemctl restart apache2
19331994
fi
19341995

1935-
# Configuring MariaDB host
1936-
if [ "$mysql" = 'yes' ]; then
1937-
$HESTIA/bin/v-add-database-host mysql localhost root $mpass
1938-
fi
1939-
1940-
# Configuring PostgreSQL host
1941-
if [ "$postgresql" = 'yes' ]; then
1942-
$HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
1943-
fi
1944-
1945-
1946-
19471996
# Adding default domain
19481997
$HESTIA/bin/v-add-web-domain admin $servername $ip
19491998
check_result $? "can't create $servername domain"

0 commit comments

Comments
 (0)