Skip to content

Commit b119fe2

Browse files
authored
Update upgrade_mariadb.sh (hestiacp#3391)
1 parent d8cba67 commit b119fe2

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
11
#!/bin/bash
22

3-
# This script validates and upgrades the MariaDB version to 10.5
3+
# This script validates and upgrades the MariaDB version
44

55
#----------------------------------------------------------#
6-
# Variable&Function #
6+
# Variable & Function #
77
#----------------------------------------------------------#
88

99
# Set MariaDB Target Version
1010
mariadb_v='10.11'
1111

12-
# Load OS informations
13-
source /etc/os-release
14-
1512
#----------------------------------------------------------#
16-
# Verifications #
13+
# Verifications #
1714
#----------------------------------------------------------#
1815

19-
# Detect installed mariadb version
20-
IFS=' ' read -r -a mysql_v <<< $(mysqld -V)
21-
mysql_v=$(echo "${mysql_v[2]}" | cut -c1-4)
16+
# Detect installed MariaDB version
17+
mysql_v="$(mysqld -V | awk '{print $3}' | cut -d: -f1)"
2218

23-
if [ "$mysql_v" = "$mariadb_v" ]; then
24-
echo "Version is already up to date, cancelling."
19+
if [ "${mysql_v%.*}" = "$mariadb_v" ]; then
20+
echo "[ ! ] MariaDB version ($mariadb_v) is already up to date."
2521
exit 0
22+
else
23+
echo "[ * ] Upgrading MariaDB version to ($mariadb_v)..."
2624
fi
2725

28-
#Get OS details
29-
os=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=')
26+
# Get OS details
27+
os="$(grep "^ID=" /etc/os-release | cut -d= -f2)"
3028
codename="$(lsb_release -s -c)"
31-
release="$(lsb_release -s -r)"
32-
RHOST='apt.hestiacp.com'
29+
30+
case $(arch) in
31+
x86_64)
32+
arch="amd64"
33+
;;
34+
aarch64)
35+
arch="arm64"
36+
;;
37+
*)
38+
echo "[ ! ] Error: $(arch) is currently not supported!"
39+
exit 1
40+
;;
41+
esac
3342

3443
#----------------------------------------------------------#
35-
# Action #
44+
# Action #
3645
#----------------------------------------------------------#
3746

38-
# Installing MariaDB repo
39-
apt="/etc/apt/sources.list.d/"
40-
echo "[ * ] MariaDB"
41-
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://dlm.mariadb.com/repo/mariadb-server/$mariadb_v/repo/$VERSION $codename main" > $apt/mariadb.list
47+
# Installing MariaDB repository
48+
apt="/etc/apt/sources.list.d"
49+
echo "[ * ] Installing MariaDB repository..."
50+
echo "deb [arch=$arch signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://dlm.mariadb.com/repo/mariadb-server/$mariadb_v/repo/$os $codename main" > $apt/mariadb.list
4251
curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg > /dev/null 2>&1
4352

4453
# Update repository
45-
echo "Update apt repository..."
54+
echo "[ * ] Update apt repository..."
4655
apt update -qq > /dev/null 2>&1
4756

48-
# Stop and uninstall mysql server
49-
echo "Stop and remove old MariaDB server..."
50-
systemctl stop mysql > /dev/null 2>&1
57+
# Stop and uninstall old version
58+
echo "[ * ] Stop and remove old MariaDB Server (${mysql_v%.*})..."
59+
systemctl -q stop mariadb mysql 2> /dev/null
5160
apt remove -qq mariadb-server -y > /dev/null 2>&1
5261

53-
# Install new version and run upgrader
54-
echo "Installing new MariaDB Server, start and run upgrade..."
62+
# Install new version and run upgrade
63+
echo "[ * ] Installing new MariaDB Server, start and run upgrade..."
5564
apt install -qq mariadb-server -y
56-
systemctl start mysql > /dev/null 2>&1
57-
mysql_upgrade
65+
update-rc.d mariadb defaults > /dev/null 2>&1
66+
systemctl -q daemon-reload
67+
systemctl -q enable mariadb
68+
systemctl -q start mariadb
69+
mariadb-upgrade

0 commit comments

Comments
 (0)