Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to create a local YUM repository for MySQL Commercial RPMs in Enterprise Linux 7.x.
#!/bin/bash
#Bash script to create a local YUM repository for MySQL Commercial RPMs in Enterprise Linux 7.x.
#You can find the commercial binaries in http://support.oracle.com (preferable) or http://edelivery.oracle.com.
#Download the ZIP files into the $DOWNLOAD_DIR and run this script as root.
#The files to be downloaded are:
# MySQL Database 5.7.* RPM for Oracle Linux / RHEL 7 x86 (64bit)
# MySQL Enterprise Backup 4.1.* RPM for Oracle Linux / RHEL 7 x86 (64bit)
# MySQL Shell 1.0.* RPM for Oracle Linux / RHEL 7 x86 (64bit)
# MySQL Router 2.1.* RPM for Oracle Linux / RHEL 7 x86 (64bit)
# MySQL Utilities 1.6.* RPM for Oracle Linux / RHEL 7 (portable)
# MySQL Connector/Python 2.1.* RPM for Oracle Linux / RHEL 7 x86 (64bit)
#
#Dependencies: unzip, createrepo
#Modify these variables as you wish
DOWNLOAD_DIR=/home/vagrant/Downloads
DIR_TO_UNZIP=/home/vagrant/Downloads/unzipped
REPO_DIR=/var/www/html/yum
REPO_FILE_DIR=/var/www/html
REPO_FILE=mysql-commercial.repo
REPO_HOST=localrepo
set -e # stop script execution on any error
echo "Checking and installing dependencies..."
if ! rpm -qa | grep -qw unzip; then
yum -y install unzip
fi
if ! rpm -qa | grep -qw createrepo; then
yum -y install createrepo
fi
echo "Looking for .zip files in $DOWNLOAD_DIR..."
ls -A1 $DOWNLOAD_DIR
echo "Extracting .zip files to $REPO_DIR..."
mkdir -p $DIR_TO_UNZIP
for filename in $DOWNLOAD_DIR/*.zip; do
shortfilename=$(echo $filename | sed 's/.*\///')
targetdir=$DIR_TO_UNZIP/${shortfilename%.*}
echo "Extracting $filename to $targetdir..."
mkdir -p "$targetdir"
unzip -n "$filename" -d "$targetdir"
done
echo "Creating local repository structure..."
basearch="x86_64"
mkdir -p $REPO_DIR/meb-3.12/el/7/$basearch/
find $DIR_TO_UNZIP -name meb-3.12*.rpm -exec cp {} $REPO_DIR/meb-3.12/el/7/$basearch/ \;
createrepo $REPO_DIR/meb-3.12/el/7/$basearch/
mkdir -p $REPO_DIR/meb-4.1/el/7/$basearch/
find $DIR_TO_UNZIP -name meb-4.1*.rpm -exec cp {} $REPO_DIR/meb-4.1/el/7/$basearch/ \;
createrepo $REPO_DIR/meb-4.1/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-connectors-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql*connector*commercial*.rpm -exec cp {} $REPO_DIR/mysql-connectors-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-connectors-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-tools-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-router-commercial*.rpm -exec cp {} $REPO_DIR/mysql-tools-commercial/el/7/$basearch/ \;
find $DIR_TO_UNZIP -name mysql-shell-commercial*.rpm -exec cp {} $REPO_DIR/mysql-tools-commercial/el/7/$basearch/ \;
find $DIR_TO_UNZIP -name mysql-utilities-commercial*.rpm -exec cp {} $REPO_DIR/mysql-tools-commercial/el/7/$basearch/ \;
find $DIR_TO_UNZIP -name mysql-workbench-commercial*.rpm -exec cp {} $REPO_DIR/mysql-tools-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-tools-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-5.6-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-commercial*5.6*.rpm -exec cp {} $REPO_DIR/mysql-5.6-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-5.6-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-5.7-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-commercial*5.7*.rpm -exec cp {} $REPO_DIR/mysql-5.7-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-5.7-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-8.0-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-commercial*8.0*.rpm -exec cp {} $REPO_DIR/mysql-8.0-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-8.0-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-cluster-7.5-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-cluster-commercial*7.5*.rpm -exec cp {} $REPO_DIR/mysql-cluster-7.5-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-cluster-7.5-commercial/el/7/$basearch/
mkdir -p $REPO_DIR/mysql-cluster-7.6-commercial/el/7/$basearch/
find $DIR_TO_UNZIP -name mysql-cluster-commercial*7.6*.rpm -exec cp {} $REPO_DIR/mysql-cluster-7.6-commercial/el/7/$basearch/ \;
createrepo $REPO_DIR/mysql-cluster-7.6-commercial/el/7/$basearch/
chmod 755 $REPO_DIR
ls -A1 $REPO_DIR
echo "Creating Repo File..."
REPO_URL=http://$REPO_HOST/yum
cat > $REPO_FILE_DIR/$REPO_FILE <<EOL
## Enable to use MySQL 8.0 Commercial Server
[meb312]
name=MySQL Enterprise Backup 3.12
baseurl=$REPO_URL/meb-3.12/el/7/$basearch/
enabled=0
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
[meb41]
name=MySQL Enterprise Backup 4.1
baseurl=$REPO_URL/meb-4.1/el/7/$basearch/
enabled=1
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
[mysql-connectors-commercial]
name=MySQL Connectors Commercial
baseurl=$REPO_URL/mysql-connectors-commercial/el/7/$basearch/
enabled=1
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
[mysql-tools-commercial]
name=MySQL Tools Commercial
baseurl=$REPO_URL/mysql-tools-commercial/el/7/$basearch/
enabled=1
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
## Enable to use MySQL 5.6 Commercial Server
[mysql56-commercial]
name=MySQL 5.6 Commercial Server
baseurl=$REPO_URL/mysql-5.6-commercial/el/7/$basearch/
enabled=0
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
[mysql57-commercial]
name=MySQL 5.7 Commercial Server
baseurl=$REPO_URL/mysql-5.7-commercial/el/7/$basearch/
enabled=1
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
## Enable to use MySQL 8.0 Commercial Server
[mysql80-commercial]
name=MySQL 8.0 Commercial Server
baseurl=$REPO_URL/mysql-8.0-commercial/el/7/$basearch/
enabled=0
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
## Enable to use MySQL Cluster Commercial 7.5
[mysql-cluster-7.5-commercial]
name=MySQL Cluster 7.5 Commercial
baseurl=$REPO_URL/mysql-cluster-7.5-commercial/el/7/$basearch/
enabled=0
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
## Enable to use MySQL Cluster Commercial 7.6
[mysql-cluster-7.6-commercial]
name=MySQL Cluster 7.6 Commercial
baseurl=$REPO_URL/mysql-cluster-7.6-commercial/el/7/$basearch/
enabled=0
gpgcheck=0
#gpgkey=$REPO_URL/RPM-GPG-KEY-mysql
EOL
echo "Updating /etc/localhost with $REPO_HOST (Local YUM Repository Server)..."
echo "127.0.0.1 $REPO_HOST $REPO_HOST.localdomain" >> /etc/hosts
#check with: ping -c4 $REPO_HOST
echo "Installing Repo File for this host..."
wget -O /etc/yum.repos.d/$REPO_FILE http://$REPO_HOST/$REPO_FILE
echo "Checking local YUM Repo..."
echo "MySQL repositories:"
yum repolist all | grep 'mysql\|meb'
echo "MySQL Commercial available packages:"
yum --disablerepo=\* --enablerepo='mysql\*commercial\*' --enablerepo='meb\*' list available
echo "Local YUM repository for MySQL Commercial RPMs installed!"
echo "Install repo in your target machines with:"
echo " $ sudo wget -O /etc/yum.repos.d/$REPO_FILE http://$REPO_HOST/$REPO_FILE"
echo "With repo installed, just install MySQL Commercial Database with:"
echo " $ sudo yum install mysql-commercial-server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment