Skip to content

Instantly share code, notes, and snippets.

@neelabhg
Created March 6, 2017 07:56
Show Gist options
  • Save neelabhg/94e3a5c3061301a47d9eb1eb47641367 to your computer and use it in GitHub Desktop.
Save neelabhg/94e3a5c3061301a47d9eb1eb47641367 to your computer and use it in GitHub Desktop.
Yum wrapper for using CentOS DVD as repository
#!/bin/bash
#Script to install packages via yum using DVD/CD as Repository
#Works on RedHat Enterprise Linux/CentOS/Scientific Linux versions above 4.0
#Change this to the location of your CD-ROM drive
cdrom=/dev/cdrom
#This location is searched by the DVD repository configuration script
mnt_point=/media/cdrom
#This is the DVD repository for CentOS 6. Change this to "c5-media" for CentOS 5. Please refer to the respective manuals for other OSes.
dvdrepo=c6-media
output=$(mount | grep $mnt_point | cut -d\ -f3)
#NOTE: in the above line there must be two spaces after cut -d\
#Mount the DVD/CD containing packages if not already mounted
if [ "$output" != "$mnt_point" ]
then
mount -t auto $cdrom $mnt_point
#Check if DVD/CD was mounted or not
output=$(mount | grep $mnt_point | cut -d\ -f3)
if [ "$output" != "$mnt_point" ]
then
echo "$cdrom cannot be mounted on $mnt_point"
exit 1
else
echo "$cdrom mounted successfully on $mnt_point"
fi
else
echo "$cdrom is already mounted on $mnt_point"
fi
#Install the packages from DVD/CD by disabling all repositories and enabling the DVD/CD repository
if [ "$1" == "install" ] then
yum --disablerepo=\* --enablerepo=$dvdrepo install $2
elif ["$1" == "groupinstall" ]
then
yum --disablerepo=\* --enablerepo=$dvdrepo groupinstall $2
else
echo "Usage: $0 install[groupinstall] <package/group name>"
umount $mnt_point
exit 1
fi
#Unmount the DVD/CD
umount $mnt_point
#Exit successfully
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment