Skip to content

Instantly share code, notes, and snippets.

@gojun077
Last active September 11, 2016 08:32
Show Gist options
  • Save gojun077/1e33b34f90e89a6d91f92fe773d7636e to your computer and use it in GitHub Desktop.
Save gojun077/1e33b34f90e89a6d91f92fe773d7636e to your computer and use it in GitHub Desktop.
#!/bin/bash
# multi-iso-baseline-gen.sh
# Last updated: 2016-09-11
# Jun Go [email protected]
#
# Given a PATH and PATTERN, this script will search for all
# iso's with filenames matching PATTERN + wildcard within the
# PATH and generate an rpm package baseline for each iso using
# 'create-baseline-pkg-list.sh'. The baseline output files
# will be named 'XXXXYY-baseline.txt' where XXXX denotes the first
# 4 characters from PATTERN and YY denotes the iso version number.
#
# This script is currently not fully automated, as the user must
# enter the 'sudo' password to mount iso's. I don't want to force
# the user to run this script as root because then all the output
# files will be owned by root.
# USAGE:
# ./multi-iso-baseline-gen.sh [path to iso's] [pattern] [iso mountpoint]
# ./multi-iso-baseline-gen.sh ~/myiso rhel-server /mnt/media
TEMPF='baseline.tmp'
ISOSPATH="$1"
PATTERN="$2"
ISOMNT="$3"
function usage()
{
echo "USAGE: $0 <path to ISO files> <iso filename search pattern> <iso mnt>"
echo ""
echo "Example: $0 /MULTIMEDIA/iso rhel-server /mnt/distro1"
}
if [ $# -ne 3 ]; then
usage
exit 1
fi
# Write list of iso files matching PATTERN to TEMPF
find "$ISOSPATH" -type f -name "${PATTERN}*.iso" -exec basename {} \; > $TEMPF
# Loop through each line in TEMPF, mount the iso and generate baseline
# file with name ${PREFIX}${VER}-baseline.txt
while read -r p; do
echo "### Mounting $p on $ISOMNT ###"
sudo mount -o loop "$ISOSPATH"/"$p" "$ISOMNT"
# PREFIX will be the first 4 chars from filename $p
PREFIX=$(echo "$p" | head -c 4 )
VER=$(echo "$p" | grep -o -E '[0-9]+\.[0-9]+')
echo "### Generating ${PREFIX}${VER}-baseline.txt ###"
./create-baseline-pkg-list.sh "$ISOMNT" "${PREFIX}""${VER}"-baseline.txt
echo "### Unmount $p from $ISOMNT ###"
sudo umount "$ISOMNT"
done<$TEMPF
# Cleanup
echo "### Cleaning Up Temp Files ###"
if [ -f "$TEMPF" ]; then
rm "$TEMPF"
else
echo "$TEMPF does not exist"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment