Skip to content

Commit ce8ffa4

Browse files
committed
Add manual update mariadb script.
1 parent 511aafe commit ce8ffa4

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# This script validates and upgrades the MariaDB version to 10.4
4+
5+
# Set MariaDB Target Version
6+
mariadb_v='10.4'
7+
8+
# Load OS informations
9+
source /etc/os-release
10+
11+
# Detect installed mariadb version
12+
IFS=' ' read -r -a mysql_v <<< $(mysqld -V)
13+
mysql_v=$(echo "${mysql_v[2]}" | cut -c1-4)
14+
15+
if [ "$mysql_v" = "$mariadb_v" ]; then
16+
echo "Version is already up to date, cancelling."
17+
exit 0
18+
fi
19+
20+
# Detect operating system and load codename
21+
if [ "$ID" = "ubuntu" ]; then
22+
codename="$(lsb_release -s -c)"
23+
else if [ "$ID" = "debian" ]; then
24+
codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
25+
else
26+
echo "Can't detect the os version, cancelling."
27+
exit 1
28+
fi
29+
30+
# Installing MariaDB repo
31+
echo "Add new MariaDB repository..."
32+
if [ "$id" = "ubuntu" ]; then
33+
echo "deb [arch=amd64] http://ams2.mirrors.digitalocean.com/mariadb/repo/$mariadb_v/$ID $codename main" > $apt/mariadb.list
34+
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 > /dev/null 2>&1
35+
else
36+
echo "deb [arch=amd64] http://ams2.mirrors.digitalocean.com/mariadb/repo/$mariadb_v/$ID $codename main" > $apt/mariadb.list
37+
if [ "$release" -eq 8 ]; then
38+
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key adv --recv-keys --keyserver keyserver.ubuntu.com CBCB082A1BB943DB > /dev/null 2>&1
39+
else
40+
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key adv --recv-keys --keyserver keyserver.ubuntu.com F1656F24C74CD1D8 > /dev/null 2>&1
41+
fi
42+
fi
43+
44+
# Update repository
45+
echo "Update apt repository..."
46+
apt update -qq
47+
48+
# Stop and uninstall mysql server
49+
echo "Stop and remove old MariaDB server..."
50+
systemctl stop mysql > /dev/null 2>&1
51+
apt remove -qq mariadb-server
52+
53+
# Install new version and run upgrader
54+
echo "Installing new MariaDB Server, start and run upgrade..."
55+
apt install -qq mariadb-server
56+
systemctl start mysql > /dev/null 2>&1
57+
mysql_upgrade

0 commit comments

Comments
 (0)