|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# This script validates and upgrades the MariaDB version to 10.5 |
| 3 | +# This script validates and upgrades the MariaDB version |
4 | 4 |
|
5 | 5 | #----------------------------------------------------------# |
6 | | -# Variable&Function # |
| 6 | +# Variable & Function # |
7 | 7 | #----------------------------------------------------------# |
8 | 8 |
|
9 | 9 | # Set MariaDB Target Version |
10 | 10 | mariadb_v='10.11' |
11 | 11 |
|
12 | | -# Load OS informations |
13 | | -source /etc/os-release |
14 | | - |
15 | 12 | #----------------------------------------------------------# |
16 | | -# Verifications # |
| 13 | +# Verifications # |
17 | 14 | #----------------------------------------------------------# |
18 | 15 |
|
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)" |
22 | 18 |
|
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." |
25 | 21 | exit 0 |
| 22 | +else |
| 23 | + echo "[ * ] Upgrading MariaDB version to ($mariadb_v)..." |
26 | 24 | fi |
27 | 25 |
|
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)" |
30 | 28 | 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 |
33 | 42 |
|
34 | 43 | #----------------------------------------------------------# |
35 | | -# Action # |
| 44 | +# Action # |
36 | 45 | #----------------------------------------------------------# |
37 | 46 |
|
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 |
42 | 51 | curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg > /dev/null 2>&1 |
43 | 52 |
|
44 | 53 | # Update repository |
45 | | -echo "Update apt repository..." |
| 54 | +echo "[ * ] Update apt repository..." |
46 | 55 | apt update -qq > /dev/null 2>&1 |
47 | 56 |
|
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 |
51 | 60 | apt remove -qq mariadb-server -y > /dev/null 2>&1 |
52 | 61 |
|
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..." |
55 | 64 | 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