Created
February 18, 2014 05:36
-
-
Save h2onda/9065196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Original version is written by Chris Kloiber <[email protected]> | |
# This fork version is modified by HONDA Hirofumi <[email protected]> | |
# A quick hack that will create a bootable DVD iso or non-bootable | |
# source DVD iso of a Red Hat Linux Distribution. Feed it either a | |
# directory containing the downloaded iso files of a distribution, | |
# or point it at a directory containing the "RedHat", "isolinux", | |
# and "images" directories. | |
# This version only works with "isolinux" based Red Hat Linux versions. | |
# Lots of disk space required to work, 3X the distribution size at least. | |
# GPL version 2 applies. No warranties, yadda, yadda. Have fun. | |
CRARGS="" | |
usage() { | |
echo "Usage: $(basename $0) [-r] [-o] source /destination/DVD.iso" > /dev/stderr | |
echo "" > /dev/stderr | |
echo " -r: rebuild repository" > /dev/stderr | |
echo " -o: create old format repository" > /dev/stderr | |
echo " The 'source' can be either a directory containing a single" > /dev/stderr | |
echo " set of isos, or an exploded tree like an ftp site." > /dev/stderr | |
} | |
while getopts 'roh' args $* | |
do | |
case $args in | |
r) | |
RFLAG=yes | |
;; | |
o) | |
CRARGS="-s sha --simple-md-filenames" | |
;; | |
h|?) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
if [ $# -lt 2 ]; then | |
usage | |
exit 1 | |
fi | |
IMPLANTISOMD5="/usr/lib/anaconda-runtime/implantisomd5" | |
if [ ! -x ${IMPLANTISOMD5} ]; then | |
IMPLANTISOMD5=`which implantisomd5 2> /dev/null` | |
fi | |
if [ -z ${IMPLANTISOMD5} ]; then | |
echo "please install isomd5sum or anaconda-runtime !" > /dev/stderr | |
exit 1 | |
fi | |
CHECKISOMD5="/usr/lib/anaconda-runtime/checkisomd5" | |
if [ ! -x ${CHECKISOMD5} ]; then | |
CHECKISOMD5=`which checkisomd5 2> /dev/null` | |
fi | |
if [ -z ${CHECKISOMD5} ]; then | |
echo "please install isomd5sum or anaconda-runtime !" > /dev/stderr | |
exit 1 | |
fi | |
CREATEREPO="/usr/bin/createrepo" | |
if [ ! -x ${CREATEREPO} ]; then | |
CREATEREPO=`which createrepo 2> /dev/null` | |
fi | |
if [ -z ${CREATEREPO} ]; then | |
echo "please install createrepo !" > /dev/stderr | |
exit 1 | |
fi | |
DVD_DIR=`dirname $2` | |
DVD_FILE=`basename $2` | |
echo "DVD directory is $DVD_DIR" | |
echo "ISO file is $DVD_FILE" | |
if [ "$DVD_DIR" = "." ]; then | |
echo "Destinaton Directory $DVD_DIR does not exist" | |
exit 1 | |
else | |
if [ ! -d "/$DVD_DIR" ]; then | |
echo "Destinaton Directory $DVD_DIR must be an absolute path" | |
exit 1 | |
else | |
if [ "$DVD_FILE" = "" ] || [ -d "$DVD_DIR/$DVD_FILE" ]; then | |
echo "Null ISO file name." | |
exit 1 | |
fi | |
fi | |
fi | |
which mkisofs >&/dev/null | |
if [ "$?" != 0 ]; then | |
echo "mkisofs Not Found" | |
echo "yum install mkisofs" | |
exit 1 | |
fi | |
which createrepo >&/dev/null | |
if [ "$?" != 0 ]; then | |
echo "createrepo Not Found" | |
echo "yum install createrepo" | |
exit 1 | |
fi | |
if [ -f $2 ]; then | |
echo "DVD ISO destination $2 already exists. Remove first to recreate." | |
exit 1 | |
fi | |
[ -w / ] || { # Very portable, but perhaps not perfect, test for superuser. | |
echo "Only 'root' may use this script for loopback mounts" 1>&2 | |
exit 1 | |
} | |
cleanup() { | |
[ ${LOOP:=/tmp/loop} = "/" ] && echo "LOOP mount point = \/, dying!" && exit | |
[ -d $LOOP ] && rm -rf $LOOP | |
[ ${DVD:=~/mkrhdvd} = "/" ] && echo "DVD data location is \/, dying!" && exit | |
[ -d $DVD ] && rm -rf $DVD | |
} | |
cleanup | |
mkdir -p $LOOP | |
mkdir -p $DVD | |
ls $1/*.iso &>/dev/null | |
if [ "$?" == 0 ]; then | |
echo "Found ISO CD images..." | |
CDS=`expr 0` | |
DISKS="1" | |
ISOFILES=`ls $1/*.iso` | |
for f in ${ISOFILES}; do | |
echo "checking `basename $f` ..." | |
${CHECKISOMD5} $f 2>&1 > /dev/null | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
echo | |
done | |
for f in `ls $1/*.iso`; do | |
mount -o loop $f $LOOP | |
cp -av $LOOP/* $DVD | |
if [ -f $LOOP/.discinfo ]; then | |
cp -av $LOOP/.discinfo $DVD | |
CDS=`expr $CDS + 1` | |
if [ $CDS != 1 ] ; then | |
DISKS=`echo ${DISKS},${CDS}` | |
fi | |
fi | |
umount $LOOP | |
done | |
if [ -e $DVD/.discinfo ]; then | |
awk '{ if ( NR == 4 ) { print disks } else { print ; } }' disks="$DISKS" $DVD/.discinfo > $DVD/.discinfo.new | |
mv $DVD/.discinfo.new $DVD/.discinfo | |
fi | |
else | |
echo "Found FTP-like tree..." | |
cp -av $1/* $DVD | |
[ -e $1/.discinfo ] && cp -av $1/.discinfo $DVD | |
fi | |
BOOTISO_OPTS="" | |
if [ -f $DVD/isolinux/boot.cat ];then | |
rm -rf $DVD/isolinux/boot.cat | |
BOOTISO_OPTS="-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 8 -boot-info-table" | |
fi | |
find $DVD -name TRANS.TBL | xargs rm -f | |
cd $DVD | |
if [ "${RFLAG}" == "yes" ]; then | |
COMPS=$(find repodata -name '*comps*.xml') | |
if [ -n ${COMPS} ]; then | |
cp $COMPS comps.xml | |
fi | |
rm -rf repodata | |
if [ -n "$COMPS" ]; then | |
CRARGS="${CRARGS} -g comps.xml" | |
fi | |
${CREATEREPO} ${CRARGS} ./ | |
if [ "$?" != 0 ]; then | |
echo "createrepo is failed!" > /dev/stderr | |
cd | |
cleanup | |
exit 1 | |
fi | |
if [ -f comps.xml ]; then | |
rm -f comps.xml | |
fi | |
fi | |
mkisofs -J -R -v -T -o $2 $BOOTISO_OPTS . | |
${IMPLANTISOMD5} --force $2 | |
# Don't like forced mediacheck? Try this instead. | |
# $IMPLANT --supported-iso --force $2 | |
cleanup | |
echo "" | |
echo "Process Complete!" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment