Redhat 6 - Generate Update DVD

The following is a script to check Red Hat Server for any updated RPMs and update the local repository and generate a DVD to be used to update the  repository of a Closed Area System.

#!/bin/bash 
LANG=en_US.UTF-8 
export LANG 
TODAY=`date +%Y%m%d` 
LOG_DIR=/var/log/ 
FILE=RPM_List 
UPDATE_OUTPUT_FILE=$LOG_DIR$FILE.$TODAY 
touch $UPDATE_OUTPUT_FILE 
NEW=NewRPMS 
UPDATE_FILE=$LOG_DIR$NEW.$TODAY 
mkdir /tmp/updates 
cd /opt/repo 
# Get latest rpms only 
reposync --gpgcheck -l -n --repoid=rhel-x86_64-server-5 | tee $UPDATE_OUTPUT_FILE 
UPDATES=`grep -m 1 Downl $UPDATE_OUTPUT_FILE` 

Get latest RPMs only

reposync --gpgcheck -l -n --repoid=rhel-x86_64-server-5 | \
tee $UPDATE_OUTPUT_FILEUPDATES=grep -m 1 Downl $UPDATE_OUTPUT_FILE

Check to see if there were any downloaded and if so generate a list of packages

if [ -n "$UPDATES" ] 
   then 

See if any RPMs were made outdated as a result of the update,

and then remove those files and recreate (update) the repository.

Create a list of outdated RPMs to be used to delete files here and on other repository servers.

   cd /opt/repo 
   echo "" 
   echo "Creating a list of outdated RPMs to be used to delete files" 
   echo "this can take up to 15 minutes to complete." 
   repomanage --old ./rhel-x86_64-server-5/getPackage/ > old-5RPMS.$TODAY 

Removes old RPMs from the repository using this command

   echo "" 
   echo "Now removing outdated files...." 
   rm -f `cat old-5RPMS.$TODAY` 
   echo "" 

Create a new inventory list

   cd ./rhel-x86_64-server-5/getPackage 
   echo "" 
   echo "Updating repository database files, this can take a few minutes. " 
   createrepo -v --update /opt/repo/rhel-x86_64-server-5/getPackage > /root/updateLog 
   rm -f /tmp/List 
   grep -v Skipp $UPDATE_OUTPUT_FILE | grep Downl | awk '{print $7}' >> /tmp/List 
   cat /tmp/List > $UPDATE_FILE 
   echo "" 

Take the list of updates, use the list to move files to a known location, then burn the updates to a DVD

   echo "Gathering new files into output directory to be copied to DVD." 
   while read line 
      do 
      echo "Adding rpm $line to output directory" 
      cp /opt/repo/rhel-x86_64-server-5/$line /tmp/updates/. 
   done < $UPDATE_FILE 
   echo "" 

Finally, burn the list of updated RPMs and the file containing the list of RPMs to be deleted to DVD

   echo "Creating DVD of Today's Updates and file containing list of RPMS" 
   echo "that need to be deleted on the Closed Server." 
   growisofs -Z /dev/dvd -R -J /tmp/updates/* /opt/repo/old-5RPMS.$TODAY 
   echo "" 
   echo "Finished creating DVD - removing temp files." 
   rm -rf /tmp/updates 
   eject 
else 
   touch $LOG_DIR/NoNewRPMS.$TODAY 
   echo "No New RPM's today, please remove the DVD-R and check again tomorrow," 
   echo "or at the next regularly scheduled update point." 
   eject 
fi 

Copy and paste the following into a file with the ".sh" extension.

!/bin/bash 
LANG=en_US.UTF-8 
export LANG 
# Script to check Red Hat Server for any updated RPMs and update the 
# local repository and generate a DVD to be used to update the 
# repository of a Closed Area System. 
TODAY=`date +%Y%m%d` 
LOG_DIR=/var/log/ 
FILE=RPM_List 
UPDATE_OUTPUT_FILE=$LOG_DIR$FILE.$TODAY 
touch $UPDATE_OUTPUT_FILE 
NEW=NewRPMS 
UPDATE_FILE=$LOG_DIR$NEW.$TODAY 
mkdir /tmp/updates 
cd /opt/repo 
# Get latest RPMs only 
reposync --gpgcheck -l -n --repoid=rhel-x86_64-server-5 | tee $UPDATE_OUTPUT_FILE 
UPDATES=`grep -m 1 Downl $UPDATE_OUTPUT_FILE` 
# Check to see if there were any downloaded and if so generate a list of packages 
if [ -n "$UPDATES" ] 
   then 
# See if any RPMs were made outdated as a result of the update, 
# and then remove those files and recreate (update) the repository. 
# Create a list of outdated RPMs to be used to delete files here 
# and on other repository servers. 
   cd /opt/repo 
   echo "" 
   echo "Creating a list of outdated RPMs to be used to delete files" 
   echo "this can take up to 15 minutes to complete." 
   repomanage --old ./rhel-x86_64-server-5/getPackage/ > old-5RPMS.$TODAY 
# Removes old RPMs from the repository using this command 
   echo "" 
   echo "Now removing outdated files...." 
   rm -f `cat old-5RPMS.$TODAY` 
   echo "" 
# Create a new inventory list 
   cd ./rhel-x86_64-server-5/getPackage 
   echo "" 
   echo "Updating repository database files, this can take a few minutes. " 
   createrepo -v --update /opt/repo/rhel-x86_64-server-5/getPackage > /root/updateLog 
   rm -f /tmp/List 
   grep -v Skipp $UPDATE_OUTPUT_FILE | grep Downl | awk '{print $7}' >> /tmp/List 
   cat /tmp/List > $UPDATE_FILE 
   echo "" 
# Take the list of updates, use the list to move files to a known location, 
# then burn the updates to a DVD 
   echo "Gathering new files into output directory to be copied to DVD." 
   while read line 
      do 
      echo "Adding rpm $line to output directory" 
      cp /opt/repo/rhel-x86_64-server-5/$line /tmp/updates/. 
   done < $UPDATE_FILE 
   echo "" 
# Finally, burn the list of updated RPMs and the file containing the 
# list of RPMs to be deleted to DVD 
   echo "Creating DVD of Today's Updates and file containing list of RPMS" 
   echo "that need to be deleted on the Closed Server." 
   growisofs -Z /dev/dvd -R -J /tmp/updates/* /opt/repo/old-5RPMS.$TODAY 
   echo "" 
   echo "Finished creating DVD - removing temp files." 
   rm -rf /tmp/updates 
   eject 
else 
   touch $LOG_DIR/NoNewRPMS.$TODAY 
   echo "No New RPM's today, please remove the DVD-R and check again tomorrow," 
   echo "or at the next regularly scheduled update point." 
   eject 
fi