Created
August 11, 2015 18:07
-
-
Save dbadapt/2f08c579b6d27dbb3c37 to your computer and use it in GitHub Desktop.
Percona apt repository installer
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
#!/bin/bash | |
# This script will enable the Percona apt Repository | |
# david dot bennett at percona dot com - 2015-08-11 | |
# Make sure we are running as root | |
if [ ! "${EUID}" == 0 ]; then | |
echo >&2 "This script must be run with root permissions." | |
exit 1; | |
fi | |
# Check to see if we have all the commands we need | |
for cmd in "apt-get" "apt-key" "curl" "grep" "awk" "head" "getopt"; do | |
hash ${cmd} &> /dev/null | |
if [ $? -eq 1 ]; then | |
echo >&2 "This system does not have '${cmd}', install before running." | |
exit 1; | |
fi | |
done | |
# everything looks good | |
echo "Enabling the Percona Server apt repository..." | |
# get key id | |
KEYID='1C4CBDCDCD2EFD2A' | |
OPTS=$(getopt -o k: -l keyid: -n 'parse-options' -- "$@") | |
eval set -- "$OPTS" | |
while true; do | |
case "$1" in | |
-k | --keyid ) KEYID="$2"; shift; shift ;; | |
* ) break; | |
esac | |
done | |
# error log | |
errorLog=$(mktemp -t percona-apt-install-XXXXX.log) | |
# install Percona apt key | |
apt-key adv --keyserver keys.gnupg.net --recv-keys "${KEYID}" >> "${errorLog}" 2>&1 | |
apt-key list | grep -qi percona || { | |
echo "Something went wrong during installation of the Percona gnupg key." | |
echo "Check log: ${errorLog}" | |
exit 1; | |
} | |
# get the distribution version | |
distver=$(grep '^deb ' /etc/apt/sources.list | awk '{print $3}' | grep -Fv '-' | head -n1) | |
if [ "${distver}" == "" ]; then | |
echo >&2 "Unable to determine distribution version." | |
exit 1; | |
fi | |
# check that release is supported by Percona apt repository | |
curl -s "http://repo.percona.com/apt/dists/${distver}/Release.gpg" | grep -Fq SIGNATURE || { | |
echo >&2 "Distribution: '${distver}' is not supported." | |
exit 1; | |
} | |
# Create percona.list in apt configuration | |
mkdir -p /etc/apt/sources.list.d | |
cat <<_EOF_ >/etc/apt/sources.list.d/percona.list | |
deb http://repo.percona.com/apt ${distver} main | |
deb-src http://repo.percona.com/apt ${distver} main | |
_EOF_ | |
# update the repository | |
apt-get update -y >> "${errorLog}" 2>&1 | |
# check and report | |
echo '-----' | |
if apt-cache madison percona-server-server | grep -q 'repo\.percona'; then | |
echo 'The Percona apt repository is ready to use.' | |
exit 0; | |
else | |
echo "Something went wrong during installation of the Percona apt repository." | |
echo "Check log: ${errorLog}" | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment