Skip to content

Instantly share code, notes, and snippets.

@mansurali901
Last active June 30, 2019 17:43
Show Gist options
  • Save mansurali901/436c997078d2d59ecc156adde83d640c to your computer and use it in GitHub Desktop.
Save mansurali901/436c997078d2d59ecc156adde83d640c to your computer and use it in GitHub Desktop.
#This script installs Docker as offline bundle in RHEL 7
#!/bin/bash
# Author : Mansur Ul Hasan
# Email : [email protected]
# This script has two functions one should be online & online system will be used as package
# collector and will be used for package bundling
# --onlybundle This function will download Docker Offline binaries"
# --onlyinstall This function install if you already preaper offline bundle"
# --bundleship This create offline bundle
DockerOfflinebuilder () {
## Collect Username & password for RHEL subscription
# Above credentials should be used to login to REDHAT subcription server
read -p "Enter RHEL Username : " username
read -s "Enter RHEL Password : " password
# Login to RHEL subscription server
# Subcriptions will allow you to download packages from RHEL repository servers
subscription-manager register --username=$username --password=$password
# After login to RHEL Customer portal check current subscription
subscription-manager list --available
# The next thing which is needed to attach system to RHEL pool with Pool ID
subscription-manager attach --pool=`subscription-manager list --available |grep "Pool ID:" |awk '{print $3}'`
# Add RHEL repository for extra packages these packages needed by Docker
subscription-manager repos --enable=rhel-7-server-extras-rpms
# Install some additional packages to setup the whole environment
yum update -y && yum install -y wget curl
# EPEL repository for extra packages which can't be served from RHEL repository servers
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm ivh epel-release-latest-7.noarch.rpm
# Docker repository addition & also this part is responsible to download docker community edition
# After downloading all the packages it will create tar ball
# for just adding notes total number of packages for RHEL 7.6 with kernel version 3.10.0-957.el7.x86_64
# below is the output of all packages along with size downloaded total number of packages are 12
# Docker is successfullyy installled with these packages
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# -rw-r--r--. 1 root root 78260 Aug 11 2018 audit-libs-python-2.8.4-4.el7.x86_64.rpm
# -rw-r--r--. 1 root root 302120 Aug 15 2018 checkpolicy-2.5-8.el7.x86_64.rpm
# -rw-r--r--. 1 root root 27119348 Jun 13 18:02 containerd.io-1.2.6-3.3.el7.x86_64.rpm
# -rw-r--r--. 1 root root 39676 May 28 07:49 container-selinux-2.99-1.el7_6.noarch.rpm
# -rw-r--r--. 1 root root 19603424 Jun 27 15:24 docker-ce-18.09.7-3.el7.x86_64.rpm
# -rw-r--r--. 1 root root 14692900 Jun 27 15:24 docker-ce-cli-18.09.7-3.el7.x86_64.rpm
# -rw-r--r--. 1 root root 67704 Sep 11 2018 libcgroup-0.41-20.el7.x86_64.rpm
# -rw-r--r--. 1 root root 115336 Sep 14 2018 libsemanage-python-2.5-14.el7.x86_64.rpm
# -rw-r--r--. 1 root root 466796 Jan 21 11:16 policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm
# -rw-r--r--. 1 root root 32828 Apr 15 2014 python-IPy-0.75-6.el7.noarch.rpm
# -rw-r--r--. 1 root root 635232 Aug 15 2018 setools-libs-3.3.8-4.el7.x86_64.rpm
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-nightly
yum makecache fast
mkdir ~/docker && cd ~/docker
yumdownloader --resolve docker-ce
cd ../ && tar -czvf docker-18.09.tar.gz docker
echo "Package download completed ..."
}
InstallOfflineDocker () {
# This function only viable when offline packages are already downloaded
# When executing this function ensure tar ball is palced on the location
# This function extract tarball and install docker binaries
# Services will be start and enable by this function for docker
echo "Docker offline installation process begin.... "
tar -xvf docker-18.09.tar.gz && cd docker
rpm -ivh --replacefiles --replacepkgs *.rpm
systemctl enable docker.service
systemctl start docker.service
}
ShipBundle () {
echo "Do you wish to ship this offline bundle to remote server ?? "
read -p " Choice must be Y|y or N|n" agree
if [ $agree -eq "Y" && $agree -eq "y" ];
then
echo "Enter destination IP Address : " destip
echo "Enter destination username : " destuser
echo "Enter Destination location : " destloc
rsync -avr docker-18.09.tar.gz $destuser@$destip:$destloc/
else
exit
fi
}
case $1 in
--onlybundle)
DockerOfflinebuilder
;;
--onlyinstall)
InstallOfflineDocker
;;
--bundleship)
DockerOfflinebuilder
ShipBundle
;;
*)
echo "No valid parameters being passed "
echo " Please ensure only below params are allowed"
echo " --onlybundle This function will download Docker Offline binaries"
echo " --onlyinstall This function install if you already preaper offline bundle"
echo " --bundleship This create offline bundle"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment