Created
April 20, 2017 10:13
-
-
Save teslamint/4d33c339dca6d7b458dc16ceccb55db7 to your computer and use it in GitHub Desktop.
fork of mariadb_repo_setup from downloads.mariadb.com/MariaDB/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# shellcheck disable=2016 disable=1091 disable=2059 | |
# This script will identify the OS distribution and version, make sure it's | |
# supported, and set up the appropriate MariaDB software repositories. | |
supported="These Linux OSs are supported, on x86-64 only: | |
RHEL/CentOS 6 & 7; Ubuntu 14.04 LTS (trusty) & 16.04 LTS (xenial); | |
Debian 7 (wheezy) & 8 (jessie); SLES 12" | |
supported_arr=( | |
"RHEL/CentOS 6" "RHEL/CentOS 7" | |
"Ubuntu 14.04 LTS (trusty)" "Ubuntu 16.05 LTS (xenial)" | |
"Debian 7 (wheezy)" "Debian 8 (jessie)" | |
"SLES 12" ) | |
# Override with --mariadb-server-version | |
mariadb_server_version=mariadb-10.1 | |
# Override with --mariadb-maxscale-version | |
mariadb_maxscale_version=latest | |
# Override with --write-to-stdout | |
write_to_stdout=0 | |
skip_server=0 | |
skip_maxscale=0 | |
skip_tools=0 | |
usage="Usage: curl -sS https://downloads.mariadb.com/Tools/mariadb_repo_setup | bash -s -- [OPTIONS] | |
$supported | |
--help Display this help and exit. | |
--mariadb-server-version=<mariadb server version> | |
Override the default MariaDB Server version. | |
By default, the script will use '$mariadb_server_version'. | |
--mariadb-maxscale-version=<mariadb maxscale version> | |
Override the default MariaDB MaxScale version. | |
By default, the script will use '$mariadb_maxscale_version'. | |
--skip-server Skip the 'MariaDB Server' repository. | |
--skip-maxscale Skip the 'MaxScale' repository. | |
--skip-tools Skip the 'Tools' repository. | |
--write-to-stdout Write output to stdout instead of to the OS's | |
repository configuration. This will also skip | |
importing GPG keys and updating the package | |
cache on platforms where that behavior exists. | |
" | |
# repo_type = deb, rhel, sles | |
repo_type= | |
# os_type = ubuntu, debian, rhel, sles | |
os_type= | |
# os_version as demanded by the OS (codename, major release, etc.) | |
os_version= | |
# These GPG key IDs are used to fetch keys from a keyserver on Ubuntu & Debian | |
key_ids=( 0x8167EE24 0xE3C94F49 0xcbcb082a1bb943db 0xF1656F24C74CD1D8 ) | |
# These GPG URLs are used to fetch GPG keys on RHEL and SLES | |
key_urls=( | |
https://downloads.mariadb.com/MariaDB/MariaDB-Server-GPG-KEY | |
https://downloads.mariadb.com/MaxScale/MariaDB-MaxScale-GPG-KEY | |
https://downloads.mariadb.com/MariaDB/MariaDB-Enterprise-GPG-KEY | |
) | |
usage(){ | |
printf "$usage" "$0" | |
} | |
error(){ | |
printf '[ERROR] %s\n' "$@" | |
exit 1 | |
} | |
while :; do | |
case $1 in | |
--mariadb-server-version) | |
if [[ -n $2 ]] && [[ $2 != --* ]]; then | |
mariadb_server_version=$2 | |
shift | |
else | |
error "The $1 option requires an argument." | |
exit 1 | |
fi | |
;; | |
--mariadb-server-version=?*) | |
mariadb_server_version=${1#*=} | |
;; | |
--mariadb-server-version=) | |
error "The $1 option requires an argument." | |
;; | |
--mariadb-maxscale-version) | |
if [[ -n $2 ]] && [[ $2 != --* ]]; then | |
mariadb_maxscale_version=$2 | |
shift | |
else | |
error "The $1 option requires an argument." | |
exit 1 | |
fi | |
;; | |
--mariadb-maxscale-version=?*) | |
mariadb_maxscale_version=${1#*=} | |
;; | |
--mariadb-maxscale-version=) | |
error "The $1 option requires an argument." | |
;; | |
--write-to-stdout) | |
write_to_stdout=1 | |
;; | |
--skip-server) | |
skip_server=1 | |
;; | |
--skip-maxscale) | |
skip_maxscale=1 | |
;; | |
--skip-tools) | |
skip_tools=1 | |
;; | |
--help) | |
usage | |
exit | |
;; | |
-?*) | |
printf '[WARN] Unknown option (ignored): %s\n' "$1" >&2 | |
;; | |
*) | |
break | |
esac | |
shift | |
done | |
open_outfile(){ | |
if (( write_to_stdout )) | |
then | |
exec 4>&1 | |
else | |
case $1 in | |
deb) outfile=/etc/apt/sources.list.d/mariadb.list ;; | |
rhel) outfile=/etc/yum.repos.d/mariadb.repo ;; | |
sles) outfile=/etc/zypp/repos.d/mariadb.repo ;; | |
esac | |
if [[ -e $outfile ]] | |
then | |
local suffix=0 | |
while [[ -e $outfile.old_$((++suffix)) ]]; do :; done | |
printf '[WARNING] Found existing file at %s. Moving to %s.\n' "$outfile" "$outfile.old_$suffix" >&2 | |
if ! mv "$outfile" "$outfile.old_$suffix" | |
then | |
error "Could not move existing '$outfile'. Aborting. Execute this script with the --write-to-stdout"\ | |
"option to see its effect without becoming root." | |
fi | |
fi | |
if ! exec 4>"$outfile" | |
then | |
error "Could not open file $outfile for writing. Aborting. Execute this script with the --write-to-stdout"\ | |
"option to see its effect without becoming root." | |
fi | |
fi | |
} | |
arch=$(uname -m) | |
case $arch in | |
x86_64) ;; | |
*) error "The MariaDB Repository only supports x86_64 (detected $arch)." "$supported" ;; | |
esac | |
# Check for macOS | |
if [[ $(uname -s) == Darwin ]] | |
then | |
printf '%s\n' \ | |
'To install MariaDB Server from a repository on macOS, please use Homebrew:'\ | |
' https://mariadb.com/kb/en/mariadb/installing-mariadb-on-macos-using-homebrew/' | |
exit | |
# Check for RHEL/CentOS, Fedora, etc. | |
elif command -v rpm >/dev/null && [[ -e /etc/redhat-release ]] | |
then | |
repo_type=rhel | |
os_type=rhel | |
el_version=$(rpm -qa '(oraclelinux|sl|redhat|centos|fedora)-release(|-server)' --queryformat '%{VERSION}') | |
case $el_version in | |
5*) os_version=5 ; error "RHEL/CentOS 5 is no longer supported." "$supported" ;; | |
6*) os_version=6 ;; | |
7*) os_version=7 ;; | |
*) error "Detected RHEL or compatible but version ($el_version) is not supported." "$supported" ;; | |
esac | |
elif [[ -e /etc/os-release ]] | |
then | |
. /etc/os-release | |
# Is it Debian? | |
case $ID in | |
debian) | |
repo_type=deb | |
os_type=debian | |
debian_version=$(< /etc/debian_version) | |
case $debian_version in | |
7*) os_version=wheezy ;; | |
8*) os_version=jessie ;; | |
# 9*) os_version=stretch ;; # not currently supported | |
*) error "Detected Debian but version ($debian_version) is not supported." "$supported" ;; | |
esac | |
;; | |
ubuntu) | |
repo_type=deb | |
os_type=ubuntu | |
. /etc/lsb-release | |
os_version=$DISTRIB_CODENAME | |
case $os_version in | |
precise ) error 'Ubuntu version 12.04 LTS has reached End of Life and is no longer supported.' ;; | |
trusty|xenial) ;; | |
*) error "Detected Ubuntu but version ($os_version) is not supported." "Only Ubuntu LTS releases are supported." ;; | |
esac | |
;; | |
sles) | |
repo_type=sles | |
os_type=sles | |
os_version=${VERSION_ID%%.*} | |
case $os_version in | |
# 11) ;; # not currently supported | |
12) ;; | |
*) error "Detected SLES but version ($os_version) is not supported." ;; | |
esac | |
;; | |
esac | |
fi | |
if ! [[ $repo_type ]] || ! [[ $os_type ]] || ! [[ $os_version ]] | |
then | |
error "Could not identify OS type or version." | |
fi | |
rhel_repo_server='[mariadb-main] | |
name = MariaDB Server | |
baseurl = https://downloads.mariadb.com/MariaDB/%s/yum/rhel/$releasever/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY | |
gpgcheck = 1 | |
enabled = 1' | |
rhel_repo_maxscale='[mariadb-maxscale] | |
# To use the latest stable release of MaxScale, use "latest" as the version | |
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version | |
name = MariaDB MaxScale | |
baseurl = https://downloads.mariadb.com/MaxScale/%s/rhel/$releasever/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY | |
gpgcheck = 1 | |
enabled = 1' | |
rhel_repo_tools='[mariadb-tools] | |
name = MariaDB Tools | |
baseurl = https://downloads.mariadb.com/Tools/rhel/$releasever/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY | |
gpgcheck = 1 | |
enabled = 1' | |
deb_repo_server='# MariaDB Server | |
# To use a different major version of the server, or to pin to a specific minor version, change URI below. | |
deb http://downloads.mariadb.com/MariaDB/%s/repo/%s %s main' | |
deb_repo_maxscale='# MariaDB MaxScale | |
# To use the latest stable release of MaxScale, use "latest" as the version | |
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version | |
deb http://downloads.mariadb.com/MaxScale/%s/%s %s main' | |
deb_repo_tools='# MariaDB Tools | |
deb http://downloads.mariadb.com/Tools/%s %s main' | |
sles_repo_server='[mariadb-server] | |
name = MariaDB Server | |
baseurl = https://downloads.mariadb.com/MariaDB/%s/yum/sles/%s/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY | |
gpgcheck = 1 | |
type=rpm-md | |
enabled = 1 | |
priority=10' | |
sles_repo_maxscale='[mariadb-maxscale] | |
# To use the latest stable release of MaxScale, use "latest" as the version | |
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version | |
name = MariaDB MaxScale | |
baseurl = https://downloads.mariadb.com/MaxScale/%s/sles/%s/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY | |
enabled = 1 | |
gpgcheck = 1 | |
type=rpm-md | |
priority=10' | |
sles_repo_tools='[mariadb-tools] | |
name = MariaDB Tools | |
baseurl = https://downloads.mariadb.com/Tools/sles/%s/$basearch | |
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY | |
enabled = 1 | |
gpgcheck = 1 | |
type=rpm-md | |
priority=10' | |
open_outfile "$repo_type" | |
case $repo_type in | |
deb) | |
{ | |
((skip_server)) || printf "$deb_repo_server\n\n" "$mariadb_server_version" "$os_type" "$os_version" | |
((skip_maxscale)) || printf "$deb_repo_maxscale\n\n" "$mariadb_maxscale_version" "$os_type" "$os_version" | |
((skip_tools)) || printf "$deb_repo_tools\n" "$os_type" "$os_version" | |
} >&4 | |
if ! ((write_to_stdout)) | |
then | |
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys "${key_ids[@]}" | |
apt-get update | |
fi | |
;; | |
rhel) | |
{ | |
((skip_server)) || printf "$rhel_repo_server\n\n" "$mariadb_server_version" | |
((skip_maxscale)) || printf "$rhel_repo_maxscale\n\n" "$mariadb_maxscale_version" | |
((skip_tools)) || printf "$rhel_repo_tools\n" | |
} >&4 | |
if ! ((write_to_stdout)) | |
then | |
rpm --import "${key_urls[@]}" | |
fi | |
;; | |
sles) | |
{ | |
((skip_server)) || printf "$sles_repo_server\n\n" "$mariadb_server_version" "$os_version" | |
((skip_maxscale)) || printf "$sles_repo_maxscale\n\n" "$mariadb_maxscale_version" "$os_version" | |
((skip_tools)) || printf "$sles_repo_tools\n" "$os_version" | |
} >&4 | |
if ! ((write_to_stdout)) | |
then | |
if [[ $os_version = 11 ]] | |
then | |
# RPM in SLES 11 doesn't support HTTPS, so munge the URLs to use standard HTTP | |
rpm --import "${key_urls[@]/#https/http}" | |
else | |
rpm --import "${key_urls[@]}" | |
fi | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment